Module:Weekly Bosses

From IdleOn MMO Wiki
Revision as of 23:40, 11 December 2024 by BHY4A (talk | contribs) (Undo revision 80277 by BHY4A (talk))
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

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

local Random = require("Module:Random")

local WeeklyBoss = {}

local weeklyBossesShop = {
    {
        {ui = "Galaxy UI", price = 50},
        {ui = "Hardwood UI", price = 15},
        {ui = "Deadwood UI", price = 15},
        {ui = "Corkboard UI", price = 25},
        {ui = "Catacomb UI", price = 40},
        {ui = "Rift UI", price = 35},
        {ui = "Magma UI", price = 40},
        {ui = "Grassy UI", price = 30},
        {ui = "Sandburn UI", price = 25},
        {ui = "Graveyard UI", price = 20},
        {ui = "Goldwood UI", price = 60},
        {ui = "Peachwood UI", price = 20}
    },
    {
        {item = "Pink Headband", display = "Pink Headband", price = 999},
        {item = "Killroy Skulls", display = "Killroy Skull", price = 14},
        {item = "Trophy Starbook", display = "Boss Battle Spillover", price = 25},
        {item = "Death Starbook", display = "Bored To Death", price = 25},
        {item = "The Crow Perch", display = "The Crow Perch", price = 125},
        {item = "Gold Food", display = "Golden Nomwich", price = 12},
        {item = "Statues", display = "Power Statue", price = 12},
        {item = "Silver Pocketwatch", display = "Silver Pocketwatch", price = 2},
        {item = "Gold Pocketwatch", display = "Gold Pocketwatch", price = 30}
    }
}

local weeklyBosses = {
    {bossName = "Eclectic Lazlo", gradient = {"#fffebf", "#c86400"}},
    {bossName = "Decibop Box", gradient = {"#ff744d", "#761728"}},
    {bossName = "Mutalius Cuboid", gradient = {"#dbfdff", "#004dc9"}},
    {bossName = "Jupiteye Major", gradient = {"#ffd985", "#bd1441"}},
    {bossName = "The Nugenator", gradient = {"#db8777", "#764431"}},
    {bossName = "Fat Eggplonk", gradient = {"#ffa4fc", "#8a37d6"}},
    {bossName = "Mollo Gomm", gradient = {"#b7f7ff", "#4f1f97"}},
    {bossName = "Unit T-31", gradient = {"#ccf3ea", "#628691"}},
    {bossName = "SWR Containment", gradient = {"#e8ffc2", "#1ba03e"}}
}

