Guest User

Untitled

a guest
Apr 28th, 2013
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 10.23 KB | None | 0 0
  1. function _M:postUseTalent(ab, ret, silent)
  2.     if not ret then return end
  3.  
  4.     self.changed = true
  5.  
  6.     if self.talent_kind_log then
  7.         if ab.is_spell then self.talent_kind_log.spell = (self.talent_kind_log.spell or 0) + 1 end
  8.         if ab.is_summon then self.talent_kind_log.summon = (self.talent_kind_log.summon or 0) + 1 end
  9.         if ab.is_mind then self.talent_kind_log.mind = (self.talent_kind_log.mind or 0) + 1 end
  10.         if ab.is_nature then self.talent_kind_log.nature = (self.talent_kind_log.nature or 0) + 1 end
  11.     end
  12.  
  13.     -- Handle inscriptions (delay it so it does not affect current inscription)
  14.     game:onTickEnd(function()
  15.         if ab.type[1] == "inscriptions/infusions" then
  16.             self:setEffect(self.EFF_INFUSION_COOLDOWN, 10, {power=1})
  17.             if self:knowTalent(self.T_FUNGAL_BLOOD) then self:triggerTalent(self.T_FUNGAL_BLOOD) end
  18.         elseif ab.type[1] == "inscriptions/runes" then
  19.             self:setEffect(self.EFF_RUNE_COOLDOWN, 10, {power=1})
  20.         elseif ab.type[1] == "inscriptions/taints" then
  21.             self:setEffect(self.EFF_TAINT_COOLDOWN, 10, {power=1})
  22.         end
  23.     end)
  24.  
  25.     if not ab.no_energy then
  26.         if ab.is_spell then
  27.             self:useEnergy(game.energy_to_act * self:combatSpellSpeed())
  28.         elseif ab.is_summon then
  29.             self:useEnergy(game.energy_to_act * self:combatSummonSpeed())
  30.         elseif ab.type[1]:find("^technique/") then
  31.             self:useEnergy(game.energy_to_act * self:combatSpeed())
  32.         elseif ab.is_mind then
  33.             self:useEnergy(game.energy_to_act * self:combatMindSpeed())
  34.         else
  35.             self:useEnergy()
  36.         end
  37.  
  38.         -- Free melee blow
  39.         if ab.is_spell and ab.mode ~= "sustained" and self:knowTalent(self.T_CORRUPTED_STRENGTH) and not self:attr("forbid_corrupted_strength_blow") and not self.turn_procs.corrupted_strength then
  40.             local tgts = {}
  41.             for _, c in pairs(util.adjacentCoords(self.x, self.y)) do
  42.                 local target = game.level.map(c[1], c[2], Map.ACTOR)
  43.                 if target and self:reactionToward(target) < 0 then tgts[#tgts+1] = target end
  44.             end
  45.             if #tgts > 0 then
  46.                 self.turn_procs.corrupted_strength = true
  47.                 DamageType:projectingFor(self, {project_type={talent=self:getTalentFromId(self.T_CORRUPTED_STRENGTH)}})
  48.                 self:attackTarget(rng.table(tgts), DamageType.BLIGHT, self:combatTalentWeaponDamage(self.T_CORRUPTED_STRENGTH, 0.5, 1.1), true)
  49.                 DamageType:projectingFor(self, nil)
  50.             end
  51.         end
  52.     end
  53.  
  54.     local trigger = false
  55.     if ab.mode == "sustained" then
  56.         if not self:isTalentActive(ab.id) then
  57.             if ab.sustain_mana then
  58.                 trigger = true; self:incMaxMana(-util.getval(ab.sustain_mana, self, ab))
  59.             end
  60.             if ab.sustain_stamina then
  61.                 trigger = true; self:incMaxStamina(-util.getval(ab.sustain_stamina, self, ab))
  62.             end
  63.             if ab.sustain_vim then
  64.                 trigger = true; self:incMaxVim(-util.getval(ab.sustain_vim, self, ab))
  65.             end
  66.             if ab.sustain_equilibrium then
  67.                 trigger = true; self:incMinEquilibrium(util.getval(ab.sustain_equilbrium, self, ab))
  68.             end
  69.             if ab.sustain_positive then
  70.                 trigger = true; self:incMaxPositive(-util.getval(ab.sustain_positive, self, ab))
  71.             end
  72.             if ab.sustain_negative then
  73.                 trigger = true; self:incMaxNegative(-util.getval(ab.sustain_negative, self, ab))
  74.             end
  75.             if ab.sustain_hate then
  76.                 trigger = true; self:incMaxHate(-util.getval(ab.sustain_hate, self, ab))
  77.             end
  78.             if ab.sustain_paradox then
  79.                 trigger = true; self:incMinParadox(util.getval(ab.sustain_paradox, self, ab));
  80.             end
  81.             if ab.sustain_psi then
  82.                 trigger = true; self:incMaxPsi(-util.getval(ab.sustain_psi, self, ab))
  83.             end
  84.             if ab.sustain_feedback then
  85.                 trigger = true; self:incMaxFeedback(-util.getval(ab.sustain_feedback, self, ab))
  86.             end
  87.             if ab.callbackOnAct then
  88.                 self.talents_on_act = self.talents_on_act or {}
  89.                 self.talents_on_act[ab.id] = true
  90.             end
  91.             if ab.callbackOnMove then
  92.                 self.talents_on_move = self.talents_on_move or {}
  93.                 self.talents_on_move[ab.id] = true
  94.             end
  95.         else
  96.             if ab.sustain_mana then
  97.                 self:incMaxMana(util.getval(ab.sustain_mana, self, ab))
  98.             end
  99.             if ab.sustain_stamina then
  100.                 self:incMaxStamina(util.getval(ab.sustain_stamina, self, ab))
  101.             end
  102.             if ab.sustain_vim then
  103.                 self:incMaxVim(util.getval(ab.sustain_vim, self, ab))
  104.             end
  105.             if ab.sustain_equilibrium then
  106.                 self:incMinEquilibrium(-util.getval(ab.sustain_equilbrium, self, ab))
  107.             end
  108.             if ab.sustain_positive then
  109.                 self:incMaxPositive(util.getval(ab.sustain_positive, self, ab))
  110.             end
  111.             if ab.sustain_negative then
  112.                 self:incMaxNegative(util.getval(ab.sustain_negative, self, ab))
  113.             end
  114.             if ab.sustain_hate then
  115.                 self:incMaxHate(util.getval(ab.sustain_hate, self, ab))
  116.             end
  117.             if ab.sustain_paradox then
  118.                 self:incMinParadox(-util.getval(ab.sustain_paradox, self, ab));
  119.             end
  120.             if ab.sustain_psi then
  121.                  self:incMaxPsi(util.getval(ab.sustain_psi, self, ab))
  122.             end
  123.             if ab.sustain_feedback then
  124.                 self:incMaxFeedback(util.getval(ab.sustain_feedback, self, ab))
  125.             end
  126.             if ab.callbackOnAct then
  127.                 self.talents_on_act[ab.id] = nil
  128.                 if not next(self.talents_on_act) then self.talents_on_act = nil end
  129.             end
  130.             if ab.callbackOnMove then
  131.                 self.talents_on_move[ab.id] = nil
  132.                 if not next(self.talents_on_move) then self.talents_on_move = nil end
  133.             end
  134.         end
  135.     elseif not self:attr("force_talent_ignore_ressources") then
  136.         if ab.mana and not self:attr("zero_resource_cost") then
  137.             trigger = true; self:incMana(-util.getval(ab.mana, self, ab) * (100 + 2 * self:combatFatigue()) / 100)
  138.         end
  139.         if ab.stamina and not self:attr("zero_resource_cost") then
  140.             trigger = true; self:incStamina(-util.getval(ab.stamina, self, ab) * (100 + self:combatFatigue()) / 100)
  141.         end
  142.         -- Vim is not affected by fatigue
  143.         if ab.vim and not self:attr("zero_resource_cost") then
  144.             trigger = true; self:incVim(-util.getval(ab.vim, self, ab)) self:incEquilibrium(ab.vim * 5)
  145.         end
  146.         if ab.positive and not (self:attr("zero_resource_cost") and ab.positive > 0) then
  147.             trigger = true; self:incPositive(-util.getval(ab.positive, self, ab) * (100 + self:combatFatigue()) / 100)
  148.         end
  149.         if ab.negative and not (self:attr("zero_resource_cost") and ab.negative > 0) then
  150.             trigger = true; self:incNegative(-util.getval(ab.negative, self, ab) * (100 + self:combatFatigue()) / 100)
  151.         end
  152.         if ab.hate and not self:attr("zero_resource_cost") then
  153.             trigger = true; self:incHate(-util.getval(ab.hate, self, ab) * (100 + self:combatFatigue()) / 100)
  154.         end
  155.         -- Equilibrium is not affected by fatigue
  156.         if ab.equilibrium and not self:attr("zero_resource_cost") then
  157.             trigger = true; self:incEquilibrium(util.getval(ab.equilibrium, self, ab))
  158.         end
  159.         -- Paradox is not affected by fatigue but it's cost does increase exponentially
  160.         if ab.paradox and not (self:attr("zero_resource_cost") or game.zone.no_anomalies) then
  161.             trigger = true; self:incParadox(util.getval(ab.paradox, self, ab) * (1 + (self.paradox / 300)))
  162.         end
  163.         if ab.psi and not self:attr("zero_resource_cost") then
  164.             trigger = true; self:incPsi(-util.getval(ab.psi, self, ab) * (100 + 2 * self:combatFatigue()) / 100)
  165.         end
  166.         if ab.feedback and not self:attr("zero_resource_cost") then
  167.             trigger = true; self:incFeedback(-util.getval(ab.feeedback, self, ab) * (100 + 2 * self:combatFatigue()) / 100)
  168.         end
  169.         if ab.fortress_energy and game:getPlayer(true):hasQuest("shertul-fortress") and not self:attr("zero_resource_cost") then
  170.             trigger = true; game:getPlayer(true):hasQuest("shertul-fortress").shertul_energy = game:getPlayer(true):hasQuest("shertul-fortress").shertul_energy - ab.fortress_energy
  171.         end
  172.     end
  173.  
  174.     local hd = {"Actor:postUseTalent", t=ab, ret=ret, trigger=trigger}
  175.     if self:triggerHook(hd) then
  176.         trigger = hd.trigger
  177.     end
  178.  
  179.     if trigger and self:hasEffect(self.EFF_BURNING_HEX) then
  180.         local p = self:hasEffect(self.EFF_BURNING_HEX)
  181.         DamageType:get(DamageType.FIRE).projector(p.src, self.x, self.y, DamageType.FIRE, p.dam)
  182.     end
  183.  
  184.     -- Cancel stealth!
  185.     if ab.id ~= self.T_STEALTH and ab.id ~= self.T_HIDE_IN_PLAIN_SIGHT and not ab.no_break_stealth then self:breakStealth() end
  186.     if ab.id ~= self.T_LIGHTNING_SPEED then self:breakLightningSpeed() end
  187.     if ab.id ~= self.T_GATHER_THE_THREADS and ab.id ~= self.T_SPACETIME_TUNING and ab.is_spell then self:breakChronoSpells() end
  188.     if not ab.no_reload_break then self:breakReloading() end
  189.     self:breakStepUp()
  190.     if not (ab.no_energy or ab.no_break_channel) and not (ab.mode == "sustained" and self:isTalentActive(ab.id)) then self:breakPsionicChannel(ab.id) end
  191.  
  192.     for tid, _ in pairs(self.sustain_talents) do
  193.         local t = self:getTalentFromId(tid)
  194.         if t and t.callbackBreakOnTalent then
  195.             self:callTalent(tid, "callbackBreakOnTalent", ab)
  196.         end
  197.     end
  198.  
  199.     if ab.id ~= self.T_REDUX and self:hasEffect(self.EFF_REDUX) and ab.type[1]:find("^chronomancy/") and ab.mode == "activated" and self:getTalentLevel(self.T_REDUX) >= self:getTalentLevel(ab.id) then
  200.         self:removeEffect(self.EFF_REDUX)
  201.         -- this still consumes energy but works as the talent suggests it does
  202.         self:forceUseTalent(ab.id, {ignore_energy=true, ignore_cd = true})
  203.     end
  204.  
  205.     if not ab.innate and self:hasEffect(self.EFF_RAMPAGE) and ab.id ~= self.T_RAMPAGE and ab.id ~= self.T_SLAM then
  206.         local eff = self:hasEffect(self.EFF_RAMPAGE)
  207.         value = self.tempeffect_def[self.EFF_RAMPAGE].do_postUseTalent(self, eff, value)
  208.     end
  209.  
  210.     if ab.is_summon and ab.is_nature and self:attr("heal_on_nature_summon") then
  211.         local tg = {type="ball", range=0, radius=3,}
  212.         self:project(tg, self.x, self.y, function(px, py)
  213.             local target = game.level.map(px, py, Map.ACTOR)
  214.             if target and self:reactionToward(target) >= 0 then
  215.                 target:heal(self:attr("heal_on_nature_summon"))
  216.             end
  217.         end)
  218.     end
  219.  
  220.     if not ab.innate and self:attr("random_talent_cooldown_on_use") and rng.percent(self:attr("random_talent_cooldown_on_use")) then
  221.         local tids = {}
  222.         for tid, lev in pairs(self.talents) do
  223.             local t = self:getTalentFromId(tid)
  224.             if tid ~= ab.id and t and not self.talents_cd[tid] and t.mode == "activated" and not t.innate then tids[#tids+1] = t end
  225.         end
  226.         for i = 1, self:attr("random_talent_cooldown_on_use_nb") do
  227.             local t = rng.tableRemove(tids)
  228.             if not t then break end
  229.             self.talents_cd[t.id] = self:attr("random_talent_cooldown_on_use_turns")
  230.             game.log("%s talent '%s%s' is disrupted by the mind parasite.", self.name:capitalize(), (t.display_entity and t.display_entity:getDisplayString() or ""), t.name)
  231.         end
  232.     end
  233.  
  234.     return true
  235. end
Advertisement
Add Comment
Please, Sign In to add comment