Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
made p.getMonsterLevel accessible to templates and added damageReduction to monster stats
(fixed passives inexplicably having percentages attached)
(made p.getMonsterLevel accessible to templates and added damageReduction to monster stats)
Line 66: Line 66:
   elseif statName == 'magicEvasionRating' then
   elseif statName == 'magicEvasionRating' then
     return p._getMonsterER(monster, 'Magic')
     return p._getMonsterER(monster, 'Magic')
  elseif statName == 'damageReduction' then
    return p.getEquipmentStat(monster, 'damageReduction')
   end
   end


Line 114: Line 116:


function p._getMonsterHP(monster)
function p._getMonsterHP(monster)
   return 10 * p.getMonsterLevel(monster, 'Hitpoints')
   return 10 * p._getMonsterLevel(monster, 'Hitpoints')
end
end


Line 127: Line 129:
end
end


function p.getMonsterLevel(monster, skillName)
function p._getMonsterLevel(monster, skillName)
   local result = 0
   local result = 0
   if monster.levels[skillName] ~= nil then
   if monster.levels[skillName] ~= nil then
Line 133: Line 135:
   end
   end
   return result
   return result
end
function p.getMonsterLevel(frame)
  local MonsterName = frame.args ~= nil and frame.args[1] or frame[1]
  local SkillName = frame.args ~= nil and frame.args[2] or frame[2]
  local monster = p.getMonster(MonsterName)
  if monster == nil then
    return "ERROR: No monster with that name found[[Category:Pages with script errors]]"
  end
  return p._getMonsterLevel(monster, SkillName)
end
end


Line 172: Line 186:


function p._getMonsterCombatLevel(monster)
function p._getMonsterCombatLevel(monster)
   local base = 0.25 * (p.getMonsterLevel(monster, 'Defence') + p.getMonsterLevel(monster, 'Hitpoints'))
   local base = 0.25 * (p._getMonsterLevel(monster, 'Defence') + p._getMonsterLevel(monster, 'Hitpoints'))
   local melee = 0.325 * (p.getMonsterLevel(monster, 'Attack') + p.getMonsterLevel(monster, 'Strength'))
   local melee = 0.325 * (p._getMonsterLevel(monster, 'Attack') + p._getMonsterLevel(monster, 'Strength'))
   local range = 0.325 * (1.5 * p.getMonsterLevel(monster, 'Ranged'))
   local range = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Ranged'))
   local magic = 0.325 * (1.5 * p.getMonsterLevel(monster, 'Magic'))
   local magic = 0.325 * (1.5 * p._getMonsterLevel(monster, 'Magic'))
   if melee > range and melee > magic then
   if melee > range and melee > magic then
     return math.floor(base + melee)
     return math.floor(base + melee)
Line 200: Line 214:
   local bonus = 0
   local bonus = 0
   if monster.attackType == 'melee' then
   if monster.attackType == 'melee' then
     baseLevel = p.getMonsterLevel(monster, 'Attack')
     baseLevel = p._getMonsterLevel(monster, 'Attack')
     bonus = p.getEquipmentStat(monster, 'stabAttackBonus')
     bonus = p.getEquipmentStat(monster, 'stabAttackBonus')
   elseif monster.attackType == 'ranged' then
   elseif monster.attackType == 'ranged' then
     baseLevel = p.getMonsterLevel(monster, 'Ranged')
     baseLevel = p._getMonsterLevel(monster, 'Ranged')
     bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')
     bonus = p.getEquipmentStat(monster, 'rangedAttackBonus')
   elseif monster.attackType == 'magic' then
   elseif monster.attackType == 'magic' then
     baseLevel = p.getMonsterLevel(monster, 'Magic')
     baseLevel = p._getMonsterLevel(monster, 'Magic')
     bonus = p.getEquipmentStat(monster, 'magicAttackBonus')
     bonus = p.getEquipmentStat(monster, 'magicAttackBonus')
   else
   else
Line 231: Line 245:


   if style == "Melee" then
   if style == "Melee" then
     baseLevel = p.getMonsterLevel(monster, 'Defence')
     baseLevel = p._getMonsterLevel(monster, 'Defence')
     bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')
     bonus = p.getEquipmentStat(monster, 'meleeDefenceBonus')
   elseif style == "Ranged" then
   elseif style == "Ranged" then
     baseLevel = p.getMonsterLevel(monster, 'Defence')
     baseLevel = p._getMonsterLevel(monster, 'Defence')
     bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')
     bonus = p.getEquipmentStat(monster, 'rangedDefenceBonus')
   elseif style == "Magic" then
   elseif style == "Magic" then
     baseLevel = math.floor(p.getMonsterLevel(monster, 'Magic') * 0.7 + p.getMonsterLevel(monster, 'Defence') * 0.3)
     baseLevel = math.floor(p._getMonsterLevel(monster, 'Magic') * 0.7 + p._getMonsterLevel(monster, 'Defence') * 0.3)
     bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')
     bonus = p.getEquipmentStat(monster, 'magicDefenceBonus')
   else
   else
Line 403: Line 417:
   local result = 0
   local result = 0
   if monster.attackType == 'melee' then
   if monster.attackType == 'melee' then
     local baseLevel = p.getMonsterLevel(monster, 'Strength')
     local baseLevel = p._getMonsterLevel(monster, 'Strength')
     local bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')
     local bonus = p.getEquipmentStat(monster, 'meleeStrengthBonus')
     result = p.calculateStandardMaxHit(baseLevel, bonus)
     result = p.calculateStandardMaxHit(baseLevel, bonus)
   elseif monster.attackType == 'ranged' then
   elseif monster.attackType == 'ranged' then
     local baseLevel = p.getMonsterLevel(monster, 'Ranged')
     local baseLevel = p._getMonsterLevel(monster, 'Ranged')
     local bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')
     local bonus = p.getEquipmentStat(monster, 'rangedStrengthBonus')
     result = p.calculateStandardMaxHit(baseLevel, bonus)
     result = p.calculateStandardMaxHit(baseLevel, bonus)
Line 415: Line 429:
        
        
     local bonus = p.getEquipmentStat(monster, 'magicDamageBonus')
     local bonus = p.getEquipmentStat(monster, 'magicDamageBonus')
     local baseLevel = p.getMonsterLevel(monster, 'Magic')
     local baseLevel = p._getMonsterLevel(monster, 'Magic')


     result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))
     result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))