Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
11,583 bytes added ,  20 November 2022
Fix (another) user export table
(Fixed MattMonsterTable)
(Fix (another) user export table)
(43 intermediate revisions by 4 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local MonsterData = mw.loadData('Module:Monsters/data')


local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Areas = require('Module:CombatAreas')
local Areas = require('Module:CombatAreas')
local Magic = require('Module:Magic')
local Magic = require('Module:Magic')
local Shared = require('Module:Shared')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Items = require('Module:Items')


function p.getMonster(name)
function p.getMonster(name)
local result = nil
    return GameData.getEntityByName('monsters', name)
if name == 'Spider (lv. 51)' or name == 'Spider' then
return p.getMonsterByID(50)
elseif name == 'Spider (lv. 52)' or name == 'Spider2' then
return p.getMonsterByID(51)
end
 
for i, monster in pairs(MonsterData.Monsters) do
if monster.name == name then
result = Shared.clone(monster)
--Make sure every monster has an ID, and account for the 1-based indexing of Lua
result.id = i - 1
break
end
end
return result
end
end


function p.getMonsterByID(ID)
function p.getMonsterByID(ID)
local result = Shared.clone(MonsterData.Monsters[ID + 1])
    return GameData.getEntityByID('monsters', ID)
if result ~= nil then
result.id = ID
return result
else
return nil
end
end
end


function p.getPassive(name)
function p.getPassive(name)
local result = nil
    return GameData.getEntityByName('combatPassives', name)
 
for i, passive in pairs(MonsterData.Passives) do
if passive.name == name then
result = Shared.clone(passive)
--Make sure every passive has an ID, and account for the 1-based indexing of Lua
result.id = i - 1
break
end
end
return result
end
end


function p.getPassiveByID(ID)
function p.getPassiveByID(ID)
return MonsterData.Passives[ID + 1]
    return GameData.getEntityByID('combatPassives', ID)
end
end


Line 85: Line 53:
elseif statName == 'damageReduction' then
elseif statName == 'damageReduction' then
return p.getEquipmentStat(monster, 'damageReduction')
return p.getEquipmentStat(monster, 'damageReduction')
elseif statName == 'drReduction' then
return p._getMonsterDrReduction(monster)
end
end


Line 115: Line 85:
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})
iconText = Icons.Icon({'Magic', type='skill', notext=notext, nolink=nolink})
elseif monster.attackType == 'random' then
elseif monster.attackType == 'random' then
iconText = Icons.Icon({'Bane', notext=notext, nolink=nolink, img='Question'})
iconText = Icons.Icon({monster.name, notext=notext, nolink=nolink, img='Question'})
end
end


Line 179: Line 149:


function p.getEquipmentStat(monster, statName)
function p.getEquipmentStat(monster, statName)
local result = 0
if monster.equipmentStats == nil then
for i, stat in Shared.skpairs(monster.equipmentStats) do
return 0
if stat.key == statName then
else
result = stat.value
    return monster.equipmentStats[statName] or 0
break
    end
end
end
return result
end
end


Line 303: Line 270:
-- item if so, or nil otherwise
-- item if so, or nil otherwise
function p._getMonsterBones(monster)
function p._getMonsterBones(monster)
if monster.bones ~= nil and monster.bones >= 0 then
if monster.bones ~= nil then
local boneItem = Items.getItemByID(monster.bones)
local boneItem = Items.getItemByID(monster.bones.itemID)
        local boneObj = { ["item"] = boneItem, ["quantity"] = monster.bones.quantity }
if boneItem.prayerPoints == nil then
if boneItem.prayerPoints == nil then
-- Assume bones without prayer points are shards (from God dungeons),
-- Assume bones without prayer points are shards (from God dungeons),
-- and drop unconditionally
-- and drop unconditionally
return boneItem
return boneObj
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then
elseif not monster.isBoss and not p._isDungeonOnlyMonster(monster) then
-- Otherwise, bones drop when the monster isn't dungeon exclusive
-- Otherwise, bones drop when the monster isn't dungeon exclusive
return boneItem
return boneObj
end
end
end
end
Line 331: Line 299:


function p.isDungeonOnlyMonster(frame)
function p.isDungeonOnlyMonster(frame)
local MonsterName = frame.args ~= nil and frame.args[1] or frame
local monsterName = frame.args ~= nil and frame.args[1] or frame
local monster = p.getMonster(MonsterName)
local monster = p.getMonster(monsterName)


if monster == nil then
if monster == nil then
Line 341: Line 309:
end
end


function p._getMonsterAreas(monster, excludeDungeons)
function p._getMonsterAreas(monster, excludeDungeons, includeEffects)
if includeEffects == nil then includeEffects = false end
local resultPart = {}
local resultPart = {}
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false
Line 347: Line 316:
for i, area in ipairs(areaList) do
for i, area in ipairs(areaList) do
if area.type ~= 'dungeon' or not hideDungeons then
if area.type ~= 'dungeon' or not hideDungeons then
table.insert(resultPart, Icons.Icon({area.name, type = area.type}))
local imgType = (area.type == 'slayerArea' and 'combatArea') or area.type
local txt = Icons.Icon({area.name, type = imgType})
if area.type == 'slayerArea' then
local areaDescrip = Areas._getAreaStat(area, 'areaEffectDesc')
if areaDescrip ~= 'None' then
txt = txt.." - ''"..areaDescrip.."''"
end
end
table.insert(resultPart, txt)
end
end
end
end
Line 354: Line 331:


function p.getMonsterAreas(frame)
function p.getMonsterAreas(frame)
local MonsterName = frame.args ~= nil and frame.args[1] or frame
local monsterName = frame.args ~= nil and frame.args[1] or frame
local hideDungeons = frame.args ~= nil and frame.args[2] or nil
local hideDungeons = frame.args ~= nil and frame.args[2] or nil
local monster = p.getMonster(MonsterName)
local includeEffects = frame.args ~= nil and frame.args[3] or true
local monster = p.getMonster(monsterName)


if monster == nil then
if monster == nil then
Line 362: Line 340:
end
end


return p._getMonsterAreas(monster, hideDungeons)
return p._getMonsterAreas(monster, hideDungeons, includeEffects)
end
end


