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

talents

git-svn-id: http://svn.net-core.org/repos/t-engine4@66 51575b47-30f0-44d4-a5cc-537603b46e54
parent f271282d
No related branches found
No related tags found
No related merge requests found
......@@ -3,82 +3,82 @@ require "engine.class"
--- Handles actors stats
module(..., package.seeall, class.make)
_M.abilities_def = {}
_M.abilities_types_def = {}
_M.talents_def = {}
_M.talents_types_def = {}
--- Defines actor abilities
--- Defines actor talents
-- Static!
function _M:loadDefinition(file)
local f = loadfile(file)
setfenv(f, setmetatable({
DamageType = require("engine.DamageType"),
newAbility = function(t) self:newAbility(t) end,
newAbilityType = function(t) self:newAbilityType(t) end,
newTalent = function(t) self:newTalent(t) end,
newTalentType = function(t) self:newTalentType(t) end,
}, {__index=_G}))
f()
end
--- Defines one ability type(group)
--- Defines one talent type(group)
-- Static!
function _M:newAbilityType(t)
assert(t.name, "no ability type name")
assert(t.type, "no ability type type")
function _M:newTalentType(t)
assert(t.name, "no talent type name")
assert(t.type, "no talent type type")
table.insert(self.abilities_types_def, t)
table.insert(self.talents_types_def, t)
end
--- Defines one ability
--- Defines one talent
-- Static!
function _M:newAbility(t)
assert(t.name, "no ability name")
assert(t.type, "no or unknown ability type")
function _M:newTalent(t)
assert(t.name, "no talent name")
assert(t.type, "no or unknown talent type")
t.short_name = t.short_name or t.name
t.short_name = t.short_name:upper():gsub("[ ]", "_")
t.mana = t.mana or 0
t.stamina = t.stamina or 0
t.mode = t.mode or "activated"
assert(t.mode == "activated" or t.mode == "sustained", "wrong ability mode, requires either 'activated' or 'sustained'")
assert(t.info, "no ability info")
assert(t.mode == "activated" or t.mode == "sustained", "wrong talent mode, requires either 'activated' or 'sustained'")
assert(t.info, "no talent info")
table.insert(self.abilities_def, t)
self["AB_"..t.short_name] = #self.abilities_def
table.insert(self.talents_def, t)
self["T_"..t.short_name] = #self.talents_def
end
--- Initialises stats with default values if needed
function _M:init(t)
self.abilities = t.abilities or {}
self.talents = t.talents or {}
end
--- Make the actor use the ability
function _M:useAbility(id)
local ab = _M.abilities_def[id]
assert(ab, "trying to cast ability "..tostring(id).." but it is not defined")
--- Make the actor use the talent
function _M:useTalent(id)
local ab = _M.talents_def[id]
assert(ab, "trying to cast talent "..tostring(id).." but it is not defined")
if ab.action then
if not self:preUseAbility(ab) then return end
if not self:preUseTalent(ab) then return end
local co = coroutine.create(function()
local ret = ab.action(self)
if not self:postUseAbility(ab, ret) then return end
if not self:postUseTalent(ab, ret) then return end
end)
local ok, err = coroutine.resume(co)
if not ok and err then error(err) end
end
end
--- Called before an ability is used
--- Called before an talent is used
-- Redefine as needed
-- @param ab the ability (not the id, the table)
-- @param ab the talent (not the id, the table)
-- @return true to continue, false to stop
function _M:preUseAbility(ab)
function _M:preUseTalent(ab)
return true
end
--- Called before an ability is used
--- Called before an talent is used
-- Redefine as needed
-- @param ab the ability (not the id, the table)
-- @param ret the return of the ability action
-- @param ab the talent (not the id, the table)
-- @param ret the return of the talent action
-- @return true to continue, false to stop
function _M:postUseAbility(ab, ret)
function _M:postUseTalent(ab, ret)
return true
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