Module:GolbinRaid: Difference between revisions

From Melvor Idle
(getRaidModifierList: Condense modifiers of the same base name into a single row)
(Fix getRaidModifierList())
 
(6 intermediate revisions by 3 users not shown)
Line 1: Line 1:
local p = {}
local p = {}


local RaidData = mw.loadData('Module:GolbinRaid/data')
local Constants = require('Module:Constants')
local Shared = require('Module:Shared')
local Shared = require('Module:Shared')
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')
local Num = require('Module:Number')


function p.getCrateContents(frame)
function p.getCrateContents(frame)
Line 16: Line 16:
[35] = 'Common'
[35] = 'Common'
}
}
local crateContents = RaidData.GolbinCrate


local resultTable = mw.html.create('table')
local resultTable = mw.html.create('table')
Line 34: Line 33:
end
end


for i, crateEntry in Shared.spairs(RaidData.GolbinCrate, sortFunc) do
for i, crateEntry in Shared.spairs(GameData.rawData.golbinRaid.crateItems, sortFunc) do
local item = Items.getItemByID(crateEntry.itemID)
local item = Items.getItemByID(crateEntry.itemID)
if item ~= nil then
if item ~= nil then
Line 59: Line 58:
-- If the item has special attacks, use those
-- If the item has special attacks, use those
local spAttText = {}
local spAttText = {}
for j, spAtt in ipairs(item.specialAttacks) do
for j, spAttID in ipairs(item.specialAttacks) do
table.insert(spAttText, '<b>' .. spAtt.name .. ' (' .. Shared.round(spAtt.defaultChance, 2, 0) .. '%)</b> - ' .. spAtt.description)
local spAtt = GameData.getEntityByID('attacks', spAttID)
if spAtt ~= nil then
table.insert(spAttText, '<b>' .. spAtt.name .. ' (' .. Num.round(spAtt.defaultChance, 2, 0) .. '%)</b> - ' .. spAtt.description)
end
end
end
descText = table.concat(spAttText, '<br/>')
descText = table.concat(spAttText, '<br/>')
Line 68: Line 70:
local tr = mw.html.create('tr')
local tr = mw.html.create('tr')
tr:tag('td'):wikitext(Icons.Icon({item.name, type='item', notext=true}))
tr:tag('td'):wikitext(Icons.Icon({item.name, type='item', notext=true}))
tr:tag('td'):wikitext(Icons.Link({item.name, type='item'}))
tr:tag('td'):wikitext('[[' .. item.name .. ']]')
tr:tag('td')
tr:tag('td')
:attr('data-sort-value', crateEntry.weight)
:attr('data-sort-value', crateEntry.weight)
Line 83: Line 85:
function p.getRaidModifierList()
function p.getRaidModifierList()
local modList = {}
local modList = {}
for i, modDet in ipairs(RaidData.PossibleModifiers) do
for i, randomMod in ipairs(GameData.rawData.golbinRaid.randomModifiers) do
local baseName, modText, modSign, isNeg, isUnsigned = Constants.getModifierDetails(modDet.key)
local baseName = randomMod.key
local prefix = ''
local modDefn = Modifiers.getModifierByAlias(baseName)
if Shared.startsWith(baseName, 'increased') or Shared.startsWith(baseName, 'decreased') then
local modID = modDefn.mod.id
prefix = string.sub(baseName, 1, 9)
local aliasData = Shared.clone(modDefn.alias)
end
aliasData.key = nil
if modList[baseName] == nil then
aliasData.value = 5 * (randomMod.multiplier or 1)
local modVal = {1, 5}
local modData = {}
local mult = modDet.multiplier
modData[modID] = aliasData
if mult ~= nil then
 
modVal = {modVal[1] * mult, modVal[2] * mult}
if modList[modID] == nil then
end
modList[modID] = { ["ord"] = i, modText = {} }
modText = Constants._getModifierText(modDet.key, modVal, false)
modList[baseName] = {modText, ["ord"] = i, ["sign"] = {modSign}}
else
table.insert(modList[baseName]['sign'], modSign)
end
end
table.insert(modList[modID].modText, Modifiers.getModifiersText(modData, false))
end
end


Line 111: 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['sign'] > 1 then
local replPat = modDet['sign'][1] .. '(%d)'
local signs = table.concat(modDet['sign'], '/')
modText = string.gsub(modDet[1], replPat, signs .. '%1', 1)
end
resultTable:tag('tr')
resultTable:tag('tr')
:tag('td'):wikitext(modText):done()
:tag('td'):wikitext(modText):done()
end
end
 
return tostring(resultTable)
return tostring(resultTable)
end
end


