Module:CombatAreas/AreaTables: Difference between revisions

From Melvor Idle
(getCombatAreaTable: Add Requirements column)
(getDungeonTable: Add Requirements column; getSlayerAreaTable: Additional formatting for Requirements & area effects columns)
Line 63: Line 63:
local lowLvl, highLvl = p.getLowHighLevels(area.monsterIDs)
local lowLvl, highLvl = p.getLowHighLevels(area.monsterIDs)
result = result..'||data-sort-value="' .. highLvl .. '"| ' .. Shared.formatnum(highLvl)
result = result..'||data-sort-value="' .. highLvl .. '"| ' .. Shared.formatnum(highLvl)
result = result..'||'..Areas._getAreaRequirements(area)
local reqText = Areas._getAreaRequirements(area)
result = result..'|| '..Areas._getAreaStat(area, 'areaEffectDesc')
if reqText == nil or reqText == '' then
result = result .. '||class="table-na"| None'
else
result = result .. '||' .. reqText
end
local effectText = Areas._getAreaStat(area, 'areaEffectDesc')
local classText = ((effectText == nil or effectText == 'None') and 'class="table-na"|') or ''
result = result..'||' .. classText .. ' ' .. effectText
end
end


Line 142: Line 149:
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!!Reward(s)!!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)
local areas = GameData.sortByOrderTable(GameData.rawData.dungeons, GameData.rawData.dungeonDisplayOrder)
Line 155: Line 162:
result = result..'||'..monsterCount
result = result..'||'..monsterCount
result = result..'||'..Shared.formatnum(Monsters._getMonsterCombatLevel(boss))
result = result..'||'..Shared.formatnum(Monsters._getMonsterCombatLevel(boss))
local reqText = Areas._getAreaRequirements(dung)
if reqText == nil or reqText == '' then
result = result .. '||class="table-na"| None'
else
result = result .. '||' .. reqText
end
result = result..'||'..p._getDungeonRewards(dung, false)
result = result..'||'..p._getDungeonRewards(dung, false)
local petAdded = false
if dung.pet ~= nil then
if dung.pet ~= nil then
local pet = GameData.getEntityByID('pets', dung.pet.petID)
local pet = GameData.getEntityByID('pets', dung.pet.petID)
Line 164: Line 178:
result = result..'<br/>'..petDrop
result = result..'<br/>'..petDrop
end
end
petAdded = true
end
end
else
end
result = result..'|| '
if not petAdded then
result = result..'||class="table-na"| None'
end
end
end
end

Revision as of 21:53, 6 October 2023

Documentation for this module may be created at Module:CombatAreas/AreaTables/doc

--Splitting this out so I can make Module:Monsters calls (Monsters calls CombatAreas, so this prevents a loop)

local p = {}

local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Monsters = require('Module:Monsters')
local Pets = require('Module:Pets')
local Areas = require('Module:CombatAreas')

function p.getLowHighLevels(idList)
	local lowLevel = 1000000
	local highLevel = 0
	for i, monID in ipairs(idList) do
		local monster = Monsters.getMonsterByID(monID)
		local cmbLevel = Monsters._getMonsterCombatLevel(monster)
		if cmbLevel < lowLevel then lowLevel = cmbLevel end
		if cmbLevel > highLevel then highLevel = cmbLevel end
	end
	return lowLevel, highLevel
end

function p.getCombatAreaTable()
	local result = '{| class="wikitable sortable stickyHeader"'
	result = result..'\r\n|- class="headerRow-0"'
	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
		result = result..'\r\n|-'
		result = result..'\r\n|class="table-img" data-sort-value="' .. area.name .. '"| '..Icons.Icon({area.name, type='combatArea', size='50', notext=true})
		result = result..'||' .. Icons.getExpansionIcon(area.id) .. Icons.Icon({area.name, type='combatArea', noicon=true})
		result = result..'||data-sort-value="'..area.difficulty[1]..'"|'..Areas._getAreaStat(area, 'difficulty')
		local lowLvl, highLvl = p.getLowHighLevels(area.monsterIDs)
		result = result .. '||data-sort-value="' .. lowLvl .. '"| ' .. Shared.formatnum(lowLvl)
		result = result .. '||data-sort-value="' .. highLvl .. '"| ' .. Shared.formatnum(highLvl)
		local reqText = Areas._getAreaRequirements(area)
		if reqText == nil or reqText == '' then
			result = result .. '||class="table-na"| None'
		else
			result = result .. '||' .. reqText
		end
	end
	result = result..'\r\n|}'

	return result
end

function p.getSlayerAreaTable()
	local result = '{| class="wikitable sortable stickyHeader"'
	result = result..'\r\n|- class="headerRow-0"'
	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
		result = result..'\r\n|-'
		result = result..'\r\n|class="table-img" data-sort-value="' .. area.name .. '"| '..Icons.Icon({area.name, type='slayer', size='50', notext=true})
		result = result..'||' .. Icons.getExpansionIcon(area.id) .. Icons.Icon({area.name, type='slayer', noicon=true})
		result = result..'||data-sort-value="'..area.difficulty[1]..'"|'..Areas._getAreaStat(area, 'difficulty')
		local lowLvl, highLvl = p.getLowHighLevels(area.monsterIDs)
		result = result..'||data-sort-value="' .. highLvl .. '"| ' .. Shared.formatnum(highLvl)
		local reqText = Areas._getAreaRequirements(area)
		if reqText == nil or reqText == '' then
			result = result .. '||class="table-na"| None'
		else
			result = result .. '||' .. reqText
		end
		local effectText = Areas._getAreaStat(area, 'areaEffectDesc')
		local classText = ((effectText == nil or effectText == 'None') and 'class="table-na"|') or ''
		result = result..'||' .. classText .. ' ' .. effectText
	end

	result = result..'\r\n|}'

	return result
end

function p._getDungeonRewards(area, asList)
	if asList == nil then
		asList = true
	elseif type(asList) == 'string' then
		asList = string.upper(asList) ~= 'FALSE'
	end

	local chr = asList and '* ' or ''
	local rewardList = {}
	
	-- GP reward
	if area.eventID == nil then
		local bossMonster = Monsters.getMonsterByID(area.monsterIDs[Shared.tableCount(area.monsterIDs)])
		local gp = bossMonster.gpDrops
		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
	
	-- Item rewards
	local itemLists = {}
	if type(area.rewardItemIDs) == 'table' then
		table.insert(itemLists, area.rewardItemIDs)
	end
	if area.eventID ~= nil then
		local event = GameData.getEntityByID('combatEvents', area.eventID)
		if event ~= nil and type(event.itemRewardIDs) == 'table' then
			table.insert(itemLists, event.itemRewardIDs)
		end
	end
	for i, itemList in ipairs(itemLists) do
		for j, rewardID in ipairs(itemList) do
			local rewardItem = Items.getItemByID(rewardID)
			if rewardItem == nil then
				table.insert(rewardList, chr .. 'Unknown item (ID ' .. rewardID .. ')[[Category:Pages with script errors]]')
			else
				table.insert(rewardList, chr .. Icons.Icon({rewardItem.name, type='item', qty=1}))
			end
		end
	end

	if asList then
		return table.concat(rewardList, '\r\n')
	else
		return table.concat(rewardList, '<br/>')
	end
end

function p.getDungeonRewards(frame)
	local areaName = frame.args ~= nil and frame.args[1] or frame
	local asList = frame.args ~= nil and frame.args[2] or true
	local area = Areas.getArea(areaName)
	if area == nil then
		return Shared.printError('Could not find an area named "' .. areaName .. '"')
	end

	if area.type == 'dungeon' then
		return p._getDungeonRewards(area, asList)
	else
		return Shared.printError('"' .. areaName .. '" is not a dungeon')
	end
end

function p.getDungeonTable(frame)
	local result = '{| class="wikitable sortable stickyHeader"'
	result = result..'\r\n|-class="headerRow-0"'
	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
		local monsterCount = Shared.tableCount(dung.monsterIDs)
		local boss = Monsters.getMonsterByID(dung.monsterIDs[monsterCount])

		result = result..'\r\n|-'
		result = result..'\r\n|class="table-img" data-sort-value="'..dung.name..'"|'..Icons.Icon({dung.name, type='dungeon', size='50', notext=true})
		result = result..'||' .. Icons.getExpansionIcon(dung.id) .. Icons.Icon({dung.name, type='dungeon', noicon=true})
		result = result..'||data-sort-value="'..dung.difficulty[1]..'"|'..Areas._getAreaStat(dung, 'difficulty')
		result = result..'||'..monsterCount
		result = result..'||'..Shared.formatnum(Monsters._getMonsterCombatLevel(boss))
		local reqText = Areas._getAreaRequirements(dung)
		if reqText == nil or reqText == '' then
			result = result .. '||class="table-na"| None'
		else
			result = result .. '||' .. reqText
		end
		result = result..'||'..p._getDungeonRewards(dung, false)
		local petAdded = false
		if dung.pet ~= nil then
			local pet = GameData.getEntityByID('pets', dung.pet.petID)
			if pet ~= nil then
				result = result..'||data-sort-value="'..pet.name..'"|'..Icons.Icon({pet.name, type='pet'})
				local petDrop = Pets._getPetChance(pet)
				if petDrop ~= nil then
					result = result..'<br/>'..petDrop
				end
				petAdded = true
			end
		end
		if not petAdded then
			result = result..'||class="table-na"| None'
		end
	end

	result = result..'\r\n|}'
	return result
end

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
	local areas = GameData.sortByOrderTable(GameData.rawData.slayerAreas, GameData.rawData.slayerAreaDisplayOrder)
	local outArray = {}
	for i, area in ipairs(areas) do
		local id = area.id
		if Shared.startsWith(id, 'melvorTotH') then
			table.insert(outArray, '|-')
			table.insert(outArray, '| {{TotH}} {{ZoneIcon|'..area.name..'}}')
			local monsterArray = {}
			for j, monsterID in ipairs(area.monsterIDs) do
				local monster = Monsters.getMonsterByID(monsterID)
				table.insert(monsterArray, '{{MonsterIcon|'..monster.name..'}}')
			end
			table.insert(outArray, '| class="center" style="vertical-align:middle;" | '..table.concat(monsterArray, ' {{*}} '))
		end
	end
	
	areas = GameData.sortByOrderTable(GameData.rawData.dungeons, GameData.rawData.dungeonDisplayOrder)
	for i, area in ipairs(areas) do
		local id = area.id
		if Shared.startsWith(id, 'melvorTotH') then
			table.insert(outArray, '|-')
			table.insert(outArray, '| {{TotH}} {{ZoneIcon|'..area.name..'}}')
			local monsterArray = {}
			local mCheck = {}
			for j, monsterID in ipairs(area.monsterIDs) do
				local monster = Monsters.getMonsterByID(monsterID)
				if mCheck[monster.name] == nil then
					table.insert(monsterArray, '{{MonsterIcon|'..monster.name..'}}')
					mCheck[monster.name] = 1
				end
					end
			table.insert(outArray, '| class="center" style="vertical-align:middle;" | '..table.concat(monsterArray, ' {{*}} '))
		end
	end
	
	return table.concat(outArray, '\r\n')
end

return p