Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
_getMonsterMaxHit: Consider curses which may increase damage taken by the player
(Move logic from getSpecAttackMaxHit to _getMonsterMaxHit, as combo effects persist beyond the special attack which grants them)
(_getMonsterMaxHit: Consider curses which may increase damage taken by the player)
Line 412: Line 412:
end
end


local dmgAdjust = { ["percent"] = 100, ["flat"] = 0 }
local dmgAdjust = { ["percent"] = 100, ["flat"] = 0, ["multiplier"] = 100 }
-- Check passives & effects that apply pre or on hit for damage modifiers
-- Check passives & effects that apply pre or on hit for damage modifiers
local dmgMods = {
local dmgMods = {
-- List of modifiers which affect damage dealt, and whether they are percentage or flat adjustments
-- List of modifiers which affect damage dealt, and whether they are percentage or flat adjustments
["increasedDamageTaken"] = { type = 'multiplier', mult = 1 },
["increasedMaxHitPercent"] = { type = 'percent', mult = 1 },
["increasedMaxHitPercent"] = { type = 'percent', mult = 1 },
["increasedMeleeMaxHit"] = { type = 'percent', mult = 1 },
["increasedMeleeMaxHit"] = { type = 'percent', mult = 1 },
Line 447: Line 448:
local normalMaxHit = p._getMonsterBaseMaxHit(monster)
local normalMaxHit = p._getMonsterBaseMaxHit(monster)
local hasActiveBuffSpec = false
local hasActiveBuffSpec = false
local damageMultiplier = 1
if monster.specialAttacks ~= nil then
if monster.specialAttacks ~= nil then
local canStun, canSleep = false, false
local canStun, canSleep = false, false
for i, specAttackID in pairs(monster.specialAttacks) do
for i, specAttackID in pairs(monster.specialAttacks) do
             local specAttack = GameData.getEntityByID('attacks', specAttackID)
             local specAttack = GameData.getEntityByID('attacks', specAttackID)
-- Check for pre or on hit effects for modifiers which affect damage dealt
for i, effectKey in ipairs(effectKeys) do
for i, effectKey in ipairs(effectKeys) do
if type(specAttack[effectKey]) == 'table' then
if type(specAttack[effectKey]) == 'table' then
for j, effect in ipairs(specAttack[effectKey]) do
for j, effect in ipairs(specAttack[effectKey]) do
local countsOnPlayer = (effect.countsOn == nil or effect.countsOn == 'Attacker')
local countsOnPlayer = (effect.countsOn == nil or effect.countsOn == 'Attacker')
if countsOnPlayer and type(effect.modifiers) == 'table' then
if countsOnPlayer then
for modName, modMagnitude in pairs(effect.modifiers) do
-- Check for pre or on hit effects for modifiers which affect damage dealt
local mod = dmgMods[modName]
if type(effect.modifiers) == 'table' then
if mod ~= nil then
for modName, modMagnitude in pairs(effect.modifiers) do
-- The modifier is one which affects damage dealt
local mod = dmgMods[modName]
local maxStacks = mod.maxStacks or effect.maxStacks or 1
if mod ~= nil then
dmgAdjust[mod.type] = dmgAdjust[mod.type] + modMagnitude * mod.mult * maxStacks
-- 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
-- Check for curses which may cause the player to incur additional damage
if effect.effectType == 'Curse' and effect.curse ~= nil then
local curse = Magic.getSpellByID(effect.curse, 'curse')
if type(curse) == 'table' and type(curse.targetModifiers) == 'table' then
for modName, modMagnitude in pairs(curse.targetModifiers) 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
Line 486: Line 502:
end
end


if canSleep and doStuns then damageMultiplier = damageMultiplier * 1.2 end
if canSleep and doStuns then dmgAdjust.multiplier = dmgAdjust.multiplier + 20 end
if canStun and doStuns then damageMultiplier = damageMultiplier * 1.3 end
if canStun and doStuns then dmgAdjust.multiplier = dmgAdjust.multiplier + 30 end
end
end
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant
--Ensure that if the monster never does a normal attack, the normal max hit is irrelevant
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end
if normalChance == 0 and not hasActiveBuffSpec then normalMaxHit = 0 end
local maxHit = math.floor(math.max(specialMaxHit, normalMaxHit) * dmgAdjust.percent / 100) + dmgAdjust.flat
local maxHit = math.floor(math.max(specialMaxHit, normalMaxHit) * dmgAdjust.percent / 100) + dmgAdjust.flat
return math.floor(maxHit * damageMultiplier)
return math.floor(maxHit * dmgAdjust.multiplier / 100)
end
end