return p
return p

Latest revision as of 23:28, 21 July 2024

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

local p = {}

local Shared = require('Module:Shared')
local GameData = require('Module:GameData')
local Modifiers = require('Module:Modifiers')
local Icons = require('Module:Icons')
local Items = require('Module:Items')
local Num = require('Module:Number')

function p.getCrateContents(frame)
	local weightDesc = {
		[1] = 'Bugged Rare',
		[4] = 'Ultra Rare',
		[10] = 'Rare',
		[20] = 'Uncommon',
		[35] = 'Common'
	}

	local resultTable = mw.html.create('table')
	resultTable:addClass('wikitable'):addClass('stickyHeader'):addClass('sortable')
	resultTable:tag('tr'):addClass('headerRow-0')
		:tag('th'):attr('colspan', 2):wikitext('Item'):done()
		:tag('th'):attr('colspan', 2):wikitext('Rarity'):done()
		:tag('th'):wikitext('Slots'):done()
		:tag('th'):wikitext('Description'):done()

	local sortFunc = function(t, a, b)
		if t[a].weight == t[b].weight then
			return t[a].itemID < t[b].itemID
		else
			return t[a].weight > t[b].weight
		end
	end

	for i, crateEntry in Shared.spairs(GameData.rawData.golbinRaid.crateItems, sortFunc) do
		local item = Items.getItemByID(crateEntry.itemID)
		if item ~= nil then
			-- Generate slot list text
			local slotText = {}
			for j, slot in ipairs(item.validSlots) do
				if slot == 'Weapon' and item.attackType ~= nil then
					local iconType = nil
					if item.attackType ~= 'melee' then
						iconType = 'skill'
					end
					table.insert(slotText, slot .. ' (' .. Icons.Icon({Shared.titleCase(item.attackType), type=iconType, notext=true}) .. ')')
				else
					table.insert(slotText, slot)
				end
			end

			-- Generate description text
			local descText = ''
			if item.description ~= nil then
				-- If the item has a description, simply use that
				descText = item.description
			elseif type(item.specialAttacks) == 'table' then
				-- If the item has special attacks, use those
				local spAttText = {}
				for j, spAttID in ipairs(item.specialAttacks) do
					local spAtt = GameData.getEntityByID('attacks', spAttID)
					if spAtt ~= nil then
						table.insert(spAttText, '<b>' .. spAtt.name .. ' (' .. Num.round(spAtt.defaultChance, 2, 0) .. '%)</b> - ' .. spAtt.description)
					end
				end
				descText = table.concat(spAttText, '<br/>')
			end

			-- Build row & append to table
			local tr = mw.html.create('tr')
			tr:tag('td'):wikitext(Icons.Icon({item.name, type='item', notext=true}))
			tr:tag('td'):wikitext('[[' .. item.name .. ']]')
			tr:tag('td')
				:attr('data-sort-value', crateEntry.weight)
				:wikitext(weightDesc[crateEntry.weight] or '')
			tr:tag('td'):wikitext(crateEntry.weight)
			tr:tag('td'):wikitext(table.concat(slotText, ', '))
			tr:tag('td'):wikitext(descText)
			resultTable:node(tr)
		end
	end
	return tostring(resultTable)
end

function p.getRaidModifierList()
	local modList = {}
	for i, randomMod in ipairs(GameData.rawData.golbinRaid.randomModifiers) do
		local baseName = randomMod.key
		local modDefn = Modifiers.getModifierByAlias(baseName)
		local modID = modDefn.mod.id
		local aliasData = Shared.clone(modDefn.alias)
		aliasData.key = nil
		aliasData.value = 5 * (randomMod.multiplier or 1)
		local modData = {}
		modData[modID] = aliasData

		if modList[modID] == nil then
			modList[modID] = { ["ord"] = i, modText = {} }
		end
		table.insert(modList[modID].modText, Modifiers.getModifiersText(modData, false))
	end

	local resultTable = mw.html.create('table')
	resultTable
		:addClass('wikitable'):addClass('stickyHeader'):addClass('sortable')
		:addClass('mw-collapsible'):addClass('mw-collapsed')
	resultTable:tag('tr'):addClass('headerRow-0')
		:tag('th'):attr('style', 'min-width:400px'):wikitext('Modifier'):done()
	
	local sortFunc = function(t, a, b) return t[a].ord < t[b].ord end
	for baseName, modDet in Shared.spairs(modList, sortFunc) do
		local modText = table.concat(modDet.modText, '<br>')
		resultTable:tag('tr')
			:tag('td'):wikitext(modText):done()
	end

	return tostring(resultTable)
end

return p