Skip to content

Commit

Permalink
fix: gold pouch validations #1168
Browse files Browse the repository at this point in the history
  • Loading branch information
libergod committed Jun 16, 2023
1 parent e8e6b21 commit f53231e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
26 changes: 20 additions & 6 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1294,7 +1294,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 @@ -1438,23 +1438,37 @@ 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);

if (!allowAnything && item->getID() != ITEM_GOLD_COIN && item->getID() != ITEM_PLATINUM_COIN && item->getID() != ITEM_CRYSTAL_COIN) {
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 @@ -1466,7 +1480,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 @@ -177,7 +177,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

0 comments on commit f53231e

Please sign in to comment.