Keep mob corpses persistent and enforce death animation state
- Stop automatic corpse removal after loot is emptied; corpses now remain in world - On all mob death paths, set dead state plus death animation (death_[dir]) and clear combat/cast targeting - Include dead mobs in spatial state feed so corpses do not disappear from clients - Add mob currentAnimation/hasLoot in payload and reject loot interaction when corpse has no loot
This commit is contained in:
@@ -412,7 +412,7 @@ public sealed partial class DungeonHandler
|
||||
x = p.X,
|
||||
y = p.Y
|
||||
}),
|
||||
mobs = instance.Simulation.Mobs.Values.Where(m => m.IsAlive).Select(m => new
|
||||
mobs = instance.Simulation.Mobs.Values.Select(m => new
|
||||
{
|
||||
id = m.Id,
|
||||
definitionId = m.DefinitionId,
|
||||
@@ -422,8 +422,10 @@ public sealed partial class DungeonHandler
|
||||
rotation = m.Rotation,
|
||||
health = m.Health,
|
||||
maxHealth = m.MaxHealth,
|
||||
hasLoot = m.HasDeathLoot,
|
||||
isAlive = m.IsAlive,
|
||||
state = m.State.ToString().ToLower(),
|
||||
currentAnimation = m.CurrentAnimation,
|
||||
spriteConfig = DeserializeSpriteConfigSafe(m.SpriteConfigJson),
|
||||
tintColor = m.TintColor,
|
||||
scale = m.Scale
|
||||
@@ -547,6 +549,7 @@ public sealed partial class DungeonHandler
|
||||
killedBoss.IsAlive = false;
|
||||
killedBoss.Health = 0;
|
||||
killedBoss.State = MobState.Dead;
|
||||
killedBoss.CurrentAnimation = killedBoss.GetDirectionalAnimation("death");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -574,6 +577,7 @@ public sealed partial class DungeonHandler
|
||||
boss.IsAlive = false;
|
||||
boss.Health = 0;
|
||||
boss.State = MobState.Dead;
|
||||
boss.CurrentAnimation = boss.GetDirectionalAnimation("death");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -640,6 +644,7 @@ public sealed partial class DungeonHandler
|
||||
mob.Value.IsAlive = false;
|
||||
mob.Value.Health = 0;
|
||||
mob.Value.State = MobState.Dead;
|
||||
mob.Value.CurrentAnimation = mob.Value.GetDirectionalAnimation("death");
|
||||
}
|
||||
|
||||
instance.Simulation.Mobs.TryAdd(mob.Key, mob.Value);
|
||||
|
||||
@@ -37,6 +37,13 @@ public sealed partial class DungeonHandler
|
||||
return;
|
||||
}
|
||||
|
||||
// No interaction once corpse loot is exhausted
|
||||
if (!mob.HasDeathLoot)
|
||||
{
|
||||
await SendErrorAsync(connection, "Mob has no loot", ct);
|
||||
return;
|
||||
}
|
||||
|
||||
// Check distance
|
||||
if (session.PlayerInstance != null)
|
||||
{
|
||||
|
||||
@@ -846,7 +846,9 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
rotation = m.Rotation,
|
||||
health = m.Health,
|
||||
maxHealth = m.MaxHealth,
|
||||
hasLoot = m.HasDeathLoot,
|
||||
state = m.State.ToString().ToLower(),
|
||||
currentAnimation = m.CurrentAnimation,
|
||||
isAlive = m.IsAlive,
|
||||
spriteConfig = DeserializeSpriteConfigSafe(m.SpriteConfigJson),
|
||||
tintColor = m.TintColor,
|
||||
@@ -2819,11 +2821,13 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
var visiblePlayerIds = visiblePlayers.Select(p => p.CharacterId).ToHashSet();
|
||||
|
||||
var nearbyOrRelevantMobs = sim.Mobs.Values
|
||||
.Where(m => m.IsAlive && (!spatialFiltering || IsNearby(m.X, m.Y) || m.TargetId == session.CharacterId))
|
||||
.Where(m => !spatialFiltering ||
|
||||
IsNearby(m.X, m.Y) ||
|
||||
(m.IsAlive && m.TargetId == session.CharacterId))
|
||||
.ToList();
|
||||
var visibleMobs = sendSpatialThisTick
|
||||
? nearbyOrRelevantMobs
|
||||
: nearbyOrRelevantMobs.Where(m => m.TargetId == session.CharacterId).ToList();
|
||||
: nearbyOrRelevantMobs.Where(m => !m.IsAlive || m.TargetId == session.CharacterId).ToList();
|
||||
var visibleMobIds = visibleMobs.Select(m => m.Id).ToHashSet();
|
||||
bool sendMobCatalog = session.CurrentDungeonId.HasValue &&
|
||||
session.InitialMobCatalogDungeonId != session.CurrentDungeonId;
|
||||
@@ -2877,8 +2881,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
rotation = m.Rotation,
|
||||
health = m.Health,
|
||||
maxHealth = m.MaxHealth,
|
||||
hasLoot = m.HasDeathLoot,
|
||||
isAlive = m.IsAlive,
|
||||
state = m.State.ToString().ToLower(),
|
||||
currentAnimation = m.CurrentAnimation,
|
||||
spriteConfig = DeserializeSpriteConfigSafe(m.SpriteConfigJson),
|
||||
tintColor = m.TintColor,
|
||||
scale = m.Scale
|
||||
|
||||
@@ -374,33 +374,16 @@ public partial class DungeonSimulation
|
||||
UpdatePlayer(player);
|
||||
}
|
||||
|
||||
// Handle corpse cleanup (remove corpses 30 seconds after loot is empty AND dungeon is cleared)
|
||||
var corpsesToRemove = new List<int>();
|
||||
if (Phase == DungeonPhase.Cleared)
|
||||
// Keep corpses in the world after death (even after loot is emptied).
|
||||
// We still stamp when loot becomes empty so UI/inspection logic can reference it.
|
||||
foreach (var mob in Mobs.Values.Where(m => !m.IsAlive))
|
||||
{
|
||||
foreach (var mob in Mobs.Values.Where(m => !m.IsAlive))
|
||||
if (!mob.HasDeathLoot && !mob.LootEmptiedAtTick.HasValue)
|
||||
{
|
||||
// Check if loot just became empty
|
||||
if (!mob.HasDeathLoot && !mob.LootEmptiedAtTick.HasValue)
|
||||
{
|
||||
mob.LootEmptiedAtTick = CurrentTick;
|
||||
}
|
||||
|
||||
// Remove corpse 30 seconds after loot emptied (10 ticks per second)
|
||||
if (mob.LootEmptiedAtTick.HasValue &&
|
||||
CurrentTick - mob.LootEmptiedAtTick.Value >= 30 * TicksPerSecond)
|
||||
{
|
||||
corpsesToRemove.Add(mob.Id);
|
||||
}
|
||||
mob.LootEmptiedAtTick = CurrentTick;
|
||||
}
|
||||
}
|
||||
|
||||
// Remove corpses
|
||||
foreach (var mobId in corpsesToRemove)
|
||||
{
|
||||
Mobs.Remove(mobId, out _);
|
||||
}
|
||||
|
||||
// Check dungeon completion (only once when phase is still Active)
|
||||
if (Phase == DungeonPhase.Active && Mobs.Values.All(m => !m.IsAlive))
|
||||
{
|
||||
@@ -786,7 +769,13 @@ public partial class DungeonSimulation
|
||||
// Check if mob died
|
||||
if (mob.Health <= 0 && mob.IsAlive)
|
||||
{
|
||||
mob.Health = 0;
|
||||
mob.IsAlive = false;
|
||||
mob.State = MobState.Dead;
|
||||
mob.TargetId = null;
|
||||
mob.CastingAbility = null;
|
||||
mob.CastTimeRemaining = 0;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("death");
|
||||
_pendingDeathEvents.Add(new DeathEvent
|
||||
{
|
||||
EntityType = EntityType.Mob,
|
||||
@@ -1302,6 +1291,10 @@ public partial class DungeonSimulation
|
||||
mob.Health = 0;
|
||||
mob.IsAlive = false;
|
||||
mob.State = MobState.Dead;
|
||||
mob.TargetId = null;
|
||||
mob.CastingAbility = null;
|
||||
mob.CastTimeRemaining = 0;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("death");
|
||||
|
||||
player.XpGained += mob.Stats.XpReward;
|
||||
player.MobsKilled++;
|
||||
|
||||
@@ -861,6 +861,10 @@ public static class MobAI
|
||||
mob.Health = 0;
|
||||
mob.IsAlive = false;
|
||||
mob.State = MobState.Dead;
|
||||
mob.TargetId = null;
|
||||
mob.CastingAbility = null;
|
||||
mob.CastTimeRemaining = 0;
|
||||
mob.CurrentAnimation = mob.GetDirectionalAnimation("death");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user