Module:ID
Jump to navigation
Jump to search
Documentation for this module may be created at Module:ID/doc
local p = {}
-- Helper function
local function has_value(tab, val)
if tab == nil then
return false
end
for index, value in ipairs(tab) do
if value == val then
return true
end
end
return false
end
function p.stat(frame)
-- Table that translates type to a link to central article / category
local typeToLink = {
["1h"] = "[[Weapons|Weapon]]",
["2h"] = "[[Weapons|Weapon]]",
["1h-m"] = "[[Weapons|Weapon]]",
["2h-m"] = "[[Weapons|Weapon]]",
["hat"] = "[[Hats|Hat]]",
["hat-style"] = "[[Hats|Hat]]",
["mask"] = "[[Hats|Hat]]",
["mask-style"] = "[[Hats|Hat]]",
["facegear"] = "[[Facegear]]",
["facegear-style"] = "[[Facegear]]",
["armor"] = "[[Armor]]",
["shoes"] = "[[Shoes]]",
["accessory"] = "[[Accessories|Accessory]]",
["shield"] = "[[Shields|Shield]]",
["misc"] = "[[:Category:Misc|Miscellaneous Item]]",
["bow"] = "[[Weapons|Bow]]",
["furniture"] = "[[:Category:Furniture|Furniture]]"
}
-- Table that translates type to a subtype / class, if applicable
local typeToClass = {
["1h"] = "One-Handed Melee",
["2h"] = "Two-Handed Melee",
["1h-m"] = "One-Handed Magic",
["2h-m"] = "Two-Handed Magic",
["hat"] = "Functional Hat",
["hat-style"] = "Style Hat",
["mask"] = "Functional Mask",
["mask-style"] = "Style Mask",
["facegear"] = "Functional Facegear",
["facegear-style"] = "Style Facegear",
["armor"] = "",
["shoes"] = "",
["accessory"] = "",
["shield"] = "",
["misc"] = "",
["bow"] = "",
["furniture"] = ""
}
local data = mw.loadData('Module:ItemStats/data')
local id = frame.args[1]
local stat = frame.args[2]
local returnValue = nil
-- Check if item exists
if data[id] == nil then
-- Error
returnValue = "Unknown Item"
return returnValue
end
-- Helper Variables | Default value for arcademod is 1
local value = data[id]["value"]
local mod = data[id]["arcademod"] or 1
local type = data[id]["type"]
local tradeable = not has_value(data[id]["tags"], "NoDropNoTrade")
local storyAvailable = not has_value(data[id]["tags"], "NotInStory")
local arcadeAvailable = not has_value(data[id]["tags"], "NotInArcade")
-- Get "default" value: either stat, or nothing (query must be calculated)
returnValue = data[id][stat] or ""
-- Check other cases which need processing
if stat == "storybuy" and tradeable and storyAvailable then
if has_value(data[id]["tags"], "StoryBuy") then
returnValue = value or returnValue
else
returnValue = "No Merchant"
end
return returnValue
end
if stat == "storysell" and tradeable and storyAvailable and value ~= nil then
returnValue = math.floor(value / 2)
return returnValue
end
if stat == "storybuyback" and tradeable and storyAvailable and value ~= nil then
returnValue = value * 2
return returnValue
end
if stat == "arcadebuy" and tradeable and arcadeAvailable and value ~= nil then
if has_value(data[id]["tags"], "ArcadeBuy") then
returnValue = value * mod
else
returnValue = "No Merchant"
end
return returnValue
end
if stat == "arcadesell" and tradeable and arcadeAvailable and value ~= nil then
returnValue = math.floor(value * mod) / 2
if type ~= nil and type ~= "misc" then
-- Equipment sell penalty in Arcade: 50%
returnValue = returnValue / 2
end
returnValue = math.floor(returnValue)
return returnValue
end
if stat == "type" then
returnValue = typeToLink[data[id]["type"]] or returnValue
return returnValue
end
if stat == "class" and type ~= nil then
returnValue = typeToClass[data[id]["type"]] or returnValue
return returnValue
end
if stat == "storyAvailable" then
if storyAvailable then
returnValue = "Yes"
else
returnValue = "No"
end
end
if stat == "arcadeAvailable" then
if arcadeAvailable then
returnValue = "Yes"
else
returnValue = "No"
end
end
return returnValue
end
function p.sprite(frame)
local data = mw.loadData('Module:ItemSprites/data')
local id = frame.args[1]
return data[id] or "Placeholder.png"
end
function p.name(frame)
local data = mw.loadData('Module:ItemNames/data')
local id = frame.args[1]
return data[id] or "Unknown Item"
end
return p