17,101
edits
(Expose eventData for use in other modules) |
(_getAreaRequirements: Crude attempt to prevent the same requirement appearing twice) |
||
Line 98: | Line 98: | ||
function p._getAreaRequirements(area) | function p._getAreaRequirements(area) | ||
local result = '' | |||
local resultArray = {} | |||
local addReqsToArray = function(reqArray, requirements) | |||
for i, reqDetails in Shared.skpairs(requirements) do | |||
if reqDetails.type == 'Level' then | |||
for j, lvlDetails in Shared.skpairs(reqDetails.levels) do | |||
local skill = Constants.getSkillName(lvlDetails.skill) | |||
table.insert(reqArray, Icons._SkillReq(skill, lvlDetails.level)) | |||
end | |||
elseif reqDetails.type == 'SlayerItem' then | |||
local item = Items.getItemByID(reqDetails.itemID) | |||
table.insert(reqArray, Icons.Icon({item.name, type='item'})..' Equipped') | |||
elseif reqDetails.type == 'Dungeon' then | |||
for j, dungDetails in Shared.skpairs(reqDetails.dungeons) do | |||
local dung = p.getAreaByID('dungeon', dungDetails.dungeonID) | |||
if dungDetails.count > 1 then | |||
table.insert(reqArray, dungDetails.count..'x '..Icons.Icon({dung.name, type='dungeon'})..' Completions') | |||
else | |||
table.insert(reqArray, Icons.Icon({dung.name, type='dungeon'})..' Completed') | |||
end | |||
end | |||
elseif reqDetails.type == 'ShopPurchase' then | |||
local shopPurchase = Shop.processPurchase(reqDetails.category, reqDetails.id) | |||
if shopPurchase ~= nil then | |||
table.insert(reqArray, Shop._getPurchaseIcon({ shopPurchase }) .. ' Purchased') | |||
end | |||
else | |||
table.insert(reqArray, 'ERROR: Unknown requirement type ' .. (reqDetails.type or 'nil') .. '[[Category:Pages with script errors]]') | |||
end | |||
end | |||
end | |||
if area.entryRequirements ~= nil then | |||
addReqsToArray(resultArray, area.entryRequirements) | |||
end | |||
if area.unlockRequirement ~= nil then | |||
-- Ensure this requirement isn't already part of the entry requirements | |||
local addReq = true | |||
if area.entryRequirements ~= nil then | |||
local unlockReqStr = mw.dumpObject(area.unlockRequirement) | |||
for i, reqDetails in ipairs(area.entryRequirements) do | |||
-- Using mw.dumpObject() as a lazy way to compare tables | |||
if area.unlockRequirement.type == reqDetails.type and mw.dumpObject(reqDetails) == unlockReqStr then | |||
addReq = false | |||
break | |||
end | |||
end | |||
end | |||
if addReq then | |||
addReqsToArray(resultArray, { area.unlockRequirement }) | |||
end | |||
end | |||
result = table.concat(resultArray, '<br/>') | |||
return result | |||
end | end | ||