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

swarms

fix entity inheritance


git-svn-id: http://svn.net-core.org/repos/t-engine4@296 51575b47-30f0-44d4-a5cc-537603b46e54
parent c4bb1f1b
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,7 @@
module(..., package.seeall, class.make)
local next_uid = 1
local entities_load_functions = {}
-- Setup the uids repository as a weak value table, when the entities are no more used anywhere else they disappear from there too
setmetatable(__uids, {__mode="v"})
......@@ -106,7 +107,7 @@ function _M:resolve(t)
for k, e in pairs(t) do
if type(e) == "table" and e.__resolver then
t[k] = resolvers.calc[e.__resolver](e, self)
elseif type(e) == "table" then
elseif type(e) == "table" and not e.__CLASSNAME then
self:resolve(e)
end
end
......@@ -163,10 +164,19 @@ end
-- @param no_default if true then no default values will be assigned
-- @usage MyEntityClass:loadList("/data/my_entities_def.lua")
function _M:loadList(file, no_default, res)
no_default = no_default and true or false
res = res or {}
print("Loading entities file", file)
local f, err = loadfile(file)
local f, err = nil, nil
if entities_load_functions[file] and entities_load_functions[file][no_default] then
print("Loading entities file from memory", file)
f = entities_load_functions[file][no_default]
else
f, err = loadfile(file)
print("Loading entities file from file", file)
entities_load_functions[file] = entities_load_functions[file] or {}
entities_load_functions[file][no_default] = f
end
if err then error(err) end
setfenv(f, setmetatable({
......@@ -176,17 +186,19 @@ function _M:loadList(file, no_default, res)
-- Do we inherit things ?
if t.base then
for k, e in pairs(res[t.base]) do
if not t[k] then
t[k] = e
elseif type(t[k]) == "table" and type(e) == "table" then
copy_recurs(t[k], e)
if k ~= "define_as" then
if not t[k] then
t[k] = e
elseif type(t[k]) == "table" and type(e) == "table" then
copy_recurs(t[k], e)
end
end
end
t.base = nil
end
local e = self.new(t, no_default)
print("loaded", e.name, no_default)
res[#res+1] = e
if t.define_as then res[t.define_as] = e end
end,
......
......@@ -55,9 +55,9 @@ function _M:init(t, no_default)
t.mana_rating = t.mana_rating or 10
t.stamina_rating = t.stamina_rating or 10
t.esp = {range=10}
t.esp = t.esp or {range=10}
t.on_melee_hit = {}
t.on_melee_hit = t.on_melee_hit or {}
-- Resistances
t.resists = t.resists or {}
......
......@@ -76,7 +76,7 @@ function _M:attackTarget(target, damtype, mult, noenergy)
end
-- Barehanded ?
if not speed then
if not speed and self.combat then
local s, h = self:attackTargetWith(target, self.combat, damtype, mult)
speed = math.max(speed or 0, s)
hit = hit or h
......
......@@ -29,6 +29,7 @@ newEntity{ base = "BASE_NPC_SKELETON",
rarity = 4,
max_life = resolvers.rngavg(40,50),
combat_armor = 5, combat_def = 1,
talents = resolvers.talents{ [Talents.T_SUMMON]=1 },
}
newEntity{ base = "BASE_NPC_SKELETON",
......@@ -38,6 +39,7 @@ newEntity{ base = "BASE_NPC_SKELETON",
max_life = resolvers.rngavg(90,100),
combat_armor = 5, combat_def = 1,
talents = resolvers.talents{ [Talents.T_STAMINA_POOL]=1, [Talents.T_STUNNING_BLOW]=1, [Talents.T_DEATH_BLOW]=1 },
ai_state = { talent_in=1, },
}
newEntity{ base = "BASE_NPC_SKELETON",
......
local Talents = require("engine.interface.ActorTalents")
newEntity{
define_as = "BASE_NPC_INSECT",
type = "insect", subtype = "swarms",
display = "I", color=colors.WHITE,
can_multiply = 2,
desc = "Buzzzzzzzzzzzzzzzzzzzzzzzzzzz.",
body = { INVEN = 1 },
autolevel = "warrior",
ai = "dumb_talented_simple", ai_state = { talent_in=1, },
stats = { str=1, dex=20, mag=3, con=1 },
energy = { mod=2 },
combat_armor = 1, combat_def = 10,
}
newEntity{ base = "BASE_NPC_INSECT",
name = "midge swarm", color=colors.UMBER,
desc = "A swarm of midges, they want blood.",
level_range = {1, 25}, exp_worth = 1,
rarity = 4,
max_life = resolvers.rngavg(1,2),
combat = { dam=1, atk=15, apr=20 },
}
newEntity{ base = "BASE_NPC_INSECT",
name = "bee swarm", color=colors.GOLD,
desc = "They buzz at you threateningly, as you have gotten too close to their hive.",
level_range = {2, 25}, exp_worth = 1,
rarity = 4,
max_life = resolvers.rngavg(1,3),
combat = { dam=2, atk=15, apr=20 },
talents = resolvers.talents{ [Talents.T_SPORE_POISON]=1 },
}
newEntity{ base = "BASE_NPC_INSECT",
name = "hornet swarm", color=colors.YELLOW,
desc = "You have intruded on their grounds, they will defend it at all costs.",
level_range = {3, 25}, exp_worth = 1,
rarity = 7,
max_life = resolvers.rngavg(3,5),
combat = { dam=5, atk=15, apr=20 },
talents = resolvers.talents{ [Talents.T_SPORE_POISON]=2 },
}
newEntity{ base = "BASE_NPC_INSECT",
name = "hummerhorn", color=colors.YELLOW,
desc = "A giant buzzing wasp, its stinger drips venom. ",
level_range = {16, 50}, exp_worth = 1,
rarity = 7,
max_life = resolvers.rngavg(5,7),
combat = { dam=10, atk=15, apr=20 },
can_multiply = 4,
talents = resolvers.talents{ [Talents.T_SPORE_POISON]=3 },
}
......@@ -205,3 +205,44 @@ newTalent{
return ([[Bites the target, infecting ti with poison.]])
end,
}
newTalent{
name = "Summon",
type = {"other/other", 1},
cooldown = 4,
range = 20,
action = function(self, t)
local filters = self.summon or {{type=self.type, subtype=self.subtype, number=1, hasxp=true, lastfor=20}}
if #filters == 0 then return end
local filter = rng.table(filters)
for i = 1, filter.number do
-- Find space
local x, y = util.findFreeGrid(self.x, self.y, 10, true, {[Map.ACTOR]=true})
if not x then
game.logPlayer(self, "Not enough space to summon!")
break
end
-- Find an actor with that filter
local m = game.zone:makeEntity(game.level, "actor", filter)
if m then
if not filter.hasxp then m.exp_worth = 0 end
m:resolve()
m.summoner = self
m.summon_time = filter.lastfor
m:move(x, y, true)
game.level:addEntity(m)
m:added()
game.logSeen(self, "%s summons %s!", self.name:capitalize(), m.name)
end
end
return true
end,
info = function(self)
return ([[Summon allies.]])
end,
}
......@@ -89,6 +89,6 @@ newTalent{
require = { stat = { dex=function(level) return 10 + level * 3 end }, },
mode = "passive",
info = function(self, t)
return [[Increases damage with knifes.]]
return [[Increases damage with knives.]]
end,
}
......@@ -118,7 +118,7 @@ newTalent{
return true
end,
info = function(self, t)
return ([[Lashes out a flurry of blows, hiting your target three times with each weapons for %d%% damage.]]):format(100 * (1.8 + self:getTalentLevel(t) / 10))
return ([[Lashes out a flurry of blows, hitting your target three times with each weapons for %d%% damage.]]):format(100 * (1.8 + self:getTalentLevel(t) / 10))
end,
}
......@@ -147,7 +147,7 @@ newTalent{
return true
end,
info = function(self, t)
return ([[Lashes out a flurry of blows, hiting your target three times with each weapons for %d%% damage.]]):format(100 * (1.8 + self:getTalentLevel(t) / 10))
return ([[Lashes out a flurry of blows, hitting your target three times with each weapons for %d%% damage.]]):format(100 * (1.8 + self:getTalentLevel(t) / 10))
end,
}
......
......@@ -2,6 +2,7 @@ load("/data/general/npcs/bear.lua")
load("/data/general/npcs/vermin.lua")
load("/data/general/npcs/wolf.lua")
load("/data/general/npcs/snake.lua")
load("/data/general/npcs/swarm.lua")
local Talents = require("engine.interface.ActorTalents")
......
load("/data/general/npcs/rodent.lua")
load("/data/general/npcs/vermin.lua")
load("/data/general/npcs/molds.lua")
--load("/data/general/npcs/rodent.lua")
--load("/data/general/npcs/vermin.lua")
--load("/data/general/npcs/molds.lua")
load("/data/general/npcs/skeleton.lua")
load("/data/general/npcs/snake.lua")
--load("/data/general/npcs/snake.lua")
local Talents = require("engine.interface.ActorTalents")
......
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