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

Objects that randomly fire a talent on hit wont check ressource or cooldowns

git-svn-id: http://svn.net-core.org/repos/t-engine4@3341 51575b47-30f0-44d4-a5cc-537603b46e54
parent feac87a0
No related branches found
No related tags found
No related merge requests found
......@@ -210,6 +210,25 @@ function _M:postUseTalent(talent, ret)
return true
end
--- Force a talent to activate without using energy or such
-- "def" can have a field "ignore_energy" to not consume energy; other parameters can be passed and handled by an overload of this method.
-- Object activation interface calls this method with an "ignore_ressources" parameter
function _M:forceUseTalent(t, def)
local oldpause = game.paused
local oldenergy = self.energy.value
if def.ignore_energy then self.energy.value = 10000 end
if def.ignore_ressources then self:attr("force_talent_ignore_ressources", 1) end
local ret = {self:useTalent(t, def.force_who, def.force_level, def.ignore_cd, def.force_target)}
if def.ignore_ressources then self:attr("force_talent_ignore_ressources", -1) end
if def.ignore_energy then
game.paused = oldpause
self.energy.value = oldenergy
end
return unpack(ret)
end
--- Is the sustained talent activated ?
function _M:isTalentActive(t_id)
return self.sustain_talents[t_id]
......
......@@ -82,7 +82,7 @@ function _M:useObject(who, ...)
elseif self.use_talent then
if not self.use_talent.power or self.power >= self.use_talent.power then
self.power = self.power - self.use_talent.power
return self:useTalent(self.use_talent.id, who, self.use_talent.level, true)
return self:forceUseTalent(self.use_talent.id, {force_who=who, force_level=self.use_talent.level, ignore_cd=true, ignore_ressources=true})
else
if self.power_regen and self.power_regen ~= 0 then
game.logPlayer(who, "%s is still recharging.", self:getName{no_count=true})
......
......@@ -1834,7 +1834,9 @@ function _M:preUseTalent(ab, silent, fake)
if not self:enoughEnergy() and not fake then return false end
if ab.mode == "sustained" then
if self:attr("force_talent_ignore_ressources") then
-- nothing
elseif ab.mode == "sustained" then
if ab.sustain_mana and self.max_mana < ab.sustain_mana and not self:isTalentActive(ab.id) then
if not silent then game.logPlayer(self, "You do not have enough mana to activate %s.", ab.name) end
return false
......@@ -1864,6 +1866,7 @@ function _M:preUseTalent(ab, silent, fake)
return false
end
else
if ab.mana then print("============ CHECKE MANA", ab.mana, self:getMana(), ab.mana * (100 + 2 * self:combatFatigue()) / 100) end
if ab.mana and self:getMana() < ab.mana * (100 + 2 * self:combatFatigue()) / 100 then
if not silent then game.logPlayer(self, "You do not have enough mana to cast %s.", ab.name) end
return false
......@@ -1896,7 +1899,7 @@ function _M:preUseTalent(ab, silent, fake)
-- Equilibrium is special, it has no max, but the higher it is the higher the chance of failure (and loss of the turn)
-- But it is not affected by fatigue
if (ab.equilibrium or (ab.sustain_equilibrium and not self:isTalentActive(ab.id))) and not fake then
if (ab.equilibrium or (ab.sustain_equilibrium and not self:isTalentActive(ab.id))) and not fake and not self:attr("force_talent_ignore_ressources") then
-- Fail ? lose energy and 1/10 more equilibrium
if not self:attr("no_equilibrium_fail") and not self:equilibriumChance(ab.equilibrium or ab.sustain_equilibrium) then
if not silent then game.logPlayer(self, "You fail to use %s due to your equilibrium!", ab.name) end
......@@ -1907,7 +1910,7 @@ function _M:preUseTalent(ab, silent, fake)
end
-- Paradox is special, it has no max, but the higher it is the higher the chance of something bad happening
if (ab.paradox or (ab.sustain_paradox and not self:isTalentActive(ab.id))) and not fake then
if (ab.paradox or (ab.sustain_paradox and not self:isTalentActive(ab.id))) and not fake and not self:attr("force_talent_ignore_ressources") then
-- Check failure first
if not self:attr("no_paradox_fail") and self:paradoxFailChance(ab.paradox or ab.sustain_paradox) and self:getParadox() > 200 then
if not silent then game.logPlayer(self, "You fail to use %s due to your paradox!", ab.name) end
......@@ -1999,7 +2002,9 @@ function _M:postUseTalent(ab, ret)
end
local trigger = false
if ab.mode == "sustained" then
if self:attr("force_talent_ignore_ressources") then
-- nothing
elseif ab.mode == "sustained" then
if not self:isTalentActive(ab.id) then
if ab.sustain_mana then
trigger = true; self:incMaxMana(-ab.sustain_mana)
......@@ -2105,20 +2110,12 @@ end
--- Force a talent to activate without using energy or such
function _M:forceUseTalent(t, def)
local oldpause = game.paused
local oldenergy = self.energy.value
if def.ignore_energy then self.energy.value = 10000 end
if def.no_equilibrium_fail then self:attr("no_equilibrium_fail", 1) end
if def.no_paradox_fail then self:attr("no_paradox_fail", 1) end
self:useTalent(t, nil, def.force_level, def.ignore_cd, def.force_target)
local ret = {engine.interface.ActorTalents.forceUseTalent(self, t, def)}
if def.no_equilibrium_fail then self:attr("no_equilibrium_fail", -1) end
if def.no_paradox_fail then self:attr("no_paradox_fail", -1) end
if def.ignore_energy then
game.paused = oldpause
self.energy.value = oldenergy
end
return unpack(ret)
end
--- Breaks stealth if active
......
......@@ -318,7 +318,7 @@ function _M:attackTargetWith(target, weapon, damtype, mult)
if hitted and not target.dead and weapon.talent_on_hit and next(weapon.talent_on_hit) then
for tid, data in pairs(weapon.talent_on_hit) do
if rng.percent(data.chance) then
self:forceUseTalent(tid, {ignore_energy=true, force_target=target, force_level=data.level})
self:forceUseTalent(tid, {ignore_cd=true, ignore_energy=true, force_target=target, force_level=data.level, ignore_ressources=true})
end
end
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