Module:ItemsByStat: Difference between revisions

From Deadlock Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 5: Line 5:
-- Someday there will be a field in the ItemData JSON that indicates if an item is in the game or not, until then...
-- Someday there will be a field in the ItemData JSON that indicates if an item is in the game or not, until then...
ingame = {
ingame = {
"Basic Magazine","Close Quarters","Headshot Booster","High-Velocity Mag","Hollow Point Ward","Monster Rounds","Rapid Rounds","Restorative Shot","Reload","Berserker","Kinetic Dash","Long Range","Melee Charge",
"Basic Magazine","Close Quarters","Headshot Booster","High-Velocity Mag","Hollow Point Ward","Monster Rounds","Rapid Rounds","Restorative Shot","Reload","Berserker","Kinetic Dash","Long Range","Melee Charge","Mystic Shot","Slowing Bullets","Soul Shredder Bullets","Swift Striker","Fleetfoot","Burst Fire","Escalating Resilience","Headhunter","Hunter's Aura","Intensifying Magazine","Point Blank","Pristine Emblem","Sharpshooter","Tesla Bullets","Titanic Magazine","Toxic Bullets","Alchemical Fire","Heroic Aura","Warp Stone","Crippling Headshot","Frenzy","Glass Cannon","Lucky Shot","Ricochet","Siphon Bullets","Spiritual Overflow","Shadow Weave","Silencer","Vampiric Burst","Enduring Spirit","Extra Health","Extra Regen","Extra Stamina","Melee Lifesteal","Sprint Boots","Healing Rite","Bullet Armor","Bullet Lifesteal","Combat Barrier","Debuff Reducer","Enchanter's Barrier","Enduring Speed","Healbane","Healing Booster","Re Barrier","Spirit Armor","Spirit Lifesteal","Divine Barrier","Health Nova","Restorative Locket","Return Fire","Fortitude","Improved Bullet Armor","Improved Spirit Armor","Lifestrike","Superior Stamina","Veil Walker","Debuff Remover","Majestic Leap","Metal Skin","Rescue Beam","Inhibitor","Leech","Soul Rebirth","Colossus","Phantom Strike","Unstoppable","Ammo Scavenger","Extra Charge","Extra Spirit","Mystic Burst","Mystic Reach","Spirit Strike","Infuser","Bullet Resist Shredder","Duration Extender","Improved Cooldown","Mystic Vulnerability","Quicksilver Reload","Suppressor","Cold Front","Decay","Slowing Hex","Withering Whip","Improved Burst","Improved Reach","Improved Spirit","Mystic Slow","Rapid Recharge","Superior Cooldown","Superior Duration","Surge of Power","Torment Pulse","Ethereal Shift","Knockdown","Silence Glyph","Boundless Spirit","Diviner's Kevlar","Escalating Exposure","Mystic Reverb","Curse","Echo Shard","Magic Carpet","Refresher"
"Mystic Shot","Slowing Bullets","Soul Shredder Bullets","Swift Striker","Fleetfoot","Burst Fire","Escalating Resilience","Headhunter","Hunter's Aura","Intensifying Magazine","Point Blank","Pristine Emblem",
"Sharpshooter","Tesla Bullets","Titanic Magazine","Toxic Bullets","Alchemical Fire","Heroic Aura","Warp Stone","Crippling Headshot","Frenzy","Glass Cannon","Lucky Shot","Ricochet","Siphon Bullets","Spiritual Overflow",
"Shadow Weave","Silencer","Vampiric Burst","Enduring Spirit","Extra Health","Extra Regen","Extra Stamina","Melee Lifesteal","Sprint Boots","Healing Rite","Bullet Armor","Bullet Lifesteal","Combat Barrier",
"Debuff Reducer","Enchanter's Barrier","Enduring Speed","Healbane","Healing Booster","Re Barrier","Spirit Armor","Spirit Lifesteal","Divine Barrier","Health Nova","Restorative Locket","Return Fire","Fortitude",
"Improved Bullet Armor","Improved Spirit Armor","Lifestrike","Superior Stamina","Veil Walker","Debuff Remover","Majestic Leap","Metal Skin","Rescue Beam","Inhibitor","Leech","Soul Rebirth","Colossus","Phantom Strike",
"Unstoppable","Ammo Scavenger","Extra Charge","Extra Spirit","Mystic Burst","Mystic Reach","Spirit Strike","Infuser","Bullet Resist Shredder","Duration Extender","Improved Cooldown","Mystic Vulnerability",
"Quicksilver Reload","Suppressor","Cold Front","Decay","Slowing Hex","Withering Whip","Improved Burst","Improved Reach","Improved Spirit","Mystic Slow","Rapid Recharge","Superior Cooldown","Superior Duration",
"Surge of Power","Torment Pulse","Ethereal Shift","Knockdown","Silence Glyph","Boundless Spirit","Diviner's Kevlar","Escalating Exposure","Mystic Reverb","Curse","Echo Shard","Magic Carpet","Refresher"
}
}
InGameItemData = {}
InGameItemData = {}
Line 38: Line 30:


