Module:CombatAreas: Difference between revisions

Update for v1.3
(Refactor _getAreaRequirements & drop dependency on Shop, Items modules)
(Update for v1.3)
(2 intermediate revisions by 2 users not shown)
Line 11: Line 11:
["combat"] = 'combatAreas',
["combat"] = 'combatAreas',
["dungeon"] = 'dungeons',
["dungeon"] = 'dungeons',
["slayer"] = 'slayerAreas'
["slayer"] = 'slayerAreas',
["depth"] = 'abyssDepths'
}
}


Line 24: Line 25:
end
end


function p.getAreaByID(id, type)
function p.getAreaByID(id, areaType)
local areaType = areaMap[type]
for aType, areaKey in pairs(areaMap) do
if areaType ~= nil then
if areaType == nil or areaType == aType then
return GameData.getEntityByID(areaType, id)
local area = GameData.getEntityByID(areaKey, id)
if area ~= nil then
return area
end
end
end
end
end
end
Line 72: Line 77:
local resultArray = {}
local resultArray = {}
if area.entryRequirements ~= nil then
if area.entryRequirements ~= nil then
table.insert(resultArray, Common.getRequirementString(area.entryRequirements, ''))
local reqText = Common.getRequirementString(area.entryRequirements)
if reqText ~= nil then
table.insert(resultArray, reqText)
end
end
end


Line 78: Line 86:
-- Avoid repeating the same requirements twice, can happen for some dungeons e.g. Impending Darkness
-- 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
if area.entryRequirements == nil or mw.dumpObject(area.unlockRequirement) ~= mw.dumpObject(area.entryRequirements) then
table.insert(resultArray, Common.getRequirementString(area.unlockRequirement, ''))
local reqText = Common.getRequirementString(area.unlockRequirement)
if reqText ~= nil then
table.insert(resultArray, reqText)
end
end
end
end
end


return table.concat(resultArray, '<br/>')
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
local reqs = p._getAreaRequirements(area)
if reqs ~= '' then
reqs = "|-\r\n|'''Requirements:'''\r\n"..reqs
end
return reqs
end
end


Line 117: Line 143:
end
end


function p.getMonsterAreas(monsterID)
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, monsterID)
local randomSpiderCheck = Shared.contains(GameData.rawData.spiderLairMonsters, monster.id)
return p.getAreas(
return p.getAreas(
function(area)
function(area)
return Shared.contains(area.monsterIDs, monsterID) or
return p._isMonsterInArea(monster, area)
(randomSpiderCheck and Shared.contains(area.monsterIDs, 'melvorTotH:RandomSpiderLair'))
end)
end)
end
end