Skip to content

Commit

Permalink
fix: house clean-up and item wrap issues (opentibiabr#840)
Browse files Browse the repository at this point in the history
This fixes two issues related to the '!leavehouse' command. Firstly, all items inside the house should be moved to the owner's mailbox after using the command. Secondly, it should now be possible to wrap unrolled carpets.

Fixes opentibiabr#631: bug causing exposed items after using the '!leavehouse' command, which allowed the new owner of the house to claim those items)."
  • Loading branch information
ElimarCosta authored Feb 12, 2023
1 parent 60cb39b commit c7a18fb
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 49 deletions.
33 changes: 18 additions & 15 deletions src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3382,7 +3382,7 @@ void Game::playerWrapableItem(uint32_t playerId, const Position& pos, uint8_t st
return;
}

Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_TOPDOWN_ITEM);
Thing* thing = internalGetThing(player, pos, stackPos, itemId, STACKPOS_FIND_THING);
if (!thing) {
return;
}
Expand Down Expand Up @@ -3444,19 +3444,7 @@ void Game::playerWrapableItem(uint32_t playerId, const Position& pos, uint8_t st
}

if (item->isWrapable() && item->getID() != ITEM_DECORATION_KIT) {
uint16_t hiddenCharges = 0;
if (isCaskItem(item->getID())) {
hiddenCharges = item->getSubType();
}
uint16_t oldItemID = item->getID();
addMagicEffect(item->getPosition(), CONST_ME_POFF);
Item* newItem = transformItem(item, ITEM_DECORATION_KIT);
newItem->setCustomAttribute("unWrapId", static_cast<int64_t>(oldItemID));
item->setAttribute(ItemAttribute_t::DESCRIPTION, "Unwrap it in your own house to create a <" + itemName + ">.");
if (hiddenCharges > 0) {
item->setAttribute(ItemAttribute_t::DATE, hiddenCharges);
}
newItem->startDecaying();
wrapItem(item);
}
else if (item->getID() == ITEM_DECORATION_KIT && unWrapId != 0) {
auto hiddenCharges = item->getAttribute<uint16_t>(ItemAttribute_t::DATE);
Expand All @@ -3465,12 +3453,27 @@ void Game::playerWrapableItem(uint32_t playerId, const Position& pos, uint8_t st
if (hiddenCharges > 0 && isCaskItem(unWrapId)) {
newItem->setSubType(hiddenCharges);
}
addMagicEffect(pos, CONST_ME_POFF);
newItem->removeCustomAttribute("unWrapId");
newItem->removeAttribute(ItemAttribute_t::DESCRIPTION);
newItem->startDecaying();
}
}
addMagicEffect(pos, CONST_ME_POFF);
}

Item* Game::wrapItem(Item *item) {
uint16_t oldItemID = item->getID();
Item* newItem = transformItem(item, ITEM_DECORATION_KIT);
newItem->setCustomAttribute("unWrapId", static_cast<int64_t>(oldItemID));
item->setAttribute(ItemAttribute_t::DESCRIPTION, "Unwrap it in your own house to create a <" + item->getName() + ">.");
if (isCaskItem(item->getID())) {
auto hiddenCharges = item->getSubType();
if (hiddenCharges > 0) {
item->setAttribute(ItemAttribute_t::DATE, hiddenCharges);
}
}
newItem->startDecaying();
return newItem;
}

void Game::playerWriteItem(uint32_t playerId, uint32_t windowTextId, const std::string& text)
Expand Down
1 change: 1 addition & 0 deletions src/game/game.h
Original file line number Diff line number Diff line change
Expand Up @@ -585,6 +585,7 @@ class Game

bool addInfluencedMonster(Monster *monster);
void sendUpdateCreature(const Creature *creature);
Item* wrapItem(Item *item);

private:
std::map<uint32_t, int32_t> forgeMonsterEventIds;
Expand Down
53 changes: 19 additions & 34 deletions src/map/house/house.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,47 +240,16 @@ bool House::transferToDepot(Player* player) const
if (townId == 0 || owner == 0) {
return false;
}

ItemList moveItemList;
for (HouseTile* tile : houseTiles) {
if (const TileItemVector* items = tile->getItemList()) {
for (auto it = items->rbegin(), end = items->rend(); it != end; ++it) {
Item* item = (*it);
for (Item* item : *items) {
if (item->isWrapable()) {
Container* container = item->getContainer();
if (container) {
for (Item* containerItem : container->getItemList()) {
moveItemList.push_back(containerItem);
}
}

uint16_t hiddenCharges = 0;
if (isCaskItem(item->getID())) {
hiddenCharges = item->getSubType();
}

std::string itemName = item->getName();
uint16_t itemID = item->getID();
Item* newItem = g_game().transformItem(item, ITEM_DECORATION_KIT);
newItem->setCustomAttribute("unWrapId", static_cast<int64_t>(itemID));
std::ostringstream ss;
ss << "Unwrap it in your own house to create a <" << itemName << ">.";
newItem->setAttribute(ItemAttribute_t::DESCRIPTION, ss.str());

if (hiddenCharges > 0) {
item->setAttribute(ItemAttribute_t::DATE, hiddenCharges);
}

moveItemList.push_back(newItem);
handleWrapableItem(moveItemList, item);
} else if (item->isPickupable()) {
moveItemList.push_back(item);
} else {
Container* container = item->getContainer();
if (container) {
for (Item* containerItem : container->getItemList()) {
moveItemList.push_back(containerItem);
}
}
handleContainer(moveItemList, item);
}
}
}
Expand All @@ -292,6 +261,22 @@ bool House::transferToDepot(Player* player) const
return true;
}

void House::handleWrapableItem(ItemList &moveItemList, Item *item) const {
if (item->isWrapContainer()) {
handleContainer(moveItemList, item);
}
Item *newItem = g_game().wrapItem(item);
moveItemList.push_back(newItem);
}

void House::handleContainer(ItemList &moveItemList, Item *item) const {
if (const auto container = item->getContainer()) {
for (Item* containerItem : container->getItemList()) {
moveItemList.push_back(containerItem);
}
}
}

bool House::getAccessList(uint32_t listId, std::string& list) const
{
if (listId == GUEST_LIST) {
Expand Down
3 changes: 3 additions & 0 deletions src/map/house/house.h
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,9 @@ class House
Position posEntry = {};

bool isLoaded = false;

void handleContainer(ItemList &moveItemList, Item *item) const;
void handleWrapableItem(ItemList &moveItemList, Item *item) const;
};

using HouseMap = std::map<uint32_t, House*>;
Expand Down

0 comments on commit c7a18fb

Please sign in to comment.