17,101
edits
(Use tabs instead of spaces for indentation; getMonsterAreas: Remove check for ID 1/Hill Giants - Game data no longer flags ITM afflicted monsters in this way) |
(Update for v1.1) |
||
Line 1: | Line 1: | ||
--NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters | --NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters | ||
local p = {} | local p = {} | ||
local Constants = require('Module:Constants') | local Constants = require('Module:Constants') | ||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local GameData = require('Module:GameData') | |||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local Items = require('Module:Items') | local Items = require('Module:Items') | ||
local Shop = require('Module:Shop') | local Shop = require('Module:Shop') | ||
local areaMap = { | |||
["combat"] = 'combatAreas', | |||
["dungeon"] = 'dungeons', | |||
["slayer"] = 'slayerAreas' | |||
} | |||
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(type | function p.getAreaByID(id, type) | ||
local areaType = areaMap[type] | |||
if areaType ~= nil then | |||
return GameData.getEntityByID(areaType, id) | |||
end | |||
end | end | ||
function p.getAreaFilterType(type | function p.getAreaFilterType(name, type) | ||
local areaType = areaMap[type] | |||
if areaType ~= nil then | |||
return GameData.getEntityByName(areaType, name) | |||
end | |||
end | end | ||
function p.getAreas(checkFunc) | function p.getAreas(checkFunc) | ||
local resultArray = | 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 | end | ||
function p._getAreaRequirements(area) | function p._getAreaRequirements(area) | ||
local resultArray = {} | local resultArray = {} | ||
local addReqsToArray = function(reqArray, requirements) | local addReqsToArray = function(reqArray, requirements) | ||
for i, reqDetails in | for i, reqDetails in ipairs(requirements) do | ||
if reqDetails.type == ' | if reqDetails.type == 'SkillLevel' then | ||
local skillName = Constants.getSkillName(reqDetails.skillID) | |||
if skillName ~= nil then | |||
table.insert(reqArray, Icons._SkillReq(skillName, reqDetails.level)) | |||
end | |||
elseif reqDetails.type == 'SlayerItem' then | elseif reqDetails.type == 'SlayerItem' then | ||
local item = Items.getItemByID(reqDetails.itemID) | local item = Items.getItemByID(reqDetails.itemID) | ||
table.insert(reqArray, Icons.Icon({item.name, type='item'})..' Equipped') | table.insert(reqArray, Icons.Icon({item.name, type='item'}) .. ' Equipped') | ||
elseif reqDetails.type == ' | elseif reqDetails.type == 'DungeonCompletion' then | ||
local dung = p.getAreaByID(reqDetails.dungeonID, 'dungeon') | |||
if dung ~= nil then | |||
if reqDetails.count > 1 then | |||
table.insert(reqArray, Shared.formatnum(reqDetails.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 | elseif reqDetails.type == 'ShopPurchase' then | ||
local shopPurchase = GameData.getEntityByID('shopPurchases', reqDetails.purchaseID) | |||
if shopPurchase ~= nil then | if shopPurchase ~= nil then | ||
table.insert(reqArray, Shop._getPurchaseIcon({ shopPurchase }) .. ' Purchased') | table.insert(reqArray, Shop._getPurchaseIcon({ shopPurchase }) .. ' Purchased') | ||
Line 135: | Line 96: | ||
if area.unlockRequirement ~= nil then | if area.unlockRequirement ~= nil then | ||
addReqsToArray(resultArray, area.unlockRequirement) | |||
end | end | ||
return table.concat(resultArray, '<br/>') | |||
end | end | ||
Line 160: | Line 106: | ||
return p._getAreaRequirements(area) | return p._getAreaRequirements(area) | ||
elseif statName == 'areaEffectDesc' then | elseif statName == 'areaEffectDesc' then | ||
if area.areaEffect ~= nil | if area.areaEffect ~= nil then | ||
local descText, subIdx = string.gsub(area.areaEffectDescription, '${effectValue}', area. | local descText, subIdx = string.gsub(area.areaEffectDescription, '${effectValue}', area.areaEffect.magnitude or 0) | ||
return descText | return descText | ||
else | else | ||
Line 189: | Line 135: | ||
function p.getMonsterAreas(monsterID) | function p.getMonsterAreas(monsterID) | ||
return p.getAreas( | |||
function(area) | |||
return Shared.contains(area.monsterIDs, monsterID) | |||
end) | |||
end | end | ||