Module:CosmeticMachine
From MCC Island Wiki
More actions
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 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
local sign = n < 0 and -1 or 1
return math.floor(n * factor + 0.5) / factor
end
local p = {}
function p.getType(name)
return typeData[name]
end
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