Module:Infobox/Item

--Get Required Modules local loadLib = require('Module:LoadLib')

loadLib(_G, {	infobox = 'Infobox',	mRarity = 'RarityTier',	mLink = 'Link',	mOdds = 'Odds',	mInvSlot = 'Inventory slot',	{ 'Bazaar', values={ 		bazaarLastUpdatedIcon='lastUpdatedIcon', 		bazaarData='getProductData',		bazaarPurchaseCalc='calcMaterialBuyPrices',		_bazaarPurchaseCalc='_calcMaterialBuyPrices',		getBazaarPriceChange='_getPriceChange',		getBazaarPriceSpred='_getPriceSpread'	} },	templates='String/Templates',	list='List',	ability='Ability',	{ 'Currency', values={ 'currency' } }, })

mw.html.create = require('Module:Html').create local curTitle = mw.title.getCurrentTitle

--Begin Exports local p = {} local yesIcon, noIcon, unknownIcon = templates.yes(1), templates.no(1), templates.unknown(1)

local function yesnodefault(val, yes, no, def) if tostring(val):sub(1, 1) == "u" then return unknownIcon end local bool = yesno(val); if bool == nil then return def or val elseif bool then return yes else return no	end end

local function addBazaarGroup(id, parent) if id then parent :addGroup{ header = { 'Bazaar', string.wrapTag({ bazaarLastUpdatedIcon, '', }, 'sup') }, layout = "horizontal", ['row-items']=2 } :addData{ label = "Buy", _bazaarPurchaseCalc({ { id, 1 } }, "buy", true) } :addData{ label = "Sell", _bazaarPurchaseCalc({ { id, 1 } }, nil, true) } :addData{ label = "Buy (stack)", _bazaarPurchaseCalc({ { id, 64 } }, "buy", true) } :addData{ label = "Sell (stack)", _bazaarPurchaseCalc({ { id, 64 } }, nil, true) } :addGroup{ ['row-items']=1 } :addData{ label = string.wrapTag("Price Spread", 'center'), string.wrapTag(getBazaarPriceSpred(id, nil, true), 'center') } :done :addData{ getBazaarPriceChange(id, "buy", true), label = { 'Buy Price Change', string.wrapTag(bazaarLastUpdatedIcon, 'sup') } } :addData{ getBazaarPriceChange(id, "sell", true), label = { 'Sell Price Change', string.wrapTag(bazaarLastUpdatedIcon, 'sup') } } :done end end

