Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
Added what is hopefully a function version of p.getMonsterDrops
(Added p.getMonsterCategories)
(Added what is hopefully a function version of p.getMonsterDrops)
Line 8: Line 8:
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')


function p.getMonster(name)
function p.getMonster(name)
Line 352: Line 353:
     result = result..'[[Category:Monsters with Special Attacks]]'
     result = result..'[[Category:Monsters with Special Attacks]]'
   end
   end
  return result
end
function p.getMonsterDrops(frame)
  local MonsterName = frame.args ~= nil and frame.args[1] or frame
  local monster = p.getMonster(MonsterName)
  if monster == nil then
    return "ERROR: No monster with that name found"
  end
  local result = ''
  if monster.bones ~= nil then
    local bones = Items.getItemByID(monster.bones)
    result = result.."'''Always Drops:'''"
    result = result..'\r\n{|class="wikitable"'
    result = result..'\r\n!Item !! Qty'
    result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})
    result = result..'||'..(monster.boneQty ~= nil and monster.boneQty or 1)..'\r\n'..'|}'
  end
  if monster.lootTable ~= nil then
    local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
    local multiDrop = Shared.tableCount(monster.lootTable) > 1
    local totalWt = 0
    for i, row in pairs(monster.lootTable) do
      totalWt = totalWt + row[2]
    end
    result = result.."'''Loot:'''"
    result = result..'\r\n{|class="wikitable"'
    result = result..'\r\n!Item!!Qty'
    if multiDrop then result = result..'!!Weight' end
    result = result..'!!Chance'
    for i, row in pairs(monster.lootTable) do
      local thisItem = Items.getItemByID(row[1])
      result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})..'||'
      if row[3] > 1 then result = result.. '1 - ' end
      result = result..row[3]
      if multiDrop then result = result..'||'..row[2]  end
      local dropChance = (row[2] / totalWt * lootChance)
      result = result..'||'..Shared.round(dropChance, 2, 0)..'%'
    end
    if multiDrop then
      result = result..'\r\n|-\r\n|colspan="2"|Total:||'..Shared.formatnum(totalWt)..'||'..lootChance..'%'
    end
    result = result..'\r\n|}'
    if monster.dropCoins ~= nil then
      local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])
      if lootChance == 100 then
        result = result.."\r\nThe player will also receive "..gpTxt
      else
        result = result.."\r\nIf loot is received, the player will also receive "..gpTxt
      end
    end
  end
   return result
   return result
end
end


return p
return p