Anonymous

Module:GolbinRaid: Difference between revisions

From Melvor Idle
Fix getRaidModifierList()
No edit summary
(Fix getRaidModifierList())
 
Line 1: Line 1:
local p = {}
local p = {}


local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local GameData = require('Module:GameData')
local Modifiers = require('Module:Modifiers')
local Icons = require('Module:Icons')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Items = require('Module:Items')
Line 85: Line 85:
function p.getRaidModifierList()
function p.getRaidModifierList()
local modList = {}
local modList = {}
for i, modDet in ipairs(GameData.rawData.golbinRaid.possibleModifiers) do
for i, randomMod in ipairs(GameData.rawData.golbinRaid.randomModifiers) do
local baseName, modText, isNeg, modifyValue = Constants.getModifierDetails(modDet.key)
local baseName = randomMod.key
if modList[baseName] == nil then
local modDefn = Modifiers.getModifierByAlias(baseName)
local modVal = {1, 5}
local modID = modDefn.mod.id
local mult = modDet.multiplier
local aliasData = Shared.clone(modDefn.alias)
if mult ~= nil then
aliasData.key = nil
modVal = {modVal[1] * mult, modVal[2] * mult}
aliasData.value = 5 * (randomMod.multiplier or 1)
end
local modData = {}
modText = Constants._getModifierText(modDet.key, modVal, false)
modData[modID] = aliasData
modList[baseName] = {modText, ["ord"] = i, ["mods"] = 1}
 
else
if modList[modID] == nil then
modList[baseName]["mods"] = modList[baseName]["mods"] + 1
modList[modID] = { ["ord"] = i, modText = {} }
end
end
table.insert(modList[modID].modText, Modifiers.getModifiersText(modData, false))
end
end


Line 109: Line 110:
local sortFunc = function(t, a, b) return t[a].ord < t[b].ord end
local sortFunc = function(t, a, b) return t[a].ord < t[b].ord end
for baseName, modDet in Shared.spairs(modList, sortFunc) do
for baseName, modDet in Shared.spairs(modList, sortFunc) do
local modText = modDet[1]
local modText = table.concat(modDet.modText, '<br>')
if modDet['mods'] > 1 then
local replPat = '[+-]'
modText = string.gsub(modDet[1], replPat, '+/-', 2)
end
resultTable:tag('tr')
resultTable:tag('tr')
:tag('td'):wikitext(modText):done()
:tag('td'):wikitext(modText):done()