From c709311115669244a748e89d5f4bd7d985c4c284 Mon Sep 17 00:00:00 2001 From: dg <dg@51575b47-30f0-44d4-a5cc-537603b46e54> Date: Wed, 6 Feb 2013 10:04:32 +0000 Subject: [PATCH] Fixed loss of resists/... in some rare conditions when being fed upon Sustained talents can now have a "callbackOnAct" method that gets automatically called each turn when sustained git-svn-id: http://svn.net-core.org/repos/t-engine4@6383 51575b47-30f0-44d4-a5cc-537603b46e54 --- game/modules/tome/class/Actor.lua | 14 +++++ .../tome/data/timed_effects/mental.lua | 57 ++++++++++++------- 2 files changed, 51 insertions(+), 20 deletions(-) diff --git a/game/modules/tome/class/Actor.lua b/game/modules/tome/class/Actor.lua index 310bb52edb..e552196cb1 100644 --- a/game/modules/tome/class/Actor.lua +++ b/game/modules/tome/class/Actor.lua @@ -676,6 +676,12 @@ function _M:act() self.tempeffect_def[self.EFF_PANICKED].do_act(self, self:hasEffect(self.EFF_PANICKED)) end + if self.talents_on_act and next(self.talents_on_act) then + for tid, _ in pairs(self.talents_on_act) do + self:callTalent(tid, "callbackOnAct") + end + end + -- Still enough energy to act ? if self.energy.value < game.energy_to_act then return false end @@ -3723,6 +3729,10 @@ function _M:postUseTalent(ab, ret, silent) if ab.sustain_feedback then trigger = true; self:incMaxFeedback(-ab.sustain_feedback) end + if ab.callbackOnAct then + self.talents_on_act = self.talents_on_act or {} + self.talents_on_act[ab.id] = true + end else if ab.sustain_mana then self:incMaxMana(ab.sustain_mana) @@ -3754,6 +3764,10 @@ function _M:postUseTalent(ab, ret, silent) if ab.sustain_feedback then self:incMaxFeedback(ab.sustain_feedback) end + if ab.callbackOnAct then + self.talents_on_act[ab.id] = nil + if not next(self.talents_on_act) then self.talents_on_act = nil end + end end elseif not self:attr("force_talent_ignore_ressources") then if ab.mana and not self:attr("zero_resource_cost") then diff --git a/game/modules/tome/data/timed_effects/mental.lua b/game/modules/tome/data/timed_effects/mental.lua index 624f135116..f2858f8279 100644 --- a/game/modules/tome/data/timed_effects/mental.lua +++ b/game/modules/tome/data/timed_effects/mental.lua @@ -579,43 +579,30 @@ newEffect{ -- health if eff.constitutionGain and eff.constitutionGain > 0 then - eff.constitutionGainId = self:addTemporaryValue("inc_stats", - { - [Stats.STAT_CON] = eff.constitutionGain, - }) - eff.constitutionLossId = eff.target:addTemporaryValue("inc_stats", - { - [Stats.STAT_CON] = -eff.constitutionGain, - }) + eff.constitutionGainId = self:addTemporaryValue("inc_stats", { [Stats.STAT_CON] = eff.constitutionGain }) end if eff.lifeRegenGain and eff.lifeRegenGain > 0 then eff.lifeRegenGainId = self:addTemporaryValue("life_regen", eff.lifeRegenGain) - eff.lifeRegenLossId = eff.target:addTemporaryValue("life_regen", -eff.lifeRegenGain) end -- power if eff.damageGain and eff.damageGain > 0 then eff.damageGainId = self:addTemporaryValue("inc_damage", {all=eff.damageGain}) - eff.damageLossId = eff.target:addTemporaryValue("inc_damage", {all=eff.damageLoss}) end -- strengths if eff.resistGain and eff.resistGain > 0 then local gainList = {} - local lossList = {} for id, resist in pairs(eff.target.resists) do if resist > 0 and id ~= "all" then - local amount = eff.resistGain * 0.01 * resist - gainList[id] = amount - lossList[id] = -amount + gainList[id] = eff.resistGain * 0.01 * resist end end eff.resistGainId = self:addTemporaryValue("resists", gainList) - eff.resistLossId = eff.target:addTemporaryValue("resists", lossList) end - eff.target:setEffect(eff.target.EFF_FED_UPON, eff.dur, { src = eff.src, target = eff.target }) + eff.target:setEffect(eff.target.EFF_FED_UPON, eff.dur, { src = eff.src, target = eff.target, constitutionLoss = -eff.constitutionGain, lifeRegenLoss = -eff.lifeRegenGain, damageLoss = -eff.damageGain, resistLoss = -eff.resistGain }) end, deactivate = function(self, eff) -- hate @@ -623,17 +610,13 @@ newEffect{ -- health if eff.constitutionGainId then self:removeTemporaryValue("inc_stats", eff.constitutionGainId) end - if eff.constitutionLossId then eff.target:removeTemporaryValue("inc_stats", eff.constitutionLossId) end if eff.lifeRegenGainId then self:removeTemporaryValue("life_regen", eff.lifeRegenGainId) end - if eff.lifeRegenLossId then eff.target:removeTemporaryValue("life_regen", eff.lifeRegenLossId) end -- power if eff.damageGainId then self:removeTemporaryValue("inc_damage", eff.damageGainId) end - if eff.damageLossId then eff.target:removeTemporaryValue("inc_damage", eff.damageLossId) end -- strengths if eff.resistGainId then self:removeTemporaryValue("resists", eff.resistGainId) end - if eff.resistLossId then eff.target:removeTemporaryValue("resists", eff.resistLossId) end if eff.particles then -- remove old particle emitter @@ -684,8 +667,42 @@ newEffect{ no_remove = true, parameters = { }, activate = function(self, eff) + -- health + if eff.constitutionLoss and eff.constitutionLoss < 0 then + eff.constitutionLossId = self:addTemporaryValue("inc_stats", { [Stats.STAT_CON] = eff.constitutionLoss }) + end + if eff.lifeRegenLoss and eff.lifeRegenLoss < 0 then + eff.lifeRegenLossId = self:addTemporaryValue("life_regen", eff.lifeRegenLoss) + end + + -- power + if eff.damageLoss and eff.damageLoss < 0 then + eff.damageLossId = self:addTemporaryValue("inc_damage", {all=eff.damageLoss}) + end + + -- strengths + if eff.resistLoss and eff.resistLoss < 0 then + local lossList = {} + for id, resist in pairs(self.resists) do + if resist > 0 and id ~= "all" then + lossList[id] = eff.resistLoss * 0.01 * resist + end + end + + eff.resistLossId = self:addTemporaryValue("resists", lossList) + end end, deactivate = function(self, eff) + -- health + if eff.constitutionLossId then self:removeTemporaryValue("inc_stats", eff.constitutionLossId) end + if eff.lifeRegenLossId then self:removeTemporaryValue("life_regen", eff.lifeRegenLossId) end + + -- power + if eff.damageLossId then self:removeTemporaryValue("inc_damage", eff.damageLossId) end + + -- strengths + if eff.resistLossId then self:removeTemporaryValue("resists", eff.resistLossId) end + if eff.target == self and eff.src:hasEffect(eff.src.EFF_FEED) then eff.src:removeEffect(eff.src.EFF_FEED) end -- GitLab