Skip to content

Commit

Permalink
fix: unjustified death (opentibiabr#1789)
Browse files Browse the repository at this point in the history
The function that clears the attackedSet was being executed beforeonKilledCreature, which caused the kills/skulls bug.
  • Loading branch information
dudantas authored Nov 8, 2023
1 parent a9c391b commit 7bba687
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,14 @@ void Creature::onCreatureMove(const std::shared_ptr<Creature> &creature, const s
void Creature::onDeath() {
bool lastHitUnjustified = false;
bool mostDamageUnjustified = false;
std::shared_ptr<Creature> lastHitCreature = g_game().getCreatureByID(lastHitCreatureId);
std::shared_ptr<Creature> lastHitCreatureMaster;
if (lastHitCreature) {
lastHitUnjustified = lastHitCreature->onKilledCreature(static_self_cast<Creature>(), true);
lastHitCreatureMaster = lastHitCreature->getMaster();
} else {
lastHitCreatureMaster = nullptr;
}

std::shared_ptr<Creature> mostDamageCreature = nullptr;

Expand Down Expand Up @@ -671,15 +679,11 @@ void Creature::onDeath() {
it.first->onGainExperience(it.second, getCreature());
}

std::shared_ptr<Creature> mostDamageCreatureMaster = nullptr;
if (mostDamageCreature) {
mostDamageCreatureMaster = mostDamageCreature->getMaster();
mostDamageUnjustified = mostDamageCreature->onKilledCreature(getCreature(), false);
}

std::shared_ptr<Creature> 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<Creature>(), false);
}
}

bool droppedCorpse = dropCorpse(lastHitCreature, mostDamageCreature, lastHitUnjustified, mostDamageUnjustified);
Expand Down

0 comments on commit 7bba687

Please sign in to comment.