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") | ||
--- 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 18: | Line 35: | ||
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 40: | ||
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 46: | ||
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", "FervorMovespeed" | friendly_to_internal["move speed"] = { "BonusMoveSpeed", "ActiveBonusMoveSpeed", "FervorMovespeed"} | ||
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" } | ||
| Line 46: | Line 62: | ||
friendly_to_internal["item cooldown reduction"] = { "ItemCooldownReduction" } | friendly_to_internal["item cooldown reduction"] = { "ItemCooldownReduction" } | ||
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 87: | ||
"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 94: | ||
"HealLifePercentOutOfCombat", | "HealLifePercentOutOfCombat", | ||
"ReloadSpeedMultipler", | "ReloadSpeedMultipler", | ||
"MeleeDistanceScale", "BonusHeavyMeleeDamage", "BonusMeleeDamagePercent", "MeleeResistPercent | "MeleeDistanceScale", "BonusHeavyMeleeDamage", "BonusMeleeDamagePercent", "MeleeResistPercent", | ||
"SlideScale", | "SlideScale", | ||
"StaminaCooldownReduction", | "StaminaCooldownReduction", | ||
"SlowPercent", "MovementSpeedSlow | "SlowPercent", "MovementSpeedSlow", | ||
"HealAmpReceivePenaltyPercent", "HealAmpRegenPenaltyPercent", | "HealAmpReceivePenaltyPercent", "HealAmpRegenPenaltyPercent", | ||
"ImbuedBonusDuration", "NonImbuedBonusDuration", "BonusAbilityDurationPercent", | "ImbuedBonusDuration", "NonImbuedBonusDuration", "BonusAbilityDurationPercent", | ||
| Line 130: | Line 109: | ||
"TechDamageReduction", | "TechDamageReduction", | ||
"OutgoingDamagePenaltyPercent", "DeathImmunityDamageReduction", "TechPowerPercent", | "OutgoingDamagePenaltyPercent", "DeathImmunityDamageReduction", "TechPowerPercent", | ||
"GroundDashReductionPercent | "GroundDashReductionPercent" | ||
}, | }, | ||
["m/s"] = { "BonusMoveSpeed", "ActiveBonusMoveSpeed", "BonusSprintSpeed", "FervorMovespeed | ["m/s"] = { "BonusMoveSpeed", "ActiveBonusMoveSpeed", "BonusSprintSpeed", "FervorMovespeed"}, | ||
[" HP"] = {"CombatBarrier", "GuardianWardCombatBarrier", "VexBarrierCombatBarrier"} | [" HP"] = {"CombatBarrier", "GuardianWardCombatBarrier", "VexBarrierCombatBarrier"} | ||
} | } | ||
| Line 198: | Line 175: | ||
listofKeysTable = friendlyNames(property) | listofKeysTable = friendlyNames(property) | ||
local filteredData = | local filteredData = {} | ||
for _, v in pairs(data) do | |||
for _, t in ipairs(listofKeysTable) do | |||
if v[t] ~= nil and v["IsDisabled"] == false and v["Name"] ~= nil and v[t] ~= "0" and v[t] ~= "0m" and v[t] ~= "" then | |||
table.insert(filteredData, v) | |||
break | |||
end | |||
end | |||
end | |||
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' } | ||
| Line 218: | Line 204: | ||
local rowspanTracker = {} | local rowspanTracker = {} | ||
for _, itemName in ipairs(filteredData) do | |||
local display = frame:expandTemplate{ | |||
title = 'ItemIcon', | |||
args = { itemName["Name"] } | |||
} | |||
local statCount = 0 | |||
for _, t in pairs(listofKeysTable) do | |||
if(itemName[t] ~= nil and itemName[t] ~= "0") then | |||
statCount = statCount + 1 | |||
end | end | ||
end | |||
if statCount == 0 then statCount = 1 end | |||
rowspanTracker[itemName["Name"]] = statCount | |||
local firstStat = true | |||
for _, t in pairs(listofKeysTable) do | |||
if(itemName[t] ~= nil and itemName[t] ~= "0") then | |||
-- Handles complex stat values from the JSON data. | -- Handles complex stat values from the JSON data. | ||
if type(statValue) == 'table' and statValue.Value ~= nil then | -- A stat can be a simple value (e.g., "BonusMoveSpeed": "1") or a table containing | ||
-- scaling info (e.g., "BonusFireRate": { "Value": 10, "Scale": ... }). | |||
-- This code checks if the stat is a table and extracts the base numerical value from its 'Value' key. | |||
local statValue = itemName[t] | |||
if type(statValue) == 'table' and statValue.Value ~= nil then | |||
statValue = statValue.Value | |||
end | |||
copyVar = copyVar:gsub("^%l", string.upper) | |||
local categoryDisplay | |||
if itemName["Slot"] == "Armor" then | |||
categoryDisplay = frame:expandTemplate{ | |||
title = 'ItemType', | |||
args = { "Armor", "Vitality" } | |||
} | |||
elseif itemName["Slot"] == "Tech" then | |||
categoryDisplay = frame:expandTemplate{ | |||
title = 'ItemType', | |||
args = { "Tech", "Spirit" } | |||
} | |||
else | |||
categoryDisplay = frame:expandTemplate{ | |||
title = 'ItemType', | |||
args = { "Weapon", "Weapon" } | |||
} | |||
end | |||
local tableData = mw.html.create('tr') | |||
if firstStat then | |||
tableData | |||
:tag('td'):attr('rowspan', statCount):wikitext(display):done() | |||
:tag('td'):attr('rowspan', statCount):wikitext(commas._add(get_cost(itemName["Name"]))):done() | |||
:tag('td'):attr('rowspan', statCount):wikitext(categoryDisplay):done() | |||
firstStat = false | |||
end | |||
tableData:tag('td'):wikitext(signPrefix(statValue) .. appendSuffix(t) .. " " .. copyVar):done() | |||
table.insert(requirements, tableData) | |||
end | end | ||
end | end | ||
end | |||
for _, row in ipairs(requirements) do | |||
createTable:node(row) | |||
end | |||
return tostring(createTable) | |||
end | end | ||
return p | return p | ||