Module:Monsters: Difference between revisions

getMonsterBones: Initial implementation; _getMonsterTable: Condense some bits to reduce table width
(Fixed an issue with a fixed typo breaking a different thing)
(getMonsterBones: Initial implementation; _getMonsterTable: Condense some bits to reduce table width)
Line 300: Line 300:


   return p._getMonsterER(monster, style)
   return p._getMonsterER(monster, style)
end
-- Determines if the monster is capable of dropping bones, and returns the bones
-- item if so, or nil otherwise
function p.getMonsterBones(monster)
if monster.bones ~= nil and monster.bones >= 0 then
local boneItem = Items.getItemByID(monster.bones)
if boneItem.prayerPoints == nil then
-- Assume bones without prayer points are shards (from God dungeons),
-- and drop unconditionally
return boneItem
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then
-- Otherwise, bones drop when the monster isn't dungeon exclusive
return boneItem
end
end
end
end


Line 663: Line 679:
   local result = ''
   local result = ''


   if monster.bones ~= nil and monster.bones >= 0 then
   local bones = p.getMonsterBones(monster)
    local bones = Items.getItemByID(monster.bones)
  --Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards
    --Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards
  if bones ~= nil then
    if not p._isDungeonOnlyMonster(monster) or Shared.contains(bones.name, 'Shard') then
    result = result.."'''Always Drops:'''"
      result = result.."'''Always Drops:'''"
    result = result..'\r\n{|class="wikitable"'
      result = result..'\r\n{|class="wikitable"'
    result = result..'\r\n!Item !! Qty'
      result = result..'\r\n!Item !! Qty'
    result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})
      result = result..'\r\n|-\r\n|'..Icons.Icon({bones.name, type='item'})
    result = result..'||'..(monster.boneQty ~= nil and monster.boneQty or 1)..'\r\n'..'|}'
      result = result..'||'..(monster.boneQty ~= nil and monster.boneQty or 1)..'\r\n'..'|}'
    end
   end
   end


Line 792: Line 806:
local dropWt = 0
local dropWt = 0
for i, row in Shared.skpairs(monster.lootTable) do
for i, row in Shared.skpairs(monster.lootTable) do
mw.log(row[2])
local thisItem = Items.getItemByID(row[1])
local thisItem = Items.getItemByID(row[1])
totalWt = totalWt + row[2]
totalWt = totalWt + row[2]
Line 1,106: Line 1,119:
   local totalGP = 0
   local totalGP = 0


   if monster.bones ~= nil and monster.bones >= 0 then
   local bones = p.getMonsterBones(monster)
    local bones = Items.getItemByID(monster.bones)
  if bones ~= nil then
    --Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards
  totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)
    if not p._isDungeonOnlyMonster(monster) or Shared.contains(bones.name, 'Shard') then
      totalGP = totalGP + bones.sellsFor
    end
   end
   end


Line 1,241: Line 1,251:
   table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')
   table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')
   table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))
   table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))
   table.insert(tableParts, '!!Attack Type !!Attack Speed (s) !!Max Hit !!Accuracy ')
   table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')
   table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))
   table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))
   table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))
   table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Ranged', type='skill', notext=true}))
   table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))
   table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Magic', type='skill', notext=true}))
   table.insert(tableParts, '!!Drop Chance !!Coins !!Bones !!Locations')
   table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')


   -- Generate row per monster
   -- Generate row per monster
Line 1,256: Line 1,266:
     local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}
     local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}


    local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
     local gpRange = {0, 0}
     local gpRange = {0, 0}
     if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
     if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
Line 1,263: Line 1,272:
     local gpTxt = nil
     local gpTxt = nil
     if gpRange[1] >= gpRange[2] then
     if gpRange[1] >= gpRange[2] then
       gpTxt = Icons.GP(gpRange[1])
       gpTxt = Shared.formatnum(gpRange[1])
     else
     else
       gpTxt = Icons.GP(gpRange[1], gpRange[2])
       gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])
    end
    local boneTxt = 'None'
    if monster.bones ~= nil and monster.bones >= 0 then
      local bones = Items.getItemByID(monster.bones)
      boneTxt = Icons.Icon({bones.name, type='item', notext=true})
     end
     end
    local bones = p.getMonsterBones(monster)
    local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'


     table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
     table.insert(tableParts, '\r\n|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
Line 1,278: Line 1,284:
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. cmbLevel .. '" |' .. Shared.formatnum(cmbLevel))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. p._getMonsterHP(monster) .. '" |' .. Shared.formatnum(p._getMonsterHP(monster)))
    table.insert(tableParts, '\r\n|style="text-align:center" |' .. p._getMonsterStyleIcon({monster, notext=true}))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))
    table.insert(tableParts, '\r\n|style="text-align:center;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '" |' .. Shared.formatnum(maxHit))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. accR .. '" |' .. Shared.formatnum(accR))
Line 1,285: Line 1,291:
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[2] .. '" |' .. Shared.formatnum(evaR[2]))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[3] .. '" |' .. Shared.formatnum(evaR[3]))
    table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootChance .. '" |' .. lootChance .. '%')
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
     table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
     table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
     table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
     table.insert(tableParts, '\r\n|style="text-align:right;white-space:nowrap" |' .. p._getMonsterAreas(monster, hideDungeons))
     table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
   end
   end