From fdfb118910fa1bfad57ad34e817f595dad23a3a8 Mon Sep 17 00:00:00 2001 From: Eduardo Dantas Date: Sat, 21 Dec 2024 01:47:35 -0300 Subject: [PATCH 1/2] fix: player death corpse description --- src/creatures/players/player.cpp | 36 ++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index 3ef1d64e982..ab25f6c5322 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -3773,17 +3773,41 @@ std::shared_ptr Player::getCorpse(const std::shared_ptr &lastHit const auto &corpse = Creature::getCorpse(lastHitCreature, mostDamageCreature); if (corpse && corpse->getContainer()) { std::ostringstream ss; - if (lastHitCreature) { - std::string subjectPronoun = getSubjectPronoun(); - capitalizeWords(subjectPronoun); - ss << "You recognize " << getNameDescription() << ". " << subjectPronoun << " " << getSubjectVerb(true) << " killed by " << lastHitCreature->getNameDescription() << '.'; + std::string subjectPronoun = getSubjectPronoun(); + capitalizeWords(subjectPronoun); + + if (!damageMap.empty()) { + ss << fmt::format("You recognize {}. {} was killed by ", getNameDescription(), subjectPronoun); + + std::vector killers; + for (const auto& [creatureId, damageInfo] : damageMap) { + const auto& [totalDamage, ticks] = damageInfo; + const auto& damageDealer = g_game().getCreatureByID(creatureId); + if (damageDealer) { + killers.push_back(damageDealer->getNameDescription()); + } + } + + if (!killers.empty()) { + for (size_t i = 0; i < killers.size(); ++i) { + if (i > 0) { + ss << (i == killers.size() - 1 ? " and " : ", "); + } + ss << killers[i]; + } + } else { + ss << "an unknown attacker"; + } + ss << '.'; } else { - ss << "You recognize " << getNameDescription() << '.'; + ss << fmt::format("You recognize {}.", getNameDescription()); } corpse->setAttribute(ItemAttribute_t::DESCRIPTION, ss.str()); + return corpse; } - return corpse; + + return nullptr; } void Player::addInFightTicks(bool pzlock /*= false*/) { From 41d95e21aa238a8619c06075934c8443f5093d02 Mon Sep 17 00:00:00 2001 From: GitHub Actions Date: Sat, 21 Dec 2024 04:48:15 +0000 Subject: [PATCH 2/2] Code format - (Clang-format) --- src/creatures/players/player.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/creatures/players/player.cpp b/src/creatures/players/player.cpp index ab25f6c5322..b64718a19ce 100644 --- a/src/creatures/players/player.cpp +++ b/src/creatures/players/player.cpp @@ -3780,9 +3780,9 @@ std::shared_ptr Player::getCorpse(const std::shared_ptr &lastHit ss << fmt::format("You recognize {}. {} was killed by ", getNameDescription(), subjectPronoun); std::vector killers; - for (const auto& [creatureId, damageInfo] : damageMap) { - const auto& [totalDamage, ticks] = damageInfo; - const auto& damageDealer = g_game().getCreatureByID(creatureId); + for (const auto &[creatureId, damageInfo] : damageMap) { + const auto &[totalDamage, ticks] = damageInfo; + const auto &damageDealer = g_game().getCreatureByID(creatureId); if (damageDealer) { killers.push_back(damageDealer->getNameDescription()); }