From 5781de718e5d22ce9e7f136151d8b4032c85843d Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Mon, 20 Jan 2025 15:57:32 -0300 Subject: [PATCH] fix: player death corpse description (#3191) --- src/creatures/players/player.cpp | 60 +++++++++++++++++++++++++++++--- 1 file changed, 56 insertions(+), 4 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index c3857a11361..4f388e6ee90 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -3812,12 +3812,64 @@ std::shared_ptr Player::getCorpse(const std::shared_ptr &lastHit const auto &corpse = Creature::getCorpse(lastHitCreature, mostDamageCreature); if (corpse && corpse->getContainer()) { std::ostringstream ss; + + ss << "You recognize " << getNameDescription() << ". "; + + std::string responsibleName; + std::string secondaryResponsibleName; + bool hasOthers = false; + if (lastHitCreature) { - std::string subjectPronoun = getSubjectPronoun(); - capitalizeWords(subjectPronoun); - ss << "You recognize " << getNameDescription() << ". " << subjectPronoun << " " << getSubjectVerb(true) << " killed by " << lastHitCreature->getNameDescription() << '.'; + if (lastHitCreature->getPlayer()) { + responsibleName = lastHitCreature->getNameDescription(); + } else if (auto master = lastHitCreature->getMaster(); master && master->getPlayer()) { + responsibleName = master->getNameDescription(); + } + } + + if (mostDamageCreature) { + if (mostDamageCreature->getPlayer()) { + if (responsibleName != mostDamageCreature->getNameDescription()) { + secondaryResponsibleName = responsibleName; + responsibleName = mostDamageCreature->getNameDescription(); + } + } else if (auto master = mostDamageCreature->getMaster(); master && master->getPlayer()) { + if (responsibleName != master->getNameDescription()) { + secondaryResponsibleName = responsibleName; + responsibleName = master->getNameDescription(); + } + } + } + + uint32_t inFightTicks = 5 * 60 * 1000; + for (const auto &[creatureId, damageInfo] : damageMap) { + const auto &[total, ticks] = damageInfo; + if ((OTSYS_TIME() - ticks) <= inFightTicks) { + const auto &attacker = g_game().getCreatureByID(creatureId); + if (attacker && !attacker->getPlayer()) { + hasOthers = true; + break; + } + } + } + + if (!responsibleName.empty()) { + ss << getSubjectPronoun() << " " << getSubjectVerb(true) << " killed by " << responsibleName; + + if (!secondaryResponsibleName.empty()) { + ss << " and " << secondaryResponsibleName; + } else if (hasOthers) { + ss << " and others"; + } + ss << '.'; + } else if (lastHitCreature) { + ss << getSubjectPronoun() << " " << getSubjectVerb(true) << " killed by " << lastHitCreature->getNameDescription(); + if (hasOthers) { + ss << " and others"; + } + ss << '.'; } else { - ss << "You recognize " << getNameDescription() << '.'; + ss << "No attackers were identified."; } corpse->setAttribute(ItemAttribute_t::DESCRIPTION, ss.str());