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

first ability is working !

git-svn-id: http://svn.net-core.org/repos/t-engine4@54 51575b47-30f0-44d4-a5cc-537603b46e54
parent 7f6144c6
No related branches found
No related tags found
No related merge requests found
require "engine.class"
--- Handles actors stats
module(..., package.seeall, class.make)
_M.dam_def = {}
-- Default damage projector
function _M.defaultProject(x, y, type, dam)
print("implement a projector!")
end
--- Defines new damage type
-- Static!
function _M:loadDefinition(file)
local f = loadfile(file)
setfenv(f, setmetatable({
DamageType = _M,
Map = require("engine.Map"),
defaultProjector = function(fct) self.defaultProjector = fct end,
newDamageType = function(t) self:newDamageType(t) end,
}, {__index=_G}))
f()
end
--- Defines one ability type(group)
-- Static!
function _M:newDamageType(t)
assert(t.name, "no ability type name")
assert(t.type, "no ability type type")
t.type = t.type:upper()
t.projector = t.projector or self.defaultProjector
table.insert(self.dam_def, t)
self[t.type] = #self.dam_def
end
function _M:get(id)
assert(_M.dam_def[id], "damage type "..id.." used but undefined")
return _M.dam_def[id]
end
......@@ -10,10 +10,11 @@ _M.abilities_types_def = {}
-- Static!
function _M:loadDefinition(file)
local f = loadfile(file)
setfenv(f, {
setfenv(f, setmetatable({
DamageType = require("engine.DamageType"),
newAbility = function(t) self:newAbility(t) end,
newAbilityType = function(t) self:newAbilityType(t) end,
})
}, {__index=_G}))
f()
end
......@@ -22,6 +23,8 @@ end
function _M:newAbilityType(t)
assert(t.name, "no ability type name")
assert(t.type, "no ability type type")
table.insert(self.abilities_types_def, t)
end
--- Defines one ability
......@@ -36,9 +39,22 @@ function _M:newAbility(t)
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")
table.insert(self.abilities_def, t)
self["AB_"..t.short_name] = #self.abilities_def
end
--- Initialises stats with default values if needed
function _M:init(t)
self.abilities = t.abilities 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")
if ab.action then
ab.action(self)
end
end
......@@ -7,6 +7,7 @@ local DebugConsole = require "engine.DebugConsole"
local Tooltip = require "engine.Tooltip"
local QuitDialog = require "mod.dialogs.Quit"
local Calendar = require "engine.Calendar"
local DamageType = require "engine.DamageType"
local Zone = require "engine.Zone"
local Map = require "engine.Map"
local Target = require "engine.Target"
......@@ -28,6 +29,8 @@ function _M:init()
end
function _M:run()
-- Damage types
DamageType:loadDefinition("/data/damage_types.lua")
-- Actor stats
ActorStats:defineStat("Strength", "str", 10, 1, 100)
ActorStats:defineStat("Dexterity", "dex", 10, 1, 100)
......@@ -35,6 +38,7 @@ function _M:run()
ActorStats:defineStat("Willpower", "wil", 10, 1, 100)
ActorStats:defineStat("Cunning", "cun", 10, 1, 100)
ActorStats:defineStat("Constitution", "con", 10, 1, 100)
-- Abilities
ActorAbilities:loadDefinition("/data/abilities.lua")
self.log = engine.LogDisplay.new(0, self.h * 0.80, self.w * 0.5, self.h * 0.20, nil, nil, nil, {255,255,255}, {30,30,30})
......@@ -154,9 +158,22 @@ function _M:targetMode(v, msg)
end
end
function _M:getTarget()
if self.target.target.entity then
return self.target.target.entity.x, self.target.target.entity.y
else
return self.target.target.x, self.target.target.y
end
end
function _M:setupCommands()
self.key:addCommands
{
-- ability test
_a = function()
self.player:useAbility(ActorAbilities.AB_MANATHRUST)
end,
_LEFT = function()
if self.player:move(self.player.x - 1, self.player.y) then
self.paused = false
......@@ -343,6 +360,8 @@ end
--- Ask if we realy want to close, if so, save the game first
function _M:onQuit()
-- HACK for quick test
os.exit()
if not self.quit_dialog then
self.quit_dialog = QuitDialog.new()
self:registerDialog(self.quit_dialog)
......
require "engine.class"
local DamageType = require "engine.DamageType"
local Map = require "engine.Map"
--- Interface to add ToME combat system
......@@ -55,3 +56,10 @@ function _M:attackTarget(target)
game.logSeen(target, "%s misses %s.", self.name:capitalize(), target.name)
end
end
--- Project damage to a distance
function _M:project(x, y, type, dam)
if dam < 0 then return end
DamageType:get(type).projector(self, x, y, type, dam)
end
......@@ -8,13 +8,13 @@ newAbility{
tactical = {
ATTACK = 10,
},
action = function(user)
user:project(game.target.x, game.target.y, Damages.MANA, 10 + user:getMag())
action = function(self)
self:project(game.target.target.x, game.target.target.y, DamageType.MANA, 10 + self:getMag())
return true
end,
require = { stat = { mag=12 }, },
info = function(user)
info = function(self)
return ([[Conjures up mana into a powerful bolt doing %d",
The damage is irresistible and will increase with magic stat]]):format(10 + user:getMag())
The damage is irresistible and will increase with magic stat]]):format(10 + self:getMag())
end
}
-- The basic stuff used to damage a grid
defaultProjector(function(src, x, y, type, dam)
print(src, x, y, type, dam)
local target = game.level.map(x, y, Map.ACTOR)
if target then
game.logSeen(target, "%s hits %s for #aaaaaa#%0.2f %s damage#ffffff#.", src.name:capitalize(), target.name, dam, DamageType:get(type).name)
target:takeHit(dam, src)
end
end)
newDamageType{
name = "mana", type = "MANA",
}
newDamageType{
name = "fire", type = "FIRE",
}
newDamageType{
name = "cold", type = "COLD",
}
newDamageType{
name = "nature", type = "NATURE",
}
newDamageType{
name = "lightning", type = "LIGHTNING",
}
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