Skip to content
Snippets Groups Projects
Commit 2e93388b authored by DarkGod's avatar DarkGod
Browse files

New resources parameter "switch_direction" to indicate the resource prefers to be lower

Talents that generate resources state "FOO gain: X" instead of "FOO cost: -X"
parent 3e284592
No related branches found
No related tags found
No related merge requests found
......@@ -53,6 +53,7 @@ function _M:defineResource(name, short_name, talent, regen_prop, desc, min, max,
talent = talent,
regen_prop = regen_prop,
invert_values = false, -- resource value decreases as it is consumed by default
switch_direction = false, -- resource value prefers to go to the min instead of max
description = desc,
minname = minname,
maxname = maxname,
......@@ -126,7 +127,7 @@ function _M:init(t)
for i, r in ipairs(_M.resources_def) do
self[r.minname] = t[r.minname] or r.min
self[r.maxname] = t[r.maxname] or r.max
self[r.short_name] = t[r.short_name] or self[r.maxname]
self[r.short_name] = t[r.short_name] or (r.switch_direction and self[r.minname] or self[r.maxname])
if r.regen_prop then
self[r.regen_prop] = t[r.regen_prop] or 0
end
......
......@@ -3311,7 +3311,7 @@ function _M:resetToFull()
self.mana = self:getMaxMana()
end
else
if res_def.invert_values then
if res_def.invert_values or res_def.switch_direction then
self[res_def.short_name] = self:check(res_def.getMinFunction) or self[res_def.short_name] or res_def.min
else
self[res_def.short_name] = self:check(res_def.getMaxFunction) or self[res_def.short_name] or res_def.max
......@@ -5380,6 +5380,7 @@ function _M:postUseTalent(ab, ret, silent)
cost = ab[res_def.sustain_prop]
if cost then
cost = (util.getval(cost, self, ab) or 0)
cost = self:alterTalentCost(ab, res_def.sustain_prop, cost)
if cost ~= 0 then
trigger = true
ret._applied_costs[res_def.short_name] = cost
......@@ -5394,6 +5395,7 @@ function _M:postUseTalent(ab, ret, silent)
cost = ab[res_def.drain_prop]
if cost then
cost = util.getval(cost, self, ab) or 0
cost = self:alterTalentCost(ab, res_def.drain_prop, cost)
if cost ~= 0 then
trigger = true
ret._applied_drains[res_def.short_name] = cost
......@@ -5726,7 +5728,7 @@ function _M:getTalentFullDescription(t, addlevel, config, fake_mastery)
cost = self:alterTalentCost(t, res_def.short_name, cost)
if cost ~= 0 then
cost = cost * (util.getval(res_def.cost_factor, self, t) or 1)
d:add({"color",0x6f,0xff,0x83}, ("%s cost: "):format(res_def.name:capitalize()), res_def.color or {"color",0xff,0xa8,0xa8}, ""..math.round(cost, .1), true)
d:add({"color",0x6f,0xff,0x83}, ("%s %s: "):format(res_def.name:capitalize(), cost >= 0 and "cost" or "gain"), res_def.color or {"color",0xff,0xa8,0xa8}, ""..math.round(math.abs(cost), .1), true)
end
-- list sustain cost
cost = t[res_def.sustain_prop] and util.getval(t[res_def.sustain_prop], self, t) or 0
......
......@@ -1012,7 +1012,7 @@ function _M:restCheck()
-- Check for resources
for res, res_def in ipairs(_M.resources_def) do
if res_def.wait_on_rest and res_def.regen_prop and self:attr(res_def.regen_prop) then
if not res_def.invert_values then
if not res_def.invert_values and not res_def.switch_direction then
if self[res_def.regen_prop] > 0.0001 and self:check(res_def.getFunction) < self:check(res_def.getMaxFunction) then return true end
else
if self[res_def.regen_prop] < -0.0001 and self:check(res_def.getFunction) > self:check(res_def.getMinFunction) then 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