Skip to content
Snippets Groups Projects
Commit 18e6cd9d authored by dg's avatar dg
Browse files

fix

git-svn-id: http://svn.net-core.org/repos/t-engine4@98 51575b47-30f0-44d4-a5cc-537603b46e54
parent dd5e50c3
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,83 @@ require "engine.class"
--- Handles actors temporary effects (temporary boost of a stat, ...)
module(..., package.seeall, class.make)
_M.tempeffect_def = {}
--- Defines actor temporary effects
-- Static!
function _M:loadDefinition(file)
local f = loadfile(file)
setfenv(f, setmetatable({
newEffect = function(t) self:newEffect(t) end,
load = function(f) self:loadDefinition(f) end
}, {__index=_G}))
f()
end
--- Defines one effect
-- Static!
function _M:newEffect(t)
assert(t.name, "no effect name")
assert(t.desc, "no effect desc")
assert(t.type, "no effect type")
t.name = t.name:upper()
t.activation = t.activation or function() end
t.deactivation = t.deactivation or function() end
t.parameters = t.parameters or {}
t.type = t.type or "physical"
t.status = t.status or "detrimental"
table.insert(self.tempeffect_def, t)
t.id = #self.tempeffect_def
self["EFF_"..t.name] = #self.tempeffect_def
end
function _M:init(t)
self.tmp = {}
end
--- Counts down timed effects, call from your actors "act" method
--
function _M:timedEffects()
for eff, p in pairs(self.tmp) do
p.dur = p.dur - 1
if p.dur <= 0 then
self.tmp[eff] = nil
if _M.tempeffect_def[eff].on_lose then
local ret = _M.tempeffect_def[eff].on_lose(self, p)
if ret then
game.logSeen(ret)
end
end
else
if _M.tempeffect_def[eff].on_timeout then
_M.tempeffect_def[eff].on_timeout(self, p)
end
end
end
end
--- Sets a timed effect on the actor
-- @param eff_id the effect to set
-- @param p a table containing the effects parameters
function _M:setEffect(eff_id, dur, p)
for k, e in pairs(_M.tempeffect_def[eff_id]).parameters do
if not p[k] then p[k] = e end
end
p.dur = dur
self.tmp[eff_id] = p
if _M.tempeffect_def[eff_id].on_gain then
local ret = _M.tempeffect_def[eff_id].on_gain(self, p)
if ret then
game.logSeen(ret)
end
end
end
--- Check timed effect
-- @param eff_id the effect to check for
-- @return either nil or the parameters table for the effect
function _M:hasEffect(eff_id)
return self.tmp[eff_id]
end
......@@ -43,6 +43,8 @@ function _M:act()
-- Regen resources
self:regenLife()
self:regenResources()
-- Compute timed effects
self:timedEffects()
end
function _M:move(x, y, force)
......
......@@ -3,6 +3,7 @@ local DamageType = require "engine.DamageType"
local ActorStats = require "engine.interface.ActorStats"
local ActorResource = require "engine.interface.ActorResource"
local ActorTalents = require "engine.interface.ActorTalents"
local ActorTemporaryEffects = require "engine.interface.ActorTemporaryEffects"
local ActorAI = require "engine.interface.ActorAI"
local Birther = require "engine.Birther"
......@@ -10,6 +11,8 @@ local Birther = require "engine.Birther"
DamageType:loadDefinition("/data/damage_types.lua")
-- Talents
ActorTalents:loadDefinition("/data/talents.lua")
-- Timed Effects
ActorTemporaryEffects:loadDefinition("/data/timed_effects.lua")
-- Actor resources
ActorResource:defineResource("Mana", "mana", ActorTalents.T_MANA_POOL, "mana_regen", "Mana represents your reserve of magical energies. Each spell cast consumes mana and each sustained spell reduces your maximun mana.")
ActorResource:defineResource("Stamina", "stamina", ActorTalents.T_STAMINA_POOL, "stamina_regen", "Stamina represents your physical fatigue. Each physical ability used reduces it.")
......
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