Module:Monsters: Difference between revisions

Updated some references to now call Constants instead of directly hitting Constants.data, added Slayer Tier to the otherMonsterBoxText
(_getMonsterTable: Optimise by using table.concat() instead of repeated string concatenation)
(Updated some references to now call Constants instead of directly hitting Constants.data, added Slayer Tier to the otherMonsterBoxText)
Line 1: Line 1:
local p = {}
local p = {}


local Constants = mw.loadData('Module:Constants/data')
local MonsterData = mw.loadData('Module:Monsters/data')
local MonsterData = mw.loadData('Module:Monsters/data')


local Constants = require('Module:Constants')
local Areas = require('Module:CombatAreas')
local Areas = require('Module:CombatAreas')
local Magic = require('Module:Magic')
local Magic = require('Module:Magic')
Line 103: Line 103:


   local iconText = ''
   local iconText = ''
   if  monster.attackType == Constants.attackType.Melee then
   if  Constants.getCombatStyleName(monster.attackType) == 'Melee' then
     iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})
     iconText = Icons.Icon({'Melee', notext=notext, nolink=nolink})
   elseif monster.attackType == Constants.attackType.Ranged then
   elseif Constants.getCombatStyleName(monster.attackType) == 'Ranged' then
     iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})
     iconText = Icons.Icon({'Ranged', type='skill', notext=notext, nolink=nolink})
   else
   elseif Constants.getCombatStyleName(monster.attackType) == 'Magic' then
     iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})
     iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})
   end
   end
Line 183: Line 183:
   local effAttLvl = 0
   local effAttLvl = 0
   local attBonus = 0
   local attBonus = 0
   if monster.attackType == Constants.attackType.Melee then
   if Constants.getCombatStyleName(monster.attackType) == 'Melee' then
     effAttLvl = monster.attackLevel + 9
     effAttLvl = monster.attackLevel + 9
     attBonus = monster.attackBonus + 64
     attBonus = monster.attackBonus + 64
   elseif monster.attackType == Constants.attackType.Ranged then
   elseif Constants.getCombatStyleName(monster.attackType) == 'Ranged' then
     effAttLvl = monster.rangedLevel + 9
     effAttLvl = monster.rangedLevel + 9
     attBonus = monster.attackBonusRanged + 64
     attBonus = monster.attackBonusRanged + 64
   elseif monster.attackType == Constants.attackType.Magic then
   elseif Constants.getCombatStyleName(monster.attackType) == 'Magic' then
     effAttLvl = monster.magicLevel + 9
     effAttLvl = monster.magicLevel + 9
     attBonus = monster.attackBonusMagic + 64
     attBonus = monster.attackBonusMagic + 64
Line 342: Line 342:
   local effStrLvl = 0
   local effStrLvl = 0
   local strBonus = 0
   local strBonus = 0
   if monster.attackType == Constants.attackType.Melee then
   if Constants.getCombatStyleName(monster.attackType) == 'Melee' then
     effStrLvl = monster.strengthLevel + 9
     effStrLvl = monster.strengthLevel + 9
     strBonus = monster.strengthBonus
     strBonus = monster.strengthBonus
   elseif monster.attackType == Constants.attackType.Ranged then
   elseif Constants.getCombatStyleName(monster.attackType) == 'Ranged' then
     effStrLvl = monster.rangedLevel + 9
     effStrLvl = monster.rangedLevel + 9
     strBonus = monster.strengthBonusRanged
     strBonus = monster.strengthBonusRanged
   elseif monster.attackType == Constants.attackType.Magic then
   elseif Constants.getCombatStyleName(monster.attackType) == 'Magic' then
     local mSpell = nil
     local mSpell = nil
     if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end
     if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end
Line 357: Line 357:
     end
     end
   else
   else
    error('blah')
     return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"
     return "ERROR: This monster has an invalid attack type somehow[[Category:Pages with script errors]]"
   end
   end
