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: container:addLoot warnings #1613

Merged
merged 4 commits into from
Sep 19, 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: 1 addition & 1 deletion data-canary/scripts/actions/other/cask_kegs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local targetIdList = {
local flasks = Action()

function flasks.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target or not player:getTile():getHouse() then
if not target or not target:getItem() then
return false
end

Expand Down
2 changes: 1 addition & 1 deletion data-canary/scripts/actions/other/potions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ local setting = {
local potions = Action()

function potions.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if type(target) == "userdata" and not target:isPlayer() then
if not target or type(target) == "userdata" and not target:isPlayer() then
return false
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ monster.Bestiary = {
monster.health = 4000
monster.maxHealth = 4000
monster.race = "blood"
monster.corpse = 28668
monster.corpse = 28667
monster.speed = 150
monster.manaCost = 0

Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/actions/other/cask_kegs.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ local targetIdList = {
local flasks = Action()

function flasks.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if not target then
if not target or not target:getItem() then
return false
end

Expand Down
2 changes: 1 addition & 1 deletion data-otservbr-global/scripts/actions/other/potions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ local potions = {
local flaskPotion = Action()

function flaskPotion.onUse(player, item, fromPosition, target, toPosition, isHotkey)
if type(target) == "userdata" and not target:isPlayer() then
if not target or type(target) == "userdata" and not target:isPlayer() then
return false
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,21 @@ local function revertHorror()
end

local function changeHorror()
local melting = Tile(Position(32267, 31071, 14)):getTopCreature()
local meltingTile = Tile(Position(32267, 31071, 14))
if not meltingTile then
logger.error("Tile not exist on position '{}'", Position(32267, 31071, 14):toString())
return
end

local meltingCreature = meltingTile:getTopCreature()
local pos = 0
local specs, spec = Game.getSpectators(Position(32269, 31091, 14), false, false, 12, 12, 12, 12)
for i = 1, #specs do
spec = specs[i]
if spec:isMonster() and spec:getName():lower() == "solid frozen horror" then
pos = spec:getPosition()
spec:teleportTo(Position(32267, 31071, 14))
melting:teleportTo(pos)
meltingCreature:teleportTo(pos)
end
end
addEvent(revertHorror, 20 * 1000)
Expand Down
8 changes: 4 additions & 4 deletions data/items/items.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48717,13 +48717,13 @@
<attribute key="fluidsource" value="blood"/>
<attribute key="duration" value="10"/>
<attribute key="decayTo" value="28664"/>
<attribute key="containersize" value="20"/>
<attribute key="containersize" value="32"/>
</item>
<item id="28664" article="a" name="dead true dawnfire asura">
<attribute key="fluidsource" value="blood"/>
<attribute key="duration" value="300"/>
<attribute key="decayTo" value="28665"/>
<attribute key="containersize" value="20"/>
<attribute key="containersize" value="32"/>
</item>
<item id="28665" article="a" name="dead true dawnfire asura">
<attribute key="duration" value="300"/>
Expand All @@ -48738,13 +48738,13 @@
<attribute key="fluidsource" value="blood"/>
<attribute key="duration" value="10"/>
<attribute key="decayTo" value="28668"/>
<attribute key="containersize" value="20"/>
<attribute key="containersize" value="32"/>
</item>
<item id="28668" article="a" name="dead true frost flower asura">
<attribute key="fluidsource" value="blood"/>
<attribute key="duration" value="300"/>
<attribute key="decayTo" value="28669"/>
<attribute key="containersize" value="20"/>
<attribute key="containersize" value="32"/>
</item>
<item id="28669" article="a" name="dead true frost flower asura">
<attribute key="duration" value="300"/>
Expand Down
4 changes: 2 additions & 2 deletions data/libs/functions/container.lua
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ end
function Container:addLoot(loot)
for itemId, item in pairs(loot) do
logger.debug("[Container:addLoot] - Adding loot item id: {} to container id: {}", itemId, self:getId())
local tmpItem = self:addItem(itemId, item.count)
local tmpItem = self:addItem(itemId, item.count, INDEX_WHEREEVER, FLAG_NOLIMIT)
if tmpItem then
if tmpItem:isContainer() and item.childLoot then
if not tmpItem:addLoot(item.childLoot) then
Expand All @@ -32,7 +32,7 @@ function Container:addLoot(loot)
tmpItem:setText(item.text)
end
else
Spdlog.warn(("Container:addLoot: failed to add item: %s"):format(ItemType(itemId):getName()))
logger.warn("Container:addLoot: failed to add item: {}, to corpse {} with id {}", ItemType(itemId):getName(), self:getName(), self:getId())
end

::continue::
Expand Down
5 changes: 5 additions & 0 deletions data/libs/functions/game.lua
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,10 @@ function Game.getStorageValue(key)
end

function Game.setStorageValue(key, value)
if key == nil then
logger.error("[Game.setStorageValue] Key is nil")
return
end

globalStorageTable[key] = value
end
4 changes: 4 additions & 0 deletions src/lua/functions/items/container_functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) {
Container* container = getUserdata<Container>(L, 1);
if (!container) {
lua_pushnil(L);
reportErrorFunc("Container is nullptr");
return 1;
}

Expand All @@ -127,6 +128,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) {
itemId = Item::items.getItemIdByName(getString(L, 2));
if (itemId == 0) {
lua_pushnil(L);
reportErrorFunc("Item id is wrong");
return 1;
}
}
Expand All @@ -140,6 +142,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) {
Item* item = Item::CreateItem(itemId, count);
if (!item) {
lua_pushnil(L);
reportErrorFunc("Item is nullptr");
return 1;
}

Expand All @@ -151,6 +154,7 @@ int ContainerFunctions::luaContainerAddItem(lua_State* L) {
pushUserdata<Item>(L, item);
setItemMetatable(L, -1, item);
} else {
reportErrorFunc(fmt::format("Cannot add item to container, error code: '{}'", getReturnMessage(ret)));
delete item;
lua_pushnil(L);
}
Expand Down
Loading