Anonymous

Module:CombatAreas/AreaTables: Difference between revisions

From Melvor Idle
Update for v1.3
(getDungeonTable: Add Requirements column; getSlayerAreaTable: Additional formatting for Requirements & area effects columns)
(Update for v1.3)
Line 4: Line 4:


local Constants = require('Module:Constants')
local Constants = require('Module:Constants')
local Common = require('Module:Common')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
Line 11: Line 12:
local Pets = require('Module:Pets')
local Pets = require('Module:Pets')
local Areas = require('Module:CombatAreas')
local Areas = require('Module:CombatAreas')


function p.getLowHighLevels(idList)
function p.getLowHighLevels(idList)
Line 24: Line 26:
end
end


function p.getCombatAreaTable()
function p.getAreaCategory(area)
for _, areaCat in ipairs(GameData.rawData.combatAreaCategories) do
if areaCat.areas ~= nil and Shared.contains(areaCat.areas, area.id) then
return areaCat
end
end
end
 
function p.getAreaCategoriesFromAreas(areas)
local areaCatIDs = {}
for i, area in ipairs(areas) do
local areaCat = p.getAreaCategory(area)
if areaCat ~= nil and areaCat.id ~= nil then
areaCatIDs[areaCat.id] = true
end
end
return GameData.getEntities('combatAreaCategories',
function(obj)
return obj.id ~= nil and areaCatIDs[obj.id] ~= nil
end
)
end
 
local function getAreasForTable(areaDataKey, categoryName, defaultCategoryID)
local areaCategories = p.getAreaCategoriesFromAreas(GameData.rawData[areaDataKey])
local areaCategory = nil
 
if categoryName == nil or categoryName == '' then
-- Default area category
areaCategory = GameData.getEntityByID(areaCategories, defaultCategoryID)
else
areaCategory = GameData.getEntityByName(areaCategories, categoryName)
end
if areaCategory == nil then
local catNames = {}
for _, areaCat in ipairs(areaCategories) do
if areaCat.name ~= nil then
table.insert(catNames, areaCat.name)
end
end
return nil, Shared.printError('Invalid area category, choose any of: ' .. table.concat(catNames, ', '))
end
 
local areas = GameData.getEntities(areaDataKey,
function(obj)
return obj.id ~= nil and Shared.contains(areaCategory.areas, obj.id)
end
)
areas = GameData.sortByOrderTable(areas, areaCategory.areas)
return areas, nil
end
 
function p.getCombatAreaTable(frame)
local args = frame.args ~= nil and frame.args or frame
local categoryName = args[1]
 
local areas, errText = getAreasForTable('combatAreas', categoryName, 'melvorD:CombatAreas')
if errText ~= nil then
return errText
elseif areas == nil then
return ''
end
 
local result = '{| class="wikitable sortable stickyHeader"'
local result = '{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Zone!!Difficulty!!Lowest Monster Level!!Highest Monster Level!!Requirements'
result = result..'\r\n!colspan="2"|Zone!!Difficulty!!Lowest Monster Level!!Highest Monster Level!!Requirements'


local areas = GameData.sortByOrderTable(GameData.rawData.combatAreas, GameData.rawData.combatAreaDisplayOrder)
for i, area in ipairs(areas) do
for i, area in ipairs(areas) do
result = result..'\r\n|-'
result = result..'\r\n|-'
Line 50: Line 113:
end
end


function p.getSlayerAreaTable()
function p.getSlayerAreaTable(frame)
local args = frame.args ~= nil and frame.args or frame
local categoryName = args[1]
 
local areas, errText = getAreasForTable('slayerAreas', categoryName, 'melvorF:SlayerAreas')
if errText ~= nil then
return errText
elseif areas == nil then
return ''
end
 
local result = '{| class="wikitable sortable stickyHeader"'
local result = '{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!colspan="2"|Zone!!Difficulty!!Highest Monster Level!!Requirements!!Area Effect'
result = result..'\r\n!colspan="2"|Zone!!Difficulty!!Highest Monster Level!!Requirements!!Area Effect'


local areas = GameData.sortByOrderTable(GameData.rawData.slayerAreas, GameData.rawData.slayerAreaDisplayOrder)
for i, area in ipairs(areas) do
for i, area in ipairs(areas) do
result = result..'\r\n|-'
result = result..'\r\n|-'
Line 86: Line 158:
end
end


