Module:CosmeticMachine: Difference between revisions
From MCC Island Wiki
More actions
No edit summary |
No edit summary |
||
Line 27: | Line 27: | ||
local rarity = getRarity(cosmeticName) | local rarity = getRarity(cosmeticName) | ||
local cType = | local cType = getType(cosmeticName) or "Standard" | ||
local pullData = machineData[pullType] | local pullData = machineData[pullType] | ||
Line 48: | Line 48: | ||
local exChance = pullData.exclusiveChance and (pullData.exclusiveChance[rarity] or pullData.exclusiveChance["All"] or 0) | local exChance = pullData.exclusiveChance and (pullData.exclusiveChance[rarity] or pullData.exclusiveChance["All"] or 0) | ||
local exclusiveCount = countEligible(function(name) | local exclusiveCount = countEligible(function(name) | ||
return getRarity(name) == rarity and | return getRarity(name) == rarity and getType(name) == cType | ||
end) | end) | ||
if exclusiveCount == 0 then return 0 end | if exclusiveCount == 0 then return 0 end | ||
Line 57: | Line 57: | ||
local arcChance = pullData.arcaneChance and pullData.arcaneChance["Mythic"] or 0 | local arcChance = pullData.arcaneChance and pullData.arcaneChance["Mythic"] or 0 | ||
local arcaneCount = countEligible(function(name) | local arcaneCount = countEligible(function(name) | ||
return getRarity(name) == "Mythic" and | return getRarity(name) == "Mythic" and getType(name) == "Arcane" | ||
end) | end) | ||
if arcaneCount == 0 then return 0 end | if arcaneCount == 0 then return 0 end | ||
Line 69: | Line 69: | ||
local standardCount = countEligible(function(name) | local standardCount = countEligible(function(name) | ||
return getRarity(name) == rarity and not | return getRarity(name) == rarity and not getType(name) | ||
end) | end) | ||
if standardCount == 0 then return 0 end | if standardCount == 0 then return 0 end | ||
Line 77: | Line 77: | ||
end | end | ||
return round(chanceShare * 100) .. "%" | return round(chanceShare * 100) .. "%" | ||
end | |||
function p.displayPullCosmetics(frame) | |||
local args = getArgs(frame) | |||
local pullType = args.pullType | |||
local pullData = machineData[pullType .. " Pull"] | |||
if not pullData then return 'No data found for pull type: ' .. pullType end | |||
local out = {'<div class="tradeable-display">'} | |||
local count = 0 | |||
for _, name in ipairs(pullData["cosmetics"]) do | |||
local chance = p.getPullChance({cosmeticName = name, pullType = pullType}) | |||
local filename = name .. '.png' | |||
local cell = string.format( | |||
'<div><center><div class="afix" style="width: 100px">[[File:%s|link=%s]]</div></center><div style="word-wrap:break-word; text-align:center"><small>[[%s]]</small><br />Pull Chance: <b>%s</b></div></div>', | |||
filename, name, name, chance) | |||
table.insert(out, cell) | |||
count = count + 1 | |||
end | |||
table.insert(out, '</div>') | |||
return table.concat(out, '\n') | |||
end | end | ||
return p | return p |
Revision as of 08:48, 17 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 = 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 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 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 getType(name)
end)
if standardCount == 0 then return 0 end
chanceShare = remainingChance / standardCount
end
return round(chanceShare * 100) .. "%"
end
function p.displayPullCosmetics(frame)
local args = getArgs(frame)
local pullType = args.pullType
local pullData = machineData[pullType .. " Pull"]
if not pullData then return 'No data found for pull type: ' .. pullType end
local out = {'<div class="tradeable-display">'}
local count = 0
for _, name in ipairs(pullData["cosmetics"]) do
local chance = p.getPullChance({cosmeticName = name, pullType = pullType})
local filename = name .. '.png'
local cell = string.format(
'<div><center><div class="afix" style="width: 100px">[[File:%s|link=%s]]</div></center><div style="word-wrap:break-word; text-align:center"><small>[[%s]]</small><br />Pull Chance: <b>%s</b></div></div>',
filename, name, name, chance)
table.insert(out, cell)
count = count + 1
end
table.insert(out, '</div>')
return table.concat(out, '\n')
end
return p