function p.getSpecAttackMaxHit(specAttack, normalMaxHit)
function p.getSpecAttackMaxHit(specAttack, normalMaxHit, monsterDR)
local result = 0
local result = 0
for i, dmg in pairs(specAttack.damage) do
for i, dmg in pairs(specAttack.damage) do
if dmg.maxRoll == 'Fixed' then
if dmg.damageType == 'Normal' then
--Account for special attacks that include a normal attack hit
local result = normalMaxHit
if dmg.amplitude ~= nil then
result = result * (dmg.amplitude / 100)
end
return result
elseif dmg.maxRoll == 'Fixed' then
result = dmg.maxPercent * 10
result = dmg.maxPercent * 10
elseif dmg.maxRoll == 'MaxHit' then
elseif dmg.maxRoll == 'MaxHit' then
Line 377: Line 362:
result = dmg.maxPercent * normalMaxHit * 0.01
result = dmg.maxPercent * normalMaxHit * 0.01
end
end
elseif Shared.contains(dmg.maxRoll, "Fixed100") then
--Handles attacks that are doubled when conditions are met like Trogark's double damage if the player is burning
result = dmg.maxPercent * 20
elseif dmg.maxRoll == 'MaxHitScaledByHP2x' then
result = normalMaxHit * 2
elseif dmg.maxRoll == 'PoisonMax35' then
result = normalMaxHit * 1.35
elseif dmg.maxRoll == "MaxHitDR" then
result = normalMaxHit * dmg.maxPercent * 0.01 * (1 + monsterDR * 0.01)
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then
elseif Shared.contains({'Bleeding', 'Poisoned'}, dmg.maxRoll) then
-- TODO: This is limited in that there is no verification that bleed/poison
-- TODO: This is limited in that there is no verification that bleed/poison
Line 387: Line 381:


function p.canSpecAttackApplyEffect(specAttack, effectType)
function p.canSpecAttackApplyEffect(specAttack, effectType)
local result = false
for i, effect in pairs(specAttack.prehitEffects) do
for i, effect in pairs(specAttack.prehitEffects) do
if effect.type == effectType then
if effect.type == effectType then
result = true
            return true
break
end
end
end
end
Line 397: Line 389:
for i, effect in pairs(specAttack.onhitEffects) do
for i, effect in pairs(specAttack.onhitEffects) do
if effect.type == effectType then
if effect.type == effectType then
result = true
return true
break
end
end
end
end
return result
return false
end
end


Line 418: Line 409:
local hasActiveBuffSpec = false
local hasActiveBuffSpec = false
local damageMultiplier = 1
local damageMultiplier = 1
if monster.specialAttacks[1] ~= nil then
if monster.specialAttacks ~= nil then
local canStun, canSleep = false, false
local canStun, canSleep = false, false
for i, specAttack in pairs(monster.specialAttacks) do
for i, specAttackID in pairs(monster.specialAttacks) do
            local specAttack = GameData.getEntityByID('attacks', specAttackID)
if monster.overrideSpecialChances ~= nil then
if monster.overrideSpecialChances ~= nil then
normalChance = normalChance - monster.overrideSpecialChances[i]
normalChance = normalChance - monster.overrideSpecialChances[i]
Line 426: Line 418:
normalChance = normalChance - specAttack.defaultChance
normalChance = normalChance - specAttack.defaultChance
end
end
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit)
local thisMax = p.getSpecAttackMaxHit(specAttack, normalMaxHit, p._getMonsterStat(monster, 'damageReduction'))
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end
if not canStun and p.canSpecAttackApplyEffect(specAttack, 'Stun') then canStun = true end
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end
if not canSleep and p.canSpecAttackApplyEffect(specAttack, 'Sleep') then canSleep = true end
Line 470: Line 462:
result = p.calculateStandardMaxHit(baseLevel, bonus)
result = p.calculateStandardMaxHit(baseLevel, bonus)
elseif monster.attackType == 'magic' then
elseif monster.attackType == 'magic' then
local mSpell = nil
        if monster.selectedSpell == nil then
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end
            result = 0
 
        else
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')
            local mSpell = Magic.getSpellByID(monster.selectedSpell, 'standard')
baseLevel = p._getMonsterLevel(monster, 'Magic')
            if mSpell == nil then
 
                result = 0
result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))
            else
                baseLevel = p._getMonsterLevel(monster, 'Magic')
                bonus = p.getEquipmentStat(monster, 'magicDamageBonus')
                result = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))
            end
        end
elseif monster.attackType == 'random' then
elseif monster.attackType == 'random' then
local hitArray = {}
local hitArray = {}
Line 490: Line 487:
iconText = Icons.Icon({'Magic', type='skill', notext=true})
iconText = Icons.Icon({'Magic', type='skill', notext=true})
local mSpell = nil
        local magicDmg = 0
if monster.selectedSpell ~= nil then mSpell = Magic.getSpellByID('Spells', monster.selectedSpell) end
        if monster.selectedSpell ~= nil then
bonus = p.getEquipmentStat(monster, 'magicDamageBonus')
            local mSpell = Magic.getSpellByID(monster.selectedSpell, 'standard')
baseLevel = p._getMonsterLevel(monster, 'Magic')
            if mSpell ~= nil then
local magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))
                baseLevel = p._getMonsterLevel(monster, 'Magic')
                bonus = p.getEquipmentStat(monster, 'magicDamageBonus')
                magicDmg = math.floor(10 * mSpell.maxHit * (1 + bonus / 100) * (1 + (baseLevel + 1) / 200))
            end
        end
table.insert(hitArray, magicDmg)
table.insert(hitArray, magicDmg)
Line 545: Line 546:


local normalAttackChance = 100
local normalAttackChance = 100
if monster.specialAttacks[1] ~= nil then
if monster.specialAttacks ~= nil then
for i, specAttack in pairs(monster.specialAttacks) do
for i, specAttackID in pairs(monster.specialAttacks) do
            local specAttack = GameData.getEntityByID('attacks', specAttackID)
local attChance = 0
local attChance = 0
if monster.overrideSpecialChances ~= nil then
if monster.overrideSpecialChances ~= nil then
Line 556: Line 558:


result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description
result = result..'\r\n* '..attChance..'% '..iconText..' '..specAttack.name..'\r\n** '..specAttack.description
--If this special attack applies a curse, let's actually list what that curse does
if specAttack.onhitEffects ~= nil then
for j, hitEffect in ipairs(specAttack.onhitEffects) do
if hitEffect.effectType == 'Curse' then
local curse = Magic.getSpellByID(hitEffect.curse, 'curse')
result = result..'\r\n*** '..Icons.Icon({curse.name, type='curse'})..': '..Magic._getSpellDescription(curse, true)
end
end
end


if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then
if Shared.contains(string.upper(specAttack.description), 'NORMAL ATTACK INSTEAD') then
Line 574: Line 586:


