Skip to content

Commit

Permalink
fix: player death corpse description (#3191)
Browse files Browse the repository at this point in the history
  • Loading branch information
dudantas authored Jan 20, 2025
1 parent 3cf3ec2 commit 5781de7
Showing 1 changed file with 56 additions and 4 deletions.
60 changes: 56 additions & 4 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3812,12 +3812,64 @@ std::shared_ptr<Item> Player::getCorpse(const std::shared_ptr<Creature> &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());
Expand Down

0 comments on commit 5781de7

Please sign in to comment.