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

Module:CosmeticMachine: Difference between revisions

From MCC Island Wiki
Created page with "local getArgs = require('Module:Arguments').getArgs local getRarity = function(name) return require('Module:CosmeticInfo').getRarity({name=name}) end local machineData = mw.loadData('Module:CosmeticMachine/Data') local typeData = mw.loadData("Module:CosmeticInfo/Type/Data") local function round(n) local frac = math.abs(n) % 1 if frac == 0 then return n end local zeros = tostring(frac):match("%.(0*)") or "" local places = #zeros + 2 local factor = 10 ^ places loc..."
 
No edit summary
Line 2: Line 2:
local getRarity = function(name)
local getRarity = function(name)
return require('Module:CosmeticInfo').getRarity({name=name})
return require('Module:CosmeticInfo').getRarity({name=name})
end
local getType = function(name)
return require('Module:CosmeticInfo').getType({name=name})
end
end


local machineData = mw.loadData('Module:CosmeticMachine/Data')
local machineData = mw.loadData('Module:CosmeticMachine/Data')
local typeData = mw.loadData("Module:CosmeticInfo/Type/Data")


local function round(n)
local function round(n)
Line 18: Line 20:


local p = {}
local p = {}
function p.getType(name)
return typeData[name]
end


function p.getPullChance(frame)
function p.getPullChance(frame)

Revision as of 14:32, 16 July 2025

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

local getArgs = require('Module:Arguments').getArgs
local getRarity = function(name)
	return require('Module:CosmeticInfo').getRarity({name=name})
end
local getType = function(name)
	return require('Module:CosmeticInfo').getType({name=name})
end

local machineData = mw.loadData('Module:CosmeticMachine/Data')

local function round(n)
	local frac = math.abs(n) % 1
	if frac == 0 then return n end
	local zeros = tostring(frac):match("%.(0*)") or ""
	local places = #zeros + 2
	local factor = 10 ^ places
	local sign = n < 0 and -1 or 1
	return math.floor(n * factor + 0.5) / factor
end

local p = {}

function p.getPullChance(frame)
	local args = getArgs(frame)
	local cosmeticName = args.cosmeticName
	local pullType = args.pullType .. " Pull"
	
	local rarity = getRarity(cosmeticName)
	local cType = p.getType(cosmeticName) or "Standard"
	
	local pullData = machineData[pullType]
	if not pullData then return 0 end
	
	local baseRarityChance = (pullData.rarityChances[rarity]) / 100

	local function countEligible(filterFunc)
		local count = 0
		for _, name in ipairs(pullData.cosmetics) do
			if getRarity(name) == rarity and filterFunc(name) then
				count = count + 1
			end
		end
		return count
	end
	
	local chanceShare
	if cType == "Exclusive" then
		local exChance = pullData.exclusiveChance and (pullData.exclusiveChance[rarity] or pullData.exclusiveChance["All"] or 0)
		local exclusiveCount = countEligible(function(name)
			return getRarity(name) == rarity and p.getType(name) == cType
		end)
		if exclusiveCount == 0 then return 0 end
		
		chanceShare = (baseRarityChance * (exChance / 100)) / exclusiveCount
		
	elseif cType == "Arcane" and rarity == "Mythic" then
		local arcChance = pullData.arcaneChance and pullData.arcaneChance["Mythic"] or 0
		local arcaneCount = countEligible(function(name)
			return getRarity(name) == "Mythic" and p.getType(name) == "Arcane"
		end)
		if arcaneCount == 0 then return 0 end
		
		chanceShare = (baseRarityChance * (arcChance / 100)) / arcaneCount
		
	else
		local exclusiveCut = pullData.exclusiveChance and (pullData.exclusiveChance[rarity] or pullData.exclusiveChance["All"] or 0)
		local arcaneCut = (rarity == "Mythic" and pullData.arcaneChance and pullData.arcaneChance["Mythic"]) or 0
		local remainingChance = baseRarityChance * (1 - (exclusiveCut + arcaneCut) / 100)
		
		local standardCount = countEligible(function(name)
			return getRarity(name) == rarity and not p.getType(name)
		end)
		if standardCount == 0 then return 0 end
		
		chanceShare = remainingChance / standardCount
		
	end
	return round(chanceShare * 100) .. "%"
end

return p