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

fix: gold pouch validations #1168

Merged
merged 4 commits into from
Jun 10, 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
26 changes: 20 additions & 6 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t item
}

// check if we can move this item
if (ReturnValue ret = checkMoveItemToCylinder(player, fromCylinder, toCylinder, item); ret != RETURNVALUE_NOERROR) {
if (ReturnValue ret = checkMoveItemToCylinder(player, fromCylinder, toCylinder, item, toPos); ret != RETURNVALUE_NOERROR) {
player->sendCancelMessage(ret);
return;
}
Expand Down Expand Up @@ -1442,13 +1442,22 @@ bool Game::isTryingToStow(const Position &toPos, Cylinder* toCylinder) const {
return toCylinder->getContainer() && toCylinder->getItem()->getID() == ITEM_LOCKER && toPos.getZ() == ITEM_SUPPLY_STASH_INDEX;
}

ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder, Cylinder* toCylinder, Item* item) {
ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder, Cylinder* toCylinder, Item* item, Position toPos) {
if (!player || !toCylinder || !item) {
return RETURNVALUE_NOTPOSSIBLE;
}

if (toCylinder->getContainer()) {
auto containerID = toCylinder->getContainer()->getID();
if (Container* toCylinderContainer = toCylinder->getContainer()) {
auto containerID = toCylinderContainer->getID();

// check the store inbox index if gold pouch forces it as containerID
if (containerID == ITEM_STORE_INBOX) {
Item* cylinderItem = toCylinderContainer->getItemByIndex(toPos.getZ());

if (cylinderItem && cylinderItem->getID() == ITEM_GOLD_POUCH) {
containerID = ITEM_GOLD_POUCH;
}
}

if (containerID == ITEM_GOLD_POUCH) {
bool allowAnything = g_configManager().getBoolean(TOGGLE_GOLD_POUCH_ALLOW_ANYTHING);
Expand All @@ -1457,10 +1466,15 @@ ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder
return RETURNVALUE_CONTAINERNOTENOUGHROOM;
}

// prevent move up
if (!item->isStoreItem() && fromCylinder->getContainer() && fromCylinder->getContainer()->getID() == ITEM_GOLD_POUCH) {
return RETURNVALUE_CONTAINERNOTENOUGHROOM;
}

return RETURNVALUE_NOERROR;
}

const Container* topParentContainer = toCylinder->getContainer()->getRootContainer();
const Container* topParentContainer = toCylinderContainer->getRootContainer();

if (!item->isStoreItem() && (containerID == ITEM_STORE_INBOX || topParentContainer->getParent() && topParentContainer->getParent()->getContainer() && topParentContainer->getParent()->getContainer()->getID() == ITEM_STORE_INBOX)) {
return RETURNVALUE_CONTAINERNOTENOUGHROOM;
Expand All @@ -1472,7 +1486,7 @@ ReturnValue Game::checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder
return RETURNVALUE_NOTPOSSIBLE;
}

if (containerID == ITEM_STORE_INBOX || containerID == ITEM_DEPOT || toCylinder->getContainer()->isDepotChest()) {
if (containerID == ITEM_STORE_INBOX || containerID == ITEM_DEPOT || toCylinderContainer->isDepotChest()) {
isValidMoveItem = true;
}

Expand Down
2 changes: 1 addition & 1 deletion src/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ class Game {
ReturnValue internalMoveCreature(Creature* creature, Direction direction, uint32_t flags = 0);
ReturnValue internalMoveCreature(Creature &creature, Tile &toTile, uint32_t flags = 0);

ReturnValue checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder, Cylinder* toCylinder, Item* item);
ReturnValue checkMoveItemToCylinder(Player* player, Cylinder* fromCylinder, Cylinder* toCylinder, Item* item, Position toPos);
ReturnValue internalMoveItem(Cylinder* fromCylinder, Cylinder* toCylinder, int32_t index, Item* item, uint32_t count, Item** internalMoveItem, uint32_t flags = 0, Creature* actor = nullptr, Item* tradeItem = nullptr);

ReturnValue internalAddItem(Cylinder* toCylinder, Item* item, int32_t index = INDEX_WHEREEVER, uint32_t flags = 0, bool test = false);
Expand Down