return result
return result
end
--Function for pulling how much the monster reduces the player DR
--Goes through the passvies to look for the decreasedPlayerDamageReduction modifier
function p._getMonsterDrReduction(monster)
local totalResult = 0
    if type(monster.passives) == 'table' and not Shared.tableIsEmpty(monster.passives) then
for i, passiveID in ipairs(monster.passives) do
local passive = p.getPassiveByID(passiveID)
if passive.modifiers ~= nil then
if passive.modifiers['decreasedPlayerDamageReduction'] ~= nil then
totalResult = totalResult + passive.modifiers['decreasedPlayerDamageReduction']
end
end
end
    end
   
    return totalResult
end
function p.getMonsterDrReduction(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[[Category:Pages with script errors]]"
end
return p._getMonsterDrReduction(monster)
end
end


Line 585: Line 627:


local result = ''
local result = ''
if type(monster.passiveID) == 'table' and Shared.tableCount(monster.passiveID) > 0 then
    if type(monster.passives) == 'table' and not Shared.tableIsEmpty(monster.passives) then
result = result .. '===Passives==='
result = result .. '===Passives==='
for i, passiveID in pairs(monster.passiveID) do
for i, passiveID in ipairs(monster.passives) do
local passive = p.getPassiveByID(passiveID)
local passive = p.getPassiveByID(passiveID)
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. passive.description
result = result .. '\r\n* ' .. passive.name .. '\r\n** ' .. Constants.getDescription(passive.customDescription, passive.modifiers)
end
end
end
end
Line 613: Line 655:
end
end


if monster.specialAttacks[1] ~= nil then
if type(monster.passives) == 'table' and not Shared.tableIsEmpty(monster.passives) then
result = result..'[[Category:Monsters with Special Attacks]]'
result = result..'[[Category:Monsters with Special Attacks]]'
end
end
Line 639: Line 681:


local areaList = Areas.getMonsterAreas(monster.id)
local areaList = Areas.getMonsterAreas(monster.id)
local counts = {combat = 0, slayer = 0, dungeon = 0}
local counts = {combatArea = 0, slayerArea = 0, dungeon = 0}
for i, area in Shared.skpairs(areaList) do
for i, area in ipairs(areaList) do
counts[area.type] = counts[area.type] + 1
counts[area.type] = counts[area.type] + 1
end
end


if counts.combat > 0 then table.insert(monsterTypes, 'Combat Area') end
if counts.combatArea > 0 then table.insert(monsterTypes, 'Combat Area') end
if counts.slayer > 0 then table.insert(monsterTypes, 'Slayer Area') end
if counts.slayerArea > 0 then table.insert(monsterTypes, 'Slayer Area') end
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end
if counts.dungeon > 0 then table.insert(monsterTypes, 'Dungeon') end


Line 676: Line 718:


local bones = p._getMonsterBones(monster)
local bones = p._getMonsterBones(monster)
local boneVal = 0
--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 bones ~= nil then
local boneQty = (bones.quantity ~= nil and bones.quantity or 1)
result = result.."'''Always Drops:'''"
result = result.."'''Always Drops:'''"
result = result..'\r\n{|class="wikitable" id="bonedrops"'
result = result..'\r\n{|class="wikitable" id="bonedrops"'
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.item.name, type='item'})
result = result..'||'..(monster.boneQty ~= nil and monster.boneQty or 1)..'\r\n'..'|}'
result = result..'||'..boneQty..'\r\n'..'|}'
boneVal = boneQty * bones.item.sellsFor
end
end


Line 693: Line 738:
local avgGp = 0
local avgGp = 0


if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
if monster.gpDrops ~= nil then
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2
avgGp = (monster.gpDrops.min + monster.gpDrops.max) / 2
local gpTxt = Icons.GP(monster.dropCoins[1], monster.dropCoins[2])
local gpTxt = Icons.GP(monster.gpDrops.min, monster.gpDrops.max)
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'
result = result.."\r\nIn addition to loot, the monster will also drop "..gpTxt..'.'
end
end
Line 701: Line 746:
local multiDrop = Shared.tableCount(monster.lootTable) > 1
local multiDrop = Shared.tableCount(monster.lootTable) > 1
local totalWt = 0
local totalWt = 0
for i, row in pairs(monster.lootTable) do
for i, row in ipairs(monster.lootTable) do
totalWt = totalWt + row[2]
totalWt = totalWt + row.weight
end
end
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'
result = result..'\r\n{|class="wikitable sortable" id="itemdrops"'
Line 709: Line 754:


--Sort the loot table by weight in descending order
--Sort the loot table by weight in descending order
table.sort(monster.lootTable, function(a, b) return a[2] > b[2] end)
table.sort(monster.lootTable, function(a, b) return a.weight > b.weight end)
for i, row in Shared.skpairs(monster.lootTable) do
for i, row in ipairs(monster.lootTable) do
local thisItem = Items.getItemByID(row[1])
local thisItem = Items.getItemByID(row.itemID)
local maxQty = row[3]
if thisItem ~= nil then
if thisItem ~= nil then
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})
Line 719: Line 763:
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'
result = result..'\r\n|-\r\n|Unknown Item[[Category:Pages with script errors]]'
end
end
result = result..'||style="text-align:right" data-sort-value="'..maxQty..'"|'
result = result..'||style="text-align:right" data-sort-value="'..row.maxQuantity..'"|'


if maxQty > 1 then
if row.maxQuantity > row.minQuantity then
result = result.. '1 - '
result = result .. Shared.formatnum(row.minQuantity) .. ' - '
end
end
result = result..Shared.formatnum(row[3])
result = result .. Shared.formatnum(row.maxQuantity)


--Adding price columns
--Adding price columns
Line 732: Line 776:
else
else
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0
if itemPrice == 0 or maxQty == 1 then
if itemPrice == 0 or row.maxQuantity == row.minQuantity then
result = result..'||'..Icons.GP(itemPrice)
result = result..'||'..Icons.GP(itemPrice * row.minQuantity)
else
else
result = result..'||'..Icons.GP(itemPrice, itemPrice * maxQty)
result = result..'||'..Icons.GP(itemPrice * row.minQuantity, itemPrice * row.maxQuantity)
end
end
end
end


