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

Entity:addTemporaryValue can use "highest" and "lowest" merge algorithms

git-svn-id: http://svn.net-core.org/repos/t-engine4@5064 51575b47-30f0-44d4-a5cc-537603b46e54
parent fb0ea448
No related branches found
No related tags found
No related merge requests found
......@@ -577,6 +577,14 @@ function _M:addTemporaryValue(prop, v, noupdate)
local b = (base[prop] or 1) - 1
b = 1 - (1 - b) * (1 - v)
base[prop] = b + 1
elseif method == "highest" then
base["__thighest_"..prop] = base["__thighest_"..prop] or {}
base["__thighest_"..prop][id] = v
base[prop] = table.max(base["__thighest_"..prop])
elseif method == "lowest" then
base["__tlowest_"..prop] = base["__tlowest_"..prop] or {}
base["__tlowest_"..prop][id] = v
base[prop] = table.min(base["__tlowest_"..prop])
else
base[prop] = (base[prop] or 0) + v
end
......@@ -645,6 +653,16 @@ function _M:removeTemporaryValue(prop, id, noupdate)
local b = base[prop] - 1
b = 1 - (1 - b) / (1 - v)
base[prop] = b + 1
elseif method == "highest" then
base["__thighest_"..prop] = base["__thighest_"..prop] or {}
base["__thighest_"..prop][id] = nil
base[prop] = table.max(base["__thighest_"..prop])
if not next(base["__thighest_"..prop]) then base["__thighest_"..prop] = nil end
elseif method == "lowest" then
base["__tlowest_"..prop] = base["__tlowest_"..prop] or {}
base["__tlowest_"..prop][id] = nil
base[prop] = table.min(base["__tlowest_"..prop])
if not next(base["__tlowest_"..prop]) then base["__tlowest_"..prop] = nil end
else
base[prop] = base[prop] - v
end
......
......@@ -23,6 +23,26 @@ function lpeg.anywhere (p)
return lpeg.P{ p + 1 * lpeg.V(1) }
end
function table.min(t)
local m = nil
for _, v in pairs(t) do
if not m then m = v
else m = math.min(m, v)
end
end
return m
end
function table.max(t)
local m = nil
for _, v in pairs(t) do
if not m then m = v
else m = math.max(m, v)
end
end
return m
end
function table.print(src, offset)
offset = offset or ""
for k, e in pairs(src) do
......@@ -263,6 +283,10 @@ function string.ordinal(number)
return number..suffix
end
function string.trim(str)
return str:gsub("^%s*(.-)%s*$", "%1")
end
function string.a_an(str)
local first = str:sub(1, 1)
if first == "a" or first == "e" or first == "i" or first == "o" or first == "u" or first == "y" then return "an "..str
......
......@@ -73,6 +73,9 @@ _M.temporary_values_conf.movement_speed = "mult0"
_M.temporary_values_conf.combat_physspeed = "mult0"
_M.temporary_values_conf.combat_spellspeed = "mult0"
-- Damage cap takes the lowest
_M.temporary_values_conf.flat_damage_cap = "lowest"
function _M:init(t, no_default)
-- Define some basic combat stats
self.energyBase = 0
......@@ -154,6 +157,9 @@ function _M:init(t, no_default)
t.inc_damage = t.inc_damage or {}
t.inc_damage_actor_type = t.inc_damage_actor_type or {}
t.flat_damage_armor = t.flat_damage_armor or {}
t.flat_damage_cap = t.flat_damage_cap or {}
-- Default regen
t.air_regen = t.air_regen or 3
t.mana_regen = t.mana_regen or 0.5
......@@ -631,14 +637,14 @@ function _M:loadBuildOrder(file)
local line = f:readLine()
if not line then break end
line = line:gsub('[\r\n"]', '')
local split = line:split(',')
local split = line:split(lpeg.S",; \t")
if split[1] == "#Name" then cur = "name"
elseif split[1] == "#Stats" then cur = "stats"
elseif split[1] == "#Talents" then cur = "talents"
elseif split[1] == "#Types" then cur = "types"
else
if cur == "name" then b.name = split[1]
if cur == "name" then b.name = table.concat(split, " "):trim()
elseif cur == "stats" then
b.stats = {}
for i, s in ipairs(split) do if s ~= "" then table.insert(b.stats, s) end end
......
......@@ -191,6 +191,24 @@ setDefaultProjector(function(src, x, y, type, dam, tmp, no_martyr)
dam = t.on_damage(target, t, type, dam)
end
-- Flat damage reduction ("armour")
if target.flat_damage_armor then
local dec = (target.flat_damage_armor.all or 0) + (target.flat_damage_armor[type] or 0)
dam = math.max(0, dam - dec)
print("[PROJECTOR] after flat damage armor", dam)
end
-- Flat damage cap
if target.flat_damage_cap then
local cap = nil
if target.flat_damage_cap.all then cap = target.flat_damage_cap.all end
if target.flat_damage_cap[type] then cap = target.flat_damage_cap[type] end
if cap and cap > 0 then
dam = math.max(math.min(dam, cap), 0)
print("[PROJECTOR] after flat damage cap", dam)
end
end
if src:attr("stunned") then
dam = dam * 0.3
print("[PROJECTOR] stunned dam", dam)
......@@ -254,7 +272,7 @@ setDefaultProjector(function(src, x, y, type, dam, tmp, no_martyr)
if target ~= src and target.attr and target:attr("damage_resonance") and not target:hasEffect(target.EFF_RESONANCE) then
target:setEffect(target.EFF_RESONANCE, 5, {damtype=type, dam=target:attr("damage_resonance_on_hit")})
end
if not target.dead and dam > 0 and type == DamageType.MIND and src and src.knowTalent and src:knowTalent(src.T_MADNESS) then
local t = src:getTalentFromId(src.T_MADNESS)
t.doMadness(target, t, src)
......
......@@ -19,11 +19,11 @@
--[[
Torques
psionic Shield
psionic shield
psychoportation
clear mind
adrenaline rush
mind wave
]]
newEntity{
......
......@@ -22,7 +22,7 @@ Totems
*healing
*cure illness
*cure poisons
thorny skin
*thorny skin
]]
newEntity{
......
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