4,951
edits
Falterfire (talk | contribs) (Added new function for auto-building dungeon monster tables) |
Falterfire (talk | contribs) (Fixed an issue with getting difficulty not working when multiple difficulties were present) |
||
(16 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
--NOTE: Some tables are in Module:CombatAreas/AreaTables to prevent loop from referencing Monsters | |||
local p = {} | local p = {} | ||
local AreaData = mw.loadData('Module:CombatAreas/data') | local AreaData = mw.loadData('Module:CombatAreas/data') | ||
local Constants = require('Module:Constants') | |||
local Shared = require('Module:Shared') | local Shared = require('Module:Shared') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
local | local Items = require('Module:Items') | ||
function processArea(area, index, type) | |||
local result = Shared.clone(area) | |||
result.id = index - 1 | |||
if result.name == nil then | |||
result.name = result.areaName | |||
end | |||
result.type = type | |||
return result | |||
end | |||
function p.getArea(name) | function p.getArea(name) | ||
Line 13: | Line 24: | ||
for i, area in pairs(AreaData.combatAreas) do | for i, area in pairs(AreaData.combatAreas) do | ||
if area.areaName == name then | if area.areaName == name then | ||
return processArea(area, i, 'combat') | |||
end | end | ||
end | end | ||
Line 21: | Line 30: | ||
for i, area in pairs(AreaData.slayerAreas) do | for i, area in pairs(AreaData.slayerAreas) do | ||
if area.areaName == name then | if area.areaName == name then | ||
return processArea(area, i, 'slayer') | |||
end | end | ||
end | end | ||
Line 29: | Line 36: | ||
for i, area in pairs(AreaData.dungeons) do | for i, area in pairs(AreaData.dungeons) do | ||
if area.name == name then | if area.name == name then | ||
return processArea(area, i, 'dungeon') | |||
end | end | ||
end | end | ||
Line 39: | Line 43: | ||
end | end | ||
function p. | function p.getAreaByID(type, id) | ||
local areaName = | if type == 'dungeon' then type = 'dungeons' | ||
elseif type == 'combat' then type = 'combatAreas' | |||
elseif type == 'slayer' then type = 'slayerAreas' end | |||
return processArea(AreaData[type][id + 1], id + 1) | |||
end | |||
function p.getAreaFilterType(type, name) | |||
local areaName = nil | |||
if type == 'dungeon' then areas = AreaData.dungeons | |||
elseif type == 'combat' then areas = AreaData.combatAreas | |||
elseif type == 'slayer' then areas = AreaData.slayerAreas | |||
else return nil end | |||
for i, area in pairs(areas) do | |||
if type == 'dungeon' then areaName = area.name | |||
else areaName = area.areaName end | |||
if areaName == name then | |||
return processArea(area, i, type) | |||
end | |||
end | end | ||
if area.type == 'dungeon' then | return nil | ||
return | end | ||
function p._getAreaStat(area, statName) | |||
if statName == 'slayerLevel' then | |||
return Icons._SkillReq('Slayer', area.slayerLevel) | |||
elseif statName == 'slayerItem' then | |||
if area.slayerItem ~= nil and area.slayerItem > 0 then | |||
local slayItem = Items.getItemByID(area.slayerItem) | |||
return Icons.Icon({slayItem.name, type='item'}) | |||
else | |||
return 'None' | |||
end | |||
elseif statName == 'dungeonReq' then | |||
if area.requiresCompletion ~= nil and area.requiresCompletion >= 0 then | |||
local dung = p.getAreaByID('dungeon', area.requiresCompletion) | |||
local compCount = area.requiresCompletionCount ~= nil and area.requiresCompletionCount or 1 | |||
if compCount > 1 then | |||
return compCount..'x '..Icons.Icon({dung.name, type='dungeon'})..' Completions' | |||
else | |||
return Icons.Icon({dung.name, type='dungeon'})..' Completed' | |||
end | |||
else | |||
return '' | |||
end | |||
elseif statName == 'areaEffectDesc' then | |||
if area.areaEffect ~= nil and area.areaEffect then | |||
return area.areaEffectDescription | |||
else | |||
return 'None' | |||
end | |||
elseif statName == 'difficulty' then | |||
local result = Constants.getDifficultyString(area.difficulty[1]) | |||
if area.difficulty[2] ~= nil then | |||
result = result..' - '..Constants.getDifficultyString(area.difficulty[2]) | |||
end | |||
return result | |||
end | end | ||
return area[statName] | |||
end | end | ||
function p. | function p.getAreaStat(frame) | ||
local areaName = frame.args ~= nil and frame.args[1] or frame | local areaName = frame.args ~= nil and frame.args[1] or frame[1] | ||
local area = p.getArea( | local statName = frame.args ~= nil and frame.args[2] or frame[2] | ||
local area = p.getArea(areaName) | |||
if area == nil then | if area == nil then | ||
return "ERROR: Could not find an area named "..areaName | return "ERROR: Could not find an area named "..areaName | ||
end | end | ||
return p._getAreaStat(area, statName) | |||
local | end | ||
for i, | |||
if | function p.getMonsterAreas(monsterID) | ||
local areaArray = {} | |||
--There are three types of areas but the lists are pretty short so looping all of them isn't a real issue | |||
for i, area in pairs(AreaData.combatAreas) do | |||
if Shared.contains(area.monsters, monsterID) then | |||
table.insert(areaArray, processArea(area, i, 'combat')) | |||
end | end | ||
end | end | ||
for i, area in pairs(AreaData.slayerAreas) do | |||
if Shared.contains(area.monsters, monsterID) then | |||
table.insert(areaArray, processArea(area, i, 'slayer')) | |||
end | |||
end | |||
--Hill Giants specifically ignore dungeons to prevent the issue with Into the Mist incorrectly being listed. | |||
if monsterID ~= 1 then | |||
for i, area in pairs(AreaData.dungeons) do | |||
if Shared.contains(area.monsters, monsterID) then | |||
table.insert(areaArray, processArea(area, i, 'dungeon')) | |||
end | |||
end | end | ||
end | end | ||
return areaArray | |||
return | end | ||
function p.getDungeonRequirements(frame) | |||
local areaName = frame.args ~= nil and frame.args[1] or frame | |||
local area = p.getArea(areaName) | |||
if area == nil then | |||
return "ERROR: Could not find an area named "..areaName | |||
end | |||
local result = p._getAreaStat(area, 'dungeonReq') | |||
if result ~= '' then | |||
result = "\r\n|-\r\n|'''Requirements:'''<br/>"..result | |||
end | |||
return result | |||
end | end | ||
return p | return p |