diff --git a/game/engine/Actor.lua b/game/engine/Actor.lua index baa58b747ab96e4030d3a52b7fcbc242ad66f9bc..6e59f35c0010deeda8a9a9ee3baee01105032060 100644 --- a/game/engine/Actor.lua +++ b/game/engine/Actor.lua @@ -186,10 +186,12 @@ function _M:addTemporaryValue(prop, v, noupdate) if type(v) == "number" then -- Simple addition self[prop] = (self[prop] or 0) + v + self:onTemporaryValueChange(prop, nil, v) print("addTmpVal", prop, v, " :=: ", #t, id) elseif type(v) == "table" then for k, e in pairs(v) do self[prop][k] = (self[prop][k] or 0) + e + self:onTemporaryValueChange(prop, k, e) print("addTmpValTable", prop, k, e, " :=: ", #t, id) if #t == 0 then print("*******************************WARNING") end end @@ -219,10 +221,12 @@ function _M:removeTemporaryValue(prop, id, noupdate) if not noupdate then if type(oldval) == "number" then self[prop] = self[prop] - oldval + self:onTemporaryValueChange(prop, nil, -oldval) print("delTmpVal", prop, oldval) elseif type(oldval) == "table" then for k, e in pairs(oldval) do self[prop][k] = self[prop][k] - e + self:onTemporaryValueChange(prop, k, -e) print("delTmpValTable", prop, k, e) end -- elseif type(oldval) == "boolean" then @@ -232,6 +236,14 @@ function _M:removeTemporaryValue(prop, id, noupdate) end end +--- Called when a temporary value changes (added or deleted) +-- This does nothing by default, you can overload it to react to changes +-- @param prop the property changing +-- @param sub the sub element of the property if it is a table, or nil +-- @param v the value of the change +function _M:onTemporaryValueChange(prop, sub, v) +end + --- Increases/decreases an attribute -- The attributes are just actor properties, but this ensures they are numbers and not booleans -- thus making them compatible with temporary values system diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index d28fdb1e135e8988c7920d6db26624be431966b0..3d556dd7c5d814d31add28e727f8b234d67c5dc6 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -333,6 +333,17 @@ function _M:onStatChange(stat, v) end end +--- Called when a temporary value changes (added or deleted) +-- Takes care to call onStatChange when needed +-- @param prop the property changing +-- @param sub the sub element of the property if it is a table, or nil +-- @param v the value of the change +function _M:onTemporaryValueChange(prop, sub, v) + if prop == "inc_stats" then + self:onStatChange(sub, v) + end +end + function _M:attack(target) self:bumpInto(target) end