17,101
edits
Falterfire (talk | contribs) (Attempted to add getCourseTable. Time to see if it works) |
(Update for v1.1) |
||
Line 1: | Line 1: | ||
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 SkillData = GameData.skillData | |||
local Items = require('Module:Items') | local Items = require('Module:Items') | ||
local Icons = require('Module:Icons') | local Icons = require('Module:Icons') | ||
function p.getObstacleByID(obstID) | function p.getObstacleByID(obstID) | ||
return GameData.getEntityByID(SkillData.Agility.obstacles, obstID) | |||
end | end | ||
function p.getObstacle(name) | function p.getObstacle(name) | ||
return GameData.getEntityByName(SkillData.Agility.obstacles, name) | |||
end | end | ||
function p.getObstacles(checkFunc) | function p.getObstacles(checkFunc) | ||
local result = {} | return GameData.getEntities(SkillData.Agility.obstacles, checkFunc) | ||
for i, | end | ||
if | |||
function p.getPillars(checkFunc) | |||
local result = nil | |||
local keys = { 'pillars', 'elitePillars' } | |||
for i, key in ipairs(keys) do | |||
local pillars = GameData.getEntities(SkillData.Agility[key]) | |||
if result == nil then | |||
result = pillars | |||
else | |||
for k, pillar in ipairs(pillars) do | |||
table.insert(result, pillar) | |||
end | |||
end | end | ||
end | |||
if result == nil then | |||
result = {} | |||
end | end | ||
return result | return result | ||
end | end | ||
function p. | function p._getObstacleLevel(obstacle) | ||
if obstacle.category ~= nil then | |||
if obstacle.category == 0 then | |||
return 1 | |||
else | |||
return SkillData.Agility.obstacleUnlockLevels[obstacle.category] | |||
end | |||
else | |||
local localID = GameData.getLocalID(obstacle.id) | |||
if localID ~= nil then | |||
if string.find(localID, '^Pillar') ~= nil then | |||
return 99 | |||
elseif string.find(localID, '^ElitePillar') ~= nil then | |||
return 120 | |||
end | |||
end | end | ||
end | end | ||
end | end | ||
function p._getObstacleRequirements(obstacle) | function p._getObstacleRequirements(obstacle) | ||
local resultPart = {} | local resultPart = {} | ||
local level = p._getObstacleLevel(obstacle) | |||
if level ~= nil then | |||
table.insert(resultPart, Icons._SkillReq('Agility', level)) | |||
table.insert(resultPart, Icons._SkillReq('Agility', | |||
end | end | ||
if type(obstacle.skillRequirements) == 'table' then | if type(obstacle.skillRequirements) == 'table' then | ||
for i, skillReq in ipairs(obstacle.skillRequirements) do | for i, skillReq in ipairs(obstacle.skillRequirements) do | ||
local skillName = Constants.getSkillName(skillReq. | local skillName = Constants.getSkillName(skillReq.skillID) | ||
if skillName ~= nil then | if skillName ~= nil then | ||
table.insert(resultPart, Icons._SkillReq(skillName, skillReq.level)) | table.insert(resultPart, Icons._SkillReq(skillName, skillReq.level)) | ||
Line 66: | Line 73: | ||
end | end | ||
return table.concat(resultPart, '<br/>') | return table.concat(resultPart, '<br/>') | ||
end | |||
function p._getObstacleCosts(obstacle) | |||
local costs = {} | |||
if obstacle.gpCost > 0 then table.insert(costs, Icons.GP(obstacle.gpCost)) end | |||
if obstacle.scCost > 0 then table.insert(costs, Icons.SC(obstacle.scCost)) end | |||
for j, itemCost in ipairs(obstacle.itemCosts) do | |||
local item = Items.getItemByID(itemCost.id) | |||
table.insert(costs, Icons.Icon({item.name, type='item', qty = itemCost.quantity, notext=true})) | |||
end | |||
return table.concat(costs, '<br/>') | |||
end | end | ||
Line 77: | Line 95: | ||
local catLog = {} | local catLog = {} | ||
local | local obstacles = p.getObstacles(function(obst) return true end) | ||
table.sort( | table.sort(obstacles, function(a, b) return a.category < b.category end) | ||
local catCounts = {} | local catCounts = {} | ||
for i, obst in ipairs( | for i, obst in ipairs(obstacles) do | ||
if catCounts[obst.category] == nil then | if catCounts[obst.category] == nil then | ||
catCounts[obst.category] = 1 | catCounts[obst.category] = 1 | ||
Line 89: | Line 107: | ||
end | end | ||
for i, obst in ipairs( | for i, obst in ipairs(obstacles) do | ||
result = result..'\r\n|-' | result = result..'\r\n|-' | ||
result = result..'\r\n|' | result = result..'\r\n|' | ||
Line 100: | Line 118: | ||
--After the name & category, doing XP, GP, Time, and rates | --After the name & category, doing XP, GP, Time, and rates | ||
local XP = obst. | local XP = obst.baseExperience | ||
local GP = obst. | local GP = obst.gpReward | ||
local Time = obst. | local Time = obst.baseInterval / 1000 | ||
result = result..'||'..XP..'||data-sort-value="'..GP..'"|'..Icons.GP(GP) | result = result..'||'..XP..'||data-sort-value="'..GP..'"|'..Icons.GP(GP) | ||
result = result..'||data-sort-value="'..Time..'"|'..Shared.timeString(Time, true) | result = result..'||data-sort-value="'..Time..'"|'..Shared.timeString(Time, true) | ||
Line 114: | Line 132: | ||
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue)) | table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue)) | ||
end | end | ||
if Shared. | if Shared.tableIsEmpty(bonuses) then | ||
table.insert(bonuses, '<span style="color:red">None :(</span>') | table.insert(bonuses, '<span style="color:red">None :(</span>') | ||
end | end | ||
Line 123: | Line 141: | ||
--Finally, the cost | --Finally, the cost | ||
result = result..'|| data-sort-value="'..obst.gpCost..'"|'..p._getObstacleCosts(obst) | |||
result = result..'|| data-sort-value="'..obst. | |||
end | end | ||
Line 145: | Line 156: | ||
result = result..'\r\n!Name!!Bonuses!!Cost' | result = result..'\r\n!Name!!Bonuses!!Cost' | ||
for i, pill in ipairs( | local pillars = p.getPillars(function(pillar) return true end) | ||
for i, pill in ipairs(pillars) do | |||
result = result..'\r\n|-' | result = result..'\r\n|-' | ||
result = result..'\r\n|'..pill.name | result = result..'\r\n|'..pill.name | ||
Line 154: | Line 166: | ||
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue)) | table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue)) | ||
end | end | ||
if Shared. | if Shared.tableIsEmpty(bonuses) then | ||
table.insert(bonuses, '<span style="color:red">None :(</span>') | table.insert(bonuses, '<span style="color:red">None :(</span>') | ||
end | end | ||
Line 160: | Line 172: | ||
--Finally, the cost | --Finally, the cost | ||
result = result..'|| data-sort-value="'..pill.gpCost..'"|'..p._getObstacleCosts(pill) | |||
result = result..'|| data-sort-value="'..pill. | |||
end | end | ||
Line 176: | Line 181: | ||
function p.getObstaclesForItem(itemID) | function p.getObstaclesForItem(itemID) | ||
local | local costFunc = | ||
function(obst) | |||
for i, itemCost in ipairs(obst.itemCosts) do | |||
if itemCost.id == itemID then | |||
return true | |||
end | |||
end | end | ||
return false | |||
end | end | ||
local pillars = p.getPillars(costFunc) | |||
local result = p.getObstacles(costFunc) | |||
for | if result == nil or Shared.tableIsEmpty(result) then | ||
result = pillars | |||
else | |||
for i, pillar in ipairs(pillars) do | |||
table.insert(result, pillar) | |||
end | end | ||
end | end | ||
Line 198: | Line 206: | ||
function p._getCourseTable(obstacleNames) | function p._getCourseTable(obstacleNames) | ||
local result = '' | local result = '' | ||
local | local obstacles = {} | ||
for i, name in | for i, name in ipairs(obstacleNames) do | ||
local obst = p.getObstacle(Shared.trim(name)) | local obst = p.getObstacle(Shared.trim(name)) | ||
if obst == nil then | if obst == nil then | ||
result = result..'ERROR: Invalid Obstacle Name "'..name..'"[[Category:Pages with script errors]]<br/>' | result = result..'ERROR: Invalid Obstacle Name "'..name..'"[[Category:Pages with script errors]]<br/>' | ||
else | else | ||
table.insert( | table.insert(obstacles, obst) | ||
end | end | ||
end | end | ||
Line 214: | Line 222: | ||
local catLog = {} | local catLog = {} | ||
table.sort( | table.sort(obstacles, function(a, b) return a.category < b.category end) | ||
local catCounts = {} | local catCounts = {} | ||
for i, obst in ipairs( | for i, obst in ipairs(obstacles) do | ||
if catCounts[obst.category] == nil then | if catCounts[obst.category] == nil then | ||
catCounts[obst.category] = 1 | catCounts[obst.category] = 1 | ||
Line 225: | Line 233: | ||
end | end | ||
for i, obst in ipairs( | for i, obst in ipairs(obstacles) do | ||
result = result..'\r\n|-' | result = result..'\r\n|-' | ||
result = result..'\r\n|' | result = result..'\r\n|' | ||
Line 240: | Line 248: | ||
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue)) | table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue)) | ||
end | end | ||
if Shared. | if Shared.tableIsEmpty(bonuses) then | ||
table.insert(bonuses, '<span style="color:red">None :(</span>') | table.insert(bonuses, '<span style="color:red">None :(</span>') | ||
end | end | ||
Line 249: | Line 257: | ||
--Finally, the cost | --Finally, the cost | ||
result = result..'|| data-sort-value="'..obst.gpCost..'"|'..p._getObstacleCosts(obst) | |||
result = result..'|| data-sort-value="'..obst. | |||
end | end | ||