local chr = asList and '* ' or ''
local lineSep = (asList and '\n' or '<br>')
local rewardList = {}
local formatLine = nil
if asList then
formatLine = function(text) return '* ' .. text end
end
-- GP reward
-- Currency rewards
local rewardCurrency = {}
if area.eventID == nil then
if area.eventID == nil then
local bossMonster = Monsters.getMonsterByID(area.monsterIDs[Shared.tableCount(area.monsterIDs)])
local bossMonster = Monsters.getMonsterByID(area.monsterIDs[Shared.tableCount(area.monsterIDs)])
local gp = bossMonster.gpDrops
rewardCurrency = bossMonster.currencyDrops
if gp.min > 0 and gp.max > 0 then
if gp.min == gp.max then
table.insert(rewardList, chr .. Icons.GP(gp.min))
else
table.insert(rewardList, chr .. Icons.GP(gp.min, gp.max))
end
end
end
end
Line 113: Line 182:
end
end
end
end
local rewardItem = {}
for i, itemList in ipairs(itemLists) do
for i, itemList in ipairs(itemLists) do
for j, rewardID in ipairs(itemList) do
for j, rewardID in ipairs(itemList) do
local rewardItem = Items.getItemByID(rewardID)
table.insert(rewardItem, {
if rewardItem == nil then
["id"] = rewardID,
table.insert(rewardList, chr .. 'Unknown item (ID ' .. rewardID .. ')[[Category:Pages with script errors]]')
["quantity"] = 1
else
})
table.insert(rewardList, chr .. Icons.Icon({rewardItem.name, type='item', qty=1}))
end
end
end
end
end


if asList then
return Common.getCostString({ ["items"] = rewardItem, ["currencies"] = rewardCurrency}, '', formatLine, lineSep)
return table.concat(rewardList, '\r\n')
else
return table.concat(rewardList, '<br/>')
end
end
end


Line 147: Line 212:


function p.getDungeonTable(frame)
function p.getDungeonTable(frame)
local args = frame.args ~= nil and frame.args or frame
local categoryName = args[1]
local areas, errText = getAreasForTable('dungeons', categoryName, 'melvorD:Dungeons')
if errText ~= nil then
return errText
elseif areas == nil then
return ''
end
local result = '{| class="wikitable sortable stickyHeader"'
local result = '{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|-class="headerRow-0"'
result = result..'\r\n|-class="headerRow-0"'
result = result..'\r\n!colspan="2"|Dungeon!!Difficulty!!Monsters!!Boss Level!!Requirements!!Rewards!!Boss Pet'
result = result..'\r\n!colspan="2"|Dungeon!!Difficulty!!Monsters!!Boss Level!!Requirements!!Rewards!!Boss Pet'


local areas = GameData.sortByOrderTable(GameData.rawData.dungeons, GameData.rawData.dungeonDisplayOrder)
for i, dung in ipairs(areas) do
for i, dung in ipairs(areas) do
local monsterCount = Shared.tableCount(dung.monsterIDs)
local monsterCount = Shared.tableCount(dung.monsterIDs)
Line 190: Line 264:
end
end


local function getAreaOrderTable(areaCategoryID)
local areaCategory = GameData.getEntityByID('combatAreaCategories', areaCategoryID)
if areaCategory == nil then
return {}
else
return areaCategory.areas
end
end
function p.buildCombatNavText(frame)
function p.buildCombatNavText(frame)
--This isn't actually called on any pages but instead exists to save me time on updating Template:CombatNav for the new expansion
--This isn't actually called on any pages but instead exists to save me time on updating Template:CombatNav for the new expansion
local areas = GameData.sortByOrderTable(GameData.rawData.slayerAreas, GameData.rawData.slayerAreaDisplayOrder)
local areas = GameData.sortByOrderTable(GameData.rawData.slayerAreas, getAreaOrderTable('melvorD:SlayerAreas'))
local outArray = {}
local outArray = {}
for i, area in ipairs(areas) do
for i, area in ipairs(areas) do
Line 208: Line 290:
end
end
areas = GameData.sortByOrderTable(GameData.rawData.dungeons, GameData.rawData.dungeonDisplayOrder)
areas = GameData.sortByOrderTable(GameData.rawData.dungeons, getAreaOrderTable('melvorD:Dungeons'))
for i, area in ipairs(areas) do
for i, area in ipairs(areas) do
local id = area.id
local id = area.id