Skip to content

Commit

Permalink
Merge pull request #9 from jprzimba/fix-death-list
Browse files Browse the repository at this point in the history
* Fix Player::getCorpse
  • Loading branch information
jprzimba authored Dec 30, 2024
2 parents d59449b + 2f8797a commit f602f6c
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 6 deletions.
3 changes: 1 addition & 2 deletions src/creatures/combat/spells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,7 @@ TalkActionResult_t Spells::playerSaySpell(const std::shared_ptr<Player> &player,
if (instantSpell->playerCastInstant(player, param)) {
if (!player->checkSpellNameInsteadOfWords()) {
words = instantSpell->getWords();
}
else {
} else {
words = instantSpell->getName();
}

Expand Down
8 changes: 8 additions & 0 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,14 @@ class Creature : virtual public Thing, public SharedObject {

virtual CreatureType_t getType() const = 0;

bool isPlayer() const {
return getType() == CreatureType_t::CREATURETYPE_PLAYER;
}

bool isMonster() const {
return getType() == CreatureType_t::CREATURETYPE_MONSTER;
}

virtual void setID() = 0;
void setRemoved() {
isInternalRemoved = true;
Expand Down
25 changes: 21 additions & 4 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3825,23 +3825,40 @@ std::shared_ptr<Item> Player::getCorpse(const std::shared_ptr<Creature> &lastHit
descriptionStream << fmt::format("You recognize {}. {} was killed by ", getNameDescription(), subjectPronoun);

std::vector<std::string> killers;
std::string firstMonster;

for (const auto &[creatureId, damageInfo] : damageMap) {
auto damageDealer = g_game().getCreatureByID(creatureId);
if (damageDealer) {
killers.push_back(damageDealer->getNameDescription());
if (damageDealer->isPlayer()) {
killers.push_back(damageDealer->getNameDescription());
} else if (damageDealer->isMonster() && firstMonster.empty()) {
auto master = damageDealer->getMaster();
if (master && master->isPlayer()) {
firstMonster = fmt::format("{} summoned by {}", damageDealer->getNameDescription(), master->getNameDescription());
} else {
firstMonster = damageDealer->getNameDescription();
}
}
}
}

if (killers.empty()) {
descriptionStream << "an unknown attacker";
} else {
if (!killers.empty()) {
for (size_t i = 0; i < killers.size(); ++i) {
if (i > 0) {
descriptionStream << (i == killers.size() - 1 ? " and " : ", ");
}
descriptionStream << killers[i];
}
if (!firstMonster.empty()) {
descriptionStream << " and " << firstMonster;
}
} else if (!firstMonster.empty()) {
descriptionStream << firstMonster;
} else {
descriptionStream << "an unknown attacker";
}

descriptionStream << '.';
}

Expand Down

0 comments on commit f602f6c

Please sign in to comment.