Line 387: Line 388:
   local iconText = ''
   local iconText = ''
   local typeText = ''
   local typeText = ''
   if  monster.attackType == Constants.attackType.Melee then
   if  Constants.getCombatStyleName(monster.attackType) == 'Melee' then
     iconText = Icons.Icon({'Melee', notext=true})
     iconText = Icons.Icon({'Melee', notext=true})
     typeText = 'Melee'
     typeText = 'Melee'
   elseif monster.attackType == Constants.attackType.Ranged then
   elseif Constants.getCombatStyleName(monster.attackType) == 'Ranged' then
     iconText = Icons.Icon({'Ranged', type='skill', notext=true})
     iconText = Icons.Icon({'Ranged', type='skill', notext=true})
     typeText = 'Ranged'
     typeText = 'Ranged'
   else
   elseif Constants.getCombatStyleName(monster.attackType) == 'Magic' then
     iconText = Icons.Icon({'Magic', type='skill', notext=true})
     iconText = Icons.Icon({'Magic', type='skill', notext=true})
     typeText = 'Magic'
     typeText = 'Magic'
Line 456: Line 457:
   local result = '[[Category:Monsters]]'
   local result = '[[Category:Monsters]]'


   if monster.attackType == Constants.attackType.Melee then
   if Constants.getCombatStyleName(monster.attackType) == 'Melee' then
     result = result..'[[Category:Melee Monsters]]'
     result = result..'[[Category:Melee Monsters]]'
   elseif monster.attackType == Constants.attackType.Ranged then
   elseif Constants.getCombatStyleName(monster.attackType) == 'Ranged' then
     result = result..'[[Category:Ranged Monsters]]'
     result = result..'[[Category:Ranged Monsters]]'
   elseif monster.attackType == Constants.attackType.Magic then
   elseif Constants.getCombatStyleName(monster.attackType) == 'Magic' then
     result = result..'[[Category:Magic Monsters]]'
     result = result..'[[Category:Magic Monsters]]'
   end
   end
Line 500: Line 501:


   result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")
   result = result.."\r\n|-\r\n|'''Monster Types:''' "..table.concat(monsterTypes, ", ")
  local SlayerTier = 'N/A'
  if not p._isDungeonOnlyMonster(monster) then
    SlayerTier = Constants.getSlayerTierNameByLevel(p._getMonsterCombatLevel(monster))
  end
  result = result.."\r\n|-\r\n|'''Slayer Tier:''' "..SlayerTier


   return result
   return result
Line 686: Line 694:
     local monster = p.getMonsterByID(monsterID)
     local monster = p.getMonsterByID(monsterID)
     tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})
     tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})
     tableTxt = tableTxt..'||'..p.getMonsterCombatLevel(monster.name)
     tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)
     tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterHP(monster.name))
     tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterHP(monster.name))
     tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterMaxHit(monster.name))
     tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterMaxHit(monster.name))
Line 723: Line 731:
       if monsterID ~= 1 then
       if monsterID ~= 1 then
         tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({name, type='monster'})
         tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({name, type='monster'})
         tableTxt = tableTxt..'||'..p.getMonsterCombatLevel(name)
         tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)
         tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterHP(name))
         tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterHP(name))
         tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterMaxHit(name))
         tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterMaxHit(name))
Line 927: Line 935:
   -- Input validation
   -- Input validation
   local tier = frame.args ~= nil and frame.args[1] or frame
   local tier = frame.args ~= nil and frame.args[1] or frame
   local SlayerTiers = Constants.Slayer.Tiers
   local slayerTier = nil
 
   if tier == nil then
   if tier == nil then
     return "ERROR: No tier specified[[Category:Pages with script errors]]"
     return "ERROR: No tier specified[[Category:Pages with script errors]]"
   elseif tonumber(tier) == nil then
   end
     return "ERROR: Tier must be an integer[[Category:Pages with script errors]]"
 
  if tonumber(tier) ~= nil then
     slayerTier = Constants.getSlayerTierByID(tonumber(tier))
   else
   else
     tier = math.floor(tonumber(tier))
     slayerTier = Constants.getSlayerTier(tier)
    local tierCount = Shared.tableCount(SlayerTiers) - 1
  end
    if tier < 0 or tier > tierCount then
 
      return "ERROR: Tier must be between 0 and " .. tierCount..'[[Category:Pages with script errors]]'
  if slayerTier == nil then
    end
    return "ERROR: Invalid slayer tier[[Category:Pages with script errors]]"
    tier = tier + 1
   end
   end


   -- Obtain required tier details
   -- Obtain required tier details
   local minLevel, maxLevel = SlayerTiers[tier].minLevel, SlayerTiers[tier].maxLevel
   local minLevel, maxLevel = slayerTier.minLevel, slayerTier.maxLevel
   if maxLevel < 0 then
   if maxLevel < 0 then
     maxLevel = nil
     maxLevel = nil