--Getting the drop chance
--Getting the drop chance
local dropChance = (row[2] / totalWt * lootChance)
local dropChance = (row.weight / totalWt * lootChance)
if dropChance < 100 then
if dropChance < 100 then
--Show fraction as long as it isn't going to be 1/1
--Show fraction as long as it isn't going to be 1/1
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'
result = result..'||style="text-align:right" data-sort-value="'..row.weight..'"'
result = result..'|'..Shared.fraction(row[2] * lootChance, totalWt * 100)
result = result..'|'..Shared.fraction(row.weight * lootChance, totalWt * 100)
result = result..'||'
result = result..'||'
else
else
result = result..'||colspan="2" data-sort-value="'..row[2]..'"'
result = result..'||colspan="2" data-sort-value="'..row.weight..'"'
end
end
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places
-- If chance is less than 0.10% then show 2 significant figures, otherwise 2 decimal places
Line 754: Line 798:


--Adding to the average loot value based on price & dropchance
--Adding to the average loot value based on price & dropchance
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((row.minQuantity + row.maxQuantity) / 2))
end
end
if multiDrop then
if multiDrop then
Line 768: Line 812:
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."
result = result..'\r\nThe loot dropped by the average kill is worth '..Icons.GP(Shared.round(lootValue, 2, 0)).." if sold."
if avgGp > 0 then
if avgGp > 0 then
result = result..'<br/>Including GP, the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue, 2, 0))..'.'
result = result.."<br/>Including GP"
if boneVal > 0 then
result = result..' and bones'
end
result = result..', the average kill is worth '..Icons.GP(Shared.round(avgGp + lootValue + boneVal, 2, 0))..'.'
end
end
end
end
Line 788: Line 836:
--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 bones ~= nil then
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1
local boneQty = (bones.quantity ~= nil and bones.quantity) or 1
boneVal = bones.sellsFor * boneQty
boneVal = bones.item.sellsFor * boneQty
result = result + boneVal
end
end


Line 799: Line 848:
local avgGp = 0
local avgGp = 0


if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
if monster.gpDrops ~= nil then
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2
avgGp = (monster.gpDrops.min + monster.gpDrops.max) / 2
end
end


Line 806: Line 855:
local totalWt = 0
local totalWt = 0
for i, row in pairs(monster.lootTable) do
for i, row in pairs(monster.lootTable) do
totalWt = totalWt + row[2]
totalWt = totalWt + row.weight
end
end


for i, row in Shared.skpairs(monster.lootTable) do
for i, row in ipairs(monster.lootTable) do
local thisItem = Items.getItemByID(row[1])
local thisItem = Items.getItemByID(row.itemID)
local maxQty = row[3]
result = result..Shared.formatnum(row[3])


--Adding price columns
--Adding price columns
Line 822: Line 868:


--Getting the drop chance
--Getting the drop chance
local dropChance = (row[2] / totalWt * lootChance)
local dropChance = (row.weight / totalWt * lootChance)
--Adding to the average loot value based on price & dropchance
--Adding to the average loot value based on price & dropchance
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((row.minQuantity + row.maxQuantity) / 2))
end
end
if avgGp > 0 then
if avgGp > 0 then
result = avgGp + lootValue
result = result + avgGp + lootValue
end
end
end
end
Line 860: Line 906:
local dropChance = 0
local dropChance = 0
local dropWt = 0
local dropWt = 0
for i, row in Shared.skpairs(monster.lootTable) do
for i, row in ipairs(monster.lootTable) do
local thisItem = Items.getItemByID(row[1])
totalWt = totalWt + row.weight
totalWt = totalWt + row[2]
if item.id == row.itemID then
if item['id'] == thisItem['id'] then
dropWt = row.weight
dropWt = row[2]
end
end
end
end
Line 873: Line 918:


function p.getChestDrops(frame)
function p.getChestDrops(frame)
local ChestName = frame.args ~= nil and frame.args[1] or frame
local chestName = frame.args ~= nil and frame.args[1] or frame
local chest = Items.getItem(ChestName)
local chest = Items.getItem(chestName)


if chest == nil then
if chest == nil then
return "ERROR: No item named "..ChestName..' found[[Category:Pages with script errors]]'
return "ERROR: No item named "..chestName..' found[[Category:Pages with script errors]]'
end
end
local result = ''
local result = ''


if chest.dropTable == nil then
if chest.dropTable == nil then
return "ERROR: "..ChestName.." does not have a drop table[[Category:Pages with script errors]]"
return "ERROR: "..chestName.." does not have a drop table[[Category:Pages with script errors]]"
else
else
local lootChance = 100
local lootValue = 0
local lootValue = 0
local multiDrop = Shared.tableCount(chest.dropTable) > 1
local totalWt = 0
local totalWt = 0
for i, row in pairs(chest.dropTable) do
for i, row in pairs(chest.dropTable) do
totalWt = totalWt + row[2]
totalWt = totalWt + row.weight
end
end
result = result..'\r\n{|class="wikitable sortable"'
result = result..'\r\n{|class="wikitable sortable"'
Line 898: Line 939:


--Sort the loot table by weight in descending order
--Sort the loot table by weight in descending order
for i, row in pairs(chest.dropTable) do
local chestDrops = {}
if chest.dropQty ~= nil then
for i, row in ipairs(chest.dropTable) do
table.insert(row, chest.dropQty[i])
table.insert(chestDrops, row)
else
table.insert(row, 1)
end
end
end
table.sort(chest.dropTable, function(a, b) return a[2] > b[2] end)
table.sort(chestDrops, function(a, b) return a.weight > b.weight end)
for i, row in Shared.skpairs(chest.dropTable) do
for i, row in ipairs(chestDrops) do
local thisItem = Items.getItemByID(row[1])
local thisItem = Items.getItemByID(row.itemID)
local qty = row[3]
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})
result = result..'\r\n|-\r\n|'..Icons.Icon({thisItem.name, type='item'})
result = result..'||style="text-align:right" data-sort-value="'..qty..'"|'
result = result..'||style="text-align:right" data-sort-value="'..(row.minQuantity + row.maxQuantity)..'"|'


if qty > 1 then
if row.minQuantity < row.maxQuantity then
result = result.. '1 - '
result = result .. Shared.formatnum(row.minQuantity) .. ' - ' .. Shared.formatnum(row.maxQuantity)
else
result = result .. Shared.formatnum(row.minQuantity)
end
end
result = result..Shared.formatnum(qty)


local dropChance = (row[2] / totalWt) * 100
local dropChance = (row.weight / totalWt) * 100
result = result..'||style="text-align:right" data-sort-value="'..row[2]..'"'
result = result..'||style="text-align:right" data-sort-value="'..row.weight..'"'
result = result..'|'..Shared.fraction(row[2], totalWt)
result = result..'|'..Shared.fraction(row.weight, totalWt)


result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'
result = result..'||style="text-align:right"|'..Shared.round(dropChance, 2, 2)..'%'


