Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve: more reliable quickloot/autoloot #1997

Merged
merged 2 commits into from
Dec 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -2545,7 +2545,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 @@ -5000,11 +5000,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 @@ -5041,7 +5041,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
Loading