local selectByStat = function(stat)
local selectByStat = function(stat)
-- List properties to grab and set up data structure to hold values
-- List properties to grab, extend as necessary
-- Probably not wise to move or remove elements because there's some hard-coded indexing later
local inKeys = {"Name","Tier","Cost","Slot",stat,"Components"}
local inKeys = {"Name","Tier","Cost","Slot",stat,"Components"}
local outData = {}
local outData = {}
local i = 1
local i = 1
for m,itemData in pairs(InGameItemData) do
for m,itemData in pairs(InGameItemData) do
if itemData[stat] ~= nil and itemData[stat] ~= "0" then -- If Item has given stat in its keys,
if itemData[stat] ~= nil and itemData[stat] ~= "0" then -- If Item has non-zero stat in its keys,
outData[i] = {}
outData[i] = {} -- start a new record of data and
for x = 1,#inKeys do
for x = 1,#inKeys do
outData[i][x] = itemData[inKeys[x]] -- grab stat and other values
outData[i][x] = itemData[inKeys[x]] -- grab stat and other values
Line 57: Line 50:
return outData
return outData
end
end


--{{#invoke:ItemsByStat|tablefy|stat|statName|suffix}}
--{{#invoke:ItemsByStat|tablefy|stat|statName|suffix}}
Line 67: Line 59:
local tableData = selectByStat(stat)
local tableData = selectByStat(stat)
local outString = '{| class="wikitable sortable"\n|-\n!Item!!Cost!!'..statName..'\n'
local outString = '{| class="wikitable sortable"\n|-\n!Item!!Cost!!'..statName..'\n'
for i=1,#tableData do
for i=1,#tableData do -- Very ugly wikitable code
outString = outString..
outString = outString..
'|-style="background:'..colorBySlot[tableData[i][4]]..'"\n|'..
'|-style="background:'..colorBySlot[tableData[i][4]]..'"\n|'..

Revision as of 22:37, 27 September 2024

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

local p = {}
local AllItemData = mw.loadJsonData("Data:ItemData.json")
local Lang = require("Module:Lang")

-- Someday there will be a field in the ItemData JSON that indicates if an item is in the game or not, until then...
ingame = {
	"Basic Magazine","Close Quarters","Headshot Booster","High-Velocity Mag","Hollow Point Ward","Monster Rounds","Rapid Rounds","Restorative Shot","Reload","Berserker","Kinetic Dash","Long Range","Melee Charge","Mystic Shot","Slowing Bullets","Soul Shredder Bullets","Swift Striker","Fleetfoot","Burst Fire","Escalating Resilience","Headhunter","Hunter's Aura","Intensifying Magazine","Point Blank","Pristine Emblem","Sharpshooter","Tesla Bullets","Titanic Magazine","Toxic Bullets","Alchemical Fire","Heroic Aura","Warp Stone","Crippling Headshot","Frenzy","Glass Cannon","Lucky Shot","Ricochet","Siphon Bullets","Spiritual Overflow","Shadow Weave","Silencer","Vampiric Burst","Enduring Spirit","Extra Health","Extra Regen","Extra Stamina","Melee Lifesteal","Sprint Boots","Healing Rite","Bullet Armor","Bullet Lifesteal","Combat Barrier","Debuff Reducer","Enchanter's Barrier","Enduring Speed","Healbane","Healing Booster","Re Barrier","Spirit Armor","Spirit Lifesteal","Divine Barrier","Health Nova","Restorative Locket","Return Fire","Fortitude","Improved Bullet Armor","Improved Spirit Armor","Lifestrike","Superior Stamina","Veil Walker","Debuff Remover","Majestic Leap","Metal Skin","Rescue Beam","Inhibitor","Leech","Soul Rebirth","Colossus","Phantom Strike","Unstoppable","Ammo Scavenger","Extra Charge","Extra Spirit","Mystic Burst","Mystic Reach","Spirit Strike","Infuser","Bullet Resist Shredder","Duration Extender","Improved Cooldown","Mystic Vulnerability","Quicksilver Reload","Suppressor","Cold Front","Decay","Slowing Hex","Withering Whip","Improved Burst","Improved Reach","Improved Spirit","Mystic Slow","Rapid Recharge","Superior Cooldown","Superior Duration","Surge of Power","Torment Pulse","Ethereal Shift","Knockdown","Silence Glyph","Boundless Spirit","Diviner's Kevlar","Escalating Exposure","Mystic Reverb","Curse","Echo Shard","Magic Carpet","Refresher"
}
InGameItemData = {}
for i, InGameItemName in pairs(ingame) do
	for j, ItemData in pairs(AllItemData) do
		if ItemData["Name"]==InGameItemName then 
			table.insert(InGameItemData, ItemData)
			break
		end
	end
end

-- I truly have no better idea of how to sort by cost within slot, so I'm gonna multiply the costs of slots I want lower in the table
local multBySlot = {}
multBySlot["Weapon"] = 1
multBySlot["Armor"] = 10000
multBySlot["Tech"] = 100000000

-- For coloring the table by slot
local colorBySlot = {}
colorBySlot["Weapon"] = "#FCAC4D"
colorBySlot["Armor"] = "#86C921"
colorBySlot["Tech"] = "#DE9CFF"

local selectByStat = function(stat)
	-- List properties to grab, extend as necessary
	-- Probably not wise to move or remove elements because there's some hard-coded indexing later
	local inKeys = {"Name","Tier","Cost","Slot",stat,"Components"}
	
	local outData = {}
	local i = 1
	for m,itemData in pairs(InGameItemData) do
		if itemData[stat] ~= nil and itemData[stat] ~= "0" then -- If Item has non-zero stat in its keys,
			outData[i] = {}							-- start a new record of data and
			for x = 1,#inKeys do
				outData[i][x] = itemData[inKeys[x]] -- grab stat and other values
			end
			i = i+1
		end
	end
	
	-- Sort by cost within slot
	table.sort(outData, function(a,b) return a[3]*multBySlot[a[4]]<b[3]*multBySlot[b[4]] end)
	return outData
end

--{{#invoke:ItemsByStat|tablefy|stat|statName|suffix}}
p.tablefy = function(frame)
	local stat = frame.args[1]
	local statName = frame.args[2]
	local suffix = frame.args[3]
	
	local tableData = selectByStat(stat)
	local outString = '{| class="wikitable sortable"\n|-\n!Item!!Cost!!'..statName..'\n'
	for i=1,#tableData do -- Very ugly wikitable code
		outString = outString..
			'|-style="background:'..colorBySlot[tableData[i][4]]..'"\n|'..
			frame:expandTemplate{title="Item", args={tableData[i][1],Lang._search_string(tableData[i][1])}}.."||"..
			frame:expandTemplate{title="Souls", args={tableData[i][3]}}.."||"..
			'style="text-align:center;"|+'..tableData[i][5]..suffix.."\n"
	end
	return outString.."|}"
end

return p