feat(skills): end a dead caster's skill when a client reports it (CasterDead)

When a client gets EchoStartSkill (or SyncSkill) from a caster it sees
as dead, aimed at another object, it logs "msgEchoStartSkill
msgCasterDead" and sends CasterDead (120: optional i64Caster, optional
uiSkillHandle) through that target
(LWOSkillComponent::msgEchoStartSkill 0x00d5dc90). 303 live packets, the
target nearly always the attacked player, the caster a spawned enemy;
the next messages were mostly Die and SetStunned for the player. DLU
dropped it.

The server now ends that skill on the caster: its behaviors with that
handle are dropped (end entries run, pending timers and syncs discarded,
its projectiles removed), so a hit an enemy scheduled before dying does
not land later. It only does so when the server also sees the caster as
dead, so a client can't cancel a living enemy's attack. What live did
with the message is inferred from the name and when it was sent.

Check in game: kill an enemy in the middle of a slow or charged attack
(e.g. a Maelstrom horseman or a spider queen add): its attack does not
hit after it has died, and other enemies' attacks still hit normally.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Aaron Kimbrell
2026-09-29 03:13:56 -05:00
parent 8d4422fa5c
commit dd116b9794
6 changed files with 104 additions and 0 deletions

View File

@@ -3,7 +3,12 @@
#include "GameDependencies.h"
#include "GameMessageTestUtils.h"
#include "CDClientDatabase.h"
#include "CharacterComponent.h"
#include "DestroyableComponent.h"
#include "EntityManager.h"
#include "SkillComponent.h"
#include "SkillMessages.h"
#include "Entity.h"
#include "PlayerMessages.h"
@@ -82,3 +87,37 @@ TEST_F(ClientMessagesTests, SetLastCustomBuildMatchesLiveCapture) {
EXPECT_EQ(characterComponent->GetLastRocketConfig(), u"1:14454;1:4714;1:4715;");
EXPECT_FALSE(characterComponent->GetIsLanding());
}
// CasterDead (120): an optional caster, then an optional skill handle. 303 live packets, sent through the targeted
// player when an enemy's skill arrived after the enemy died.
TEST_F(ClientMessagesTests, CasterDeadMatchesLiveCapture) {
auto msg = FromLiveClientCapture<GameMessages::CasterDead>(std::string(PLAYER_HEADER) + "7800" + "dade8000002000024040000000");
EXPECT_EQ(msg.i64Caster, 0x40040000000bdb5LL);
EXPECT_EQ(msg.uiSkillHandle, 1u);
EXPECT_EQ(RoundTrip(msg).i64Caster, msg.i64Caster);
ExpectTruncatedFails(msg);
}
// The caster's skill with that handle ends only when the server also sees the caster as dead.
TEST_F(ClientMessagesTests, CasterDeadEndsTheDeadCastersSkill) {
CDClientDatabase::Connect(":memory:"); // the entity manager looks the new entity up
CDClientDatabase::ExecuteDML("CREATE TABLE ComponentsRegistry (id INTEGER, component_type INTEGER, component_id INTEGER);");
auto* const caster = Game::entityManager->CreateEntity(info, nullptr, nullptr, false, 0x40040000000bdb5LL);
ASSERT_NE(caster, nullptr);
auto* const destroyable = caster->AddComponent<DestroyableComponent>(-1);
auto* const skills = caster->AddComponent<SkillComponent>(-1);
RakNet::BitStream empty;
skills->CastPlayerSkill(0, 1, empty, player->GetObjectID());
skills->CastPlayerSkill(0, 2, empty, player->GetObjectID());
GameMessages::CasterDead msg;
msg.i64Caster = caster->GetObjectID();
msg.uiSkillHandle = 1;
msg.Handle(*player, UNASSIGNED_SYSTEM_ADDRESS);
EXPECT_TRUE(skills->HasSkill(1)); // alive: a client can't cancel it
destroyable->SetIsDead(true);
msg.Handle(*player, UNASSIGNED_SYSTEM_ADDRESS);
EXPECT_FALSE(skills->HasSkill(1));
EXPECT_TRUE(skills->HasSkill(2));
}