result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'
result = result..'||style="text-align:left" data-sort-value="'..thisItem.sellsFor..'"'
if qty > 1 then
if thisItem.sellsFor == 0 or row.minQuantity == row.maxQuantity then
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)
result = result..'|'..Icons.GP(thisItem.sellsFor * row.minQuantity)
else
else
result = result..'|'..Icons.GP(thisItem.sellsFor)
result = result..'|'..Icons.GP(thisItem.sellsFor * row.minQuantity, thisItem.sellsFor * row.maxQuantity)
end
end
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((row.minQuantity + row.maxQuantity)/ 2))
end
end
result = result..'\r\n|}'
result = result..'\r\n|}'
Line 950: Line 988:


local tableTxt = '{| class="wikitable sortable"'
local tableTxt = '{| class="wikitable sortable"'
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]]'
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! colspan=2| Max Hit !! [[Combat Triangle|Combat Style]]'
for i, monsterID in pairs(area.monsters) do
for i, monsterID in ipairs(area.monsterIDs) do
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)
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterMaxHit(monster))
local drReduction = p._getMonsterDrReduction(monster)
local maxHit = p._getMonsterMaxHit(monster)
if drReduction > 0 then
tableTxt = tableTxt..'||style="text-align:right" data-sort-value="'..maxHit..'"| -'..drReduction..'% DR'
tableTxt = tableTxt..'||style="text-align:right"|'..Shared.formatnum(maxHit)
else
tableTxt = tableTxt..'||style="text-align:right" colspan="2" data-sort-value="'..maxHit..'"|'..Shared.formatnum(maxHit)
end
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})
end
end
Line 972: Line 1,017:
--For Dungeons, go through and count how many of each monster are in the dungeon first
--For Dungeons, go through and count how many of each monster are in the dungeon first
local monsterCounts = {}
local monsterCounts = {}
for i, monsterID in pairs(area.monsters) do
for i, monsterID in ipairs(area.monsterIDs) do
if monsterCounts[monsterID] == nil then
if monsterCounts[monsterID] == nil then
monsterCounts[monsterID] = 1
monsterCounts[monsterID] = 1
Line 984: Line 1,029:
-- Declare function for building table rows to avoid repeating code
-- Declare function for building table rows to avoid repeating code
local buildRow = function(entityID, monsterCount, specialType)
local buildRow = function(entityID, monsterCount, specialType)
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount, monDrReduce
local monData = {}
local monData = {}
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then
if specialType ~= nil and Shared.contains({'Afflicted', 'Spider', 'SlayerArea'}, specialType) then
-- Special handling for Into the Mist
-- Special handling for Into the Mist
if specialType == 'Afflicted' then
if specialType == 'Afflicted' then
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})
local iconQ = Icons.Icon({'Into the Mist', notext=true, nolink=true, img='Question'})
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})
monIcon = Icons.Icon({'Into the Mist', 'Afflicted Monster', nolink=true, img='Question'})
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount
monLevel, monHP, monMaxHit, monDrReduce, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, iconQ, monsterCount
elseif specialType == 'Spider' then
local iconQ = Icons.Icon({'', notext=true, nolink=true, img='Question'})
local monIconPart = { 'Any of the following:' }
for i, monsterID in ipairs(GameData.rawData.spiderLairMonsters) do
local monster = p.getMonsterByID(monsterID)
if monster ~= nil then
table.insert(monIconPart, Icons.Icon({monster.name, type='monster'}))
end
end
monIcon = table.concat(monIconPart, '<br/>')
monLevel, monHP, monMaxHit, monDrReduce, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, iconQ, monsterCount
elseif specialType == 'SlayerArea' then
elseif specialType == 'SlayerArea' then
-- entityID corresponds to a slayer area
-- entityID corresponds to a slayer area
local area = Areas.getAreaByID('slayer', entityID)
local area = Areas.getAreaByID('slayer', entityID)
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)}
monLevel = {p.getLowHighStat(area.monsterIDs, function(monster) return p._getMonsterCombatLevel(monster) end)}
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)}
monHP = {p.getLowHighStat(area.monsterIDs, function(monster) return p._getMonsterHP(monster) end)}
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end)
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsterIDs, function(monster) return p._getMonsterMaxHit(monster) end)
local lowDrReduce, highDrReduce = p.getLowHighStat(area.monsterIDs, function(monster) return p._getMonsterDrReduction(monster) end)
monMaxHit = highMaxHit
monMaxHit = highMaxHit
monDrReduce = highDrReduce
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'})
monCount = monsterCount
monCount = monsterCount
Line 1,009: Line 1,067:
monLevel = p._getMonsterCombatLevel(monster)
monLevel = p._getMonsterCombatLevel(monster)
monHP = p._getMonsterHP(monster)
monHP = p._getMonsterHP(monster)
monDrReduce = p._getMonsterDrReduction(monster)
monMaxHit = p._getMonsterMaxHit(monster)
monMaxHit = p._getMonsterMaxHit(monster)
monStyle = p._getMonsterStyleIcon({monster})
monStyle = p._getMonsterStyleIcon({monster})
Line 1,042: Line 1,101:
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monLevel) .. '"| ' .. getValText(monLevel))
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monHP) .. '"| ' .. getValText(monHP))
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monMaxHit) .. '"| ' .. getValText(monMaxHit))
if type(monDrReduce) == 'number' and monDrReduce > 0 then
table.insert(resultPart, '\r\n|style="text-align:right" data-sort-value="'..getValSort(monMaxHit)..'"| -'..monDrReduce..'% DR')
table.insert(resultPart, '\r\n|style="text-align:right"|'..getValText(monMaxHit))
else
table.insert(resultPart, '\r\n|style="text-align:right" colspan="2" data-sort-value="'..getValSort(monMaxHit)..'"|'..getValText(monMaxHit))
end
table.insert(resultPart, '\r\n| ' .. monStyle)
table.insert(resultPart, '\r\n| ' .. monStyle)
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount))
Line 1,050: Line 1,114:
local returnPart = {}
local returnPart = {}
table.insert(returnPart, '{| class="wikitable sortable"')
table.insert(returnPart, '{| class="wikitable sortable"')
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count')
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! colspan="2" | Max Hit !! [[Combat Triangle|Combat Style]] !! Count')
-- Special handing for Impending Darkness event
-- Special handing for Impending Darkness event
-- TODO needs to be revised once there is a better understanding of how the event works
-- TODO needs to be revised once there is a better understanding of how the event works
Line 1,060: Line 1,124:
--  table.insert(returnPart, buildRow(152, 4))
--  table.insert(returnPart, buildRow(152, 4))
--end
--end
for i, monsterID in pairs(area.monsters) do
for i, monsterID in ipairs(area.monsterIDs) do
if not Shared.contains(usedMonsters, monsterID) then
if not Shared.contains(usedMonsters, monsterID) then
if monsterID >= 0 then
if monsterID == 'melvorF:RandomITM' then
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))
else
--Special handling for Into the Mist
--Special handling for Into the Mist
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted'))
elseif monsterID == 'melvorTotH:RandomSpiderLair' then
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Spider'))
else
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))
end
end
table.insert(usedMonsters, monsterID)
table.insert(usedMonsters, monsterID)
Line 1,083: Line 1,149:
local totalHP = 0
local totalHP = 0


