Skip to content
Snippets Groups Projects
Commit ea5ab16c authored by Hachem_Muche's avatar Hachem_Muche
Browse files

engine.interface.ActorInventory:initBody may be reapplied to an actor without...

engine.interface.ActorInventory:initBody may be reapplied to an actor without overwriting existing inventories (merges properties)
parent 237d606b
No related branches found
No related tags found
No related merge requests found
......@@ -66,20 +66,22 @@ function _M:init(t)
self:initBody()
end
--- generate inventories according to the body definition table
--- Generate inventories according to the body definition table
-- This creates new inventories or updates existing ones
-- @param self.body = {SLOT_ID = max, ...}
-- @param max = number of slots if number or table of properties (max = , stack_limit = , ..) merged into definition
function _M:initBody()
if self.body then
local def
local long_name, def
for inven, max in pairs(self.body) do
def = self.inven_def[self["INVEN_"..inven]]
assert(def, "inventory slot undefined")
self.inven[self["INVEN_"..inven]] = {worn=def.is_worn, id=self["INVEN_"..inven], name=inven, stack_limit = def.stack_limit}
long_name = "INVEN_"..inven
def = self.inven_def[self[long_name]]
assert(def, "inventory slot undefined: "..inven)
self.inven[self[long_name]] = table.merge(self.inven[self[long_name]] or {}, {worn=def.is_worn, id=self[long_name], name=inven, stack_limit = def.stack_limit})
if type(max) == "table" then
table.merge(self.inven[self["INVEN_"..inven]], max, true)
table.merge(self.inven[self[long_name]], max, true)
else
self.inven[self["INVEN_"..inven]].max = max
self.inven[self[long_name]].max = max
end
end
self.body = nil
......
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