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 function yesnodefault(val, yes, no, def) local bool = yesno(val); if bool == nil then return def or val elseif bool then return yes else return no	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 "" local yesIcon, noIcon = templates.yes(1), templates.no(1) 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 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") -- 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.wrapTag(mInvSlot.slot{ s.slot_item }:gsub("\n", ""), 'center') s.type = argI("type") or "Item" 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.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.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" s.sack_items = argI("sack_items") and ' ' s.sack_capacity = argI("sack_capacity") -- Block Data 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.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") if s["ability_desc"..counter] and s["ability_desc"..counter] then s['ability_name_desc'..counter] = table.concat{ "", colorText("Gold", s["ability_name"..counter]), "", " - ", s["ability_desc"..counter] } elseif s["ability_name"..counter] then s['ability_name_desc'..counter] = table.concat{ "", colorText("Gold", s["ability_name"..counter]), "", " - description missing" } elseif s["ability_desc"..counter] then s['ability_name_desc'..counter] = table.concat{ "", colorText(""), " - ", s["ability_desc"..counter] } end s["ability_activation"..counter] = arg("ability_activation") or arg("ia_activation") s["mana_cost"..counter] = arg("mana_cost") or arg("mana.cost") 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)") -- Properties group s.upgradeable = yesnodefault(argI("upgradeable"), yesIcon, noIcon) s.enchant = yesnodefault(argI("enchant") or argI("enchantable"), yesIcon, noIcon) s.reforge = yesnodefault(argI("reforge") or argI("reforgeable"), yesIcon, noIcon) s.salable = yesnodefault(argI("salable") or argI("sellable") 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") } 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") -- 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 } } :addData{ sdata.slot_item } :addData{ sdata.type, label ="Type" } :addData{ sdata.id, label ="Item ID" } :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 ="Other Skill Level Requirement" } :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" } :addData{ sdata.sack_items, label ="Items" } :addData{ sdata.sack_capacity, label ="Max Capacity" } :addGroup{ header ="Block Data" } :addData{ sdata.location, label ="Location" } :addData{ sdata.tool, label =string.makeLink("Tool") } :addData{ sdata.skill_xp_given, label ="Skill XP Given" } :addData{ sdata.experience_given, label ="Experience Given" } :addGroup{ 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" } :addData{ sdata.stats } :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", nil, true) } :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") } :addData{ sdata.mining_fortune, label =makeStat("Mining Fortune") } :addData{ sdata.farming_fortune, label =makeStat("Farming Fortune") } :addData{ sdata.foraging_fortune, label =makeStat("Foraging Fortune") } :done :addGroup{ header ="Special Effects", layout ="horizontal" } :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" } :addData{ sdata["ability_name_desc"..counter], label =ability.itemAbility } :addData{ sdata["ability_activation"..counter], label ="Activation Type" } :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 ="Properties", layout ="horizontal", ['row-items']=2 } :addData{ sdata.upgradeable, label ="Upgradeable" } :addData{ sdata.enchant, label ="Enchantable" } :addData{ sdata.reforge, label ="Reforgeable" } :addData{ sdata.salable, label ="Salable" } :addData{ sdata.auctionable, label ="Auctionable" } :done :addGroup :addData{ sdata.color, label ="Color" } :done :addGroup{ header ="Shop", layout ="horizontal", ['row-items']=2 } :addData{ sdata.merchant, label ="Merchant"..(sdata.merchant and sdata.merchant:find("%s*%*%s*") and "s" or "") } :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 end mw.log(ibox) return table.concat{ ibox:preprocess, curTitle.namespace == 0 and category_to_add or "", curTitle.namespace == 0 and not idsExistForAllTabs and "" or "", } end

function addBazaarGroup(id, parent) if id then parent :addGroup{ header =string.wrapTag(bazaarLastUpdatedIcon..'', 'sup'), layout ="horizontal", ['row-items']=2 } :addData{ label ="Buy", bazaarData{ id, "buy", coin =1 } } :addData{ label ="Sell", bazaarData{ id, "buy", coin =1 } } :addData{ label ="Buy (stack)", _bazaarPurchaseCalc({ { id, 64 } }, "buy") } :addData{ label ="Sell (stack)", _bazaarPurchaseCalc({ { id, 64 } }) } :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 = { 'Buy Price Change', string.wrapTag(bazaarLastUpdatedIcon, 'sup') } } :done end end

--Finish Module/Exports return p