for i, monsterID in pairs(area.monsters) do
for i, monsterID in ipairs(area.monsterIDs) do
if not Shared.contains(usedMonsters, monsterID) then
        local monster = p.getMonsterByID(monsterID)
local monster = p.getMonsterByID(monsterID)
        totalHP = totalHP + p._getMonsterHP(monster)
totalHP = totalHP + p._getMonsterHP(monster)
end
end
end
return totalHP
return totalHP
Line 1,094: Line 1,158:
function p._getAreaMonsterList(area)
function p._getAreaMonsterList(area)
local monsterList = {}
local monsterList = {}
for i, monsterID in pairs(area.monsters) do
for i, monsterID in ipairs(area.monsterIDs) do
local monster = p.getMonsterByID(monsterID)
local monster = p.getMonsterByID(monsterID)
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))
table.insert(monsterList, Icons.Icon({monster.name, type='monster'}))
Line 1,103: Line 1,167:
function p._getDungeonMonsterList(area)
function p._getDungeonMonsterList(area)
local monsterList = {}
local monsterList = {}
local lastMonster = nil
local lastID = ''
local lastID = -2
local count = 0
local count = 0
-- Special handing for Impending Darkness event
-- Special handing for Impending Darkness event
Line 1,115: Line 1,178:
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))
--end
--end
for i, monsterID in Shared.skpairs(area.monsters) do
if monsterID ~= lastID then
local monsterCounts = {}
local monster = nil
for i, monsterID in ipairs(area.monsterIDs) do
if monsterID ~= -1 then monster = p.getMonsterByID(monsterID) end
if lastID == '' then
if lastID ~= -2 then
if lastID == -1 then
--Special handling for Afflicted Monsters
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=count}))
else
local name = lastMonster.name
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count}))
end
end
lastMonster = monster
lastID = monsterID
lastID = monsterID
count = 1
count = 1
elseif lastID == monsterID then
count = count + 1
else
else
count = count + 1
table.insert(monsterCounts, { id = lastID, count = count })
lastID = monsterID
count = 1
end
end
--Make sure the final monster in the dungeon gets counted
end
if i == Shared.tableCount(area.monsters) then
table.insert(monsterCounts, { id = lastID, count = count })
local name = lastMonster.name
 
table.insert(monsterList, Icons.Icon({lastMonster.name, type='monster', qty=count}))
for i, monster in ipairs(monsterCounts) do
if monster.id == 'melvorF:RandomITM' then
--Special handling for Afflicted Monsters
table.insert(monsterList, Icons.Icon({'Affliction', 'Afflicted Monster', img='Question', qty=monster.count}))
elseif monster.id == 'melvorTotH:RandomSpiderLair' then
local monIconPart = { Shared.formatnum(monster.count) .. ' Spiders:' }
for i, monsterID in ipairs(GameData.rawData.spiderLairMonsters) do
local monster = p.getMonsterByID(monsterID)
if monster ~= nil then
table.insert(monIconPart, '&nbsp;&nbsp;&nbsp;' .. Icons.Icon({monster.name, type='monster'}))
end
end
table.insert(monsterList, table.concat(monIconPart, '<br/>'))
else
local monsterObj = p.getMonsterByID(monster.id)
table.insert(monsterList, Icons.Icon({monsterObj.name, type='monster', qty=monster.count}))
end
end
end
end
return table.concat(monsterList, '<br/>')
return table.concat(monsterList, '<br/>')
end
end
Line 1,159: Line 1,232:
function p.getFoxyTable(frame)
function p.getFoxyTable(frame)
local result = 'Monster,Min GP,Max GP,Average GP'
local result = 'Monster,Min GP,Max GP,Average GP'
for i, monster in Shared.skpairs(MonsterData.Monsters) do
for i, monster in ipairs(GameData.rawData.monsters) do
if not p._isDungeonOnlyMonster(monster) then
if not p._isDungeonOnlyMonster(monster) then
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
if monster.gpDrops ~= nil and monster.gpDrops.max > 0 then
local avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2
local avgGp = (monster.gpDrops.min + monster.gpDrops.max) / 2
result = result..'<br/>'..monster.name..','..monster.dropCoins[1]..','..(monster.dropCoins[2])..','..avgGp
result = result .. '<br/>' .. monster.name .. ',' .. monster.gpDrops.min .. ',' .. monster.gpDrops.max .. ',' .. avgGp
end
end
end
end
Line 1,176: Line 1,249:
local bones = p._getMonsterBones(monster)
local bones = p._getMonsterBones(monster)
if bones ~= nil then
if bones ~= nil then
totalGP = totalGP + bones.sellsFor * (type(monster.boneQty) == 'number' and monster.boneQty or 1)
totalGP = totalGP + bones.item.sellsFor * bones.quantity
end
end


Line 1,186: Line 1,259:
local avgGp = 0
local avgGp = 0


if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
if monster.gpDrops ~= nil then
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2
avgGp = (monster.gpDrops.min + monster.gpDrops.max) / 2
end
end


totalGP = totalGP + avgGp
totalGP = totalGP + avgGp


local multiDrop = Shared.tableCount(monster.lootTable) > 1
local totalWt = 0
local totalWt = 0
for i, row in pairs(monster.lootTable) do
for i, row in ipairs(monster.lootTable) do
totalWt = totalWt + row[2]
totalWt = totalWt + row.weight
end
end


for i, row in Shared.skpairs(monster.lootTable) do
for i, row in ipairs(monster.lootTable) do
local thisItem = Items.getItemByID(row[1])
local thisItem = Items.getItemByID(row.itemID)
local maxQty = row[3]


local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0
local itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0


--Getting the drop chance
--Getting the drop chance
local dropChance = (row[2] / totalWt * lootChance)
local dropChance = (row.weight / totalWt * lootChance)


