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: item loaded by map decays duration when moved by player #875

Merged
merged 2 commits into from
Feb 23, 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
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