Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
Creating monster table with average drop value for matt
m (getMonsterByID now returns nil instead of erroring)
(Creating monster table with average drop value for matt)
Line 774: Line 774:
--If no other drops, make sure to at least say so.
--If no other drops, make sure to at least say so.
if result == '' then result = 'None' end
if result == '' then result = 'None' end
return result
end
function p._getMonsterLootValue(monster)
if monster == nil then
return "ERROR: No monster with that name found[[Category:Pages with script errors]]"
end
local result = 0
local boneVal = 0
local bones = p._getMonsterBones(monster)
--Show the bones only if either the monster shows up outside of dungeons _or_ the monster drops shards
if bones ~= nil then
local boneQty = monster.boneQty ~= nil and monster.boneQty or 1
boneVal = bones.sellsFor * boneQty
end
--Likewise, seeing the loot table is tied to the monster appearing outside of dungeons
if not p._isDungeonOnlyMonster(monster) then
local lootChance = monster.lootChance ~= nil and monster.lootChance or 100
local lootValue = 0
local avgGp = 0
if monster.dropCoins ~= nil and monster.dropCoins[2] > 1 then
avgGp = (monster.dropCoins[1] + monster.dropCoins[2]) / 2
end
local multiDrop = Shared.tableCount(monster.lootTable) > 1
local totalWt = 0
for i, row in pairs(monster.lootTable) do
totalWt = totalWt + row[2]
end
for i, row in Shared.skpairs(monster.lootTable) do
local thisItem = Items.getItemByID(row[1])
local maxQty = row[3]
result = result..Shared.formatnum(row[3])
--Adding price columns
local itemPrice = 0
if thisItem ~= nil then
itemPrice = thisItem.sellsFor ~= nil and thisItem.sellsFor or 0
end
--Getting the drop chance
local dropChance = (row[2] / totalWt * lootChance)
--Adding to the average loot value based on price & dropchance
lootValue = lootValue + (dropChance * 0.01 * itemPrice * ((1 + maxQty) / 2))
end
if avgGp > 0 then
result = avgGp + lootValue
end
end
return result
return result
end
end
Line 1,291: Line 1,348:
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
table.insert(tableParts, '\r\n|style="text-align:right" data-sort-value="' .. (gpRange[1] + gpRange[2]) / 2 .. '" |' .. gpTxt)
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
table.insert(tableParts, '\r\n|style="text-align:center" |' .. boneTxt)
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
end
table.insert(tableParts, '\r\n|}')
return table.concat(tableParts)
end
function p.getMattMonsterTable(frame)
--Making a single function for getting a table of monsters given a list of IDs.
local tableParts = {}
table.insert(tableParts, '{| class="wikitable sortable stickyHeader"')
-- Second header row
table.insert(tableParts, '\r\n|- class="headerRow-1"\r\n!Monster !!Name !!ID !!Combat Level ')
table.insert(tableParts, '!!style="padding:0 1em 0 0"|' .. Icons.Icon({'Hitpoints', type='skill'}))
table.insert(tableParts, '!!' .. Icons.Icon({'Coins', notext=true, nolink=true}) .. ' Coins !!Avg. Kill Value!!Locations')
-- Generate row per monster
for i, monster in Shared.skpairs(MonsterData.Monsters) do
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
if gpRange[1] >= gpRange[2] then
gpTxt = Shared.formatnum(gpRange[1])
else
gpTxt = Shared.formatnum(gpRange[1]) .. ' - ' .. Shared.formatnum(gpRange[2])
end
local lootVal = p._getMonsterLootValue(monster)
local lootTxt = nil
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;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
table.insert(tableParts, '\r\n|style="text-align:right;width:190px" |' .. p._getMonsterAreas(monster, hideDungeons))
end
end