Module:Monsters: Difference between revisions

Update for v1.1
(_getMonsterStyleIcon: Revert change to use adjusted Icon override instead)
(Update for v1.1)
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 179: Line 147:


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


Line 303: Line 264:
-- 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 293:


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 354: Line 316:


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 monster = p.getMonster(monsterName)


if monster == nil then
if monster == nil then
Line 387: Line 349:


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 357:
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 377:
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 470: Line 430:
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('Spells', monster.selectedSpell)
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 455:
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('Spells', monster.selectedSpell)
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 514:


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 585: Line 555:


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** ' .. passive.customDescription
end
end
end
end
Line 613: Line 583:
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 640: Line 610:
local areaList = Areas.getMonsterAreas(monster.id)
local areaList = Areas.getMonsterAreas(monster.id)
local counts = {combat = 0, slayer = 0, dungeon = 0}
local counts = {combat = 0, slayer = 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
Line 679: Line 649:
--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)
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..'||'..boneQty..'\r\n'..'|}'
result = result..'||'..boneQty..'\r\n'..'|}'
boneVal = boneQty * bones.sellsFor
boneVal = boneQty * bones.item.sellsFor
end
end


Line 696: Line 666:
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 704: Line 674:
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 712: Line 682:


--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 ipairs(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 722: Line 691:
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 735: Line 704:
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 757: Line 726:


--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 795: Line 764:
--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
result = result + boneVal
end
end
Line 807: Line 776:
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 814: Line 783:
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 ipairs(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]


--Adding price columns
--Adding price columns
Line 829: Line 796:


--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
Line 868: Line 835:
local dropWt = 0
local dropWt = 0
for i, row in ipairs(monster.lootTable) do
for i, row in ipairs(monster.lootTable) do
totalWt = totalWt + row[2]
totalWt = totalWt + row.weight
if item.id == row[1] then
if item.id == row.itemID then
dropWt = row[2]
dropWt = row.weight
end
end
end
end
Line 879: Line 846:


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 903: Line 867:


--Sort the loot table by weight in descending order
--Sort the loot table by weight in descending order
local chestDrops, dropIdx = {}, 0
local chestDrops = {}
local hasQty = type(chest.dropQty) == 'table'
for i, row in ipairs(chest.dropTable) do
for i, row in pairs(chest.dropTable) do
table.insert(chestDrops, row)
local qty = hasQty and chest.dropQty[i] or 1
dropIdx = dropIdx + 1
chestDrops[dropIdx] = {row[1], row[2], qty}
end
end
table.sort(chestDrops, 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 ipairs(chestDrops) 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
result = result..'|'..Icons.GP(thisItem.sellsFor * row.minQuantity, thisItem.sellsFor * row.maxQuantity)
result = result..'|'..Icons.GP(thisItem.sellsFor, thisItem.sellsFor * qty)
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((row.minQuantity + row.maxQuantity)/ 2))
else
result = result..'|'..Icons.GP(thisItem.sellsFor)
end
lootValue = lootValue + (dropChance * 0.01 * thisItem.sellsFor * ((1 + qty)/ 2))
end
end
result = result..'\r\n|}'
result = result..'\r\n|}'
Line 1,088: Line 1,045:
local totalHP = 0
local totalHP = 0


for i, monsterID in pairs(area.monsters) do
for i, monsterID in ipairs(area.monsters) 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,164: Line 1,119:
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,181: Line 1,136:
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,191: Line 1,146:
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,236: Line 1,189:
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,274: Line 1,225:
-- 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,318: Line 1,263:


-- 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)
local cmbLevel = p._getMonsterCombatLevel(monster)
local cmbLevel = p._getMonsterCombatLevel(monster)
local atkSpeed = p._getMonsterAttackSpeed(monster)
local atkSpeed = p._getMonsterAttackSpeed(monster)
Line 1,326: Line 1,270:
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 gpRange = {0, 0}
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}
end
local gpTxt = nil
local gpTxt = nil
if gpRange[1] >= gpRange[2] then
if monster.gpDrops.min >= monster.gpDrops.max then
gpTxt = Shared.formatnum(gpRange[1])
gpTxt = Shared.formatnum(monster.gpDrops.min)
else
else
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])
gpTxt = Shared.formatnum(monster.gpDrops.min) .. ' - ' .. Shared.formatnum(monster.gpDrops.max)
end
end
local bones = p._getMonsterBones(monster)
local bones = p._getMonsterBones(monster)
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'
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|-\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: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" |' .. 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="' .. 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)))
Line 1,351: 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="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
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:center" |' .. boneTxt)
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
Line 1,370: Line 1,310:


-- 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)
local cmbLevel = p._getMonsterCombatLevel(monster)


local gpRange = {0, 0}
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}
end
local gpTxt = nil
local gpTxt = nil
if gpRange[1] >= gpRange[2] then
if monster.gpDrops.min >= monster.gpDrops.max then
gpTxt = Shared.formatnum(gpRange[1])
gpTxt = Shared.formatnum(monster.gpDrops.min)
else
else
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])
gpTxt = Shared.formatnum(monster.gpDrops.min) .. ' - ' .. Shared.formatnum(monster.gpDrops.max)
end
end
Line 1,396: Line 1,332:
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:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
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" data-sort-value="' .. lootVal .. '" |' .. lootTxt)
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, false))
end
end


Line 1,420: Line 1,356:


-- 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)
local cmbLevel = p._getMonsterCombatLevel(monster)


local gpRange = {0, 0}
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
gpRange = {monster.dropCoins[1], monster.dropCoins[2]}
end
local gpTxt = nil
local gpTxt = nil
if gpRange[1] >= gpRange[2] then
if monster.gpDrops.min >= monster.gpDrops.max then
gpTxt = Shared.formatnum(gpRange[1])
gpTxt = Shared.formatnum(monster.gpDrops.min)
else
else
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])
gpTxt = Shared.formatnum(monster.gpDrops.min) .. ' - ' .. Shared.formatnum(monster.gpDrops.max)
end
end
Line 1,446: Line 1,378:
local bones = p._getMonsterBones(monster)
local bones = p._getMonsterBones(monster)
local boneTxt = (bones ~= nil and Icons.Icon({bones.name, type='item', notext=true})) or 'None'
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|-\r\n|style="text-align: center;" |' .. Icons.Icon({monster.name, type='monster', size=50, notext=true}))
Line 1,461: Line 1,393:
--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="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
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" data-sort-value="' .. lootVal .. '" |' .. lootTxt)
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
Line 1,474: Line 1,406:
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,511: Line 1,444:
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')
table.insert(resultPart, '\r\n|data-sort-value="' .. chance .. '"| ' .. Shared.round(chance, 2, 0) .. '%')
if firstRow then
if firstRow then
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.description)
table.insert(resultPart, '\r\n' .. rowSuffix .. '| ' .. spAtt.customDescription)
firstRow = false
firstRow = false
end
end