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

combat !

git-svn-id: http://svn.net-core.org/repos/t-engine4@24 51575b47-30f0-44d4-a5cc-537603b46e54
parent 0d7bf1e5
No related branches found
No related tags found
No related merge requests found
require "engine.class"
--- Interface to add a bloodyDeath() method to actords
--- Interface to add a bloodyDeath() method to actors
-- When this method is called, the floor or walls around the late actor is covered in blood
module(..., package.seeall, class.make)
......
......@@ -3,8 +3,16 @@ require "engine.Actor"
require "engine.interface.ActorLife"
require "engine.interface.ActorLevel"
require "engine.interface.BloodyDeath"
require "mod.class.interface.Combat"
module(..., package.seeall, class.inherit(engine.Actor, engine.interface.ActorLife, engine.interface.ActorLevel, engine.interface.BloodyDeath))
module(..., package.seeall, class.inherit(
-- a ToME actor is a complex beast it uses may inetrfaces
engine.Actor,
engine.interface.ActorLife,
engine.interface.ActorLevel,
engine.interface.BloodyDeath,
mod.class.interface.Combat
))
function _M:init(t)
engine.Actor.init(self, t)
......@@ -36,3 +44,7 @@ end
function _M:levelup()
end
function _M:attack(target)
self:attackTarget(target)
end
......@@ -8,5 +8,5 @@ function _M:init(t)
end
function _M:act()
self:move(self.x + 1, self.y)
-- self:move(self.x + 1, self.y)
end
......@@ -5,6 +5,8 @@ module(..., package.seeall, class.inherit(mod.class.Actor))
function _M:init(t)
mod.class.Actor.init(self, t)
self.combat = { dam=10, atk=4, apr=2, def=6, armor=4 }
end
function _M:move(x, y, force)
......
require "engine.class"
--- Interface to add ToME combat system
module(..., package.seeall, class.make)
--- Makes the bloody death happen
--[[
The ToME combat system has the following attributes:
- attack power: increases chances to hit against high defence
- defence: increases chances to miss against high attack power
- armor: direct reduction of damage done
- armor penetration: reduction of target's armor
- damage: raw damage done
]]
function _M:attackTarget(target)
local sc = self.combat
local tc = target.combat
if not sc then sc = {dam=0, atk=0, apr=0, def=0, armor=0} end
if not tc then tc = {dam=0, atk=0, apr=0, def=0, armor=0} end
-- Does the blow connect?
local hit = rng.avg(sc.atk * 2 / 3, sc.atk) - tc.def
-- If hit is over 0 it connects, if it is 0 we still have 50% chance
if hit > 0 or (hit == 0 and rng.percent(50)) then
local dam = rng.avg(sc.dam * 2 / 3, sc.dam) - math.max(0, tc.armor - sc.apr)
game.logSeen(target, "%s hits %s for #aaaaaa#%0.2f physical damage#ffffff#.", self.name:capitalize(), target.name, dam)
target:takeHit(dam, self)
else
game.logSeen(target, "%s misses %s.", self.name:capitalize(), target.name)
end
end
......@@ -8,6 +8,7 @@ return {
mana = 1000,
energy = { mod=0.8 },
has_blood = true,
combat = { dam=8, atk=10, apr=2, def=4, armor=6},
},
{
name = "baby dragon",
......@@ -17,6 +18,7 @@ return {
mana = 1000,
energy = { mod=0.3 },
has_blood = true,
combat = { dam=5, atk=6, def=2, apr=1, armor=2},
},
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ return {
level_npcs = {5, 10},
generator = {
map = {
class= "engine.generator.map.Rooms",
class= "engine.generator.map.Empty",
floor = "FLOOR",
wall = "WALL",
up = "UP",
......
......@@ -419,6 +419,20 @@ static int rng_range(lua_State *L)
return 1;
}
static int rng_avg(lua_State *L)
{
int x = luaL_checknumber(L, 1);
int y = luaL_checknumber(L, 2);
int nb = 2;
double res = 0;
int i;
if (lua_isnumber(L, 3)) nb = luaL_checknumber(L, 3);
for (i = 0; i < nb; i++)
res += x + rand_div(1 + y - x);
lua_pushnumber(L, res / nb);
return 1;
}
static int rng_call(lua_State *L)
{
int x = luaL_checknumber(L, 1);
......@@ -462,6 +476,7 @@ static const struct luaL_reg rnglib[] =
{
{"__call", rng_call},
{"range", rng_range},
{"avg", rng_avg},
{"dice", rng_dice},
{"seed", rng_seed},
{"chance", rng_chance},
......
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