Skip to content
Snippets Groups Projects
Commit 3f950b2d authored by dg's avatar dg
Browse files

Actors can be notified of temporary value changes

Stat increasing objects now correctly affact mana/hp


git-svn-id: http://svn.net-core.org/repos/t-engine4@399 51575b47-30f0-44d4-a5cc-537603b46e54
parent 6da189a8
No related branches found
No related tags found
No related merge requests found
......@@ -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
......
......@@ -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
......
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