Re: Ask a simple question, get a simple answer
Posted: Tue Sep 10, 2019 8:37 pm
It should work fine to use a skill/trait onRecomputeStats hook to subtract the appropriate amount for each resistance. Resistances only get clamped to 0-100 at the very end of recomputation, fortunately.
However, calculating the amount to subtract will be a bit annoying: you will absolutely get wrong results if you poll stats from inside an onRecomputeStats hook. The order in which onRecomputeStats hooks are called in each set is undefined. The only way to get correct results with the naive approach of calling getCurrentStat() inside an onRecomputeStats hook is if the onRecomputeStats hook is on a trait and it is your only onRecomputeStats hook on a trait; trait onRecomputeStats hooks are called after item/condition/skill ones.
So your options are:
1. manually account for the effects of all your other onRecomputeStats hooks in your elemental resistance-calculating onRecomputeStats hook.
2. make your elemental resistance-calculating hook your only trait onRecomputeStats hook, moving all the other trait onRecomputeStats hooks' effects into it.
Option 2 is less error-prone, though it's still pretty ugly.
You also need to manually account for leadership (+1 to all stats per hasTrait("leadership") party member that is alive) and nightstalker (+5 vitality when time of day >= 1, -5 vitality otherwise) since those are only applied after all onRecomputeStats hooks are called.
So your trait would look something like this (untested, as usual):And you'd make sure to start every champion with this trait and not have any other onRecomputeStats hooks on traits.
However, calculating the amount to subtract will be a bit annoying: you will absolutely get wrong results if you poll stats from inside an onRecomputeStats hook. The order in which onRecomputeStats hooks are called in each set is undefined. The only way to get correct results with the naive approach of calling getCurrentStat() inside an onRecomputeStats hook is if the onRecomputeStats hook is on a trait and it is your only onRecomputeStats hook on a trait; trait onRecomputeStats hooks are called after item/condition/skill ones.
So your options are:
1. manually account for the effects of all your other onRecomputeStats hooks in your elemental resistance-calculating onRecomputeStats hook.
2. make your elemental resistance-calculating hook your only trait onRecomputeStats hook, moving all the other trait onRecomputeStats hooks' effects into it.
Option 2 is less error-prone, though it's still pretty ugly.
You also need to manually account for leadership (+1 to all stats per hasTrait("leadership") party member that is alive) and nightstalker (+5 vitality when time of day >= 1, -5 vitality otherwise) since those are only applied after all onRecomputeStats hooks are called.
So your trait would look something like this (untested, as usual):
Code: Select all
defineTrait{
name = "resistance_hack",
uiName = "Players shouldn't see this uiName",
icon = 0,
description = "Players shouldn't see this either",
hidden = true,
onRecomputeStats = function(champion, level)
level = champion:getLevel()
if champion:hasTrait("fighter") then
champion:addStatModifier("max_health", 60 + (level-1) * 7)
champion:addStatModifier("max_energy", 30 + (level-1) * 3)
end
if champion:hasTrait("barbarian") then
champion:addStatModifier("strength", level)
champion:addStatModifier("max_health", 80 + (level-1) * 10)
champion:addStatModifier("max_energy", 30 + (level-1) * 3)
end
[...and so on for all the other traits]
local leadershipBonus = 0
for c=1,4 do
local champ = party.party:getChampion(c)
if champ:isAlive() and champ:hasTrait("leadership") then
leadershipBonus = leadershipBonus+1
end
end
local trueStrength = champion:getCurrentStat("strength")+leadershipBonus
local trueDexterity = champion:getCurrentStat("dexterity")+leadershipBonus
local trueVitality = champion:getCurrentStat("vitality")+leadershipBonus
local trueWillpower = champion:getCurrentStat("willpower")+leadershipBonus
if champion:hasTrait("nightstalker") then
trueVitality = trueVitality+(GameMode.getTimeOfDay() >= 1 and 5 or -5)
end
-- Resistances get stat*2-20 added to them, so subtract stat*2-20 here.
champion:addStatModifier("resist_fire", -trueStrength*2+20)
champion:addStatModifier("resist_shock", -trueDexterity*2+20)
champion:addStatModifier("resist_poison", -trueVitality*2+20)
champion:addStatModifier("resist_cold", -trueWillpower*2+20)
end,
}