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);