Commit b0ff350fed1922816fdc96588258f86fc5ca6206

Authored by dg
1 parent feac87a0

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
... ... @@ -210,6 +210,25 @@ function _M:postUseTalent(talent, ret)
210 210 return true
211 211 end
212 212
  213 +--- Force a talent to activate without using energy or such
  214 +-- "def" can have a field "ignore_energy" to not consume energy; other parameters can be passed and handled by an overload of this method.
  215 +-- Object activation interface calls this method with an "ignore_ressources" parameter
  216 +function _M:forceUseTalent(t, def)
  217 + local oldpause = game.paused
  218 + local oldenergy = self.energy.value
  219 + if def.ignore_energy then self.energy.value = 10000 end
  220 +
  221 + if def.ignore_ressources then self:attr("force_talent_ignore_ressources", 1) end
  222 + local ret = {self:useTalent(t, def.force_who, def.force_level, def.ignore_cd, def.force_target)}
  223 + if def.ignore_ressources then self:attr("force_talent_ignore_ressources", -1) end
  224 +
  225 + if def.ignore_energy then
  226 + game.paused = oldpause
  227 + self.energy.value = oldenergy
  228 + end
  229 + return unpack(ret)
  230 +end
  231 +
213 232 --- Is the sustained talent activated ?
214 233 function _M:isTalentActive(t_id)
215 234 return self.sustain_talents[t_id]
... ...
... ... @@ -82,7 +82,7 @@ function _M:useObject(who, ...)
82 82 elseif self.use_talent then
83 83 if not self.use_talent.power or self.power >= self.use_talent.power then
84 84 self.power = self.power - self.use_talent.power
85   - return self:useTalent(self.use_talent.id, who, self.use_talent.level, true)
  85 + return self:forceUseTalent(self.use_talent.id, {force_who=who, force_level=self.use_talent.level, ignore_cd=true, ignore_ressources=true})
86 86 else
87 87 if self.power_regen and self.power_regen ~= 0 then
88 88 game.logPlayer(who, "%s is still recharging.", self:getName{no_count=true})
... ...
... ... @@ -1834,7 +1834,9 @@ function _M:preUseTalent(ab, silent, fake)
1834 1834
1835 1835 if not self:enoughEnergy() and not fake then return false end
1836 1836
1837   - if ab.mode == "sustained" then
  1837 + if self:attr("force_talent_ignore_ressources") then
  1838 + -- nothing
  1839 + elseif ab.mode == "sustained" then
1838 1840 if ab.sustain_mana and self.max_mana < ab.sustain_mana and not self:isTalentActive(ab.id) then
1839 1841 if not silent then game.logPlayer(self, "You do not have enough mana to activate %s.", ab.name) end
1840 1842 return false
... ... @@ -1864,6 +1866,7 @@ function _M:preUseTalent(ab, silent, fake)
1864 1866 return false
1865 1867 end
1866 1868 else
  1869 + if ab.mana then print("============ CHECKE MANA", ab.mana, self:getMana(), ab.mana * (100 + 2 * self:combatFatigue()) / 100) end
1867 1870 if ab.mana and self:getMana() < ab.mana * (100 + 2 * self:combatFatigue()) / 100 then
1868 1871 if not silent then game.logPlayer(self, "You do not have enough mana to cast %s.", ab.name) end
1869 1872 return false
... ... @@ -1896,7 +1899,7 @@ function _M:preUseTalent(ab, silent, fake)
1896 1899
1897 1900 -- Equilibrium is special, it has no max, but the higher it is the higher the chance of failure (and loss of the turn)
1898 1901 -- But it is not affected by fatigue
1899   - if (ab.equilibrium or (ab.sustain_equilibrium and not self:isTalentActive(ab.id))) and not fake then
  1902 + 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
1900 1903 -- Fail ? lose energy and 1/10 more equilibrium
1901 1904 if not self:attr("no_equilibrium_fail") and not self:equilibriumChance(ab.equilibrium or ab.sustain_equilibrium) then
1902 1905 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)
1907 1910 end
1908 1911
1909 1912 -- Paradox is special, it has no max, but the higher it is the higher the chance of something bad happening
1910   - if (ab.paradox or (ab.sustain_paradox and not self:isTalentActive(ab.id))) and not fake then
  1913 + 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
1911 1914 -- Check failure first
1912 1915 if not self:attr("no_paradox_fail") and self:paradoxFailChance(ab.paradox or ab.sustain_paradox) and self:getParadox() > 200 then
1913 1916 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)
1999 2002 end
2000 2003
2001 2004 local trigger = false
2002   - if ab.mode == "sustained" then
  2005 + if self:attr("force_talent_ignore_ressources") then
  2006 + -- nothing
  2007 + elseif ab.mode == "sustained" then
2003 2008 if not self:isTalentActive(ab.id) then
2004 2009 if ab.sustain_mana then
2005 2010 trigger = true; self:incMaxMana(-ab.sustain_mana)
... ... @@ -2105,20 +2110,12 @@ end
2105 2110
2106 2111 --- Force a talent to activate without using energy or such
2107 2112 function _M:forceUseTalent(t, def)
2108   - local oldpause = game.paused
2109   - local oldenergy = self.energy.value
2110   - if def.ignore_energy then self.energy.value = 10000 end
2111   -
2112 2113 if def.no_equilibrium_fail then self:attr("no_equilibrium_fail", 1) end
2113 2114 if def.no_paradox_fail then self:attr("no_paradox_fail", 1) end
2114   - self:useTalent(t, nil, def.force_level, def.ignore_cd, def.force_target)
  2115 + local ret = {engine.interface.ActorTalents.forceUseTalent(self, t, def)}
2115 2116 if def.no_equilibrium_fail then self:attr("no_equilibrium_fail", -1) end
2116 2117 if def.no_paradox_fail then self:attr("no_paradox_fail", -1) end
2117   -
2118   - if def.ignore_energy then
2119   - game.paused = oldpause
2120   - self.energy.value = oldenergy
2121   - end
  2118 + return unpack(ret)
2122 2119 end
2123 2120
2124 2121 --- Breaks stealth if active
... ...
... ... @@ -318,7 +318,7 @@ function _M:attackTargetWith(target, weapon, damtype, mult)
318 318 if hitted and not target.dead and weapon.talent_on_hit and next(weapon.talent_on_hit) then
319 319 for tid, data in pairs(weapon.talent_on_hit) do
320 320 if rng.percent(data.chance) then
321   - self:forceUseTalent(tid, {ignore_energy=true, force_target=target, force_level=data.level})
  321 + self:forceUseTalent(tid, {ignore_cd=true, ignore_energy=true, force_target=target, force_level=data.level, ignore_ressources=true})
322 322 end
323 323 end
324 324 end
... ...