Anonymous

Module:Monsters: Difference between revisions

From Melvor Idle
Added handling for barriers
(Added getMonsterBoxBarrierText function)
(Added handling for barriers)
Line 1,229: Line 1,229:
return p.getDungeonMonsterTable(frame)
return p.getDungeonMonsterTable(frame)
end
end
 
local tableTxt = '{| class="wikitable sortable"'
tableTxt = tableTxt..'\r\n! Name !! Combat Level !! Hitpoints !! colspan=2| Max Hit !! [[Combat Triangle|Combat Style]]'
local monsters = {}
local hasBarrier = false
for i, monsterID in ipairs(area.monsterIDs) 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({p.getMonsterName(monster), type='monster'})
if not hasBarrier and p._getMonsterBarrier(monster) > 0 then
tableTxt = tableTxt..'||'..p._getMonsterCombatLevel(monster)
hasBarrier = true
tableTxt = tableTxt..'||'..Shared.formatnum(p._getMonsterHP(monster))
end
table.insert(monsters, monster)
end
 
local tableBits = {}
table.insert(tableBits, '{| class="wikitable sortable"')
table.insert(tableBits, '\r\n! Name !! Combat Level ')
if hasBarrier then
table.insert(tableBits, '!! [[Barrier]] ')
end
table.insert(tableBits, '!! Hitpoints !! colspan=2| Max Hit !! [[Combat Triangle|Combat Style]]')
for i, monster in ipairs(monsters) do
local rowBits = {}
table.insert(tableBits, '\r\n|-\r\n|'..Icons.Icon({p.getMonsterName(monster), type='monster'}))
table.insert(tableBits, '||'..p._getMonsterCombatLevel(monster))
if hasBarrier then
table.insert(tableBits, '||'..Shared.formatnum(p._getMonsterBarrier(monster)))
end
table.insert(tableBits, '||'..Shared.formatnum(p._getMonsterHP(monster)))
local drReduction = p._getMonsterDrReduction(monster)
local drReduction = p._getMonsterDrReduction(monster)
local maxHit = p._getMonsterMaxHit(monster)
local maxHit = p._getMonsterMaxHit(monster)
if drReduction > 0 then
if drReduction > 0 then
tableTxt = tableTxt..'||style="text-align:right" data-sort-value="'..maxHit..'"| -'..drReduction..'% DR'
table.insert(tableBits, '||style="text-align:right" data-sort-value="'..maxHit..'"| -'..drReduction..'% DR')
tableTxt = tableTxt..'||style="text-align:right"|'..Shared.formatnum(maxHit)
table.insert(tableBits, '||style="text-align:right"|'..Shared.formatnum(maxHit))
else
else
tableTxt = tableTxt..'||style="text-align:right" colspan="2" data-sort-value="'..maxHit..'"|'..Shared.formatnum(maxHit)
table.insert(tableBits, '||style="text-align:right" colspan="2" data-sort-value="'..maxHit..'"|'..Shared.formatnum(maxHit))
end
end
tableTxt = tableTxt..'||'..p._getMonsterStyleIcon({monster, nolink=true})
table.insert(tableBits, '||'..p._getMonsterStyleIcon({monster, nolink=true}))
end
end
tableTxt = tableTxt..'\r\n|}'
table.insert(tableBits, '\r\n|}')
return tableTxt
return table.concat(tableBits, '')
end
end


