Skip to content

Commit

Permalink
improve: more reliable quickloot/autoloot
Browse files Browse the repository at this point in the history
  • Loading branch information
luan committed Dec 11, 2023
1 parent 029fee6 commit 9a6b88d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
14 changes: 7 additions & 7 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -800,23 +800,23 @@ bool Creature::dropCorpse(std::shared_ptr<Creature> 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<std::string>(ItemAttribute_t::LOOTMESSAGE_SUFFIX);
lootMessage << "Loot of " << getNameDescription() << ": " << corpseContainer->getContentDescription(player->getProtocolVersion() < 1200) << ".";
auto suffix = corpseContainer->getAttribute<std::string>(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"
);
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2539,7 +2539,7 @@ ReturnValue Game::internalTeleport(const std::shared_ptr<Thing> &thing, const Po
return RETURNVALUE_NOTPOSSIBLE;
}

void Game::internalQuickLootCorpse(std::shared_ptr<Player> player, std::shared_ptr<Container> corpse) {
void Game::playerQuickLootCorpse(std::shared_ptr<Player> player, std::shared_ptr<Container> corpse) {
if (!player || !corpse) {
return;
}
Expand Down Expand Up @@ -4994,11 +4994,11 @@ void Game::playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t item
auto rewardId = corpse->getAttribute<time_t>(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);
}
Expand Down Expand Up @@ -5035,7 +5035,7 @@ void Game::playerLootAllCorpses(std::shared_ptr<Player> player, const Position &
}

corpses++;
internalQuickLootCorpse(player, tileCorpse);
playerQuickLootCorpse(player, tileCorpse);
if (corpses >= 30) {
break;
}
Expand Down
8 changes: 1 addition & 7 deletions src/game/game.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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> player, std::shared_ptr<Container> corpse);
void playerQuickLoot(uint32_t playerId, const Position &pos, uint16_t itemId, uint8_t stackPos, std::shared_ptr<Item> defaultItem = nullptr, bool lootAllCorpses = false, bool autoLoot = false);
void playerLootAllCorpses(std::shared_ptr<Player> player, const Position &pos, bool lootAllCorpses);
void playerSetLootContainer(uint32_t playerId, ObjectCategory_t category, const Position &pos, uint16_t itemId, uint8_t stackPos);
Expand Down Expand Up @@ -697,13 +698,6 @@ class Game {
void playerSpeakToNpc(std::shared_ptr<Player> player, const std::string &text);
std::shared_ptr<Task> createPlayerTask(uint32_t delay, std::function<void(void)> 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> player, std::shared_ptr<Container> corpse);

/**
* @brief Finds the container for loot based on the given parameters.
*
Expand Down

0 comments on commit 9a6b88d

Please sign in to comment.