Module:ModifierTables: Difference between revisions
From Melvor Idle
Falterfire (talk | contribs) m (Falterfire moved page Module:BonusTables to Module:ModifierTables without leaving a redirect: let's name this consistently, yeah?) |
Falterfire (talk | contribs) (Created initial pass at this) |
||
Line 8: | Line 8: | ||
local Pets = require('Module:Pets') | local Pets = require('Module:Pets') | ||
local Items = require('Module:Items') | local Items = require('Module:Items') | ||
local Agility = require('Module:Skills/Agility') | |||
local Shop = require('Module:Shop') | |||
-- | --First up, functions to get all the things in a category that have a given modifier: | ||
function p.getModifierValue(modifiers, modifier, skill, getOpposites) | |||
--Sometimes nil modifier sets will get here, which is fine. Just return 0 immediately | |||
if modifiers == nil then | |||
return 0 | |||
end | |||
--Make sure we have the skillID and not the name | |||
if skill == '' then | |||
skill = nil | |||
elseif type(skill) == 'string' then | |||
skill = Constants.getSkillID(skill) | |||
end | |||
--By default, attempt to add the increased and decreased prefixes to the modifier | |||
--But if getOpposites is false, only look for an exact match | |||
local increaseMod, decreaseMod = '', '' | |||
if getOpposites == nil or getOpposites then | |||
increaseMod = 'increased'..modifier | |||
decreaseMod = 'decreased'..modifier | |||
else | |||
increaseMod = modifier | |||
end | |||
if not p.hasLogged then | |||
mw.log(increaseMod..', '..decreaseMod) | |||
p.hasLogged = true | |||
end | |||
local increaseVal, decreaseVal = 0, 0 | |||
if modifiers[increaseMod] ~= nil and modifiers[increaseMod] ~= nil then | |||
if type(modifiers[increaseMod]) == 'table' then | |||
for i, subVal in Shared.skpairs(modifiers[increaseMod]) do | |||
if subVal[1] == skill then | |||
increaseVal = subVal[2] | |||
end | |||
end | |||
else | |||
increaseVal = modifiers[increaseMod] | |||
end | |||
end | |||
if modifiers[decreaseMod] ~= nil and modifiers[decreaseMod] ~= nil then | |||
if type(modifiers[decreaseMod]) == 'table' then | |||
for i, subVal in Shared.skpairs(modifiers[decreaseMod]) do | |||
if subVal[1] == skill then | |||
decreaseVal = subVal[2] | |||
end | |||
end | |||
else | |||
decreaseVal = modifiers[decreaseMod] | |||
end | |||
end | |||
return increaseVal - decreaseVal | |||
end | |||
function p.getItemsWithModifier(modifier, skill, getOpposites) | |||
local itemList = Items.getItems( | |||
function(item) | |||
return p.getModifierValue(item.modifiers, modifier, skill, getOpposites) ~= 0 | |||
end) | |||
return itemList | |||
end | |||
function p.getObstaclesWithModifier(modifier, skill, getOpposites) | |||
local obstList = Agility.getObstacles( | |||
function(obst) | |||
return p.getModifierValue(obst.modifiers, modifier, skill, getOpposites) ~= 0 | |||
end) | |||
return obstList | |||
end | |||
function p.getPetsWithModifier(modifier, skill, getOpposites) | |||
local petList = Pets.getPets( | |||
function(pet) | |||
return p.getModifierValue(pet.modifiers, modifier, skill, getOpposites) ~= 0 | |||
end) | |||
return petList | |||
end | |||
function p.getUpgradesWithModifier(modifier, skill, getOpposites) | |||
local upgradeList = Shop.getPurchases( | |||
function(purchase) | |||
return p.getModifierValue(purchase.contains.modifiers, modifier, skill, getOpposites) ~= 0 | |||
end) | |||
return upgradeList | |||
end | |||
return p | return p |
Revision as of 22:37, 22 April 2021
Documentation for this module may be created at Module:ModifierTables/doc
--Module that constructs tables for all things that can affect Player Modifiers
--This includes Agility, Equipment, and Pets right now
local p = {}
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Pets = require('Module:Pets')
local Items = require('Module:Items')
local Agility = require('Module:Skills/Agility')
local Shop = require('Module:Shop')
--First up, functions to get all the things in a category that have a given modifier:
function p.getModifierValue(modifiers, modifier, skill, getOpposites)
--Sometimes nil modifier sets will get here, which is fine. Just return 0 immediately
if modifiers == nil then
return 0
end
--Make sure we have the skillID and not the name
if skill == '' then
skill = nil
elseif type(skill) == 'string' then
skill = Constants.getSkillID(skill)
end
--By default, attempt to add the increased and decreased prefixes to the modifier
--But if getOpposites is false, only look for an exact match
local increaseMod, decreaseMod = '', ''
if getOpposites == nil or getOpposites then
increaseMod = 'increased'..modifier
decreaseMod = 'decreased'..modifier
else
increaseMod = modifier
end
if not p.hasLogged then
mw.log(increaseMod..', '..decreaseMod)
p.hasLogged = true
end
local increaseVal, decreaseVal = 0, 0
if modifiers[increaseMod] ~= nil and modifiers[increaseMod] ~= nil then
if type(modifiers[increaseMod]) == 'table' then
for i, subVal in Shared.skpairs(modifiers[increaseMod]) do
if subVal[1] == skill then
increaseVal = subVal[2]
end
end
else
increaseVal = modifiers[increaseMod]
end
end
if modifiers[decreaseMod] ~= nil and modifiers[decreaseMod] ~= nil then
if type(modifiers[decreaseMod]) == 'table' then
for i, subVal in Shared.skpairs(modifiers[decreaseMod]) do
if subVal[1] == skill then
decreaseVal = subVal[2]
end
end
else
decreaseVal = modifiers[decreaseMod]
end
end
return increaseVal - decreaseVal
end
function p.getItemsWithModifier(modifier, skill, getOpposites)
local itemList = Items.getItems(
function(item)
return p.getModifierValue(item.modifiers, modifier, skill, getOpposites) ~= 0
end)
return itemList
end
function p.getObstaclesWithModifier(modifier, skill, getOpposites)
local obstList = Agility.getObstacles(
function(obst)
return p.getModifierValue(obst.modifiers, modifier, skill, getOpposites) ~= 0
end)
return obstList
end
function p.getPetsWithModifier(modifier, skill, getOpposites)
local petList = Pets.getPets(
function(pet)
return p.getModifierValue(pet.modifiers, modifier, skill, getOpposites) ~= 0
end)
return petList
end
function p.getUpgradesWithModifier(modifier, skill, getOpposites)
local upgradeList = Shop.getPurchases(
function(purchase)
return p.getModifierValue(purchase.contains.modifiers, modifier, skill, getOpposites) ~= 0
end)
return upgradeList
end
return p