Editing Module:ItemTablesGive feedback
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then publish the changes below to finish undoing the edit.
| Latest revision | Your text | ||
| Line 1: | Line 1: | ||
local p = {}; | local p = {}; | ||
local data = mw.loadJsonData("Data:ItemData.json") | |||
local get_cost = require("Module:ItemData")._get_cost | local get_cost = require("Module:ItemData")._get_cost | ||
local get_type = require("Module:ItemData")._get_type | local get_type = require("Module:ItemData")._get_type | ||
local commas = require("Module:Addcommas") | local commas = require("Module:Addcommas") | ||
-- Returns an array of item tables that have the same properties | |||
-- @function get_similar_items_array | |||
-- @param {array} | |||
-- @return {array of tables} | |||
local function get_similar_items_array(property) | |||
local similarItems = {} | |||
local hash = {} | |||
local noDuplicates = {} | |||
for _, v in pairs(data) do | |||
for _, value in ipairs(property) do | |||
if (v[value] ~= nil and v["IsDisabled"] == false and v["Name"] ~= nil and v[value] ~= "0" and v[value] ~= "0m" and v[value] ~= "") then | |||
table.insert(similarItems, v) | |||
end | |||
end | |||
end | |||
-- remove duplicate items if that item contains multiple keys of the same stat increase (eg. Fleetfoot has both "BonusMoveSpeed", "ActiveBonusMoveSpeed" in move speed). | |||
-- there might be a more efficient way to prevent adding duplicate items in the first place in the above for loop | |||
for _, v in pairs(similarItems) do | |||
if (not hash[v]) then | |||
noDuplicates[#noDuplicates+1] = v | |||
hash[v] = true | |||
end | |||
end | |||
return noDuplicates | |||
end | |||
--- Copies original table with its children as deep as possible. Does not handle metatables. (Copy is needed because Lua passes by reference, not value) | |||
-- @function Deepcopy | |||
-- @param {n-D table} | |||
-- @return {n-D table} | |||
function Deepcopy(orig) | |||
local orig_type = type(orig) | |||
local copy | |||
if orig_type == 'table' then | |||
copy = {} | |||
for orig_key, orig_value in next, orig, nil do | |||
copy[Deepcopy(orig_key)] = Deepcopy(orig_value) | |||
end | |||
else | |||
copy = orig | |||
end | |||
return copy | |||
end | |||
local friendly_to_internal = {} | local friendly_to_internal = {} | ||
friendly_to_internal["ammo"] = { "BonusClipSizePercent", "BonusClipSize", "ActiveReloadPercent" } | friendly_to_internal["ammo"] = { "BonusClipSizePercent", "BonusClipSize", "ActiveReloadPercent" } | ||
| Line 12: | Line 56: | ||
friendly_to_internal["bullet shield health"] = { "BulletShieldMaxHealth", "BulletShieldOnCast", "SaviorBulletShieldHealth", "FlyingBulletShield", "VexBarrierBulletMaxHealth" } | friendly_to_internal["bullet shield health"] = { "BulletShieldMaxHealth", "BulletShieldOnCast", "SaviorBulletShieldHealth", "FlyingBulletShield", "VexBarrierBulletMaxHealth" } | ||
friendly_to_internal["spirit shield health"] = { "TechShieldMaxHealth", "TechShieldOnCast", "SaviorMagicShieldHealth", "FlyingTechShield", "VexBarrierTechMaxHealth" } | friendly_to_internal["spirit shield health"] = { "TechShieldMaxHealth", "TechShieldOnCast", "SaviorMagicShieldHealth", "FlyingTechShield", "VexBarrierTechMaxHealth" } | ||
friendly_to_internal["barrier"] = { "CombatBarrier | friendly_to_internal["barrier"] = { "CombatBarrier" } | ||
friendly_to_internal["bullet resist"] = { "BulletResist", "LocalBulletArmorReduction", "ReturnFireBulletResist", "BulletResistPerStack" } | friendly_to_internal["bullet resist"] = { "BulletResist", "LocalBulletArmorReduction", "ReturnFireBulletResist", "BulletResistPerStack" } | ||
friendly_to_internal["bullet resist reduction"] = { "BulletArmorReduction", "BulletResistReduction" } | friendly_to_internal["bullet resist reduction"] = { "BulletArmorReduction", "BulletResistReduction" } | ||
| Line 18: | Line 62: | ||
friendly_to_internal["spirit resist reduction"] = { "TechArmorDamageReduction", "MagicResistReduction" } | friendly_to_internal["spirit resist reduction"] = { "TechArmorDamageReduction", "MagicResistReduction" } | ||
friendly_to_internal["bonus health"] = { "BonusHealth" } | friendly_to_internal["bonus health"] = { "BonusHealth" } | ||
friendly_to_internal["health regen"] = { "BonusHealthRegen" } | friendly_to_internal["health regen"] = { "BonusHealthRegen" } | ||
friendly_to_internal["regeneration"] = { "Regeneration" } | friendly_to_internal["regeneration"] = { "Regeneration" } | ||
| Line 24: | Line 67: | ||
friendly_to_internal["out of combat health regen"] = { "OutOfCombatHealthRegen" } | friendly_to_internal["out of combat health regen"] = { "OutOfCombatHealthRegen" } | ||
friendly_to_internal["max health regen"] = { "HealLifePercentOutOfCombat" } | friendly_to_internal["max health regen"] = { "HealLifePercentOutOfCombat" } | ||
friendly_to_internal["fire rate"] = { "BonusFireRate", "FireRateWhenShielded", "FireRateBonus", "FervorFireRate", "AmbushBonusFireRate", "ActiveBonusFireRate | friendly_to_internal["fire rate"] = { "BonusFireRate", "FireRateWhenShielded", "FireRateBonus", "FervorFireRate", "AmbushBonusFireRate", "ActiveBonusFireRate" } | ||
friendly_to_internal["fire rate slow"] = { "FireRateSlow" } | friendly_to_internal["fire rate slow"] = { "FireRateSlow" } | ||
friendly_to_internal["bullet velocity"] = { "BonusBulletSpeedPercent" } | friendly_to_internal["bullet velocity"] = { "BonusBulletSpeedPercent" } | ||
| Line 30: | Line 73: | ||
friendly_to_internal["bullet lifesteal"] = { "BulletLifestealPercent", "ActiveBonusLifesteal" } | friendly_to_internal["bullet lifesteal"] = { "BulletLifestealPercent", "ActiveBonusLifesteal" } | ||
friendly_to_internal["spirit lifesteal"] = { "AbilityLifestealPercentHero" } | friendly_to_internal["spirit lifesteal"] = { "AbilityLifestealPercentHero" } | ||
friendly_to_internal["move speed"] = { "BonusMoveSpeed", "ActiveBonusMoveSpeed" | friendly_to_internal["move speed"] = { "BonusMoveSpeed", "ActiveBonusMoveSpeed" } | ||
friendly_to_internal["sprint speed"] = { "BonusSprintSpeed | friendly_to_internal["sprint speed"] = { "BonusSprintSpeed" } | ||
friendly_to_internal["movement slow"] = { "SlowPercent", "MovementSpeedSlow | friendly_to_internal["movement slow"] = { "SlowPercent", "MovementSpeedSlow" } | ||
friendly_to_internal["reload time"] = { "ReloadSpeedMultipler" } | friendly_to_internal["reload time"] = { "ReloadSpeedMultipler" } | ||
friendly_to_internal["heavy melee distance"] = { "MeleeDistanceScale" } | friendly_to_internal["heavy melee distance"] = { "MeleeDistanceScale" } | ||
friendly_to_internal["bonus heavy damage"] = { "BonusHeavyMeleeDamage" } | friendly_to_internal["bonus heavy damage"] = { "BonusHeavyMeleeDamage" } | ||
friendly_to_internal["bonus melee damage"] = { "BonusMeleeDamagePercent | friendly_to_internal["bonus melee damage"] = { "BonusMeleeDamagePercent" } | ||
friendly_to_internal["melee resist"] = { "MeleeResistPercent" } | friendly_to_internal["melee resist"] = { "MeleeResistPercent" } | ||
friendly_to_internal["stamina"] = { "Stamina" } | friendly_to_internal["stamina"] = { "Stamina" } | ||
friendly_to_internal["slide distance"] = { "SlideScale" } | friendly_to_internal["slide distance"] = { "SlideScale" } | ||
friendly_to_internal["stamina recovery"] = { "StaminaCooldownReduction" } | friendly_to_internal["stamina recovery"] = { "StaminaCooldownReduction" } | ||
friendly_to_internal["healing reduction"] = { " | friendly_to_internal["healing reduction"] = { "HealAmpReceivePenaltyPercent" } | ||
friendly_to_internal["ability duration"] = { "ImbuedBonusDuration", "BonusAbilityDurationPercent" } | friendly_to_internal["ability duration"] = { "ImbuedBonusDuration", "BonusAbilityDurationPercent" } | ||
friendly_to_internal[" | friendly_to_internal["cooldown reduction"] = { "ImbuedCooldownReduction", "CooldownReduction" } | ||
friendly_to_internal["charge cooldown reduction"] = { "CooldownReductionOnChargedAbilities" } | friendly_to_internal["charge cooldown reduction"] = { "CooldownReductionOnChargedAbilities" } | ||
friendly_to_internal["debuff resist"] = { "StatusResistancePercent | friendly_to_internal["debuff resist"] = { "StatusResistancePercent" } | ||
friendly_to_internal["ability range"] = { "TechRangeMultiplier", "ImbuedTechRangeMultiplier"} | friendly_to_internal["ability range"] = { "TechRangeMultiplier", "ImbuedTechRangeMultiplier"} | ||
friendly_to_internal["falloff range"] = { "BonusAttackRangePercent" } | friendly_to_internal["falloff range"] = { "BonusAttackRangePercent" } | ||
friendly_to_internal["spirit amp"] = { "ShreddersTechAmp", "MagicIncreasePerStack" } | friendly_to_internal["spirit amp"] = { "ShreddersTechAmp", "MagicIncreasePerStack" } | ||
friendly_to_internal["spirit damage reduction"] = { "TechDamageReduction" } | friendly_to_internal["spirit damage reduction"] = { "TechDamageReduction" } | ||
friendly_to_internal["dash distance"] = { "GroundDashReductionPercent | friendly_to_internal["dash distance"] = { "GroundDashReductionPercent" } | ||
friendly_to_internal["damage reduction"] = { "OutgoingDamagePenaltyPercent", "DeathImmunityDamageReduction" } | friendly_to_internal["damage reduction"] = { "OutgoingDamagePenaltyPercent", "DeathImmunityDamageReduction" } | ||
-- Returns a table of internal properties | -- Returns a table of internal properties | ||
| Line 108: | Line 113: | ||
"BaseAttackDamagePercent", "CloseRangeBonusWeaponPower", "LongRangeBonusWeaponPower", "AttackDamageWhenShielded", | "BaseAttackDamagePercent", "CloseRangeBonusWeaponPower", "LongRangeBonusWeaponPower", "AttackDamageWhenShielded", | ||
"TechResist", "BulletResist", | "TechResist", "BulletResist", | ||
"BonusFireRate", "FireRateWhenShielded", "FervorFireRate", "FireRateBonus", "AmbushBonusFireRate", "ActiveBonusFireRate | "BonusFireRate", "FireRateWhenShielded", "FervorFireRate", "FireRateBonus", "AmbushBonusFireRate", "ActiveBonusFireRate", "FireRateSlow", | ||
"LocalBulletArmorReduction", "ReturnFireBulletResist", "BulletArmorReduction", "BulletResistReduction", "BulletResistPerStack", | "LocalBulletArmorReduction", "ReturnFireBulletResist", "BulletArmorReduction", "BulletResistReduction", "BulletResistPerStack", | ||
"TechArmorDamageReduction", "MagicResistReduction", | "TechArmorDamageReduction", "MagicResistReduction", | ||
| Line 115: | Line 120: | ||
"HealLifePercentOutOfCombat", | "HealLifePercentOutOfCombat", | ||
"ReloadSpeedMultipler", | "ReloadSpeedMultipler", | ||
"MeleeDistanceScale", "BonusHeavyMeleeDamage", "BonusMeleeDamagePercent", "MeleeResistPercent | "MeleeDistanceScale", "BonusHeavyMeleeDamage", "BonusMeleeDamagePercent", "MeleeResistPercent", | ||
"SlideScale", | "SlideScale", | ||
"StaminaCooldownReduction", | "StaminaCooldownReduction", | ||
"SlowPercent", "MovementSpeedSlow | "SlowPercent", "MovementSpeedSlow", | ||
"HealAmpReceivePenaltyPercent | "HealAmpReceivePenaltyPercent", | ||
"ImbuedBonusDuration", "NonImbuedBonusDuration", "BonusAbilityDurationPercent", | "ImbuedBonusDuration", "NonImbuedBonusDuration", "BonusAbilityDurationPercent", | ||
"ImbuedCooldownReduction", "CooldownReduction", | "ImbuedCooldownReduction", "CooldownReduction", | ||
"CooldownReductionOnChargedAbilities", | "CooldownReductionOnChargedAbilities", | ||
"StatusResistancePercent", | "StatusResistancePercent", | ||
| Line 129: | Line 133: | ||
"ShreddersTechAmp", "BonusAmpPerHeadshot", "MagicIncreasePerStack", | "ShreddersTechAmp", "BonusAmpPerHeadshot", "MagicIncreasePerStack", | ||
"TechDamageReduction", | "TechDamageReduction", | ||
"OutgoingDamagePenaltyPercent", "DeathImmunityDamageReduction", "TechPowerPercent | "OutgoingDamagePenaltyPercent", "DeathImmunityDamageReduction", "TechPowerPercent" | ||
}, | }, | ||
["m/s"] = { "BonusMoveSpeed", "ActiveBonusMoveSpeed", "BonusSprintSpeed | ["m/s"] = { "BonusMoveSpeed", "ActiveBonusMoveSpeed", "BonusSprintSpeed" }, | ||
[" HP"] = {"CombatBarrier | [" HP"] = {"CombatBarrier"} | ||
} | } | ||
| Line 162: | Line 163: | ||
end | end | ||
-- Formats | -- Formats the value of the stat with a + or - | ||
-- @function signPrefix | -- @function signPrefix | ||
-- @param { | -- @param {string} | ||
-- @return {string} | -- @return {string} | ||
local function signPrefix(value) | local function signPrefix(value) | ||
local signString = "" | |||
value = value:gsub( "m", "" ) | |||
value = value:gsub("m", "") | |||
value = tonumber(value) | value = tonumber(value) | ||
if (value >= 0) then | if (value >= 0) then | ||
return "+<b>" .. value .. "</b>" | return "+<b>" .. value .. "</b>" | ||
| Line 192: | Line 186: | ||
local requirements = {} | local requirements = {} | ||
local listofKeysTable = {} | local listofKeysTable = {} | ||
local listofItems = "" | |||
local property = frame:getParent().args[1] or mw.title.getCurrentTitle().text | local property = frame:getParent().args[1] or mw.title.getCurrentTitle().text | ||
local copyVar = property | local copyVar = property | ||
listofKeysTable = friendlyNames(property) | listofKeysTable = friendlyNames(property) | ||
local filteredData = {} | |||
filteredData = get_similar_items_array(listofKeysTable) | |||
table.sort(filteredData, defaultSort()) | table.sort(filteredData, defaultSort()) | ||
local createTable = mw.html.create('table') | local createTable = mw.html.create('table') | ||
:addClass('wikitable sortable') | |||
:tag('caption'):wikitext("List of items"):done() | |||
local soulIcon = frame:expandTemplate{ title = 'Souls' } | local soulIcon = frame:expandTemplate{ title = 'Souls' } | ||
local createTableHeader = mw.html.create('tr') | local createTableHeader = mw.html.create('tr') | ||
createTableHeader | createTableHeader | ||
| Line 213: | Line 206: | ||
:tag('th'):wikitext('Category'):done() | :tag('th'):wikitext('Category'):done() | ||
:tag('th'):wikitext('Stat change'):done() | :tag('th'):wikitext('Stat change'):done() | ||
createTable:node(createTableHeader) | createTable:node(createTableHeader) | ||
-- | -- query all the filtered items. itemName is the item table. | ||
for internalName, itemName in ipairs(filteredData) do | |||
for | |||
local display = frame:expandTemplate{ | local display = frame:expandTemplate{ | ||
title = 'ItemIcon', | title = 'ItemIcon', | ||
args = { itemName["Name"] } | args = { | ||
itemName["Name"] | |||
} | |||
} | } | ||
for k, t in pairs(listofKeysTable) do | |||
for | -- filter out items that: don't have the property and the value isn't zero | ||
if(itemName[t] ~= nil and itemName[t] ~= "0" ) then | |||
if( | listofItems = listofItems .. itemName["Name"] .. "<br/>" | ||
copyVar = copyVar:gsub("^%l", string.upper) | copyVar = copyVar:gsub("^%l", string.upper) | ||
-- Get category display using ItemType template with appropriate parameters | |||
local categoryDisplay | local categoryDisplay | ||
if itemName["Slot"] == "Armor" then | if itemName["Slot"] == "Armor" then | ||
| Line 256: | Line 236: | ||
args = { "Tech", "Spirit" } | args = { "Tech", "Spirit" } | ||
} | } | ||
else | else -- Weapon | ||
categoryDisplay = frame:expandTemplate{ | categoryDisplay = frame:expandTemplate{ | ||
title = 'ItemType', | title = 'ItemType', | ||
| Line 262: | Line 242: | ||
} | } | ||
end | end | ||
local tableData = mw.html.create('tr') | local tableData = mw.html.create('tr') | ||
tableData | |||
:tag('td'):wikitext(display):done() | |||
:tag('td'):wikitext(commas._add(get_cost(itemName["Name"]))):done() | |||
:tag('td'):wikitext(categoryDisplay):done() | |||
if (t == "LocalBulletArmorReduction") then | |||
tableData | |||
:tag('td'):wikitext("<span style=\"color:red;\">" .. signPrefix(itemName[t]) .. appendSuffix(t) .. "</span> " .. copyVar):done() | |||
else | |||
tableData | |||
:tag('td'):wikitext(signPrefix(itemName[t]) .. appendSuffix(t) .. "</span> " .. copyVar):done() | |||
end | |||
table.insert(requirements, tableData) | table.insert(requirements, tableData) | ||
end | end | ||
end | end | ||
end | |||
for _, row in ipairs(requirements) do | |||
createTable:node(row) | |||
end | end | ||
return tostring(createTable) | |||
end | end | ||
return p | return p | ||