From 7bba687c11d3a221703b57fca3d07a7c3ae10bac Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 8 Nov 2023 11:55:59 -0300 Subject: [PATCH] fix: unjustified death (#1789) The function that clears the attackedSet was being executed beforeonKilledCreature, which caused the kills/skulls bug. --- src/creatures/creature.cpp | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 2b3d9ae0ebd..c29fe9067ab 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -630,6 +630,14 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s void Creature::onDeath() { bool lastHitUnjustified = false; bool mostDamageUnjustified = false; + std::shared_ptr lastHitCreature = g_game().getCreatureByID(lastHitCreatureId); + std::shared_ptr lastHitCreatureMaster; + if (lastHitCreature) { + lastHitUnjustified = lastHitCreature->onKilledCreature(static_self_cast(), true); + lastHitCreatureMaster = lastHitCreature->getMaster(); + } else { + lastHitCreatureMaster = nullptr; + } std::shared_ptr mostDamageCreature = nullptr; @@ -671,15 +679,11 @@ void Creature::onDeath() { it.first->onGainExperience(it.second, getCreature()); } - std::shared_ptr mostDamageCreatureMaster = nullptr; - if (mostDamageCreature) { - mostDamageCreatureMaster = mostDamageCreature->getMaster(); - mostDamageUnjustified = mostDamageCreature->onKilledCreature(getCreature(), false); - } - - std::shared_ptr lastHitCreature = g_game().getCreatureByID(lastHitCreatureId); - if (lastHitCreature && lastHitCreature != mostDamageCreature && lastHitCreature != mostDamageCreatureMaster) { - lastHitUnjustified = lastHitCreature->onKilledCreature(getCreature(), true); + if (mostDamageCreature && mostDamageCreature != lastHitCreature && mostDamageCreature != lastHitCreatureMaster) { + auto mostDamageCreatureMaster = mostDamageCreature->getMaster(); + if (lastHitCreature != mostDamageCreatureMaster && (lastHitCreatureMaster == nullptr || mostDamageCreatureMaster != lastHitCreatureMaster)) { + mostDamageUnjustified = mostDamageCreature->onKilledCreature(static_self_cast(), false); + } } bool droppedCorpse = dropCorpse(lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified);