16,254
edits
(getMonsterAreas: Add handling for Lair of the Spider Queen random monster pool) |
(Update for v1.3) |
||
(7 intermediate revisions by 2 users not shown) | |||
Line 5: | Line 5: | ||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local GameData = require('Module:GameData') | local GameData = require('Module:GameData') | ||
local Common = require('Module:Common') | |||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local areaMap = { | local areaMap = { | ||
["combat"] = 'combatAreas', | |||
["dungeon"] = 'dungeons', | |||
["slayer"] = 'slayerAreas', | |||
["depth"] = 'abyssDepths' | |||
} | } | ||
function p.getArea(name) | function p.getArea(name) | ||
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue | --There are three types of areas but the lists are pretty short so looping all of them isn't a real issue | ||
for k, areaType in pairs(areaMap) do | |||
local area = GameData.getEntityByName(areaType, name) | |||
if area ~= nil then | |||
return area | |||
end | |||
end | |||
end | end | ||
function p.getAreaByID(id, | function p.getAreaByID(id, areaType) | ||
for aType, areaKey in pairs(areaMap) do | |||
if areaType == nil or areaType == aType then | |||
local area = GameData.getEntityByID(areaKey, id) | |||
if area ~= nil then | |||
return area | |||
end | |||
end | |||
end | |||
end | end | ||
function p.getAreaFilterType(name, type) | function p.getAreaFilterType(name, type) | ||
local areaType = areaMap[type] | |||
if areaType ~= nil then | |||
return GameData.getEntityByName(areaType, name) | |||
end | |||
end | end | ||
Line 42: | Line 46: | ||
local resultArray = nil | local resultArray = nil | ||
for i, areaType in pairs(areaMap) do | |||
local areas = GameData.getEntities(areaType, checkFunc) | |||
if resultArray == nil then | |||
resultArray = areas | |||
else | |||
for k, area in ipairs(areas) do | |||
table.insert(resultArray, area) | |||
end | |||
end | |||
end | |||
if resultArray == nil then | |||
resultArray = {} | |||
end | |||
return resultArray | |||
end | |||
--Returns the expansion icon for the area if it has one | |||
function p.getExpansionIcon(frame) | |||
local areaName = frame.args ~= nil and frame.args[1] or frame | |||
local area = p.getArea(areaName) | |||
if area == nil then | |||
return Shared.printError('No area named "' .. areaName .. '" exists in the data module') | |||
end | |||
return Icons.getExpansionIcon(area.id) | |||
end | end | ||
function p._getAreaRequirements(area) | function p._getAreaRequirements(area) | ||
local resultArray = {} | local resultArray = {} | ||
if area.entryRequirements ~= nil then | |||
local reqText = Common.getRequirementString(area.entryRequirements) | |||
if reqText ~= nil then | |||
table.insert(resultArray, reqText) | |||
end | |||
end | |||
if area.unlockRequirement ~= nil then | |||
-- Avoid repeating the same requirements twice, can happen for some dungeons e.g. Impending Darkness | |||
if area.entryRequirements == nil or mw.dumpObject(area.unlockRequirement) ~= mw.dumpObject(area.entryRequirements) then | |||
local reqText = Common.getRequirementString(area.unlockRequirement) | |||
if reqText ~= nil then | |||
table.insert(resultArray, reqText) | |||
table.insert( | |||
end | end | ||
end | end | ||
end | end | ||
if area. | return table.concat(resultArray, '<br/>') | ||
end | |||
function p.getAreaRequirementsForBox(frame) | |||
--Returns infobox formatting for requirements, or returns nothing if there are none. | |||
local areaName = frame.args ~= nil and frame.args[1] or frame | |||
local area = p.getArea(areaName) | |||
if area == nil then | |||
return Shared.printError('No area named "' .. areaName .. '" exists in the data module') | |||
end | end | ||
if | local reqs = p._getAreaRequirements(area) | ||
if reqs ~= '' then | |||
reqs = "|-\r\n|'''Requirements:'''\r\n"..reqs | |||
end | end | ||
return reqs | |||
return | |||
end | end | ||
Line 128: | Line 137: | ||
local area = p.getArea(areaName) | local area = p.getArea(areaName) | ||
if area == nil then | if area == nil then | ||
return | return Shared.printError('No area named "' .. areaName .. '" exists in the data module') | ||
end | end | ||
Line 134: | Line 143: | ||
end | end | ||
function p. | function p._isMonsterInArea(monster, area) | ||
return ( | |||
Shared.contains(area.monsterIDs, monster.id) | |||
-- Check for Lair of the Spider Queen random spiders | |||
or ( | |||
Shared.contains(area.monsterIDs, 'melvorTotH:RandomSpiderLair') | |||
and Shared.contains(GameData.rawData.spiderLairMonsters, monster.id) | |||
) | |||
) | |||
end | |||
function p._getMonsterAreas(monster) | |||
-- Special handling for Lair of the Spider Queen, which has a random list of enemies | -- Special handling for Lair of the Spider Queen, which has a random list of enemies | ||
local randomSpiderCheck = Shared.contains(GameData.rawData.spiderLairMonsters, | local randomSpiderCheck = Shared.contains(GameData.rawData.spiderLairMonsters, monster.id) | ||
return p.getAreas( | return p.getAreas( | ||
function(area) | function(area) | ||
return | return p._isMonsterInArea(monster, area) | ||
end) | end) | ||
end | end | ||
Line 148: | Line 167: | ||
local area = p.getArea(areaName) | local area = p.getArea(areaName) | ||
if area == nil then | if area == nil then | ||
return | return Shared.printError('No area named "' .. areaName .. '" exists in the data module') | ||
end | end | ||