Module:Monsters: Difference between revisions

unfortunately lua is being finnicky so i'll have to save this and then test it
(typo fixing)
(unfortunately lua is being finnicky so i'll have to save this and then test it)
Line 583: Line 583:
end
end


function p._getAreaMonsterList(area)
  local monsterList = {}
  for i, monsterID in pairs(area.monsters) do
    local monster = p.getMonsterByID(monsterID)
    table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))
  end
  return table.concat(monsterList, '\r\n')
end
function p._getDungeonMonsterList(area)
  local monsterList = {}
  local lastMonster = nil
  local lastID = -1
  local count = 0
  for i, monsterID in pairs(area.monsters) do
    local monster = p.getMonsterByID(monsterID)
    if monster.id ~= lastID or i == Shared.tableCount(monsterList) then
      if lastMonster ~= nil then
        table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster'})..' x'..count)
      end
      lastMonster = monster
      lastID = monster.id
      count = 1
    else
      count = count + 1
    end
  end
  return table.concat(monsterList, '\r\n')
end
function p.getAreaMonsterList(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._getDungeonMonsterList(area)
  else
    return p._getAreaMonsterList(area)
  end
end


return p
return p