diff --git a/src/creatures/creature.cpp b/src/creatures/creature.cpp index 4720b903233..bc77050268d 100644 --- a/src/creatures/creature.cpp +++ b/src/creatures/creature.cpp @@ -800,23 +800,23 @@ bool Creature::dropCorpse(std::shared_ptr lastHitCreature, std::shared corpse->startDecaying(); bool corpses = corpse->isRewardCorpse() || (corpse->getID() == ITEM_MALE_CORPSE || corpse->getID() == ITEM_FEMALE_CORPSE); const auto player = mostDamageCreature ? mostDamageCreature->getPlayer() : nullptr; - if (corpse->getContainer() && player && !corpses) { + auto corpseContainer = corpse->getContainer(); + if (corpseContainer && player && !corpses) { auto monster = getMonster(); if (monster && !monster->isRewardBoss()) { std::ostringstream lootMessage; - lootMessage << "Loot of " << getNameDescription() << ": " << corpse->getContainer()->getContentDescription(player->getProtocolVersion() < 1200) << "."; - auto suffix = corpse->getContainer()->getAttribute(ItemAttribute_t::LOOTMESSAGE_SUFFIX); + lootMessage << "Loot of " << getNameDescription() << ": " << corpseContainer->getContentDescription(player->getProtocolVersion() < 1200) << "."; + auto suffix = corpseContainer->getAttribute(ItemAttribute_t::LOOTMESSAGE_SUFFIX); if (!suffix.empty()) { lootMessage << suffix; } player->sendLootMessage(lootMessage.str()); } - if (player->checkAutoLoot()) { - int32_t pos = tile->getStackposOfItem(player, corpse); + if (player->checkAutoLoot() && corpseContainer && mostDamageCreature->getPlayer()) { g_dispatcher().addEvent( - std::bind(&Game::playerQuickLoot, &g_game(), mostDamageCreature->getID(), this->getPosition(), corpse->getID(), pos - 1, nullptr, false, true), - "Game::playerQuickLoot" + std::bind(&Game::playerQuickLootCorpse, &g_game(), player, corpseContainer), + "Game::playerQuickLootCorpse" ); } } diff --git a/src/game/game.cpp b/src/game/game.cpp index d741b24b1a2..f70af5cf864 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -2545,7 +2545,7 @@ ReturnValue Game::internalTeleport(const std::shared_ptr &thing, const Po return RETURNVALUE_NOTPOSSIBLE; } -void Game::internalQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse) { +void Game::playerQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse) { if (!player || !corpse) { return; } @@ -5000,11 +5000,11 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item auto rewardId = corpse->getAttribute(ItemAttribute_t::DATE); auto reward = player->getReward(rewardId, false); if (reward) { - internalQuickLootCorpse(player, reward->getContainer()); + playerQuickLootCorpse(player, reward->getContainer()); } } else { if (!lootAllCorpses) { - internalQuickLootCorpse(player, corpse); + playerQuickLootCorpse(player, corpse); } else { playerLootAllCorpses(player, pos, lootAllCorpses); } @@ -5041,7 +5041,7 @@ void Game::playerLootAllCorpses(std::shared_ptr player, const Position & } corpses++; - internalQuickLootCorpse(player, tileCorpse); + playerQuickLootCorpse(player, tileCorpse); if (corpses >= 30) { break; } diff --git a/src/game/game.hpp b/src/game/game.hpp index f446615e29a..263119d3518 100644 --- a/src/game/game.hpp +++ b/src/game/game.hpp @@ -350,6 +350,7 @@ class Game { void playerSetFightModes(uint32_t playerId, FightMode_t fightMode, bool chaseMode, bool secureMode); void playerLookAt(uint32_t playerId, uint16_t itemId, const Position &pos, uint8_t stackPos); void playerLookInBattleList(uint32_t playerId, uint32_t creatureId); + void playerQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse); void playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, std::shared_ptr defaultItem = nullptr, bool lootAllCorpses = false, bool autoLoot = false); void playerLootAllCorpses(std::shared_ptr player, const Position &pos, bool lootAllCorpses); void playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, const Position &pos, uint16_t itemId, uint8_t stackPos); @@ -697,13 +698,6 @@ class Game { void playerSpeakToNpc(std::shared_ptr player, const std::string &text); std::shared_ptr createPlayerTask(uint32_t delay, std::function f, std::string context) const; - /** - * Player wants to loot a corpse - * \param player Player pointer - * \param corpse Container pointer to be looted - */ - void internalQuickLootCorpse(std::shared_ptr player, std::shared_ptr corpse); - /** * @brief Finds the container for loot based on the given parameters. *