Skip to content

Commit

Permalink
Merge branch 'main' into fix-2728
Browse files Browse the repository at this point in the history
  • Loading branch information
luanluciano93 authored Sep 9, 2024
2 parents 6448a46 + b330a33 commit 51f087a
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ monster.loot = {
{ name = "two-headed turtle heads", chance = 8700 },
{ name = "strong mana potion", chance = 13373 },
{ name = "hydrophytes", chance = 11000 },
{ id = 1047, chance = 6388 }, -- bone
{ id = 3115, chance = 6388 }, -- bone
{ name = "glacier shoes", chance = 4650 },
{ id = 281, chance = 3582 }, -- giant shimmering pearl (green)
{ name = "small tropical fish", chance = 3582 },
Expand Down
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
6 changes: 3 additions & 3 deletions data/libs/functions/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ function Container:addLoot(loot)
local countToAdd = math.min(remainingCount, stackSize)
local tmpItem = self:addItem(itemId, countToAdd, INDEX_WHEREEVER, FLAG_NOLIMIT)
if not tmpItem then
logger.warn("Container:addLoot: failed to add stackable item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId())
logger.warn("Container:addLoot: failed to add stackable item: {} with id {}, to corpse {} with id {}", ItemType(itemId):getName(), itemId, self:getName(), self:getId())
goto continue
end
remainingCount = remainingCount - countToAdd
end
elseif iType:getCharges() ~= 0 then
local tmpItem = self:addItem(itemId, item.count, INDEX_WHEREEVER, FLAG_NOLIMIT)
if not tmpItem then
logger.warn("Container:addLoot: failed to add charge item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId())
logger.warn("Container:addLoot: failed to add charge item: {} with id {}, to corpse {} with id {}", ItemType(itemId):getName(), itemId, self:getName(), self:getId())
end
else
for i = 1, item.count do
local tmpItem = self:addItem(itemId, 1, INDEX_WHEREEVER, FLAG_NOLIMIT)
if not tmpItem then
logger.warn("Container:addLoot: failed to add item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId())
logger.warn("Container:addLoot: failed to add item: {} with id {}, to corpse {} with id {}", ItemType(itemId):getName(), itemId, self:getName(), self:getId())
goto continue
end

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
1 change: 1 addition & 0 deletions src/lua/functions/items/container_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) {
setItemMetatable(L, -1, item);
} else {
reportErrorFunc(fmt::format("Cannot add item to container, error code: '{}'", getReturnMessage(ret)));
pushBoolean(L, false);
}
return 1;
}
Expand Down

0 comments on commit 51f087a

Please sign in to comment.