--Adding to the average loot value based on price & dropchance
--Adding to the average loot value based on price & dropchance
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((row.minQuantity + row.maxQuantity) / 2))
end
end


Line 1,231: Line 1,302:
local result = '{| class="wikitable sortable"'
local result = '{| class="wikitable sortable"'
result = result..'\r\n!Monster!!Combat Level!!Average GP'
result = result..'\r\n!Monster!!Combat Level!!Average GP'
for i, monsterTemp in Shared.skpairs(MonsterData.Monsters) do
for i, monster in ipairs(GameData.rawData.monsters) do
local monster = Shared.clone(monsterTemp)
monster.id = i - 1
if not p._isDungeonOnlyMonster(monster) then
if not p._isDungeonOnlyMonster(monster) then
local monsterGP = p._getMonsterAverageGP(monster)
local monsterGP = p._getMonsterAverageGP(monster)
local combatLevel = p._getMonsterCombatLevel(monster, 'Combat Level')
local combatLevel = p._getMonsterCombatLevel(monster)
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP
result = result..'\r\n|-\r\n|'..Icons.Icon({monster.name, type='monster', noicon=true})..'||'..combatLevel..'||'..monsterGP
end
end
Line 1,269: Line 1,338:
-- Right now hiddenMonsterIDs is empty
-- Right now hiddenMonsterIDs is empty
local hiddenMonsterIDs = {}
local hiddenMonsterIDs = {}
local monsterIDs = {}
local monsterList = GameData.getEntities('monsters',
for i, monster in Shared.skpairs(MonsterData.Monsters) do
        function(monster)
if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, i - 1) then
            if monster.canSlayer and not Shared.contains(hiddenMonsterIDs, monster.id) then
local cmbLevel = p._getMonsterCombatLevel(monster)
                local cmbLevel = p._getMonsterCombatLevel(monster)
if cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel) then
                return cmbLevel >= minLevel and (maxLevel == nil or cmbLevel <= maxLevel)
table.insert(monsterIDs, i - 1)
            end
end
            return false
end
        end)
end


if Shared.tableCount(monsterIDs) == 0 then
if Shared.tableIsEmpty(monsterList) then
-- Somehow no monsters are in the tier, return nothing
-- Somehow no monsters are in the tier, return nothing
return ''
return ''
else
else
return p._getMonsterTable(monsterIDs, true)
return p._getMonsterTable(monsterList, true)
end
end
end
end


function p.getFullMonsterTable(frame)
function p.getFullMonsterTable(frame)
local monsterIDs = {}
return p._getMonsterTable(GameData.rawData.monsters, false)
for i = 0, Shared.tableCount(MonsterData.Monsters) - 1, 1 do
table.insert(monsterIDs, i)
end
 
return p._getMonsterTable(monsterIDs, false)
end
end


function p._getMonsterTable(monsterIDs, excludeDungeons)
function p._getMonsterTable(monsters, excludeDungeons)
--Making a single function for getting a table of monsters given a list of IDs.
--Making a single function for getting a table of monsters given a list of IDs.
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false
local hideDungeons = excludeDungeons ~= nil and excludeDungeons or false
Line 1,302: Line 1,365:
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')
-- First header row
-- First header row
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="5" | !! colspan="4" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')
table.insert(tableParts, '\r\n|- class="headerRow-0"\r\n! colspan="4" | !! colspan="5" |Offensive Stats !! colspan="3" |Evasion Rating !! colspan="4" |')
-- Second header row
-- Second header row
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 !!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 Speed (s) !!colspan="2"|Max Hit !!Accuracy ')
table.insert(tableParts, '!!Attack Speed (s) !!colspan="3"|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, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')
table.insert(tableParts, '!!DR!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Bones !!Locations')


-- Generate row per monster
-- Generate row per monster
for i, monsterID in Shared.skpairs(monsterIDs) do
for i, monster in ipairs(monsters) do
local monster = p.getMonsterByID(monsterID)
-- Avoid processing monsters without equipment stats. These aren't actual
local cmbLevel = p._getMonsterCombatLevel(monster)
-- monsters, but instead are placeholders such as 'melvorF:RandomITM'
local atkSpeed = p._getMonsterAttackSpeed(monster)
-- and 'melvorTotH:RandomSpiderLair' to denote a random selection from
local maxHit = p._getMonsterMaxHit(monster)
-- a pool of monsters
local accR = p._getMonsterAR(monster)
if monster.equipmentStats ~= nil then
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}
local cmbLevel = p._getMonsterCombatLevel(monster)
 
local atkSpeed = p._getMonsterAttackSpeed(monster)
local gpRange = {0, 0}
local maxHit = p._getMonsterMaxHit(monster)
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
local dr = p._getMonsterStat(monster, 'damageReduction')
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}
local drReduce = p._getMonsterDrReduction(monster)
end
local accR = p._getMonsterAR(monster)
local gpTxt = nil
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}
if gpRange[1] >= gpRange[2] then
gpTxt = Shared.formatnum(gpRange[1])
local gpTxt = nil
else
if monster.gpDrops.min >= monster.gpDrops.max then
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])
gpTxt = Shared.formatnum(monster.gpDrops.min)
else
gpTxt = Shared.formatnum(monster.gpDrops.min) .. ' - ' .. Shared.formatnum(monster.gpDrops.max)
end
local bones = p._getMonsterBones(monster)
local boneTxt = (bones ~= nil and Icons.Icon({bones.item.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|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
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="' .. atkSpeed .. '" |' .. Shared.round(atkSpeed, 1, 1))
if drReduce > 0 then
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. maxHit .. '"| -' .. drReduce..'% DR')
table.insert(tableParts, '\r\n|style="text-align:right;border-right:hidden" |' .. p._getMonsterStyleIcon({monster, notext=true}))
table.insert(tableParts, '\r\n|style="text-align:right" |' .. Shared.formatnum(maxHit))
else
table.insert(tableParts, '\r\n|style="text-align:right;border-right:hidden" colspan="2" data-sort-value="' .. maxHit .. '"|' .. p._getMonsterStyleIcon({monster, notext=true}))
table.insert(tableParts, '\r\n|style="text-align:right"|' .. Shared.formatnum(maxHit))
end
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="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))
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="' .. dr .. '" |' .. dr..'%')
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (monster.gpDrops.min + monster.gpDrops.max) / 2 .. '" |' .. gpTxt)
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
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|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monsterID)
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="' .. 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="' .. accR .. '" |' .. Shared.formatnum(accR))
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[1]))
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="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
end
end


