Skip to content

Commit

Permalink
fix: item loaded by map decays duration when moved by player (#875)
Browse files Browse the repository at this point in the history
This fix ensures that map items decay properly when moved, preventing infinite items from accumulating in the game. When a player interacts with the item by moving it, it will decay and become a common item on the map.
  • Loading branch information
dudantas authored Feb 23, 2023
1 parent fc33666 commit c33202a
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1305,6 +1305,8 @@ void Game::playerMoveItem(Player* player, const Position &fromPos, uint16_t item
}
player->cancelPush();

item->checkDecayMapItemOnMove();

g_events().eventPlayerOnItemMoved(player, item, count, fromPos, toPos, fromCylinder, toCylinder);
}

Expand Down
7 changes: 7 additions & 0 deletions src/items/item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -969,6 +969,13 @@ bool Item::canBeMoved() const {
return isMoveable() && !hasAttribute(UNIQUEID) && (!hasAttribute(ACTIONID) || getAttribute<uint16_t>(ItemAttribute_t::ACTIONID) != IMMOVABLE_ACTION_ID);
}

void Item::checkDecayMapItemOnMove() {
if (getDuration() > 0 && getLoadedFromMap() && canBeMoved()) {
setLoadedFromMap(false);
startDecaying();
}
}

uint32_t Item::getWeight() const {
uint32_t baseWeight = getBaseWeight();
if (isStackable()) {
Expand Down
4 changes: 2 additions & 2 deletions src/items/item.h
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,8 @@ class Item : virtual public Thing, public ItemProperties {
}

void updateTileFlags();
bool canBeMoved() const;
void checkDecayMapItemOnMove();

protected:
Cylinder* parent = nullptr;
Expand All @@ -658,8 +660,6 @@ class Item : virtual public Thing, public ItemProperties {
std::string getWeightDescription(uint32_t weight) const;

friend class Decay;

bool canBeMoved() const;
};

using ItemList = std::list<Item*>;
Expand Down

0 comments on commit c33202a

Please sign in to comment.