Tags: Removed redirect Reverted |
Tags: New redirect Manual revert |
| Line 1: |
Line 1: |
| -- ENCHANT MODULE
| | #REDIRECT [[Main Page]] |
| -- Define your MediaWiki Lua Module:GetEnchants
| |
| local GetEnchants = {}
| |
| | |
| -- Mapping of color IDs to color values
| |
| local colorMap = {
| |
| [1] = "orange",
| |
| [2] = "yellow",
| |
| [3] = "green",
| |
| [4] = "#164459",
| |
| [5] = "#591639",
| |
| [6] = "lime",
| |
| [7] = "white"
| |
| }
| |
| | |
| -- Function to fetch Weapon Fixes data from the Cargo table
| |
| function GetEnchants.getFixes(name, suffix)
| |
| -- Query the Cargo table
| |
| local cargoTable = mw.ext.cargo.query({
| |
| tables = "WeaponFixes",
| |
| fields = "Name, NameSuffix, NameColorID, Probability, WF_AttackMin, WF_AttackMax, WF_Accuracy, WF_Reattack, WF_Pierce, WF_Weight, WF_ValidAngle, WF_Range, WF_Overheat",
| |
| where = string.format("Name = '%s' AND NameSuffix = '%s'", name, suffix)
| |
| })
| |
| | |
| -- Check if the query was successful
| |
| if not cargoTable or #cargoTable == 0 then
| |
| return nil, "No data found in the Cargo table"
| |
| end
| |
| | |
| -- Map cargo table data to a Lua table
| |
| local data = cargoTable[1]
| |
| | |
| -- Calculate the sum of prefix and suffix values for specific parameters
| |
| calculateSum(data, suffix, "WF_AttackMin")
| |
| calculateSum(data, suffix, "WF_AttackMax")
| |
| calculateSum(data, suffix, "WF_Accuracy")
| |
| calculateSum(data, suffix, "WF_Reattack")
| |
| calculateSum(data, suffix, "WF_Pierce")
| |
| calculateSum(data, suffix, "WF_Weight")
| |
| calculateSum(data, suffix, "WF_ValidAngle")
| |
| calculateSum(data, suffix, "WF_Range")
| |
| calculateSum(data, suffix, "WF_Overheat")
| |
| | |
| -- Return the mapped values
| |
| return data
| |
| end
| |
| | |
| -- Function to parse and sum prefix and suffix values for a specific parameter
| |
| local function calculateSum(data, suffix, parameter)
| |
| if data[parameter] and suffix[parameter] then
| |
| -- Parse numerical values from strings
| |
| local prefixNum = tonumber(data[parameter]) or 0
| |
| local suffixNum = tonumber(suffix[parameter]) or 0
| |
| | |
| -- If the parameter is WF_Reattack or WF_Weight, consider them as negative values
| |
| if parameter == "WF_Reattack" or parameter == "WF_Weight" then
| |
| suffixNum = -suffixNum
| |
| end
| |
| | |
| -- Add prefix and suffix values together
| |
| local sum = prefixNum + suffixNum
| |
| | |
| -- Store the sum in data
| |
| data[parameter] = sum
| |
| end
| |
| end
| |
| | |
| -- Function to get the color value based on the NameColorID
| |
| function GetEnchants.getColorPre(nameColorID)
| |
| local colorValue = colorMap[tonumber(nameColorID)]
| |
| if colorValue then
| |
| return string.format('<span color="%s">', colorValue)
| |
| else
| |
| return "" -- Return empty string if color ID is invalid
| |
| end
| |
| end
| |
| | |
| -- Function to get the NameColorID for a given Name or NameSuffix
| |
| function GetEnchants.getNameColorID(name)
| |
| -- Query the Cargo table to get NameColorID for the given Name or NameSuffix
| |
| local cargoTable = mw.ext.cargo.query({
| |
| tables = "WeaponFixes",
| |
| fields = "NameColorID",
| |
| where = string.format("Name = '%s' OR NameSuffix = '%s'", name, name)
| |
| })
| |
| | |
| -- Check if the query was successful and if it returned any results
| |
| if cargoTable and #cargoTable > 0 then
| |
| return cargoTable[1].NameColorID
| |
| else
| |
| return nil -- Return nil(nothing) if no data found
| |
| end
| |
| end
| |
| | |
| -- Export the Lua module
| |
| return GetEnchants
| |