17,101
edits
Falterfire (talk | contribs) (fixed icon not working properly) |
(getDungeonMonsterTable/_getDungeonMonsterList: Add support for Impending Darkness event) |
||
Line 51: | Line 51: | ||
function p.getPassiveByID(ID) | function p.getPassiveByID(ID) | ||
return MonsterData.Passives[ID + 1] | return MonsterData.Passives[ID + 1] | ||
end | |||
-- Given a list of monster IDs, calls statFunc with each monster and returns | |||
-- the lowest & highest values | |||
function p.getLowHighStat(idList, statFunc) | |||
local lowVal, highVal = nil, nil | |||
for i, monID in ipairs(idList) do | |||
local monster = p.getMonsterByID(monID) | |||
local statVal = statFunc(monster) | |||
if lowVal == nil or statVal < lowVal then lowVal = statVal end | |||
if highVal == nil or statVal > highVal then highVal = statVal end | |||
end | |||
return lowVal, highVal | |||
end | end | ||
Line 850: | Line 863: | ||
local usedMonsters = {} | local usedMonsters = {} | ||
local | -- Declare function for building table rows to avoid repeating code | ||
local buildRow = function(entityID, monsterCount, specialType) | |||
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount | |||
local monData = {} | |||
if specialType ~= nil and Shared.contains({'Afflicted', 'SlayerArea'}, specialType) then | |||
-- Special handling for Into the Mist | |||
if specialType == 'Afflicted' then | |||
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'}) | |||
monLevel, monHP, monMaxHit, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, monsterCount | |||
elseif specialType == 'SlayerArea' then | |||
-- entityID corresponds to a slayer area | |||
local area = Areas.getAreaByID('slayer', entityID) | |||
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters' | |||
monLevel = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterCombatLevel(monster) end)} | |||
monHP = {p.getLowHighStat(area.monsters, function(monster) return p._getMonsterHP(monster) end)} | |||
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsters, function(monster) return p._getMonsterMaxHit(monster) end) | |||
monMaxHit = highMaxHit | |||
monStyle = Icons.Icon({area.name, area.name, notext=true, nolink=true, img='Question'}) | |||
monCount = monsterCount | |||
end | |||
else | |||
-- entityID corresponds to a monster | |||
local monster = p.getMonsterByID(entityID) | |||
monIcon = Icons.Icon({monster.name, type='monster'}) | |||
monLevel = p._getMonsterCombatLevel(monster) | |||
monHP = p._getMonsterHP(monster) | |||
monMaxHit = p._getMonsterMaxHit(monster) | |||
monStyle = p._getMonsterStyleIcon({monster}) | |||
monCount = monsterCount | |||
end | |||
local getValSort = function(val) | |||
if type(val) == 'table' then | |||
if type(val[1]) == 'number' and type(val[2]) == 'number' then | |||
return (val[1] + val[2]) / 2 | |||
else | |||
return (type(val[1]) == 'number' and val[1]) or 0 | |||
end | |||
else | |||
return (type(val) == 'number' and val) or 0 | |||
end | |||
end | |||
local getValText = function(val) | |||
if type(val) == 'table' and Shared.tableCount(val) == 2 then | |||
if type(val[1]) == 'number' and type(val[2]) == 'number' then | |||
return Shared.formatnum(val[1]) .. ' - ' .. Shared.formatnum(val[2]) | |||
else | |||
return val[1] .. ' - ' .. val[2] | |||
end | |||
elseif type(val) == 'number' then | |||
return Shared.formatnum(val) | |||
else | |||
return val | |||
end | |||
end | |||
local resultPart = {} | |||
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon) | |||
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(monMaxHit) .. '"| ' .. getValText(monMaxHit)) | |||
table.insert(resultPart, '\r\n| ' .. monStyle) | |||
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monCount) .. '"| ' .. getValText(monCount)) | |||
return table.concat(resultPart) | |||
end | |||
local returnPart = {} | |||
table.insert(returnPart, '{| class="wikitable sortable"') | |||
table.insert(returnPart, '\r\n! Name !! Combat Level !! Hitpoints !! Max Hit !! [[Combat Triangle|Combat Style]] !! Count') | |||
-- Special handing for Impending Darkness event | |||
if area.isEvent ~= nil and area.isEvent then | |||
for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do | |||
table.insert(returnPart, buildRow(eventAreaID, {5, 8}, 'SlayerArea')) | |||
end | |||
-- Add Bane * 4 | |||
table.insert(returnPart, buildRow(152, 4)) | |||
end | |||
for i, monsterID in pairs(area.monsters) do | for i, monsterID in pairs(area.monsters) do | ||
if not Shared.contains(usedMonsters, monsterID) then | if not Shared.contains(usedMonsters, monsterID) then | ||
if monsterID >= 0 then | if monsterID >= 0 then | ||
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID])) | |||
else | else | ||
--Special handling for Into the Mist | --Special handling for Into the Mist | ||
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Afflicted')) | |||
end | end | ||
table.insert(usedMonsters, monsterID) | table.insert(usedMonsters, monsterID) | ||
end | end | ||
end | end | ||
table.insert(returnPart, '\r\n|}') | |||
return | return table.concat(returnPart) | ||
end | end | ||
Line 894: | Line 969: | ||
local lastID = -2 | local lastID = -2 | ||
local count = 0 | local count = 0 | ||
-- Special handing for Impending Darkness event | |||
if area.isEvent ~= nil and area.isEvent then | |||
for i, eventAreaID in ipairs(Areas.eventData.slayerAreas) do | |||
local eventArea = Areas.getAreaByID('slayer', eventAreaID) | |||
table.insert(monsterList, '5-8 ' .. Icons.Icon({eventArea.name, type='combatArea'}) .. ' Monsters') | |||
end | |||
end | |||
for i, monsterID in Shared.skpairs(area.monsters) do | for i, monsterID in Shared.skpairs(area.monsters) do | ||
if monsterID ~= lastID then | if monsterID ~= lastID then | ||
Line 904: | Line 986: | ||
else | else | ||
local name = lastMonster.name | local name = lastMonster.name | ||
table.insert(monsterList, Icons.Icon({name, type='monster', qty=count})) | table.insert(monsterList, Icons.Icon({name, type='monster', qty=count})) | ||
end | end |