Line 1,260: Line 1,281:
--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 = {}
local monsters = {}
local hasBarrier = false
for i, monsterID in ipairs(area.monsterIDs) do
for i, monsterID in ipairs(area.monsterIDs) do
if monsterCounts[monsterID] == nil then
if monsterCounts[monsterID] == nil then
Line 1,265: Line 1,288:
else
else
monsterCounts[monsterID] = monsterCounts[monsterID] + 1
monsterCounts[monsterID] = monsterCounts[monsterID] + 1
if monsterID ~= 'melvorF:RandomITM' and monsterID ~= 'melvorTotH:RandomSpiderLair' then
monsters[monsterID] = p.getMonsterByID(monsterID)
if not hasBarrier and p._getMonsterBarrier(monsters[monsterID]) > 0 then
hasBarrier = true
end
end
end
end
end
end
Line 1,272: Line 1,301:
-- 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, monDrReduce
local monIcon, monLevel, monHP, monMaxHit, monStyle, monCount, monDrReduce, monBarrier
local monData = {}
local monData = {}
if specialType ~= nil and Shared.contains({'Afflicted', 'Spider', 'SlayerArea'}, specialType) then
if specialType ~= nil and Shared.contains({'Afflicted', 'Spider', 'SlayerArea'}, specialType) then
Line 1,279: Line 1,308:
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, monDrReduce, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, iconQ, monsterCount
monLevel, monBarrier, monHP, monMaxHit, monDrReduce, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, iconQ, iconQ, monsterCount
elseif specialType == 'Spider' then
elseif specialType == 'Spider' then
local iconQ = Icons.Icon({'', notext=true, nolink=true, img='Question'})
local iconQ = Icons.Icon({'', notext=true, nolink=true, img='Question'})
Line 1,290: Line 1,319:
end
end
monIcon = table.concat(monIconPart, '<br/>')
monIcon = table.concat(monIconPart, '<br/>')
monLevel, monHP, monMaxHit, monDrReduce, monStyle, monCount = iconQ, iconQ, iconQ, iconQ, iconQ, monsterCount
monLevel, monBarrier, monHP, monMaxHit, monDrReduce, monStyle, monCount = iconQ, 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
Line 1,296: Line 1,325:
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'
monIcon = Icons.Icon({area.name, type='combatArea'}) .. ' Monsters'
monLevel = {p.getLowHighStat(area.monsterIDs, function(monster) return p._getMonsterCombatLevel(monster) end)}
monLevel = {p.getLowHighStat(area.monsterIDs, function(monster) return p._getMonsterCombatLevel(monster) end)}
if hasBarrier then
monBarrier = {p.getLowHighStat(area.monsterIDs, function(monster) return p._getMonsterBarrier(monster) end)}
end
monHP = {p.getLowHighStat(area.monsterIDs, 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.monsterIDs, function(monster) return p._getMonsterMaxHit(monster) end)
local lowMaxHit, highMaxHit = p.getLowHighStat(area.monsterIDs, function(monster) return p._getMonsterMaxHit(monster) end)
Line 1,309: Line 1,341:
monIcon = Icons.Icon({p.getMonsterName(monster), type='monster'})
monIcon = Icons.Icon({p.getMonsterName(monster), type='monster'})
monLevel = p._getMonsterCombatLevel(monster)
monLevel = p._getMonsterCombatLevel(monster)
if hasBarrier then
monBarrier = p._getMonsterBarrier(monster)
end
monHP = p._getMonsterHP(monster)
monHP = p._getMonsterHP(monster)
monDrReduce = p._getMonsterDrReduction(monster)
monDrReduce = p._getMonsterDrReduction(monster)
Line 1,343: Line 1,378:
table.insert(resultPart, '\r\n|-\r\n| ' .. monIcon)
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(monLevel) .. '"| ' .. getValText(monLevel))
if hasBarrier then
table.insert(resultPart, '\r\n|style="text-align:right;" data-sort-value="' .. getValSort(monBarrier) .. '"| ' .. getValText(monBarrier))
end
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))
if type(monDrReduce) == 'number' and monDrReduce > 0 then
if type(monDrReduce) == 'number' and monDrReduce > 0 then
Line 1,357: Line 1,395:
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 !! colspan="2" | Max Hit !! [[Combat Triangle|Combat Style]] !! Count')
table.insert(returnPart, '\r\n! Name !! Combat Level ')
if hasBarrier then
table.insert(returnPart, '!! Barrier ')
end
table.insert(returnPart, '!! 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
--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 ipairs(area.monsterIDs) do
for i, monsterID in ipairs(area.monsterIDs) do
if not Shared.contains(usedMonsters, monsterID) then
if not Shared.contains(usedMonsters, monsterID) then
Line 1,375: Line 1,410:
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Spider'))
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], 'Spider'))
else
else
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID]))
table.insert(returnPart, buildRow(monsterID, monsterCounts[monsterID], hasBarrier))
end
end
table.insert(usedMonsters, monsterID)
table.insert(usedMonsters, monsterID)
Line 1,412: Line 1,447:
local lastID = ''
local lastID = ''
local count = 0
local count = 0
-- Special handing for Impending Darkness event
-- TODO needs to be revised once there is a better understanding of how the event works
--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
-- table.insert(monsterList, '4 ' .. Icons.Icon({'Bane', type='monster'}))
--end
local monsterCounts = {}
local monsterCounts = {}