Module:Monsters: Difference between revisions

getSpecAttackMaxHit: Account for modifiers which adjust the max hit when present in on hit/pre-hit effects or monster passives
(getMonsterAttacks: Include normal attack damage when a special attack deals normal damage, even if the normal attack chance is 0%)
(getSpecAttackMaxHit: Account for modifiers which adjust the max hit when present in on hit/pre-hit effects or monster passives)
Line 343: Line 343:
end
end


function p.getSpecAttackMaxHit(specAttack, normalMaxHit, monsterDR)
function p.getSpecAttackMaxHit(specAttack, normalMaxHit, monster)
local bestHit = 0
local bestHit = 0
local dmgAdjust = { ["percent"] = 100, ["flat"] = 0 }
-- Check effects that apply pre or on hit for damage modifiers
local dmgMods = {
-- List of modifiers which affect damage dealt, and whether they are percentage or flat adjustments
["increasedMaxHitPercent"] = { type = 'percent', mult = 1 },
["increasedMeleeMaxHit"] = { type = 'percent', mult = 1 },
["increasedRangedMaxHit"] = { type = 'percent', mult = 1 },
["increasedMagicMaxHit"] = { type = 'percent', mult = 1 },
["increasedMeleeMaxHitFlat"] = { type = 'flat', mult = 1 },
["increasedRangedMaxHitFlat"] = { type = 'flat', mult = 1 },
["increasedMagicMaxHitFlat"] = { type = 'flat', mult = 1 },
["increasedRage"] = { type = 'percent', mult = 2, maxStacks = 10 }
}
local effectKeys = { 'prehitEffects', 'onhitEffects' }
for i, effectKey in ipairs(effectKeys) do
if type(specAttack[effectKey]) == 'table' then
for j, effect in ipairs(specAttack[effectKey]) do
local countsOnPlayer = (effect.countsOn == nil or effect.countsOn == 'Attacker')
if countsOnPlayer and type(effect.modifiers) == 'table' then
for modName, modMagnitude in pairs(effect.modifiers) do
local mod = dmgMods[modName]
if mod ~= nil then
-- The modifier is one which affects damage dealt
local maxStacks = mod.maxStacks or effect.maxStacks or 1
dmgAdjust[mod.type] = dmgAdjust[mod.type] + modMagnitude * mod.mult * maxStacks
end
end
end
end
end
end
-- Check monster passives for modifiers which affect damage dealt
if monster ~= nil and type(monster.passives) ~= nil then
for i, passiveID in ipairs(monster.passives) do
local passive = p.getPassiveByID(passiveID)
if passive ~= nil and type(passive.modifiers) == 'table' then
for modName, modMagnitude in pairs(passive.modifiers) do
local mod = dmgMods[modName]
if mod ~= nil then
-- The modifier is one which affects damage dealt
local maxStacks = mod.maxStacks or 1
dmgAdjust[mod.type] = dmgAdjust[mod.type] + modMagnitude * mod.mult * maxStacks
end
end
end
end
end
for i, dmg in pairs(specAttack.damage) do
for i, dmg in pairs(specAttack.damage) do
local thisHit = 0
local thisHit = 0
Line 370: Line 418:
thisHit = normalMaxHit * 1.35
thisHit = normalMaxHit * 1.35
elseif dmg.maxRoll == "MaxHitDR" then
elseif dmg.maxRoll == "MaxHitDR" then
local monsterDR = 0
if monster ~= nil then
monsterDR = p._getMonsterStat(monster, 'damageReduction')
end
thisHit = normalMaxHit * dmg.maxPercent * 0.01 * (1 + monsterDR * 0.01)
thisHit = normalMaxHit * dmg.maxPercent * 0.01 * (1 + monsterDR * 0.01)
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then
Line 380: Line 432:
end
end
end
end
return bestHit
return math.floor(bestHit * dmgAdjust.percent / 100) + dmgAdjust.flat
end
end


Line 421: Line 473:
normalChance = normalChance - specAttack.defaultChance
normalChance = normalChance - specAttack.defaultChance
end
end
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit, p._getMonsterStat(monster, 'damageReduction'))
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit, monster)
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end