Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Module:CosmeticInfo/Paragraph

From MCC Island Wiki

Documentation for this module may be created at Module:CosmeticInfo/Paragraph/doc

local getArgs = require('Module:Arguments').getArgs
local info = require('Module:CosmeticInfo')
local crates = require('Module:CosmeticCrates')
local machine = require('Module:CosmeticMachine')

local p = {}

local function articleFor(word)
	if word:sub(1,1):lower():match("[aeiou]") then
		return "an"
	end
	return "a"
end

local function expand(frame, title, ...)
	local args = {...}
	local templateArgs = {}
	
	for i, arg in ipairs(args) do
		if type(arg) == "string" and arg:match("^[^=]+=.+$") then
			local key, value = arg:match("^([^=]+)=(.+)$")
			templateArgs[key] = value
		else
			templateArgs[i] = tostring(arg)
		end
	end
	
	if frame.expandTemplate then
		return frame:expandTemplate{ title = title, args = templateArgs }
	else
		local argString = {}
		for i, arg in ipairs(args) do
			table.insert(argString, tostring(arg))
		end
		return string.format("{{%s|%s}}", title, table.concat(argString, "|"))
	end
end

function p.make(frame)
	local args = getArgs(frame)
	local name = args.name
	
	local rarity = info.getRarity{ name = name }
	local cType = info.getType{ name = name}
	local category = info.getCategory{ name = name }
	local collection = info.getCollection{ name = name }
	local added_date = args.added_date or ""
	local added_in = args.added_in or ""
	local unlock_method = args.unlock_method
	local stylePerk = args.style_perk or ""
	local image = args.image or name
	
	local out = {}
	table.insert(out, string.format("'''%s''' is %s %s", name, articleFor(rarity), expand(frame, "Rarity", rarity, "Text")))

	if cType and cType ~= "Standard" then
		table.insert(out, " and " .. expand(frame, "CosmeticType", cType))
	end

	table.insert(out, string.format(" %s [[cosmetic]], found within the %s, that was introduced ", 
		expand(frame, "CosmeticCategory", category),
		expand(frame, "Collection", collection)
	))

	if added_date and added_date ~= "" then
		table.insert(out, "on " .. added_date)
	else
		table.insert(out, "in [[Patch " .. added_in .. "]]")
	end

	table.insert(out, ".")
	
	if info.isInCrateCollection{ name = name } == true then
		local typeToUse = cType
		if cType == "Standard" then
			typeToUse = ""
		end
		local blueprintIcon = string.format('[[File:%s%s Cosmetic Blueprint.png|20px|link=]]', rarity, (typeToUse ~= "" and " " or "") .. typeToUse)
		table.insert(out, string.format(" Its %s blueprint form can be obtained in a number of ways:\n", blueprintIcon))
		table.insert(out, '*' .. crates.makeSentence(frame) .. "\n")
		if cType == "Standard" then
			local vendorPurchaseText = "Purchasing from [[File:Head-Frank.png|20px|link=Frank]] [[Frank]] for "
			local crate = crates.getCrate{ name = name }
			if rarity == "Epic" then
				vendorPurchaseText = vendorPurchaseText .. "'''8x'''"
			elseif rarity == "Legendary" then
				vendorPurchaseText = vendorPurchaseText .. "'''18x'''"
			elseif rarity == "Mythic" then
				vendorPurchaseText = vendorPurchaseText .. "'''2x'''"
			end
			vendorPurchaseText = vendorPurchaseText .. string.format(" [[File:%s.png|20px|link=%s]] [[%s]]s\n", crate, crate, crate)
			table.insert(out, '* ' .. vendorPurchaseText)
		elseif cType == "Exclusive" then
			local vendorPurchaseText = "Purchasing from [[File:Head-Big Cheese.png|20px|link=Big Cheese]] [[Big Cheese]] for "
			local crate = crates.getCrate{ name = name }
			if rarity == "Legendary" then
				vendorPurchaseText = vendorPurchaseText .. "'''5x'''"
			elseif rarity == "Mythic" then
				vendorPurchaseText = vendorPurchaseText .. "'''15x'''"
			end
			vendorPurchaseText = vendorPurchaseText .. string.format(" [[File:%s.png|20px|link=%s]] [[%s]]s\n", crate, crate, crate)
			table.insert(out, '* ' .. vendorPurchaseText .. '\n')
		end
		table.insert(out, machine.makeSentences{ name = name, mode = "list" })
	elseif info.isArcaneGateCosmetic{ name = name} == true then
		local typeToUse = cType
		if cType == "Standard" then
			typeToUse = ""
		end
		local blueprintIcon = string.format('[[File:%s%s Cosmetic Blueprint.png|20px|link=]]', rarity, " " .. typeToUse)
		table.insert(out, string.format(" Its %s blueprint form can be obtained in a number of ways:\n", blueprintIcon))
		table.insert(out, "* '''8.3%''' chance from the [[File:Icon-Arcane Gate.png|20px|link=Arcane Gate]] [[Arcane Gate]]\n")
		table.insert(out, "* Purchasing from [[File:Head-Suspicious Stu.png|20px|link=Suspicious Stu]] [[Suspicious Stu]] for '''2x''' [[File:Arcane Gate Key.png|20px|link=Arcane Gate Key]] [[Arcane Gate Key]]s\n")
		table.insert(out, machine.makeSentences{ name = name, mode = "list" })
	else
		if args.unlock_method then
			table.insert(out, " " .. unlock_method)
		end
	end
	table.insert(out, '\n\n')
	
	if info.isColorable{ name = name } == true then
		local trophies = tonumber(info.getTrophiesAwarded{ name = name }) or 0
		local bonus = info.isBonusTrophies{ name = name }
		local trophyType = bonus and "Bonus" or "Style"
		table.insert(out, string.format(
			"It is %s, meaning players can apply [[Chroma Pack|chroma packs]] to it, allowing them to change its colour.",
			expand(frame, "Colorable")
		))
		table.insert(out, '\n\n')
		table.insert(out, string.format("It can reward the player with up to %s: %s for owning it and an extra %s if all 4 [[Chroma Pack|chroma packs]] are applied to it.",
			expand(frame, string.format("%s Trophy", trophyType), trophies+10, "text=yes"),
			expand(frame, string.format("%s Trophy", trophyType), trophies),
			expand(frame, string.format("%s Trophy", trophyType), 10)
		))
	else
		local trophies = tonumber(info.getTrophiesAwarded{ name = name }) or 0
		if trophies > 0 then
			local trophyType = info.isBonusTrophies{ name = name } and "Bonus" or "Style"
			table.insert(out, string.format("Owning it rewards the player with a total of %s.", expand(frame, string.format("%s Trophy", trophyType), trophies, "text=yes")))
			if info.isArcaneGateCosmetic{ name = name} == true then
				local perkIncrease = stylePerk:match("^([%w]+)") == "Expanded" and "+1" or "5%"
				table.insert(out, string.format("<br /> It also grants %s [[File:Perk-%s.png|24px]] [[%s]] while in the player's wardrobe.", perkIncrease, stylePerk, stylePerk))
			end
		end
	end
	
	if info.getReputationAmount{ name = name} > 0 then
		table.insert(out, '\n\n')
		table.insert(out, string.format(
			"Its token form can be [[Scavenging|scavenged]] in the [[Scavenger's Hideout]] for %s.<br /> The first %s donations also grant %s [[Royal Reputation]].",
			expand(frame, "CosmeticScavengeRewards", string.format("name=%s", name), "inline=true", "show_text=true"),
			info.getDonationLimit{ name = name },
			expand(frame, "Royal Reputation", info.getReputationAmount{ name = name})
		))
		table.insert(out, '\n\n')
		table.insert(out, '==== Blueprint Recipe ====\n')
		table.insert(out, string.format(
			"'''%s''''s blueprint form must be crafted at the [[Blueprint Assembler]] into a cosmetic token before use.",
			name
		))
		table.insert(out, string.format(
			'\nAlternatively, it can be scavenged for %s.\n',
			expand(frame, "CosmeticScavengeRewards", "Blueprint", string.format("name=%s", name), "inline=true", "show_text=true")
		))
		local blueprintTableHeader = string.format('[[File:%s.png|25px|link=]] %s Token', image, name)
		local crafting_materials = "" or args.crafting_materials -- the empty string is a placeholder until something like Module:BlueprintRecipes is made
		table.insert(out, expand(frame, "Blueprint",
			string.format("item=%s", blueprintTableHeader), string.format("required_materials=%s", crafting_materials), string.format("rarity=%s", rarity)
		))
	end

	return table.concat(out)
end

return p