Skip to content
Snippets Groups Projects
Commit 5bfcb7fe authored by DarkGod's avatar DarkGod
Browse files

New set of inventories parsing methods: findInAllWornInventories,...

New set of inventories parsing methods: findInAllWornInventories, findInAllWornInventoriesBy, findInAllWornInventoriesByObject, wornInventoryApplyAll
parent 86cf248c
No related branches found
No related tags found
No related merge requests found
......@@ -666,6 +666,23 @@ function _M:findInAllInventories(name, getname)
end
end
--- Finds an object by name in all the actor's worn (or not) inventories
-- @param worn true to search in worn inventories, false in non worn ones
-- @param name the name to look for
-- @param getname the parameters to pass to getName(), if nil the default is {no_count=true, force_id=true}
-- @return[1] nil if not found
-- @return[2] object
-- @return[2] position
-- @return[2] inven_id
function _M:findInAllWornInventories(worn, name, getname)
for inven_id, inven in pairs(self.inven) do
if (worn and inven.worn) or (not worn and not inven.worn) then
local o, item = self:findInInventory(inven, name, getname)
if o and item then return o, item, inven_id end
end
end
end
--- Finds an object by property in an inventory
-- @param inven the inventory to look into
-- @param prop the property to look for
......@@ -699,6 +716,23 @@ function _M:findInAllInventoriesBy(prop, value)
end
end
--- Finds an object by property in all the actor's worn (or not) inventories
-- @param worn true to search in worn inventories, false in non worn ones
-- @param prop the property to look for
-- @param value the value to look for, can be a function
-- @return[1] nil if not found
-- @return[2] object
-- @return[2] position
-- @return[2] inven_id
function _M:findInAllWornInventoriesBy(worn, prop, value)
for inven_id, inven in pairs(self.inven) do
if (worn and inven.worn) or (not worn and not inven.worn) then
local o, item = self:findInInventoryBy(inven, prop, value)
if o and item then return o, item, inven_id end
end
end
end
--- Finds an object by reference in an inventory
-- @param inven the inventory to look into
-- @param so the object(reference) to look for
......@@ -724,6 +758,22 @@ function _M:findInAllInventoriesByObject(so)
end
end
--- Finds an object by reference in all the actor's worn (or not) inventories
-- @param worn true to search in worn inventories, false in non worn ones
-- @param so the object(reference) to look for
-- @return[1] nil if not found
-- @return[2] object
-- @return[2] position
-- @return[2] inven_id
function _M:findInAllWornInventoriesByObject(worn, so)
for inven_id, inven in pairs(self.inven) do
if (worn and inven.worn) or (not worn and not inven.worn) then
local o, item = self:findInInventoryByObject(inven, so)
if o and item then return o, item, inven_id end
end
end
end
--- Applies fct over all items
-- @param inven the inventory to look into
-- @func fct the function to be called. It will receive three parameters: inven, item, object
......@@ -741,6 +791,17 @@ function _M:inventoryApplyAll(fct)
end
end
--- Applies fct over all items in all worn (or not) inventories
-- @param worn true to search in worn inventories, false in non worn ones
-- @func fct the function to be called. It will receive three parameters: inven, item, object
function _M:wornInventoryApplyAll(worn, fct)
for inven_id, inven in pairs(self.inven) do
if (worn and inven.worn) or (not worn and not inven.worn) then
self:inventoryApply(inven, fct)
end
end
end
--- Empties given inventory and marks items inside as never generated
-- @param inven the inventory to empty
function _M:forgetInven(inven)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment