Module:Skills/Agility: Difference between revisions

From Melvor Idle
(Applied same change to getModifierText to the PassivePillars function)
(_getObstacleLevel: Remove in favour of getRecipeLevel from Module:Skills)
 
(18 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}
local ItemData = mw.loadData('Module:Items/data')
local SkillData = mw.loadData('Module:Skills/data')


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 Skills = require('Module:Skills')
local Items = require('Module:Items')
local Items = require('Module:Items')
local ItemSourceTables = require('Module:Items/SourceTables')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')


function p.getObstacleByID(obstID)
function p.getObstacleByID(obstID)
  local result = Shared.clone(SkillData.Agility.Obstacles[obstID + 1])
return GameData.getEntityByID(SkillData.Agility.obstacles, obstID)
  return result
end
end


function p.getObstacle(name)
function p.getObstacle(name)
  for i, obst in Shared.skpairs(SkillData.Agility.Obstacles) do
return GameData.getEntityByName(SkillData.Agility.obstacles, name)
    if obst.name == name then
end
      local result = Shared.clone(obst)
 
      result.id = i - 1
function p.getObstacles(checkFunc)
      return result
return GameData.getEntities(SkillData.Agility.obstacles, checkFunc)
    end
end
  end
 
  return nil
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], checkFunc)
if result == nil then
result = pillars
else
for k, pillar in ipairs(pillars) do
table.insert(result, pillar)
end
end
end
if result == nil then
result = {}
end
return result
end
 
function p._getObstacleRequirements(obstacle)
local resultPart = {}
local level = Skills.getRecipeLevel('Agility', obstacle)
if level ~= nil then
table.insert(resultPart, Icons._SkillReq('Agility', level))
end
if type(obstacle.skillRequirements) == 'table' then
for i, skillReq in ipairs(obstacle.skillRequirements) do
local skillName = Constants.getSkillName(skillReq.skillID)
if skillName ~= nil then
table.insert(resultPart, Icons._SkillReq(skillName, skillReq.level))
end
end
end
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


function p.getObstacleCourseTable(frame)
function p.getObstacleCourseTable(frame)
  local result = ''
local result = ''
 
result = '{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!Slot!!Name!!XP!!GP!!Time!!XP/s!!GP/s'--!!XP/s!!GP/s (left comment here for posterity)
result = result..'!!Bonuses!!Requirements!!Cost'


  result = '{| class="wikitable sortable stickyHeader"'
local catLog = {}
  result = result..'\r\n|- class="headerRow-0"'
local obstacles = p.getObstacles(function(obst) return true end)
  result = result..'\r\n!Slot!!Name!!XP!!GP!!Time'--!!XP/s!!GP/s
table.sort(obstacles, function(a, b) return a.category < b.category end)
  result = result..'!!Bonuses!!Requirements!!Cost'


  local catLog = {}
local catCounts = {}
for i, obst in ipairs(obstacles) do
if catCounts[obst.category] == nil then
catCounts[obst.category] = 1
else
catCounts[obst.category] = catCounts[obst.category] + 1
end
end


  for i, obst in Shared.skpairs(SkillData.Agility.Obstacles) do
for i, obst in ipairs(obstacles) do
    result = result..'\r\n|-'
result = result..'\r\n|-'
    result = result..'\r\n|'
result = result..'\r\n|'
    if catLog[obst.category] == nil then
if catLog[obst.category] == nil then
      local rowspan = obst.category > 1 and 5 or 3
local rowspan = catCounts[obst.category]
      result = result..'rowspan="'..rowspan..'" style="border:1px solid black"|'..(obst.category + 1)..'||'
result = result..'rowspan="'..rowspan..'" style="border:1px solid black"|'..(obst.category + 1)..'||'
      catLog[obst.category] = true
catLog[obst.category] = true
    end
end
    result = result..obst.name
result = result .. 'id="'..string.gsub(obst.name,' ', '')..'"|'.. Icons.getExpansionIcon(obst.id) .. obst.name


    --After the name & category, doing XP, GP, Time, and rates
--After the name & category, doing XP, GP, Time, and rates
    local XP = obst.completionBonuses.xp
local XP = obst.baseExperience
    local GP = obst.completionBonuses.gp
local GP = obst.gpReward
    local Time = obst.interval / 1000
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)
    --result = result..'||'..Shared.round(XP / Time, 2, 2)
-- Readded XP/Time and GP/Time (previously commented out)
    --result = result..'||data-sort-value="'..GP/Time..'"|'..Icons.GP(Shared.round(GP/Time, 2, 2))
result = result..'||'..Shared.round(XP / Time, 2, 2)
result = result..'||data-sort-value="'..GP/Time..'"|'..Icons.GP(Shared.round(GP/Time, 2, 2))


    local bonuses = {}
local bonuses = {}
    --After that, adding the bonuses
--After that, adding the bonuses
    for bonusName, bonusValue in pairs(obst.modifiers) do
for bonusName, bonusValue in pairs(obst.modifiers) do
      table.insert(bonuses, Constants.getModifierText(bonusName, bonusValue))
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
    end
end
    if Shared.tableCount(bonuses) == 0 then
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
    result = result..'||'..table.concat(bonuses, '<br/>')
result = result..'||'..table.concat(bonuses, '<br/>')


    --Grabbing requirements to create
--Grabbing requirements to create
    result = result..'||'
result = result..'|| ' .. p._getObstacleRequirements(obst)
    if obst.category > 0 then
      result = result..Icons._SkillReq('Agility', obst.category * 10)
    end
    if obst.requirements ~= nil and obst.requirements.skillLevel ~= nil then
      for j, skillReq in Shared.skpairs(obst.requirements.skillLevel) do
        result = result..'<br/>'..Icons._SkillReq(Constants.getSkillName(skillReq[1]), skillReq[2])
      end
    end


    --Finally, the cost
--Finally, the cost
    local costs = {}
result = result..'|| data-sort-value="'..obst.gpCost..'"|'..p._getObstacleCosts(obst)
    if obst.cost.gp > 0 then table.insert(costs, Icons.GP(obst.cost.gp)) end
end
    if obst.cost.slayerCoins > 0 then table.insert(costs, Icons.SC(obst.cost.slayerCoins)) end
    for j, itemCost in Shared.skpairs(obst.cost.items) do
      local item = Items.getItemByID(itemCost[1])
      table.insert(costs, Icons.Icon({item.name, type='item', qty = itemCost[2], notext=true}))
    end
    result = result..'|| data-sort-value="'..obst.cost.gp..'"|'..table.concat(costs, '<br/>')
  end


  result = result..'\r\n|}'
result = result..'\r\n|}'


  return result
return result
end
end


function p.getPassivePillarTable(frame)
function p.getPassivePillarTable(frame)
  local result = ''
local result = ''


  result = '{| class="wikitable sortable stickyHeader"'
result = '{| class="wikitable sortable stickyHeader"'
  result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n|- class="headerRow-0"'
  result = result..'\r\n!Name!!Bonuses!!Cost'
result = result..'\r\n!Name!!Bonuses!!Cost'


  for i, pill in Shared.skpairs(SkillData.Agility.Pillars) do
local pillars = p.getPillars(function(pillar) return true end)
    result = result..'\r\n|-'
for i, pill in ipairs(pillars) do
    result = result..'\r\n|'..pill.name
result = result..'\r\n|-'
result = result..'\r\n|' .. 'id="'..string.gsub(pill.name,' ', '')..'"|'..Icons.getExpansionIcon(pill.id) .. pill.name


    --After that, adding the bonuses
--After that, adding the bonuses
    local bonuses = {}
local bonuses = {}
    for bonusName, bonusValue in pairs(pill.modifiers) do
for bonusName, bonusValue in pairs(pill.modifiers) do
      table.insert(bonuses, Constants.getModifierText(bonusName, bonusValue))
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
    end
end
    if Shared.tableCount(bonuses) == 0 then
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
    result = result..'||'..table.concat(bonuses, '<br/>')
result = result..'||'..table.concat(bonuses, '<br/>')


    --Finally, the cost
--Finally, the cost
    local costs = {}
result = result..'|| data-sort-value="'..pill.gpCost..'"|'..p._getObstacleCosts(pill)
    if pill.cost.gp > 0 then table.insert(costs, Icons.GP(pill.cost.gp)) end
end
    if pill.cost.slayerCoins > 0 then table.insert(costs, Icons.SC(pill.cost.slayerCoins)) end
    for j, itemCost in Shared.skpairs(pill.cost.items) do
      local item = Items.getItemByID(itemCost[1])
      table.insert(costs, Icons.Icon({item.name, type='item', qty = itemCost[2], notext=true}))
    end
    result = result..'|| data-sort-value="'..pill.cost.gp..'"|'..table.concat(costs, '<br/>')
  end


  result = result..'\r\n|}'
result = result..'\r\n|}'


  return result
return result
end
end


function p.getObstaclesForItem(itemID)
function p.getObstaclesForItem(itemID)
  local result = {}
local costFunc =
  for i, obst in Shared.skpairs(SkillData.Agility.Obstacles) do
function(obst)
    for j, costLine in Shared.skpairs(obst.cost.items) do
for i, itemCost in ipairs(obst.itemCosts) do
      if costLine[1] == itemID then
if itemCost.id == itemID then
        table.insert(result, obst)
return true
      end
end
    end
end
  end
return false
end
local pillars = p.getPillars(costFunc)


  for i, obst in Shared.skpairs(SkillData.Agility.Pillars) do
local result = p.getObstacles(costFunc)
    for j, costLine in Shared.skpairs(obst.cost.items) do
if result == nil or Shared.tableIsEmpty(result) then
      if costLine[1] == itemID then
result = pillars
        table.insert(result, obst)
else
      end
for i, pillar in ipairs(pillars) do
    end
table.insert(result, pillar)
  end
end
end
 
return result
end
 
function p._getCourseTable(obstacleNames)
local result = ''
local obstacles = {}
for i, name in ipairs(obstacleNames) do
local obst = p.getObstacle(Shared.trim(name))
if obst == nil then
result = result .. Shared.printError('Invalid Obstacle Name "' .. name .. '"') .. '<br/>'
else
table.insert(obstacles, obst)
end
end
 
result = result..'{| class="wikitable sortable stickyHeader"'
result = result..'\r\n|- class="headerRow-0"'
result = result..'\r\n!Slot!!Name!!Bonuses!!Requirements!!Cost'
 
local catLog = {}
table.sort(obstacles, function(a, b) return a.category < b.category end)
 
local catCounts = {}
for i, obst in ipairs(obstacles) do
if catCounts[obst.category] == nil then
catCounts[obst.category] = 1
else
catCounts[obst.category] = catCounts[obst.category] + 1
end
end
 
for i, obst in ipairs(obstacles) do
result = result..'\r\n|-'
result = result..'\r\n|'
if catLog[obst.category] == nil then
local rowspan = catCounts[obst.category]
result = result..'rowspan="'..rowspan..'" style="border:1px solid black"|'..(obst.category + 1)..'||'
catLog[obst.category] = true
end
result = result..obst.name
 
local bonuses = {}
--After that, adding the bonuses
for bonusName, bonusValue in pairs(obst.modifiers) do
table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
end
if Shared.tableIsEmpty(bonuses) then
table.insert(bonuses, '<span style="color:red">None :(</span>')
end
result = result..'||'..table.concat(bonuses, '<br/>')
 
--Grabbing requirements to create
result = result..'|| ' .. p._getObstacleRequirements(obst)
 
--Finally, the cost
result = result..'|| data-sort-value="'..obst.gpCost..'"|'..p._getObstacleCosts(obst)
end
 
result = result..'\r\n|}'
 
return result
end


  return result
function p.getCourseTable(frame)
local obstNameStr = frame.args ~= nil and frame.args[1] or frame
local obstacleNames = Shared.splitString(obstNameStr, ',')
return p._getCourseTable(obstacleNames)
end
end


return p
return p

Latest revision as of 11:57, 9 April 2023

Documentation for this module may be created at Module:Skills/Agility/doc

local p = {}

local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local SkillData = GameData.skillData
local Skills = require('Module:Skills')
local Items = require('Module:Items')
local Icons = require('Module:Icons')

function p.getObstacleByID(obstID)
	return GameData.getEntityByID(SkillData.Agility.obstacles, obstID)
end

function p.getObstacle(name)
	return GameData.getEntityByName(SkillData.Agility.obstacles, name)
end

function p.getObstacles(checkFunc)
	return GameData.getEntities(SkillData.Agility.obstacles, checkFunc)
end

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], checkFunc)
		if result == nil then
			result = pillars
		else
			for k, pillar in ipairs(pillars) do
				table.insert(result, pillar)
			end
		end
	end
	if result == nil then
		result = {}
	end
	return result
end

function p._getObstacleRequirements(obstacle)
	local resultPart = {}
	local level = Skills.getRecipeLevel('Agility', obstacle)
	if level ~= nil then
		table.insert(resultPart, Icons._SkillReq('Agility', level))
	end
	if type(obstacle.skillRequirements) == 'table' then
		for i, skillReq in ipairs(obstacle.skillRequirements) do
			local skillName = Constants.getSkillName(skillReq.skillID)
			if skillName ~= nil then
				table.insert(resultPart, Icons._SkillReq(skillName, skillReq.level))
			end
		end
	end
	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

function p.getObstacleCourseTable(frame)
	local result = ''

	result = '{| class="wikitable sortable stickyHeader"'
	result = result..'\r\n|- class="headerRow-0"'
	result = result..'\r\n!Slot!!Name!!XP!!GP!!Time!!XP/s!!GP/s'--!!XP/s!!GP/s (left comment here for posterity)
	result = result..'!!Bonuses!!Requirements!!Cost'

	local catLog = {}
	local obstacles = p.getObstacles(function(obst) return true end)
	table.sort(obstacles, function(a, b) return a.category < b.category end)

	local catCounts = {}
	for i, obst in ipairs(obstacles) do
		if catCounts[obst.category] == nil then
			catCounts[obst.category] = 1
		else
			catCounts[obst.category] = catCounts[obst.category] + 1
		end
	end

	for i, obst in ipairs(obstacles) do
		result = result..'\r\n|-'
		result = result..'\r\n|'
		if catLog[obst.category] == nil then
			local rowspan = catCounts[obst.category]
			result = result..'rowspan="'..rowspan..'" style="border:1px solid black"|'..(obst.category + 1)..'||'
			catLog[obst.category] = true
		end
		result = result .. 'id="'..string.gsub(obst.name,' ', '')..'"|'.. Icons.getExpansionIcon(obst.id) .. obst.name

		--After the name & category, doing XP, GP, Time, and rates
		local XP = obst.baseExperience
		local GP = obst.gpReward
		local Time = obst.baseInterval / 1000
		result = result..'||'..XP..'||data-sort-value="'..GP..'"|'..Icons.GP(GP)
		result = result..'||data-sort-value="'..Time..'"|'..Shared.timeString(Time, true)
		-- Readded XP/Time and GP/Time (previously commented out)
		result = result..'||'..Shared.round(XP / Time, 2, 2)
		result = result..'||data-sort-value="'..GP/Time..'"|'..Icons.GP(Shared.round(GP/Time, 2, 2))

		local bonuses = {}
		--After that, adding the bonuses
		for bonusName, bonusValue in pairs(obst.modifiers) do
			table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
		end
		if Shared.tableIsEmpty(bonuses) then
			table.insert(bonuses, '<span style="color:red">None :(</span>')
		end
		result = result..'||'..table.concat(bonuses, '<br/>')

		--Grabbing requirements to create
		result = result..'|| ' .. p._getObstacleRequirements(obst)

		--Finally, the cost
		result = result..'|| data-sort-value="'..obst.gpCost..'"|'..p._getObstacleCosts(obst)
	end

	result = result..'\r\n|}'

	return result
end

function p.getPassivePillarTable(frame)
	local result = ''

	result = '{| class="wikitable sortable stickyHeader"'
	result = result..'\r\n|- class="headerRow-0"'
	result = result..'\r\n!Name!!Bonuses!!Cost'

	local pillars = p.getPillars(function(pillar) return true end)
	for i, pill in ipairs(pillars) do
		result = result..'\r\n|-'
		result = result..'\r\n|' .. 'id="'..string.gsub(pill.name,' ', '')..'"|'..Icons.getExpansionIcon(pill.id) .. pill.name

		--After that, adding the bonuses
		local bonuses = {}
		for bonusName, bonusValue in pairs(pill.modifiers) do
			table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
		end
		if Shared.tableIsEmpty(bonuses) then
			table.insert(bonuses, '<span style="color:red">None :(</span>')
		end
		result = result..'||'..table.concat(bonuses, '<br/>')

		--Finally, the cost
		result = result..'|| data-sort-value="'..pill.gpCost..'"|'..p._getObstacleCosts(pill)
	end

	result = result..'\r\n|}'

	return result
end

function p.getObstaclesForItem(itemID)
	local costFunc =
		function(obst)
			for i, itemCost in ipairs(obst.itemCosts) do
				if itemCost.id == itemID then
					return true
				end
			end
			return false
		end
	local pillars = p.getPillars(costFunc)

	local result = p.getObstacles(costFunc)
	if result == nil or Shared.tableIsEmpty(result) then
		result = pillars
	else
		for i, pillar in ipairs(pillars) do
			table.insert(result, pillar)
		end
	end

	return result
end

function p._getCourseTable(obstacleNames)
	local result = ''
	local obstacles = {}
	for i, name in ipairs(obstacleNames) do
		local obst = p.getObstacle(Shared.trim(name))
		if obst == nil then
			result = result .. Shared.printError('Invalid Obstacle Name "' .. name .. '"') .. '<br/>'
		else
			table.insert(obstacles, obst)
		end
	end

	result = result..'{| class="wikitable sortable stickyHeader"'
	result = result..'\r\n|- class="headerRow-0"'
	result = result..'\r\n!Slot!!Name!!Bonuses!!Requirements!!Cost'

	local catLog = {}
	
	table.sort(obstacles, function(a, b) return a.category < b.category end)

	local catCounts = {}
	for i, obst in ipairs(obstacles) do
		if catCounts[obst.category] == nil then
			catCounts[obst.category] = 1
		else
			catCounts[obst.category] = catCounts[obst.category] + 1
		end
	end

	for i, obst in ipairs(obstacles) do
		result = result..'\r\n|-'
		result = result..'\r\n|'
		if catLog[obst.category] == nil then
			local rowspan = catCounts[obst.category]
			result = result..'rowspan="'..rowspan..'" style="border:1px solid black"|'..(obst.category + 1)..'||'
			catLog[obst.category] = true
		end
		result = result..obst.name

		local bonuses = {}
		--After that, adding the bonuses
		for bonusName, bonusValue in pairs(obst.modifiers) do
			table.insert(bonuses, Constants._getModifierText(bonusName, bonusValue))
		end
		if Shared.tableIsEmpty(bonuses) then
			table.insert(bonuses, '<span style="color:red">None :(</span>')
		end
		result = result..'||'..table.concat(bonuses, '<br/>')

		--Grabbing requirements to create
		result = result..'|| ' .. p._getObstacleRequirements(obst)

		--Finally, the cost
		result = result..'|| data-sort-value="'..obst.gpCost..'"|'..p._getObstacleCosts(obst)
	end

	result = result..'\r\n|}'

	return result
end

function p.getCourseTable(frame)
	local obstNameStr = frame.args ~= nil and frame.args[1] or frame
	local obstacleNames = Shared.splitString(obstNameStr, ',')
	
	return p._getCourseTable(obstacleNames)
end

return p