diff --git a/src/container.cpp b/src/container.cpp index ec11f4a953..74ecfad9c8 100644 --- a/src/container.cpp +++ b/src/container.cpp @@ -26,8 +26,7 @@ Container::Container(Tile* tile) : Container(ITEM_BROWSEFIELD, 30, false, true) TileItemVector* itemVector = tile->getItemList(); if (itemVector) { for (Item* item : *itemVector) { - if ((item->getContainer() || item->hasProperty(CONST_PROP_MOVEABLE)) && - !item->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID)) { + if (item->shouldTriggerBrowseFieldUpdate() && !item->hasAttribute(ITEM_ATTRIBUTE_UNIQUEID)) { itemlist.push_front(item); item->setParent(this); } diff --git a/src/item.h b/src/item.h index 0dafd089ec..fcccc8ef9b 100644 --- a/src/item.h +++ b/src/item.h @@ -905,6 +905,8 @@ class Item : virtual public Thing return attributes; } + bool shouldTriggerBrowseFieldUpdate() const { return getContainer() || hasProperty(CONST_PROP_MOVEABLE); } + void incrementReferenceCounter() { ++referenceCounter; } void decrementReferenceCounter() { diff --git a/src/tile.cpp b/src/tile.cpp index e03fb7b431..190a7b2549 100644 --- a/src/tile.cpp +++ b/src/tile.cpp @@ -349,7 +349,7 @@ Thing* Tile::getTopVisibleThing(const Creature* creature) void Tile::onAddTileItem(Item* item) { - if (item->hasProperty(CONST_PROP_MOVEABLE) || item->getContainer()) { + if (item->shouldTriggerBrowseFieldUpdate()) { auto it = g_game.browseFields.find(this); if (it != g_game.browseFields.end()) { it->second->addItemBack(item); @@ -386,7 +386,7 @@ void Tile::onAddTileItem(Item* item) void Tile::onUpdateTileItem(Item* oldItem, const ItemType& oldType, Item* newItem, const ItemType& newType) { - if (newItem->hasProperty(CONST_PROP_MOVEABLE) || newItem->getContainer()) { + if (newItem->shouldTriggerBrowseFieldUpdate()) { auto it = g_game.browseFields.find(this); if (it != g_game.browseFields.end()) { int32_t index = it->second->getThingIndex(oldItem); @@ -395,7 +395,7 @@ void Tile::onUpdateTileItem(Item* oldItem, const ItemType& oldType, Item* newIte newItem->setParent(it->second); } } - } else if (oldItem->hasProperty(CONST_PROP_MOVEABLE) || oldItem->getContainer()) { + } else if (oldItem->shouldTriggerBrowseFieldUpdate()) { auto it = g_game.browseFields.find(this); if (it != g_game.browseFields.end()) { Cylinder* oldParent = oldItem->getParent(); @@ -424,7 +424,7 @@ void Tile::onUpdateTileItem(Item* oldItem, const ItemType& oldType, Item* newIte void Tile::onRemoveTileItem(const SpectatorVec& spectators, const std::vector& oldStackPosVector, Item* item) { - if (item->hasProperty(CONST_PROP_MOVEABLE) || item->getContainer()) { + if (item->shouldTriggerBrowseFieldUpdate()) { auto it = g_game.browseFields.find(this); if (it != g_game.browseFields.end()) { it->second->removeThing(item, item->getItemCount()); @@ -967,13 +967,16 @@ void Tile::updateThing(Thing* thing, uint16_t itemId, uint32_t count) return /*RETURNVALUE_NOTPOSSIBLE*/; } + Item* realOldItem = item->clone(); + const ItemType& oldType = Item::items[item->getID()]; const ItemType& newType = Item::items[itemId]; + resetTileFlags(item); item->setID(itemId); item->setSubType(count); setTileFlags(item); - onUpdateTileItem(item, oldType, item, newType); + onUpdateTileItem(realOldItem, oldType, item, newType); } void Tile::replaceThing(uint32_t index, Thing* thing)