Module:Item Description
Jump to navigation
Jump to search
Documentation for this module may be created at Module:Item Description/doc
local p = {}
function p.item_description(frame)
-- Check if the item type is a weapon or armor
local item = mw.text.jsonDecode(frame:callParserFunction("#var", { "itemData" }))
if p.isWeaponType(item.Item_Type) or p.isArmorType(item.Item_Type) and item.Item_Type ~= "Boots" and item.Item_Type ~= "Gloves" then
-- For items that are weapons or armor and should display rarity
return string.format('<p>%s is a %s <span>[[%s|%s]]</span></p>',
item.Item_Name,
p.ItemPageDescriptionRarityCheck(item),
item.Item_Type, item.Item_Type)
elseif item.Item_Type == "Boots" or item.Item_Type == "Gloves" then
-- For Boots or Gloves which will always show rarity
return string.format('<p>%s is a pair of <span class="item-page-%s">[[%s|%s]]</span> <span>[[%s|%s]]</span></p>',
item.Item_Name,
item.Item_Rarity, item.Item_Rarity, item.Item_Rarity,
item.Item_Type, item.Item_Type)
else
-- For all other types that do not fall into the above categories and should not display rarity
return string.format('<p>%s is a [[%s|%s]]</p>', item.Item_Name, item.Item_Type, item.Item_Type)
end
end
function p.ItemPageDescriptionRarityCheck(item)
if p.isWeaponType(item.Item_Type) or p.isArmorType(item.Item_Type) then
return string.format('<span class="item-page-%s">[[%s|%s]]</span>', item.Item_Rarity, item.Item_Rarity, item.Item_Rarity) else
return ""
end
end
function p.isWeaponType(itemType)
local weaponTypes = {
Sword = true,
Dagger = true,
Mace = true,
Axe = true,
Claw = true,
Polearm = true,
Chainsaw = true,
Staff = true,
Cane = true,
Wand = true,
Book = true,
Spellblade = true,
Bow = true,
Gun = true,
Flask = true,
["Throwing Weapon"] = true }
return weaponTypes[itemType] or false
end
function p.isArmorType(itemType)
local armorTypes = {
Helmet = true,
["Body Armor"] = true,
Gloves = true,
Belt = true,
Amulet = true,
Ring = true,
Boots = true,
Shield = true,
Charm = true,
}
return armorTypes[itemType] or false
end
function p.isMiscType(itemType)
local miscTypes = {
Consumable = true,
Potion = true,
Key = true,
Material = true,
Collectible = true
}
return miscTypes[itemType] or false
end
return p