function WeeklyBoss.getBossId(seed)
    local bossIndex = math.floor((seed / 1e3) * #weeklyBosses)
    return math.max(0, math.min(#weeklyBosses - 1, bossIndex))
end

function WeeklyBoss.getShopItems(seed)
    local rng1 = Random:new(math.floor(seed + 36))
    local firstRandom = math.floor(rng1:rand() * #weeklyBossesShop[1])
    firstRandom = math.max(0, math.min(#weeklyBossesShop[1] - 1, firstRandom))

    local rng2 = Random:new(math.floor(seed + 72))
    local secondRandom = math.floor(rng2:rand() * #weeklyBossesShop[1])
    secondRandom = math.max(0, math.min(#weeklyBossesShop[1] - 1, secondRandom))
    local l = 0
    while firstRandom == secondRandom and l < 100 do
        l = l + 1
        rng2 = Random:new(seed + l)
        secondRandom = math.floor(rng2:rand() * #weeklyBossesShop[1])
        secondRandom = math.max(0, math.min(#weeklyBossesShop[1] - 1, secondRandom))
    end

    local rng3 = Random:new(math.floor(seed + 10))
    local thirdRandom = math.floor(rng3:rand() * #weeklyBossesShop[2])
    thirdRandom = math.max(0, math.min(#weeklyBossesShop[2] - 1, thirdRandom))

    local rng4 = Random:new(seed + 20)
    local fourthRandom = math.floor(rng4:rand() * #weeklyBossesShop[2])
    fourthRandom = math.max(0, math.min(#weeklyBossesShop[2] - 1, fourthRandom))
    local k = 0
    while thirdRandom == fourthRandom and k < 710 do
        k = k + 71
        rng4 = Random:new(seed + k)
        fourthRandom = math.floor(rng4:rand() * #weeklyBossesShop[2])
        fourthRandom = math.max(0, math.min(#weeklyBossesShop[2] - 1, fourthRandom))
    end

    return {
        shopItems = {
            weeklyBossesShop[1][firstRandom + 1],
            weeklyBossesShop[1][secondRandom + 1],
            weeklyBossesShop[2][thirdRandom + 1],
            weeklyBossesShop[2][fourthRandom + 1]
        },
        extraSeed = k
    }
end

function WeeklyBoss.getCurrentAndNext(frame)
    local seed = math.floor(os.time() / 604800)
    local results = {}

    for i = 0, 1 do
        local weeklySeed = seed + i
        local rng = Random:new(weeklySeed)
        local randomSeed = math.floor(rng:rand() * 1e3)

        local shopData = WeeklyBoss.getShopItems(randomSeed)
        local bossId = WeeklyBoss.getBossId(randomSeed)

        local boss = weeklyBosses[bossId + 1]
        local bossDate = os.date("%d %B, %Y", weeklySeed * 604800)

        table.insert(
            results,
            {
                boss = boss,
                date = bossDate,
                shopItems = shopData.shopItems
            }
        )
    end

    local current = results[1]
    local nextBoss = results[2]

    local gradientStyle =
        string.format(
        "background: linear-gradient(to bottom, %s, %s); border: 1px solid black; border-radius: 3px;",
        current.boss.gradient[1],
        current.boss.gradient[2]
    )

    local result =
        string.format(
        '<div style="color: #fff; text-shadow: -1px 0 #000, 0 1px #000, 1px 0 #000, 0 -1px #000; margin: var(--pi-margin); width: calc(var(--pi-width) - 20px); padding: 10px; %s">',
        gradientStyle
    )

    result =
        result ..
        string.format(
            '<div style="text-align: center; margin-bottom: 5px"><strong>Weekly Battle</strong><br>[[File:%s Icon.png|link=]] %s<br></div>',
            current.boss.bossName,
            current.boss.bossName
        )

    result = result .. "<div style='font-size: 0.7em; display: flex; flex-wrap: wrap; align-items: center'>"

    result =
        result ..
        string.format(
            "<div style='flex: 0 0 50%%;'><div style='display: flex; align-items: center;'><div style='margin-right: 5px;'>[[File:Main %s.png|32px|link=]]</div><div><b>%s</b><br>%dx [[File:Trophie.png|18px|link=]]</div></div></div>",
            current.shopItems[1].ui,
            current.shopItems[1].ui,
            current.shopItems[1].price
        )

    result =
        result ..
        string.format(
            "<div style='flex: 0 0 50%%;'><div style='display: flex; align-items: center;'><div style='margin-right: 5px;'>[[File:Main %s.png|32px|link=]]</div><div><b>%s</b><br>%dx [[File:Trophie.png|18px|link=]]</div></div></div>",
            current.shopItems[2].ui,
            current.shopItems[2].ui,
            current.shopItems[2].price
        )

    result =
        result ..
        string.format(
            "<div style='flex: 0 0 50%%;'><div style='display: flex; align-items: center;'><div style='margin-right: 5px;'>[[File:%s.png|32px|link=]]</div><div><b>%s</b><br>%dx [[File:Trophie.png|18px|link=]]</div></div></div>",
            current.shopItems[3].display,
            current.shopItems[3].item,
            current.shopItems[3].price
        )

    result =
        result ..
        string.format(
            "<div style='flex: 0 0 50%%;'><div style='display: flex; align-items: center;'><div style='margin-right: 5px;'>[[File:%s.png|32px|link=]]</div><div><b>%s</b><br>%dx [[File:Trophie.png|18px|link=]]</div></div></div>",
            current.shopItems[4].display,
            current.shopItems[4].item,
            current.shopItems[4].price
        )

    result = result .. "</div>"

    if nextBoss then
        result =
            result ..
            string.format(
                '<div style="font-size: 0.7em;"><strong>Next Weekly Boss</strong><br>[[File:%s Icon.png|19px|link=]] %s (%s)</div>',
                nextBoss.boss.bossName,
                nextBoss.boss.bossName,
                nextBoss.date
            )
    end

    return result
end

return WeeklyBoss