From 2ce99ead1e136ece947fa9da74c607e73e9246d4 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 8 Nov 2023 11:18:38 -0300 Subject: [PATCH 1/2] fix: unjustified death --- src/creatures/creature.cpp | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 2b3d9ae0ebd..f319d5a862a 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -630,8 +630,16 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s void Creature::onDeath() { bool lastHitUnjustified = false; bool mostDamageUnjustified = false; - + std::shared_ptr mostDamageCreatureMaster = nullptr; std::shared_ptr mostDamageCreature = 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); + } const int64_t timeNow = OTSYS_TIME(); const uint32_t inFightTicks = g_configManager().getNumber(PZ_LOCKED); @@ -671,17 +679,6 @@ 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); - } - bool droppedCorpse = dropCorpse(lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified); death(lastHitCreature); From aaaeff5b0756a0cda5efa7dd69502b9c7f2ffcc5 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Wed, 8 Nov 2023 11:27:19 -0300 Subject: [PATCH 2/2] fix: conditions order --- src/creatures/creature.cpp | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index f319d5a862a..c29fe9067ab 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -630,17 +630,17 @@ void Creature::onCreatureMove(const std::shared_ptr &creature, const s void Creature::onDeath() { bool lastHitUnjustified = false; bool mostDamageUnjustified = false; - std::shared_ptr mostDamageCreatureMaster = nullptr; - std::shared_ptr mostDamageCreature = 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); + std::shared_ptr lastHitCreatureMaster; + if (lastHitCreature) { + lastHitUnjustified = lastHitCreature->onKilledCreature(static_self_cast(), true); + lastHitCreatureMaster = lastHitCreature->getMaster(); + } else { + lastHitCreatureMaster = nullptr; } + std::shared_ptr mostDamageCreature = nullptr; + const int64_t timeNow = OTSYS_TIME(); const uint32_t inFightTicks = g_configManager().getNumber(PZ_LOCKED); int32_t mostDamage = 0; @@ -679,6 +679,13 @@ void Creature::onDeath() { it.first->onGainExperience(it.second, getCreature()); } + 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); death(lastHitCreature);