Line 1,365: Line 1,437:


-- Generate row per monster
-- Generate row per monster
for i, monster in Shared.skpairs(MonsterData.Monsters) do
for i, monster in ipairs(GameData.rawData.monsters) do
local cmbLevel = p._getMonsterCombatLevel(monster)
if monster.name ~= nil then
local cmbLevel = p._getMonsterCombatLevel(monster)
local gpTxt = nil
if monster.gpDrops.min >= monster.gpDrops.max then
gpTxt = Shared.formatnum(monster.gpDrops.min)
else
gpTxt = Shared.formatnum(monster.gpDrops.min) .. ' - ' .. Shared.formatnum(monster.gpDrops.max)
end
local lootVal = p._getMonsterLootValue(monster)
local lootTxt = '0'
if lootVal ~= 0 then
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))
end
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|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)
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="' .. (monster.gpDrops.min + monster.gpDrops.max) / 2 .. '" |' .. gpTxt)
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, false))
end
end
 
table.insert(tableParts, '\r\n|}')
return table.concat(tableParts)
end


local gpRange = {0, 0}
function p.getMattMonsterTableV2(frame)
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
--Making a single function for getting a table of monsters given a list of IDs.
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}
local tableParts = {}
end
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')
local gpTxt = nil
-- Second header row
if gpRange[1] >= gpRange[2] then
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!Combat Level ')
gpTxt = Shared.formatnum(gpRange[1])
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))
else
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Defence', type='skill', notext=true}))
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])
table.insert(tableParts, '!!Attack Speed (s) !!colspan="2"|Max Hit !!Accuracy ')
 
-- 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, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value !!Bones')
 
-- Generate row per monster
for i, monster in ipairs(GameData.rawData.monsters) do
if monster.name ~= nil then
local cmbLevel = p._getMonsterCombatLevel(monster)
local gpTxt = nil
if monster.gpDrops.min >= monster.gpDrops.max then
gpTxt = Shared.formatnum(monster.gpDrops.min)
else
gpTxt = Shared.formatnum(monster.gpDrops.min) .. ' - ' .. Shared.formatnum(monster.gpDrops.max)
end
local lootVal = p._getMonsterLootValue(monster)
local lootTxt = '0'
if lootVal ~= 0 then
lootTxt = Shared.formatnum(Shared.round(lootVal, 2, 2))
end
local atkSpeed = p._getMonsterAttackSpeed(monster)
local maxHit = p._getMonsterMaxHit(monster)
local accR = p._getMonsterAR(monster)
local evaR = {p._getMonsterER(monster, "Melee"), p._getMonsterER(monster, "Ranged"), p._getMonsterER(monster, "Magic")}
local bones = p._getMonsterBones(monster)
local boneTxt = (bones ~= nil and Icons.Icon({bones.item.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|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
-- table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)
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="' .. evaR[1] .. '" |' .. Shared.formatnum(evaR[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="' .. accR .. '" |' .. Shared.formatnum(accR))
--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="' .. (monster.gpDrops.min + monster.gpDrops.max) / 2 .. '" |' .. gpTxt)
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
-- table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
end
end
local lootVal = p._getMonsterLootValue(monster)
local lootTxt = '0'
if lootVal ~= 0 then
lootTxt = Shared.formatnum(lootVal)
end
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|style="text-align:left" |' .. Icons.Icon({monster.name, type='monster', noicon=true}))
table.insert(tableParts, '\r\n|style="text-align:right" |' .. monster.id)
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="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. lootVal .. '" |' .. lootTxt)
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
end
end


Line 1,403: Line 1,537:
local spAttTable = {}
local spAttTable = {}


for i, monster in ipairs(MonsterData.Monsters) do
for i, monster in ipairs(GameData.rawData.monsters) do
if monster.specialAttacks ~= nil and Shared.tableCount(monster.specialAttacks) > 0 then
if monster.specialAttacks ~= nil and not Shared.tableIsEmpty(monster.specialAttacks) then
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)
local overrideChance = (monster.overrideSpecialChances ~= nil and Shared.tableCount(monster.overrideSpecialChances) > 0)
for j, spAtt in ipairs(monster.specialAttacks) do
for j, spAttID in ipairs(monster.specialAttacks) do
                local spAtt = GameData.getEntityByID('attacks', spAttID)
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)
local attChance = (overrideChance and monster.overrideSpecialChances[j] or spAtt.defaultChance)
if spAttTable[spAtt.id] == nil then
if spAttTable[spAtt.id] == nil then
Line 1,448: Line 1,583:


return table.concat(resultPart)
return table.concat(resultPart)
end
--NOTE: This is not a function that should be called directly. It generates text to be pasted into Chest Loot TablesTemplate:MonsterLootTables
--It exists because I'm too lazy to manually type up all the new monsters - User:Falterfire
function p.getMonsterLootTableText()
local getAreaText = function(area)
local outArray = {}
table.insert(outArray, "==={{ZoneIcon|"..area.name.."|size=50}}===")
table.insert(outArray, "")
for i, monsterID in ipairs(area.monsterIDs) do
local monster = p.getMonsterByID(monsterID)
table.insert(outArray, "===={{MonsterIcon|"..monster.name.."|size=40}}====")
table.insert(outArray, "{{MonsterDrops|"..monster.name.."|size=40}}")
end
return table.concat(outArray, "\r\n")
end
local fullArray = {}
local areaArray = Areas.getAreas(function(a) return a.type == 'combatArea' end)
for i, area in ipairs(areaArray) do
table.insert(fullArray, getAreaText(area))
end
areaArray = Areas.getAreas(function(a) return a.type == 'slayerArea' end)
for i, area in ipairs(areaArray) do
table.insert(fullArray, getAreaText(area))
end
return table.concat(fullArray, "\r\n\r\n----\r\n")
end
--NOTE: This is not a function that should be called directly. It generates text to be pasted into Chest Loot Tables
--It exists because I'm too lazy to manually type up all the new chests - User:Falterfire
function p.getChestLootTables()
local items = Items.getItems(function(item) return item.dropTable ~= nil end)
local outArray = {}
for i, item in ipairs(items) do
table.insert(outArray, "==={{ItemIcon|"..item.name.."|size=30}}===")
table.insert(outArray, "{{ChestDrops|"..item.name.."}}")
end
return table.concat(outArray, "\r\n")
end
--Returns the expansion icon for the item if it has one
function p.getExpansionIcon(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[[Category:Pages with script errors]]"
end
return Icons.getExpansionIcon(monster.id)
end
end


return p
return p