function p.infoboxItem(frame) local args = getArgs(frame) local pagename = curTitle.text or "Diamond" local title = args.title or pagename local category_to_add = args.category_to_add or "" -- Need to check if reforge stone due to naming conflict with "reforge" and a "reforgeable" alt name local isReforgeStone = args["default_type"] == "Reforge Stone" local sections = {} local idsExistForAllTabs = true for j = 1,16,1 do		local function argJ(name, default) return args[name..j] ~= nil and args[name..j] or default end local sectionExists = j==1 or argJ("tab") if sectionExists then -- section one does have numbers after params; on 2+ do that local i = j==1 and "" or j			local _i = j==1 and "" or "_"..j -- needed for when a param ends in a number naturally -- Support custom syntax if args["default_type"] == "Sack" then if j == 1 then i = "_s" elseif j == 2 then i = "_m" elseif j == 3 then i = "_l" end end local function argI(name, default) return args[name..i] ~= nil and args[name..i] or default end if not argI("id") then idsExistForAllTabs = false end -- table of all params for this section local s = {} -- Top level infobox values s.tab = argJ("tab") or argI("tab") -- purposefully use "j" here since default section does actually use "tab1" s.image = argI("image") or pagename..".png" s.caption = argI("caption") or argI("imagecaption") s.slot_item = argI("slot_item") or argI("slot") -- If a value is passed in, set to value; if no value is passed in set to page name; if the value passed in is a "no" type value, set to nil s.slot_item = yesno(s.slot_item, true) and (s.slot_item or pagename) or nil -- Unless a "false" value is set, show ; if a value that isn't "false" is given, uses that instead. "true" values being passed in break this -- Since slot{} has newlines that messes up formatting here for some reason, remove the newlines s.slot_item = s.slot_item and string.wrapHtml(mInvSlot.slot{ s.slot_item, text=argI("slot_text"), title=argI("slot_title"), link=argI("slot_link"), }:gsub("\n", ""), 'center', { style="width:250px;" }) s.type = argI("type") or args["default_type"] or "Item" s.aka = argI("aka") s.rarity = argI("rarity") and mRarity.link{ argI("rarity"), addcategory = true } s.collection = argI("collection") and mLink.collectionLink{ argI("collection"), showIcon = true } s.source = argI("source") s.reforge_name = (isReforgeStone and argI("reforge")) or argI("reforge_name") s.combat_level_requirement = argI("combat_level_requirement") s.dungeon_level_requirement = argI("dungeon_level_requirement") s.dungeon_floor_clearing_requirement = argI("dungeon_floor_clearing_requirement") s.hotm_requirement = argI("hotm_requirement") s.other_level_requirement = argI("other_level_requirement") s.obtained = argI("obtained") or argI("obtain") or argI("obtaining") s.drop_chance = argI("drop_chance") or argI("odds") if s.drop_chance then s.drop_chance = mOdds.odds{ s.drop_chance, big = true } end s.uses = argI("uses") or argI("usage") s.minion_xp = argI("minion_xp") and "" s.lore = argI("lore") s.item_slots = argI("item_slots") or argI("slots") -- not sure what this is used for actually; first was in "item" infobox, and the later "accessory" -- Sack Stats group -- since all sacks share same items, no reason to pass it in multiple times s.sack_items = argI("sack_items") or args["sack_items"] if s.sack_items then -- If the list of items is to large to easily fit, collapse it				local _, count = string.gsub(s.sack_items, "%*", "") if count > 4 then s.sack_items = ' ' else s.sack_items = '' end end s.sack_capacity = argI("sack_capacity") -- Block Details group s.location = argI("location") and "" s.tool = argI("tool") and "" s.breaking_power_required = argI("breaking_power_required") s.skill_xp_given = argI("skill_xp_given") and "" s.experience_given = argI("experience_given") s.normal_drop = argI("normal_drop") s.silk_touch_drop = argI("silk_touch_drop") s.smelting_touch_drop = argI("smelting_touch_drop") -- Stats group s.stats = argI("stats") s.ability_damage = argI("ability_damage") s.health = argI("health") s.defense = argI("defense") s.damage = argI("damage") s.strength = argI("strength") s.crit_chance = argI("crit_chance") s.crit_damage = argI("crit_damage") s.attack_speed = argI("attack_speed") s.intelligence = argI("intelligence") s.speed = argI("speed") s.true_defense = argI("true_defense") s.magic_find = argI("magic_find") s.fishing_speed = argI("fishing_speed") s.sea_creature_chance = argI("sea_creature_chance") s.ferocity = argI("ferocity") s.mining_speed = argI("mining_speed") s.breaking_power = argI("breaking_power") s.mining_fortune = argI("mining_fortune") s.farming_fortune = argI("farming_fortune") s.foraging_fortune = argI("foraging_fortune") -- Special Effects s.effects = argI("effects") or argI("effect") or argI("special_effect") or argI("additional_effects") s.duration = argI("duration") s.speed_boost = argI("speed_boost") -- used by minion fuel s.full_set_bonus = argI("full_set_bonus") s.piece_bonus = argI("piece_bonus") s.full_set_bonus2 = argI("full_set_bonus2") s.piece_bonus2 = argI("piece_bonus2") -- Abilities (up to 4) for k = 1, 4, 1 do				local counter = k > 1 and k or "" local function arg(name) return args[name..counter.._i] end s["ability_name"..counter] = arg("ability_name") or arg("ability") or arg("ia_name") or arg("abilityname") s["ability_desc"..counter] = arg("ability_desc") or arg("item_ability") or arg("ia_desc") or arg("abilitydesc") s["ability_activation"..counter] = arg("ability_activation") or arg("ia_activation") if s["ability_name"..counter] or s["ability_desc"..counter] then local abnmdc = {} -- ability_name_desc abnmdc[#abnmdc+1] = "'''" if s["ability_name"..counter] then abnmdc[#abnmdc+1] = ability.itemAbility{ s["ability_name"..counter] } else abnmdc[#abnmdc+1] = colorText("Gray", "") end if s["ability_activation"..counter] then abnmdc[#abnmdc+1] = " "..colorText("Yellow", s["ability_activation"..counter]:upper) end abnmdc[#abnmdc+1] = "'''" abnmdc[#abnmdc+1] = " " abnmdc[#abnmdc+1] = s["ability_desc"..counter] or "description missing" -- Combine final product s['ability_name_desc'..counter] = table.concat(abnmdc) end s["soulflow_cost"..counter] = arg("soulflow cost") or arg("soulflow.cost") or arg("soulflow") or arg("sfcost") or arg("ia_soulflow") s["mana_cost"..counter] = arg("mana_cost") or arg("mana.cost") or arg("mana") or arg("manacost") or arg("ia_mana_cost") s["cooldown"..counter] = arg("cooldown") or arg("ia_cooldown") s["int_scaling"..counter] = arg("int_scaling") end -- Function group s["function"]= argI("function") -- Material Tiers group s.prev_material = argI("prev_material") and list.imageList{ argI("prev_material") } or (argI("next_material") and "None (lowest tier material)") s.next_material = argI("next_material") and list.imageList{ argI("next_material") } or (argI("prev_material") and "None (top tier material)") -- Upgrades group s.upgrades_from = argI("upgrades_from") and itemDisplay(argI("upgrades_from")) or (argI("upgrades_to") and "None (lowest tier item)") s.upgrades_to = argI("upgrades_to") and itemDisplay(argI("upgrades_to")) or (argI("upgrades_from") and "None (top tier item)") -- Reforge Requirements s.req_item_rarity = argI("req_item_rarity") s.apply_cost = argI("apply_cost") s.req_skill_level = argI("req_skill_level") and "" -- Properties group s.upgradeable = yesnodefault(argI("upgradeable"), yesIcon, noIcon) s.enchantable = yesnodefault(argI("enchant") or argI("enchantable"), yesIcon, noIcon) s.reforgeable = yesnodefault((not isReforgeStone and argI("reforge")) or argI("reforgeable"), yesIcon, noIcon) s.salable = yesnodefault(argI("salable") or argI("sellable") or true, yesIcon, noIcon) s.tradeable = yesnodefault(argI("tradeable") or argI("trade") or true, yesIcon, noIcon) s.auctionable = yesnodefault(argI("auctionable") or true, yesIcon, noIcon) s.color = argI("color") and "" -- Shop s.merchant = argI("merchant") and list.npcList{ argI("merchant"), noerr=true } s.daily_limit = argI("daily_limit") s.buy = argI("buy") and currency{ argI("buy") } s.sell = argI("sell") and currency{ argI("sell") } -- Bazaar s.bazaar = argI("bazaar") -- Materials s.raw_materials = argI("raw_materials") and list.resourceList{ image=1, argI("raw_materials") } s.material_cost = argI("material_cost") and coins{ argI("material_cost") } s.bazaar_not_including = argI("bazaar_not_including") s.mat_cost_bazaar = argI("mat_cost_bazaar") and bazaarPurchaseCalc{ argI("mat_cost_bazaar") or argI("raw_materials"), not_including = argI("bazaar_not_including") }:gsub("\n", "") s.raw_materials_upgr = argI("raw_materials_upgr") and list.resourceList{ image=1, argI("raw_materials_upgr") } s.material_cost_upgr = argI("material_cost_upgr") and coins{ argI("material_cost_upgr") } s.bazaar_not_including_upgr = argI("bazaar_not_including_upgr") s.mat_cost_bazaar_upgr = argI("mat_cost_bazaar_upgr") and bazaarPurchaseCalc{ argI("mat_cost_bazaar_upgr") or argI("raw_materials_upgr"), not_including = argI("bazaar_not_including_upgr") }:gsub("\n", "") -- Trade s.trade_requirement = argI("trade_requirement") or argI("trade.requirement") if s.trade_requirement then s.trade_requirement = link._collectionLink(s.trade_requirement, nil, true) end s.trade_from = argI("trade_from") or argI("trade.from") s.trade_to = argI("trade_to") or argI("trade.to") -- Item Metadata s.id = argI("id") or argI("item_id") if s.id then -- Always show ID in all caps s.id = string.wrapTag(s.id:upper, 'code') -- If array syntax, make a list s.id = s.id:gsub(" ", "") -- lazy trim for array; ids never naturally have spaces s.id = table.concat(mw.text.split(s.id, ","), " ") end s.head_id = argI("head_id") s.head_id = s.head_id and string.wrapTag(s.head_id, 'code') s.head_texture = argI("head_texture") or argI("head_tex") s.head_texture = s.head_texture and string.wrapTag(s.head_texture, 'code') s.nbt = argI("nbt") and argI("nbt"):gsub("(   +)", " %1") -- Since newlines are being deleted, can't be used; and since exscape br tags, need to make own fake pre tag s.nbt = s.nbt and table.concat{ "",				s.nbt, " ",			}:gsub("} ", " } ") -- Push section data into array sections[#sections+1] = s		end end

-- Make infobox local ibox = infobox.create ibox:addTitle{ title } local panel = ibox:addPanel for i,sdata in ipairs(sections) do		local section = panel:addSection{ label = sdata.tab } section :addImage{ sdata.image, caption = { sdata.caption }, source="image"..i } :addData{ sdata.slot_item } :addData{ sdata.type, label = "Type" } :addData{ sdata.aka, label = "Also known as" } :addData{ sdata.rarity, label = "Rarity" } :addData{ sdata.collection, label = string.makeLink("Collections", "Collection") } :addData{ sdata.combat_level_requirement, label = "Combat Level Requirement" } :addData{ sdata.dungeon_level_requirement, label = "Dungeon Level Requirement" } :addData{ sdata.dungeon_floor_clearing_requirement, label = "Requires Dungeon Floor Cleared" } :addData{ sdata.hotm_requirement, label = "Heart of the Mountain Level Requirement" } :addData{ sdata.other_level_requirement, label = "Skill Level Requirement" } :addData{ sdata.reforge_name, label = "Reforge" } :addData{ sdata.source, label = "Source" } :addData{ sdata.obtained, label = "Obtained via" } :addData{ sdata.drop_chance, label = "Drop Chance" } :addData{ sdata.uses, label = "Uses" } :addData{ sdata.minion_xp, label = string.makeTitle('Minion XP', 'The amount of xp a player receives when taking this material from a minion inventory.') } :addData{ sdata.lore, label = "Lore" } :addData{ sdata.item_slots, label = "Item Slots" } :addGroup{ header = "Sack Stats" } :addData{ sdata.sack_capacity, label = "Max Capacity" } :addData{ sdata.sack_items, label = "Items" } :done :addGroup{ header = "Block Details" } :addData{ sdata.location, label = "Location" } :addData{ sdata.tool, label = string.makeLink("Tool") } :addData{ sdata.breaking_power_required, label = " Required" } :addData{ sdata.skill_xp_given, label = "Skill XP Given" } :addData{ sdata.experience_given, label = "Experience Given" } :addGroup{ header = "Block Drops", layout = "horizontal", ['row-items']=3 } :addData{ sdata.normal_drop, label = "Normal drop" } :addData{ sdata.silk_touch_drop, label = "Silk Touch drop" } :addData{ sdata.smelting_touch_drop, label = "Smelting Touch Drop" } :done :done :addGroup{ header = "Function" } :addData{ sdata["function"] } :done :addGroup{ header = "Stats", name = "infobox-stats-list" } :addData{ sdata.stats } :addData{ sdata.ability_damage, label = makeStat("Ability Damage") } :addData{ sdata.health, label = makeStat("Health") } :addData{ sdata.defense, label = makeStat("Defense") } :addData{ sdata.damage, label = makeStat("Damage") } :addData{ sdata.strength, label = makeStat("Strength") } :addData{ sdata.crit_chance, label = makeStat("Crit Chance") } :addData{ sdata.crit_damage, label = makeStat("Crit Damage") } :addData{ sdata.attack_speed, label = makeStat("Attack Speed") } :addData{ sdata.intelligence, label = makeStat("Intelligence") } :addData{ sdata.speed, label = makeStat("Speed") } :addData{ sdata.true_defense, label = makeStat("true defense") } :addData{ sdata.magic_find, label = makeStat("mf") } :addData{ sdata.fishing_speed, label = makeStat("Fishing Speed") } :addData{ sdata.sea_creature_chance, label = makeStat("scc", nil, true) } :addData{ sdata.ferocity, label = makeStat("Ferocity") } :addData{ sdata.mining_speed, label = makeStat("Mining Speed") } :addData{ sdata.breaking_power, label = makeStat("Breaking Power", nil, true) } :addData{ sdata.mining_fortune, label = makeStat("Mining Fortune", nil, true) } :addData{ sdata.farming_fortune, label = makeStat("Farming Fortune", nil, true) } :addData{ sdata.foraging_fortune, label = makeStat("Foraging Fortune", nil, true) } :done :addGroup{ header = "Special Effects" } :addData{ sdata.effects } :addData{ sdata.duration, label = "Duration" } :addData{ sdata.speed_boost, label = "Speed Boost" } :addData{ sdata.full_set_bonus, label = ability.fullSetBonus } :addData{ sdata.piece_bonus, label = ability.pieceBonus } :addData{ sdata.full_set_bonus2, label = ability.fullSetBonus } :addData{ sdata.piece_bonus2, label = ability.pieceBonus } :done local ability_places = { "", "Second", "Third", "Fourth" } for k = 1, 4, 1 do			local counter = k > 1 and k or "" section:addGroup{ header = ability_places[k].." Ability", name="infobox-stats-list" } :addData{ sdata["ability_name_desc"..counter] } :addData{ sdata["soulflow_cost"..counter], label = makeStat("Soulflow Cost") } :addData{ sdata["mana_cost"..counter], label = makeStat("Manacost") } :addData{ sdata["cooldown"..counter], label = "Cooldown" } :addData{ sdata["int_scaling"..counter], label = { "%s Scaling", makeStat('int', nil, true) } } :done end section:addGroup{ header = "Material Tiers", layout = "horizontal" } :addData{ sdata.prev_material, label = "← Previous" } :addData{ sdata.next_material, label = "Next →" } :done :addGroup{ header = "Upgrades", layout = "horizontal" } :addData{ sdata.upgrades_from, label = "← Previous" } :addData{ sdata.upgrades_to, label = "Next →" } :done :addGroup{ header = "Reforge Requirements", collapse="open" } :addData{ sdata.req_item_rarity, label = "Req. Item Rarity" } :addData{ sdata.apply_cost, label = "Apply Cost" } :addData{ sdata.req_skill_level, label = "Req. Skill Level" } :done :addGroup{ header = "Properties", layout = "horizontal", ['row-items']=2 } :addData{ sdata.upgradeable, label = "Upgradeable" } :addData{ sdata.enchantable, label = "Enchantable" } :addData{ sdata.reforgeable, label = "Reforgeable" } :addData{ sdata.salable, label = "Salable" } :addData{ sdata.tradeable, label = "Tradeable" } :addData{ sdata.auctionable, label = "Auctionable" } :done :addGroup :addData{ sdata.color, label = "Color" } :done :addGroup{ header = "Shop", layout = "horizontal", ['row-items']=2 } :addGroup{ ['row-items']=1 } :addData{ sdata.merchant, label = "Merchant"..(sdata.merchant and sdata.merchant:find("%s*%*%s*") and "s" or "") } :done :addData{ sdata.daily_limit, label = string.makeTitle("Daily Limit", "A limit on how much items of this type a player can buy in one day.") } :addData{ sdata.buy, label = "Buy" } :addData{ sdata.sell, label = "Sell" } :done addBazaarGroup(sdata.bazaar, section) section:addGroup{ header = "Materials" } :addData{ sdata.raw_materials, label=string.makeTitle("Raw Materials", "All materials in their most basic form needed to obtain the item.") } :addData{ sdata.material_cost, label=string.makeTitle("Material cost", "Cost to buy all necessary materials from merchants.") } :addData{ sdata.mat_cost_bazaar, label=string.makeTitle("Bazaar Material cost", "Cost to buy all necessary materials from the Bazaar.") } :addData{ sdata.raw_materials_upgr, label=string.makeTitle("Raw Materials to upgrade", "All materials in their most basic form needed to obtain the item.") } :addData{ sdata.material_cost_upgr, label=string.makeTitle("Material cost to upgrade", "Cost to buy all necessary materials from merchants.") } :addData{ sdata.mat_cost_bazaar_upgr, label=string.makeTitle("Bazaar Material cost to upgrade", "Cost to buy all necessary materials from the Bazaar.") } :done :addGroup{ header = "Trade", layout = "horizontal" } :addData{ sdata.trade_requirement, label = "Requires" } :addData{ sdata.trade_from, label = "From" } :addData{ sdata.trade_to, label = "To" } :done :addGroup{ header = "Item Metadata", ['row-items']=1, collapse="closed" } :addData{ sdata.id, label = "Item ID" } :addData{ sdata.head_id, label = "Head ID" } :addData{ sdata.head_texture, label = "Head Texture" } :addData{ sdata.nbt, label = "NBT Data" } :done end return table.concat{ ibox:preprocess, curTitle.namespace == 0 and category_to_add or "", curTitle.namespace == 0 and not idsExistForAllTabs and "" or "", } end

--Finish Module/Exports return p