Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
Moved getAreaMonsterTable and getDungeonMonsterTable over from Module:CombatAreas to prevent dependency loop
(Now uses Module:CombatAreas instead of directly pulling from Module:CombatAreas/data)
(Moved getAreaMonsterTable and getDungeonMonsterTable over from Module:CombatAreas to prevent dependency loop)
Line 515: Line 515:


   return result
   return result
end
function p.getAreaMonsterTable(frame)
  local areaName = frame.args ~= nil and frame.args[1] or frame
  local area = Areas.getArea(areaName)
  if area == nil then
    return "ERROR: Could not find an area named "..areaName
  end
  if area.type == 'dungeon' then
    return p.getDungeonMonsterTable(frame)
  end
  local tableTxt = '{| class="wikitable sortable"'
  tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'
  for i, monsterID in pairs(area.monsters) do
    local monster = p.getMonsterByID(monsterID)
    tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster'})
    tableTxt = tableTxt..'||'..p.getMonsterCombatLevel(monster.name)
    tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterHP(monster.name))
    tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterMaxHit(monster.name))
    tableTxt = tableTxt..'||'..p.getMonsterStyleIcon({monster.name, nolink='true'})
  end
  tableTxt = tableTxt..'\r\n|}'
  return tableTxt
end
function p.getDungeonMonsterTable(frame)
  local areaName = frame.args ~= nil and frame.args[1] or frame
  local area = Areas.getArea(areaName)
  if area == nil then
    return "ERROR: Could not find a dungeon named "..areaName
  end
  --For Dungeons, go through and count how many of each monster are in the dungeon first
  local monsterCounts = {}
  for i, monsterID in pairs(area.monsters) do
    if monsterCounts[monsterID] == nil then
      monsterCounts[monsterID] = 1
    else
      monsterCounts[monsterID] = monsterCounts[monsterID] + 1
    end
  end
  local usedMonsters = {}
  local tableTxt = '{| class="wikitable sortable"'
  tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count'
  for i, monsterID in pairs(area.monsters) do
    if not Shared.contains(usedMonsters, monsterID) then
      local monster = p.getMonsterByID(monsterID)
      local name = monster.name
      if monsterID == 51 then name = 'Spider2' end
      tableTxt = tableTxt..'\r\n|-\r\n|'..Icons.Icon({name, type='monster'})
      tableTxt = tableTxt..'||'..p.getMonsterCombatLevel(name)
      tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterHP(name))
      tableTxt = tableTxt..'||'..Shared.formatnum(p.getMonsterMaxHit(name))
      tableTxt = tableTxt..'||'..p.getMonsterStyleIcon({name, nolink='true'})
      tableTxt = tableTxt..'||'..monsterCounts[monsterID]
      table.insert(usedMonsters, monsterID)
    end
  end
  tableTxt = tableTxt..'\r\n|}'
  return tableTxt
end
end




return p
return p