From 2e93388b82d494d285207b557ff63d5fcacd753c Mon Sep 17 00:00:00 2001 From: DarkGod <darkgod@net-core.org> Date: Thu, 20 Apr 2017 19:11:10 +0200 Subject: [PATCH] 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" --- game/engines/default/engine/interface/ActorResource.lua | 3 ++- game/modules/tome/class/Actor.lua | 6 ++++-- game/modules/tome/class/Player.lua | 2 +- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/game/engines/default/engine/interface/ActorResource.lua b/game/engines/default/engine/interface/ActorResource.lua index 5876f1c131..d39574d9cb 100644 --- a/game/engines/default/engine/interface/ActorResource.lua +++ b/game/engines/default/engine/interface/ActorResource.lua @@ -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 diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index a2f893a3e2..6440e9d321 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -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 diff --git a/game/modules/tome/class/Player.lua b/game/modules/tome/class/Player.lua index 6edbea35ee..310cc5364e 100644 --- a/game/modules/tome/class/Player.lua +++ b/game/modules/tome/class/Player.lua @@ -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 -- GitLab