Guest User

Untitled

a guest
Apr 28th, 2013
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 18.39 KB | None | 0 0
  1. function _M:getTalentFullDescription(t, addlevel, config, fake_mastery)
  2.     if not t then return tstring{"no talent"} end
  3.  
  4.     config = config or {}
  5.     local old = self.talents[t.id]
  6.     if config.force_level then
  7.         self.talents[t.id] = config.force_level
  8.     else
  9.         self.talents[t.id] = (self.talents[t.id] or 0) + (addlevel or 0)
  10.     end
  11.  
  12.     local oldmastery = nil
  13.     if fake_mastery then
  14.         self.talents_types_mastery[t.type[1]] = fake_mastery - 1
  15.     end
  16.  
  17.     local d = tstring{}
  18.  
  19.     d:add({"color",0x6f,0xff,0x83}, "Effective talent level: ", {"color",0x00,0xFF,0x00}, ("%.1f"):format(self:getTalentLevel(t)), true)
  20.  
  21.     if not config.ignore_mode then
  22.         if t.mode == "passive" then d:add({"color",0x6f,0xff,0x83}, "Use mode: ", {"color",0x00,0xFF,0x00}, "Passive", true)
  23.         elseif t.mode == "sustained" then d:add({"color",0x6f,0xff,0x83}, "Use mode: ", {"color",0x00,0xFF,0x00}, "Sustained", true)
  24.         else d:add({"color",0x6f,0xff,0x83}, "Use mode: ", {"color",0x00,0xFF,0x00}, "Activated", true)
  25.         end
  26.     end
  27.  
  28.     if config.custom then
  29.         d:merge(config.custom)
  30.         d:add(true)
  31.     end
  32.     if not config.ignore_ressources then
  33.         if t.mana then d:add({"color",0x6f,0xff,0x83}, "Mana cost: ", {"color",0x7f,0xff,0xd4}, ""..(util.getval(t.mana, self, t) * (100 + 2 * self:combatFatigue()) / 100), true) end
  34.         if t.stamina then d:add({"color",0x6f,0xff,0x83}, "Stamina cost: ", {"color",0xff,0xcc,0x80}, ""..(util.getval(t.stamina, self, t) * (100 + self:combatFatigue()) / 100), true) end
  35.         if t.equilibrium then d:add({"color",0x6f,0xff,0x83}, "Equilibrium cost: ", {"color",0x00,0xff,0x74}, ""..(util.getval(t.equilibrium, self, t)), true) end
  36.         if t.vim then d:add({"color",0x6f,0xff,0x83}, "Vim cost: ", {"color",0x88,0x88,0x88}, ""..(util.getval(t.vim, self, t)), true) end
  37.         if t.positive then d:add({"color",0x6f,0xff,0x83}, "Positive energy cost: ", {"color",255, 215, 0}, ""..(util.getval(t.positive, self, t) * (100 + self:combatFatigue()) / 100), true) end
  38.         if t.negative then d:add({"color",0x6f,0xff,0x83}, "Negative energy cost: ", {"color", 127, 127, 127}, ""..(util.getval(t.negative, self, t) * (100 + self:combatFatigue()) / 100), true) end
  39.         if t.hate then d:add({"color",0x6f,0xff,0x83}, "Hate cost:  ", {"color", 127, 127, 127}, ""..(util.getval(t.hate, self, t) * (100 + 2 * self:combatFatigue()) / 100), true) end
  40.         if t.paradox then d:add({"color",0x6f,0xff,0x83}, "Paradox cost: ", {"color",  176, 196, 222}, ("%0.2f"):format(util.getval(t.paradox, self, t) * (1 + (self.paradox / 300))), true) end
  41.         if t.psi then d:add({"color",0x6f,0xff,0x83}, "Psi cost: ", {"color",0x7f,0xff,0xd4}, ""..(util.getval(t.psi, self, t) * (100 + 2 * self:combatFatigue()) / 100), true) end
  42.         if t.feedback then d:add({"color",0x6f,0xff,0x83}, "Feedback cost: ", {"color",0xFF, 0xFF, 0x00}, ""..(util.getval(t.psi, self, t) * (100 + 2 * self:combatFatigue()) / 100), true) end
  43.         if t.fortress_energy then d:add({"color",0x6f,0xff,0x83}, "Fortress Energy cost: ", {"color",0x00,0xff,0xa0}, ""..(t.fortress_energy), true) end
  44.  
  45.         if t.sustain_mana then d:add({"color",0x6f,0xff,0x83}, "Sustain mana cost: ", {"color",0x7f,0xff,0xd4}, ""..(util.getval(t.sustain_mana, self, t)), true) end
  46.         if t.sustain_stamina then d:add({"color",0x6f,0xff,0x83}, "Sustain stamina cost: ", {"color",0xff,0xcc,0x80}, ""..(util.getval(t.sustain_stamina, self, t)), true) end
  47.         if t.sustain_equilibrium then d:add({"color",0x6f,0xff,0x83}, "Sustain equilibrium cost: ", {"color",0x00,0xff,0x74}, ""..(util.getval(t.sustain_equilibrium, self, t)), true) end
  48.         if t.sustain_vim then d:add({"color",0x6f,0xff,0x83}, "Sustain vim cost: ", {"color",0x88,0x88,0x88}, ""..(util.getval(t.sustain_vim, self, t)), true) end
  49.         if t.sustain_positive then d:add({"color",0x6f,0xff,0x83}, "Sustain positive energy cost: ", {"color",255, 215, 0}, ""..(util.getval(t.sustain_positive, self, t)), true) end
  50.         if t.sustain_negative then d:add({"color",0x6f,0xff,0x83}, "Sustain negative energy cost: ", {"color", 127, 127, 127}, ""..(util.getval(t.sustain_negative, self, t)), true) end
  51.         if t.sustain_hate then d:add({"color",0x6f,0xff,0x83}, "Sustain hate cost:  ", {"color", 127, 127, 127}, ""..(util.getval(t.sustain_hate, self, t)), true) end
  52.         if t.sustain_paradox then d:add({"color",0x6f,0xff,0x83}, "Sustain paradox cost: ", {"color",  176, 196, 222}, ("%0.2f"):format(util.getval(t.sustain_paradox, self, t)), true) end
  53.         if t.sustain_psi then d:add({"color",0x6f,0xff,0x83}, "Sustain psi cost: ", {"color",0x7f,0xff,0xd4}, ""..(util.getval(t.sustain_psi, self, t)), true) end
  54.         if t.sustain_feedback then d:add({"color",0x6f,0xff,0x83}, "Sustain feedback cost: ", {"color",0xFF, 0xFF, 0x00}, ""..(util.getval(t.sustain_feedback, self, t)), true) end
  55.  
  56.         self:triggerHook{"Actor:getTalentFullDescription:ressources", str=d, t=t, addlevel=addlevel, config=config, fake_mastery=fake_mastery}
  57.     end
  58.     if t.mode ~= "passive" then
  59.         if self:getTalentRange(t) > 1 then d:add({"color",0x6f,0xff,0x83}, "Range: ", {"color",0xFF,0xFF,0xFF}, ("%0.2f"):format(self:getTalentRange(t)), true)
  60.         else d:add({"color",0x6f,0xff,0x83}, "Range: ", {"color",0xFF,0xFF,0xFF}, "melee/personal", true)
  61.         end
  62.         if not config.ignore_ressources then
  63.             if self:getTalentCooldown(t) then d:add({"color",0x6f,0xff,0x83}, "Cooldown: ", {"color",0xFF,0xFF,0xFF}, ""..self:getTalentCooldown(t), true) end
  64.         end
  65.         local speed = self:getTalentProjectileSpeed(t)
  66.         if speed then d:add({"color",0x6f,0xff,0x83}, "Travel Speed: ", {"color",0xFF,0xFF,0xFF}, ""..(speed * 100).."% of base", true)
  67.         else d:add({"color",0x6f,0xff,0x83}, "Travel Speed: ", {"color",0xFF,0xFF,0xFF}, "instantaneous", true)
  68.         end
  69.         if not config.ignore_use_time then
  70.             local uspeed = "1 turn"
  71.             if t.no_energy and type(t.no_energy) == "boolean" and t.no_energy == true then uspeed = "instant" end
  72.             d:add({"color",0x6f,0xff,0x83}, "Usage Speed: ", {"color",0xFF,0xFF,0xFF}, uspeed, true)
  73.         end
  74.         local is_a = {}
  75.         if t.is_spell then is_a[#is_a+1] = "a spell" end
  76.         if t.is_mind then is_a[#is_a+1] = "a mind power" end
  77.         if t.is_nature then is_a[#is_a+1] = "a nature gift" end
  78.         if t.is_summon then is_a[#is_a+1] = " a summon power" end
  79.         if #is_a > 0 then
  80.             d:add({"color",0x6f,0xff,0x83}, "Is: ", {"color",0xFF,0xFF,0xFF}, table.concatNice(is_a, ", ", " and "), true)
  81.         end
  82.     else
  83.         if not config.ignore_ressources then
  84.             if self:getTalentCooldown(t) then d:add({"color",0x6f,0xff,0x83}, "Cooldown: ", {"color",0xFF,0xFF,0xFF}, ""..self:getTalentCooldown(t), true) end
  85.         end
  86.     end
  87.  
  88.     self:triggerHook{"Actor:getTalentFullDescription", str=d, t=t, addlevel=addlevel, config=config, fake_mastery=fake_mastery}
  89.  
  90.     d:add({"color",0x6f,0xff,0x83}, "Description: ", {"color",0xFF,0xFF,0xFF})
  91.     d:merge(t.info(self, t):toTString():tokenize(" ()[]"))
  92.  
  93.     self.talents[t.id] = old
  94.  
  95.     if fake_mastery then
  96.         self.talents_types_mastery[t.type[1]] = oldmastery
  97.     end
  98.  
  99.     return d
  100. end
  101.  
  102.  
  103. function _M:preUseTalent(ab, silent, fake)
  104.     if self:attr("feared") and (ab.mode ~= "sustained" or not self:isTalentActive(ab.id)) then
  105.         if not silent then game.logSeen(self, "%s is too afraid to use %s.", self.name:capitalize(), ab.name) end
  106.         return false
  107.     end
  108.     -- When silenced you can deactivate spells but not activate them
  109.     if ab.no_silence and self:attr("silence") and (ab.mode ~= "sustained" or not self:isTalentActive(ab.id)) then
  110.         if not silent then game.logSeen(self, "%s is silenced and cannot use %s.", self.name:capitalize(), ab.name) end
  111.         return false
  112.     end
  113.     if ab.is_spell and self:attr("forbid_arcane") and (ab.mode ~= "sustained" or not self:isTalentActive(ab.id)) then
  114.         if not silent then game.logSeen(self, "The spell fizzles.") end
  115.         return false
  116.     end
  117.     -- Nature is forbidden to undead (just wild-gifts for now)
  118.     if ab.is_nature and self:attr("forbid_nature") and (ab.mode ~= "sustained" or not self:isTalentActive(ab.id)) then
  119.         if not silent then game.logSeen(self, "%s is too disconnected from Nature to use %s.", self.name:capitalize(), ab.name) end
  120.         return false
  121.     end
  122.  
  123.     if ab.is_inscription and self.inscription_restrictions and not self.inscription_restrictions[ab.type[1]] then
  124.         if not silent then game.logSeen(self, "%s is unable to use this kind of inscription.", self.name:capitalize()) end
  125.         return false
  126.     end
  127.  
  128.     -- when using unarmed techniques check for weapons and heavy armor
  129.     if ab.is_unarmed and not (ab.mode == "sustained" and self:isTalentActive(ab.id)) then
  130.         -- first check for heavy and massive armor
  131.         if self:hasMassiveArmor() then
  132.             if not silent then game.logSeen(self, "You are too heavily armoured to use this talent.") end
  133.             return false
  134.         -- next make sure we're unarmed
  135.         elseif not self:isUnarmed() then
  136.             if not silent then game.logSeen(self, "You can't use this talent while holding a weapon or shield.") end
  137.             return false
  138.         end
  139.     end
  140.  
  141.  
  142.     if not self:enoughEnergy() and not fake then return false end
  143.  
  144.     if ab.mode == "sustained" then
  145.         if ab.sustain_mana and self.max_mana < util.getval(ab.sustain_mana, self, ab) and not self:isTalentActive(ab.id) then
  146.             if not silent then game.logPlayer(self, "You do not have enough mana to activate %s.", ab.name) end
  147.             return false
  148.         end
  149.         if ab.sustain_stamina and self.max_stamina < util.getval(ab.sustain_stamina, self, ab) and not self:isTalentActive(ab.id) then
  150.             if not silent then game.logPlayer(self, "You do not have enough stamina to activate %s.", ab.name) end
  151.             return false
  152.         end
  153.         if ab.sustain_vim and self.max_vim < util.getval(ab.sustain_vim, self, ab) and not self:isTalentActive(ab.id) then
  154.             if not silent then game.logPlayer(self, "You do not have enough vim to activate %s.", ab.name) end
  155.             return false
  156.         end
  157.         if ab.sustain_positive and self.max_positive < util.getval(ab.sustain_positive, self, ab) and not self:isTalentActive(ab.id) then
  158.             if not silent then game.logPlayer(self, "You do not have enough positive energy to activate %s.", ab.name) end
  159.             return false
  160.         end
  161.         if ab.sustain_negative and self.max_negative < util.getval(ab.sustain_negative, self, ab) and not self:isTalentActive(ab.id) then
  162.             if not silent then game.logPlayer(self, "You do not have enough negative energy to activate %s.", ab.name) end
  163.             return false
  164.         end
  165.         if ab.sustain_hate and self.max_hate < util.getval(ab.sustain_hate, self, ab) and not self:isTalentActive(ab.id) then
  166.             if not silent then game.logPlayer(self, "You do not have enough hate to activate %s.", ab.name) end
  167.             return false
  168.         end
  169.         if ab.sustain_psi and self.max_psi < util.getval(ab.sustain_psi, self, ab) and not self:isTalentActive(ab.id) then
  170.             if not silent then game.logPlayer(self, "You do not have enough energy to activate %s.", ab.name) end
  171.             return false
  172.         end
  173.     elseif not self:attr("force_talent_ignore_ressources") then
  174.         if ab.mana and self:getMana() < util.getval(ab.mana, self, ab) * (100 + 2 * self:combatFatigue()) / 100 then
  175.             if not silent then game.logPlayer(self, "You do not have enough mana to cast %s.", ab.name) end
  176.             return false
  177.         end
  178.         if ab.stamina and self:getStamina() < util.getval(ab.stamina, self, ab) * (100 + self:combatFatigue()) / 100 and (not self:hasEffect(self.EFF_ADRENALINE_SURGE) or self.life < ab.stamina * (100 + self:combatFatigue()) / 100) then
  179.             if not silent then game.logPlayer(self, "You do not have enough stamina to use %s.", ab.name) end
  180.             return false
  181.         end
  182.         if ab.vim and self:getVim() < util.getval(ab.vim, self, ab) and (not self:attr("bloodcasting") or self.life < ab.vim) then
  183.             if not silent then game.logPlayer(self, "You do not have enough vim to use %s.", ab.name) end
  184.             return false
  185.         end
  186.         if ab.positive and self:getPositive() < util.getval(ab.positive, self, ab) * (100 + self:combatFatigue()) / 100 then
  187.             if not silent then game.logPlayer(self, "You do not have enough positive energy to use %s.", ab.name) end
  188.             return false
  189.         end
  190.         if ab.negative and self:getNegative() < util.getval(ab.negative, self, ab) * (100 + self:combatFatigue()) / 100 then
  191.             if not silent then game.logPlayer(self, "You do not have enough negative energy to use %s.", ab.name) end
  192.             return false
  193.         end
  194.         if ab.hate and self:getHate() < util.getval(ab.hate, self, ab) * (100 + self:combatFatigue()) / 100 then
  195.             if not silent then game.logPlayer(self, "You do not have enough hate to use %s.", ab.name) end
  196.             return false
  197.         end
  198.         if ab.psi and self:getPsi() < util.getval(ab.psi, self, ab) * (100 + 2 * self:combatFatigue()) / 100 then
  199.             if not silent then game.logPlayer(self, "You do not have enough energy to use %s.", ab.name) end
  200.             return false
  201.         end
  202.         if ab.feedback and self:getFeedback() < util.getval(ab.feedback, self, ab) * (100 + 2 * self:combatFatigue()) / 100 then
  203.             if not silent then game.logPlayer(self, "You do not have enough feedback to use %s.", ab.name) end
  204.             return false
  205.         end
  206.         if ab.fortress_energy and game:getPlayer(true):hasQuest("shertul-fortress") and game:getPlayer(true):hasQuest("shertul-fortress").shertul_energy < ab.fortress_energy then
  207.             if not silent then game.logPlayer(self, "You do not have enough fortress energy to use %s.", ab.name) end
  208.             return false
  209.         end
  210.     end
  211.  
  212.     -- Equilibrium is special, it has no max, but the higher it is the higher the chance of failure (and loss of the turn)
  213.     -- But it is not affected by fatigue
  214.     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
  215.         -- Fail ? lose energy and 1/10 more equilibrium
  216.         if (not self:attr("no_equilibrium_fail") and (not self:attr("no_equilibrium_summon_fail") or not ab.is_summon)) and not self:equilibriumChance(ab.equilibrium or ab.sustain_equilibrium) then
  217.             if not silent then game.logPlayer(self, "You fail to use %s due to your equilibrium!", ab.name) end
  218.             self:incEquilibrium((ab.equilibrium or ab.sustain_equilibrium) / 10)
  219.             self:useEnergy()
  220.             return false
  221.         end
  222.     end
  223.  
  224.     -- Spells can fail
  225.     if (ab.is_spell and not self:isTalentActive(ab.id)) and not fake and self:attr("spell_failure") then
  226.         if rng.percent(self:attr("spell_failure")) then
  227.             if not silent then game.logSeen(self, "%s's %s has been disrupted by #ORCHID#anti-magic forces#LAST#!", self.name:capitalize(), ab.name) end
  228.             self:useEnergy()
  229.             return false
  230.         end
  231.     end
  232.  
  233.     -- Paradox is special, it has no max, but the higher it is the higher the chance of something bad happening
  234.     if (ab.paradox and ab.paradox > 0 or (ab.sustain_paradox and ab.sustain_paradox > 0 and not self:isTalentActive(ab.id))) and not fake and not self:attr("force_talent_ignore_ressources") then
  235.         -- Check anomalies first since they can reduce paradox, this way paradox is a self correcting resource
  236.         local paradox_scaling = 1 + self.paradox / 300
  237.         if not game.zone.no_anomalies and not self:attr("no_paradox_fail") and self:paradoxAnomalyChance() then
  238.             -- Random anomaly
  239.             local ts = {}
  240.             for id, t in pairs(self.talents_def) do
  241.                 if t.type[1] == "chronomancy/anomalies" then ts[#ts+1] = id end
  242.             end
  243.             if not silent then game.logPlayer(self, "#LIGHT_RED#You lose control and unleash an anomaly!") end
  244.             self:forceUseTalent(rng.table(ts), {ignore_energy=true})
  245.             -- Anomalies correct the timeline and reduce Paradox
  246.             self:incParadox(- (ab.paradox and (ab.paradox * paradox_scaling) or ab.sustain_paradox) * 2)
  247.             game:playSoundNear(self, "talents/distortion")
  248.             self:useEnergy()
  249.             return false
  250.         -- Now check for failure
  251.         elseif not self:attr("no_paradox_fail") and self:paradoxFailChance() and not self:hasEffect(self.EFF_SPACETIME_STABILITY) then
  252.             if not silent then game.logPlayer(self, "#LIGHT_RED#You fail to use %s due to your paradox!", ab.name) end
  253.             self:incParadox(ab.paradox and (ab.paradox * paradox_scaling) or ab.sustain_paradox)
  254.             self:useEnergy()
  255.             game:playSoundNear(self, "talents/dispel")
  256.             return false
  257.         end
  258.     end
  259.  
  260.     if self:triggerHook{"Actor:preUseTalent", t=ab, silent=silent, fale=fake} then
  261.         return false
  262.     end
  263.  
  264.     -- Confused ? lose a turn!
  265.     if self:attr("confused") and (ab.mode ~= "sustained" or not self:isTalentActive(ab.id)) and ab.no_energy ~= true and not fake and not self:attr("force_talent_ignore_ressources") then
  266.         if rng.percent(self:attr("confused")) then
  267.             if not silent then game.logSeen(self, "%s is confused and fails to use %s.", self.name:capitalize(), ab.name) end
  268.             self:useEnergy()
  269.             return false
  270.         end
  271.     end
  272.  
  273.     -- Failure chance?
  274.     if self:attr("talent_fail_chance") and (ab.mode ~= "sustained" or not self:isTalentActive(ab.id)) and ab.no_energy ~= true and not fake and not self:attr("force_talent_ignore_ressources") then
  275.         if rng.percent(self:attr("talent_fail_chance")) then
  276.             if not silent then game.logSeen(self, "%s fails to use %s.", self.name:capitalize(), ab.name) end
  277.             self:useEnergy()
  278.             return false
  279.         end
  280.     end
  281.  
  282.     -- terrified effect
  283.     if self:attr("terrified") and (ab.mode ~= "sustained" or not self:isTalentActive(ab.id)) and ab.no_energy ~= true and not fake and not self:attr("force_talent_ignore_ressources") then
  284.         local eff = self:hasEffect(self.EFF_TERRIFIED)
  285.         if rng.percent(self:attr("terrified")) then
  286.             if not silent then game.logSeen(self, "%s is too terrified to use %s.", self.name:capitalize(), ab.name) end
  287.             self:useEnergy()
  288.             return false
  289.         end
  290.     end
  291.  
  292.     -- Special checks
  293.     if ab.on_pre_use and not (ab.mode == "sustained" and self:isTalentActive(ab.id)) and not ab.on_pre_use(self, ab, silent, fake) then return false end
  294.  
  295.     if self:attr("use_only_arcane") then
  296.         if self:attr("use_only_arcane") >= 2 then if ab.type[1] ~= "spell/arcane" and ab.type[1] ~= "spell/aether" and ab.type[1] ~= "spell/aegis" then return false end
  297.         elseif self:attr("use_only_arcane") >= 1 then if ab.type[1] ~= "spell/arcane" and ab.type[1] ~= "spell/aether" then return false end
  298.         end
  299.     end
  300.  
  301.     -- Cant heal
  302.     if ab.is_heal and (self:attr("no_healing") or ((self.healing_factor or 1) <= 0)) then return false end
  303.     if ab.is_teleport and self:attr("encased_in_ice") then return false end
  304.  
  305.     if not silent then
  306.         -- Allow for silent talents
  307.         if ab.message ~= nil then
  308.             if ab.message then
  309.                 game.logSeen(self, "%s", self:useTalentMessage(ab))
  310.             end
  311.         elseif ab.mode == "sustained" and not self:isTalentActive(ab.id) then
  312.             game.logSeen(self, "%s activates %s.", self.name:capitalize(), ab.name)
  313.         elseif ab.mode == "sustained" and self:isTalentActive(ab.id) then
  314.             game.logSeen(self, "%s deactivates %s.", self.name:capitalize(), ab.name)
  315.         elseif ab.is_spell then
  316.             game.logSeen(self, "%s casts %s.", self.name:capitalize(), ab.name)
  317.         elseif not ab.no_message then
  318.             game.logSeen(self, "%s uses %s.", self.name:capitalize(), ab.name)
  319.         end
  320.     end
  321.  
  322.     return true
  323. end
Advertisement
Add Comment
Please, Sign In to add comment