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: fix load unique items from map #2881

Merged
merged 7 commits into from
Sep 9, 2024
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
19 changes: 12 additions & 7 deletions data-otservbr-global/startup/others/functions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ function loadLuaMapAction(tablename)
if not value.itemId == false and tile:getItemCountById(value.itemId) == 0 then
logger.error("[loadLuaMapAction] - Wrong item id {} found", value.itemId)
logger.warn("Action id: {}, position {}", index, tile:getPosition():toString())
break
goto continue
end

if value.itemId ~= false and tile:getItemCountById(value.itemId) > 0 then
Expand All @@ -49,6 +49,7 @@ function loadLuaMapAction(tablename)
tile:getGround():setAttribute(ITEM_ATTRIBUTE_ACTIONID, index)
end
end
::continue::
end
end
end
Expand All @@ -64,19 +65,21 @@ function loadLuaMapUnique(tablename)
if not value.itemId == false and tile:getItemCountById(value.itemId) == 0 then
logger.error("[loadLuaMapUnique] - Wrong item id {} found", value.itemId)
logger.warn("Unique id: {}, position {}", index, tile:getPosition():toString())
break
goto continue
end
if tile:getItemCountById(value.itemId) < 1 or value.itemId == false then
logger.warn("[loadLuaMapUnique] - Wrong item id {} found", value.itemId)
logger.warn("Unique id: {}, position {}, item id: wrong", index, tile:getPosition():toString())
break
goto continue
end
item = tile:getItemById(value.itemId)
-- If he found the item, add the unique id
if item then
item:setAttribute(ITEM_ATTRIBUTE_UNIQUEID, index)
end
end

::continue::
end
end

Expand All @@ -91,7 +94,7 @@ function loadLuaMapSign(tablename)
if tile:getItemCountById(value.itemId) == 0 then
logger.error("[loadLuaMapSign] - Wrong item id {} found", value.itemId)
logger.warn("Sign id: {}, position {}, item id: wrong", index, tile:getPosition():toString())
break
goto continue
end
if tile:getItemCountById(value.itemId) == 1 then
item = tile:getItemById(value.itemId)
Expand All @@ -101,6 +104,7 @@ function loadLuaMapSign(tablename)
item:setAttribute(ITEM_ATTRIBUTE_TEXT, value.text)
end
end
::continue::
end
end

Expand Down Expand Up @@ -137,17 +141,18 @@ function loadLuaMapBookDocument(tablename)
totals[2] = totals[2] + 1
else
logger.warn("[loadLuaMapBookDocument] - Item not found! Index: {}, itemId: {}", index, value.itemId)
break
goto continue
end
else
logger.warn("[loadLuaMapBookDocument] - Container not found! Index: {}, containerId: {}", index, value.containerId)
break
goto continue
end
else
logger.warn("[loadLuaMapBookDocument] - Tile not found! Index: {}, position: x: {} y: {} z: {}", index, value.position.x, value.position.y, value.position.z)
break
goto continue
end
end
::continue::
end
if totals[1] == totals[2] then
logger.debug("Loaded {} books and documents in the map", totals[2])
Expand Down
4 changes: 2 additions & 2 deletions src/creatures/npcs/npc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ void Npc::onPlayerBuyItem(std::shared_ptr<Player> player, uint16_t itemId, uint8
return;
}

// Check if the player not have empty slots
if (!ignore && player->getFreeBackpackSlots() == 0) {
// Check if the player not have empty slots or the item is not a container
if (!ignore && (player->getFreeBackpackSlots() == 0 && (player->getInventoryItem(CONST_SLOT_BACKPACK) || (!Item::items[itemId].isContainer() || !(Item::items[itemId].slotPosition & SLOTP_BACKPACK))))) {
player->sendCancelMessage(RETURNVALUE_NOTENOUGHROOM);
return;
}
Expand Down
Loading