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',		getBazaarPriceSpread='_getPriceSpread'	} },	templates='String/Templates',	list='List',	ability='Ability',	{ 'Currency', values={ 'currency' } }, })

-- https://test.com 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(getBazaarPriceSpread(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] 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] or default end if not argI("id") then idsExistForAllTabs = false end -- table of all params for this section local s = {} -- Top level infobox values --0			s.tab = argJ("tab") or argI("tab") -- purposefully use "j" here since default section does actually use "tab1" --1			s.image = argI("image") or pagename..".png" --2			s.caption = argI("caption") or argI("imagecaption") --3			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("", 				'center') --4			s.type = argI("type") or args["default_type"] or "Item" --5			s.aka = argI("aka") --6			s.rarity = argI("rarity") and mRarity.link{ argI("rarity"), addcategory = true } --7			s.collection = argI("collection") and mLink.collectionLink{ argI("collection"), showIcon = true } --8			s.combat_level_requirement = argI("combat_level_requirement") --9			s.dungeon_level_requirement = argI("dungeon_level_requirement") --10			s.dungeon_floor_clearing_requirement = argI("dungeon_floor_clearing_requirement") --11			s.hotm_requirement = argI("hotm_requirement") --12			s.other_level_requirement = argI("other_level_requirement") --13			s.reforge_name = (isReforgeStone and argI("reforge")) or argI("reforge_name") --14			s.source = argI("source") --15			s.obtained = argI("obtained") or argI("obtain") or argI("obtaining") --16			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 --17			s.uses = argI("uses") or argI("usage") --18			s.minion_xp = argI("minion_xp") and "" --19			s.lore = argI("lore") -- Sack Stats group -- since all sacks share same items, no reason to pass it in multiple times --A0 s.sack_capacity = argI("sack_capacity") --A1 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 -- Block Details group --B0 s.location = argI("location") and "" --B1 s.tool = argI("tool") and "" --B2 s.breaking_power_required = argI("breaking_power_required") --B3 s.skill_xp_given = argI("skill_xp_given") and "" --B4 -- Block Drops s.experience_given = argI("experience_given") --B5 s.normal_drop = argI("normal_drop") --B6 s.silk_touch_drop = argI("silk_touch_drop") --B7 s.smelting_touch_drop = argI("smelting_touch_drop") -- Function group --C0 s["function"]= argI("function") -- Stats group --D0 s.stats = argI("stats") --D1 s.ability_damage = argI("ability_damage") --D2 s.health = argI("health") --D3 s.defense = argI("defense") --D4 s.damage = argI("damage") --D5 s.strength = argI("strength") --D6 s.crit_chance = argI("crit_chance") --D7 s.crit_damage = argI("crit_damage") --D8 s.attack_speed = argI("attack_speed") --D9 s.intelligence = argI("intelligence") --D10 s.speed = argI("speed") --D11 s.true_defense = argI("true_defense") --D12 s.magic_find = argI("magic_find") --D13 s.fishing_speed = argI("fishing_speed") --D14 s.sea_creature_chance = argI("sea_creature_chance") --D15 s.ferocity = argI("ferocity") --D16 s.mining_speed = argI("mining_speed") --D17 s.breaking_power = argI("breaking_power") --D18 s.mining_fortune = argI("mining_fortune") --D19 s.farming_fortune = argI("farming_fortune") --D20 s.foraging_fortune = argI("foraging_fortune") -- Special Effects --E0 s.effects = argI("effects") or argI("effect") or argI("special_effect") or argI("additional_effects") --E1 s.duration = argI("duration") --E2 s.speed_boost = argI("speed_boost") -- used by minion fuel --E3 s.full_set_bonus = argI("full_set_bonus") --E4 s.piece_bonus = argI("piece_bonus") --E5 s.full_set_bonus2 = argI("full_set_bonus2") --E6 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 --F0 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.ability{ 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 --F1 s["soulflow_cost"..counter] = arg("soulflow cost") or arg("soulflow.cost") or arg("soulflow") or arg("sfcost") or arg("ia_soulflow") --F2 s["mana_cost"..counter] = arg("mana_cost") or arg("mana.cost") or arg("mana") or arg("manacost") or arg("ia_mana_cost") --F3 s["cooldown"..counter] = arg("cooldown") or arg("ia_cooldown") --F4 s["int_scaling"..counter] = arg("int_scaling") end -- Material Tiers group --G0 s.prev_material = argI("prev_material") and list.imageList{ argI("prev_material") } or (argI("next_material") and "None (lowest tier material)") --G1 s.next_material = argI("next_material") and list.imageList{ argI("next_material") } or (argI("prev_material") and "None (top tier material)") -- Upgrades group --H0 s.upgrades_from = argI("upgrades_from") and itemDisplay(argI("upgrades_from")) or (argI("upgrades_to") and "None (lowest tier item)") --H1 s.upgrades_to = argI("upgrades_to") and itemDisplay(argI("upgrades_to")) or (argI("upgrades_from") and "None (top tier item)") -- Tiers group --I0 s.lower_tier = argI("lower_tier") and itemDisplay(argI("lower_tier")) or (argI("higher_tier") and "None (lowest tier item)") --I1 s.higher_tier = argI("higher_tier") and itemDisplay(argI("higher_tier")) or (argI("lower_tier") and "None (top tier item)") -- Gemstone Upgrades --R0 s.gemstone_upgrades = argI("gemstone_upgrades") and list.imageList{ argI("gemstone_upgrades"), noErr=true } -- Reforge Requirements --J0 s.req_item_rarity = argI("req_item_rarity") --J1 s.apply_cost = argI("apply_cost") --J2 s.req_skill_level = argI("req_skill_level") and "" -- Properties group --K0 s.upgradeable = yesnodefault(argI("upgradeable"), yesIcon, noIcon) --K1 s.enchantable = yesnodefault(argI("enchant") or argI("enchantable"), yesIcon, noIcon) --K2 s.reforgeable = yesnodefault((not isReforgeStone and argI("reforge")) or argI("reforgeable"), yesIcon, noIcon) --K3 s.salable = yesnodefault(argI("salable") or argI("sellable") or true, yesIcon, noIcon) --K4 s.tradeable = yesnodefault(argI("tradeable") or argI("trade") or true, yesIcon, noIcon) --K5 s.auctionable = yesnodefault(argI("auctionable") or true, yesIcon, noIcon) -- Color Group --L0 s.color = argI("color") and "" -- Shop --M0 s.merchant = argI("merchant") and list.npcList{ argI("merchant"), noErr=true } --M1 s.daily_limit = argI("daily_limit") --M2 s.buy = argI("buy") and currency{ argI("buy") } --M3 s.sell = argI("sell") and currency{ argI("sell") } -- Bazaar --N0 s.bazaar = argI("bazaar") -- Materials --O0 s.raw_materials = argI("raw_materials") and list.resourceList{ image=1, argI("raw_materials") } --O1 s.material_cost = argI("material_cost") and coins{ argI("material_cost") } --O2 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", "") --O3 s.raw_materials_upgr = argI("raw_materials_upgr") and list.resourceList{ image=1, argI("raw_materials_upgr") } --O4 s.material_cost_upgr = argI("material_cost_upgr") and coins{ argI("material_cost_upgr") } --O5 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 --P0 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 --P1 s.trade_from = argI("trade_from") or argI("trade.from") --P2 s.trade_to = argI("trade_to") or argI("trade.to") -- Item Metadata --Q0 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 --Q1 s.head_id = argI("head_id") s.head_id = s.head_id and string.wrapTag(s.head_id, 'code') --Q5 s.head_texture = argI("head_texture") or argI("head_tex") s.head_texture = s.head_texture and string.wrapTag(s.head_texture, 'code') --Q6 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 string.wrapHtml(s.nbt, 'div', {				style = {					['background-color'] = 'rgba(0,0,0,0.35)',					border = '1px solid #9b8d8e',					overflow = 'auto',					['word-wrap'] = normal,					['white-space'] = pre,				}			}):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 = --0panel:addSection{ label = sdata.tab } section --1|2:addImage{ sdata.image, caption = { sdata.caption }, source="image"..i } --3 :addData{ sdata.slot_item } --4 :addData{ sdata.type, label = "Type" } --5 :addData{ sdata.aka, label = "Also known as" } --6 :addData{ sdata.rarity, label = "Rarity" } --7 :addData{ sdata.collection, label = string.makeLink("Collections", "Collection") } --8 :addData{ sdata.combat_level_requirement, label = "Combat Level Requirement" } --9 :addData{ sdata.dungeon_level_requirement, label = "Dungeon Level Requirement" } --10 :addData{ sdata.dungeon_floor_clearing_requirement, label = "Requires Dungeon Floor Cleared" } --11 :addData{ sdata.hotm_requirement, label = "Heart of the Mountain Level Requirement" } --12 :addData{ sdata.other_level_requirement, label = "Skill Level Requirement" } --13 :addData{ sdata.reforge_name, label = "Reforge" } --14 :addData{ sdata.source, label = "Source" } --15 :addData{ sdata.obtained, label = "Obtained via" } --16 :addData{ sdata.drop_chance, label = "Drop Chance" } --17 :addData{ sdata.uses, label = "Uses" } --18 :addData{ sdata.minion_xp, label = string.makeTitle('Minion XP', 'The amount of xp a player receives when taking this material from a minion inventory.') } --19 :addData{ sdata.lore, label = "Lore" } :addGroup{ header = "Sack Stats" } --A0 :addData{ sdata.sack_capacity, label = "Max Capacity" } --A1 :addData{ sdata.sack_items, label = "Items" } :done :addGroup{ header = "Block Details" } --B0 :addData{ sdata.location, label = "Location" } --B1 :addData{ sdata.tool, label = string.makeLink("Tool") } --B2 :addData{ sdata.breaking_power_required, label = " Required" } --B3 :addData{ sdata.skill_xp_given, label = "Skill XP Given" } --B4 :addData{ sdata.experience_given, label = "Experience Given" } :addGroup{ header = "Block Drops", layout = "horizontal", ['row-items']=3 } --B5 :addData{ sdata.normal_drop, label = "Normal drop" } --B6 :addData{ sdata.silk_touch_drop, label = "Silk Touch drop" } --B7 :addData{ sdata.smelting_touch_drop, label = "Smelting Touch Drop" } :done :done :addGroup{ header = "Function" } --C0 :addData{ sdata["function"] } :done :addGroup{ header = "Stats", name = "infobox-stats-list" } --D0 :addData{ sdata.stats } --D1 :addData{ sdata.ability_damage, label = makeStat("Ability Damage") } --D2 :addData{ sdata.health, label = makeStat("Health") } --D3 :addData{ sdata.defense, label = makeStat("Defense") } --D4 :addData{ sdata.damage, label = makeStat("Damage") } --D5 :addData{ sdata.strength, label = makeStat("Strength") } --D6 :addData{ sdata.crit_chance, label = makeStat("Crit Chance") } --D7 :addData{ sdata.crit_damage, label = makeStat("Crit Damage") } --D8 :addData{ sdata.attack_speed, label = makeStat("Attack Speed") } --D9 :addData{ sdata.intelligence, label = makeStat("Intelligence") } --D10:addData{ sdata.speed, label = makeStat("Speed") } --D11:addData{ sdata.true_defense, label = makeStat("true defense") } --D12:addData{ sdata.magic_find, label = makeStat("mf") } --D13:addData{ sdata.fishing_speed, label = makeStat("Fishing Speed") } --D14:addData{ sdata.sea_creature_chance, label = makeStat("scc", nil, true) } --D15:addData{ sdata.ferocity, label = makeStat("Ferocity") } --D16:addData{ sdata.mining_speed, label = makeStat("Mining Speed") } --D17:addData{ sdata.breaking_power, label = makeStat("Breaking Power", nil, true) } --D18:addData{ sdata.mining_fortune, label = makeStat("Mining Fortune", nil, true) } --D19:addData{ sdata.farming_fortune, label = makeStat("Farming Fortune", nil, true) } --D20:addData{ sdata.foraging_fortune, label = makeStat("Foraging Fortune", nil, true) } :done :addGroup{ header = "Special Effects" } --E0 :addData{ sdata.effects } --E1 :addData{ sdata.duration, label = "Duration" } --E2 :addData{ sdata.speed_boost, label = "Speed Boost" } --E3 :addData{ sdata.full_set_bonus, label = ability.fullSetBonus } --E4 :addData{ sdata.piece_bonus, label = ability.pieceBonus } --E5 :addData{ sdata.full_set_bonus2, label = ability.fullSetBonus } --E6 :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" } --F0 :addData{ sdata["ability_name_desc"..counter] } --F1 :addData{ sdata["soulflow_cost"..counter], label = makeStat("Soulflow Cost") } --F2 :addData{ sdata["mana_cost"..counter], label = makeStat("Manacost") } --F3 :addData{ sdata["cooldown"..counter], label = "Cooldown" } --F4 :addData{ sdata["int_scaling"..counter], label = { "%s Scaling", makeStat('int', nil, true) } } :done end section:addGroup{ header = "Material Tiers", layout = "horizontal" } --G0 :addData{ sdata.prev_material, label = "← Previous" } --G1 :addData{ sdata.next_material, label = "Next →" } :done :addGroup{ header = "Upgrades", layout = "horizontal" } --H0 :addData{ sdata.upgrades_from, label = "← Previous" } --H1 :addData{ sdata.upgrades_to, label = "Next →" } :done :addGroup{ header = "Tiers", layout = "horizontal" } --I0 :addData{ sdata.lower_tier, label = "← Previous" } --I1 :addData{ sdata.higher_tier, label = "Next →" } :done :addGroup{ header = "Gemstone Upgrades", layout = "horizontal" } --R0 :addData{ sdata.gemstone_upgrades } :done :addGroup{ header = "Reforge Requirements", collapse="open" } --J0 :addData{ sdata.req_item_rarity, label = "Req. Item Rarity" } --J1 :addData{ sdata.apply_cost, label = "Apply Cost" } --J2 :addData{ sdata.req_skill_level, label = "Req. Skill Level" } :done :addGroup{ header = "Properties", layout = "horizontal", ['row-items']=2 } --K0 :addData{ sdata.upgradeable, label = "Upgradeable" } --K1 :addData{ sdata.enchantable, label = "Enchantable" } --K2 :addData{ sdata.reforgeable, label = "Reforgeable" } --K3 :addData{ sdata.salable, label = "Salable" } --K4 :addData{ sdata.tradeable, label = "Tradeable" } --K5 :addData{ sdata.auctionable, label = "Auctionable" } :done :addGroup --L0 :addData{ sdata.color, label = "Color" } :done :addGroup{ header = "Shop", layout = "horizontal", ['row-items']=2 } :addGroup{ ['row-items']=1 } --M0 :addData{ sdata.merchant, label = "Merchant"..(sdata.merchant and sdata.merchant:find("%s*%*%s*") and "s" or "") } :done --M1 :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.") } --M2 :addData{ sdata.buy, label = "Buy" } --M3 :addData{ sdata.sell, label = "Sell" } :done addBazaarGroup(--N0 sdata.bazaar, section) section:addGroup{ header = "Materials" } --O0 :addData{ sdata.raw_materials, label=string.makeTitle("Raw Materials", "All materials in their most basic form needed to obtain the item.") } --O1 :addData{ sdata.material_cost, label=string.makeTitle("Material cost", "Cost to buy all necessary materials from merchants.") } --O2 :addData{ sdata.mat_cost_bazaar, label=string.makeTitle("Bazaar Material cost", "Cost to buy all necessary materials from the Bazaar.") } --O3 :addData{ sdata.raw_materials_upgr, label=string.makeTitle("Raw Materials to upgrade", "All materials in their most basic form needed to obtain the item.") } --O4 :addData{ sdata.material_cost_upgr, label=string.makeTitle("Material cost to upgrade", "Cost to buy all necessary materials from merchants.") } --O5 :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" } --P0 :addData{ sdata.trade_requirement, label = "Requires" } --P1 :addData{ sdata.trade_from, label = "From" } --P2 :addData{ sdata.trade_to, label = "To" } :done :addGroup{ header = "Item Metadata", ['row-items']=1, collapse="closed" } --Q0 :addData{ sdata.id, label = "Item ID" } --Q1 :addData{ sdata.head_id, label = "Head ID" } --Q5 :addData{ sdata.head_texture, label = "Head Texture" } --Q6 :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