for _, v in pairs({"7granddad", "betmma", "oxy", "peppino"}) do
    SMODS.Atlas {
        px = 71,
        py = 95,
        key = "jane" .. v,
        path = Jane.config.texture_pack .. "/j_jane_" .. v .. ".png",
    }
end

for i = 1, 6 do
    SMODS.Sound({key = 'grand' .. i, path = 'grand_dad' .. i .. '.ogg'})
end

local exotic = Cryptid and "cry_exotic" or 4

local food = {
    "j_gros_michel",
    "j_egg",
    "j_ice_cream",
    "j_cavendish",
    "j_turtle_bean",
    "j_diet_cola",
    "j_popcorn",
    "j_ramen",
    "j_selzer",
    "j_cry_pickle",
    "j_cry_chili_pepper",
    "j_cry_oldcandy",
    "j_cry_caramel",
    "j_cry_foodm",
    "j_cry_cotton_candy",
    "j_cry_wrapped",
    "j_cry_candy_cane",
    "j_cry_candy_buttons",
    "j_cry_jawbreaker",
    "j_cry_mellowcreme",
    "j_cry_brittle",
    "j_jane_peppino",
}

local granddad_palette = {
    HEX("155fd9"),
    HEX("ff8170"),
    HEX("ffffff"),
    HEX("6c0700")
}

local function food_jokers_count()
    if not G.jokers then
        return 0
    end

    local amount = 0

    for _, v in pairs(food) do
        amount = amount + #SMODS.find_card(v)
    end

    return amount
end

local function grand_dad(card)
    Jane.q(function()
        card:juice_up(0.5, 0.5)
        return true
    end)

    local rnd = math.random(6)
    local obj = card.edition or {}

    Jane.play_sound(
        "jane_grand" .. rnd,
        obj.jane_jumbo and (1 / Jane.config.wee_sizemod) or 1,
        0.5
    )

    Jane.card_status_text(
        card,
        rnd == 2 and "Flintstones?!" or rnd == 6 and "Gruhh- Dad!" or "Grand Dad!",
        nil,
        0.05 * card.T.h,
        granddad_palette[math.random(#granddad_palette)],
        0.6,
        0.6,
        nil,
        nil,
        "bm"
    )
end

local function voucher_count()
    if not G.GAME.used_vouchers then
        return 0
    end

    local count = 0

    for _, v in pairs(G.GAME.used_vouchers) do
        if v then
            count = count + 1
        end
    end

    return count
end

SMODS.Joker {
    key = "oxy",
    atlas = "janeoxy",
    loc_txt = {
        name = "Oxy",
        text = {
            "{C:attention}Scored steel{} cards give",
            "{X:mult,C:white}x#1#{} {C:mult}Mult {}& {X:chips,C:white}x#1#{} {C:chips}Chips",
            " ",
            "{C:inactive,s:0.75,E:1}#2#{C:red,s:1.5,E:1}#3#",
        }
    },
    pos = {x = 0, y = 0},
    config = {steel = 1.5},
    sinis = {x = 2, y = 0},
    soul_pos = {x = 1, y = 0},
    cost = 10,
    blueprint_compat = true,
    rarity = Cryptid and 3 or 4,
    loc_vars = function(_, _, center)
        return {vars = {
            center.ability.steel,
            Jane.sinister and "" or "We all cut close...",
            Jane.sinister and "WHAT ARE YOU DOING DOWN THERE?!?" or "",
        }}
    end,
    calculate = function(_, card, context)
        if context.individual and
            context.cardarea == G.play and
            context.other_card.ability.name == "Steel Card" then
            return {
                x_chips = card.ability.steel,
                x_mult = card.ability.steel,
                colour = G.C.PURPLE,
                card = card
            }, true
        end
    end
}

SMODS.Joker {
    key = "7granddad",
    loc_txt = {
        name = "7 GRAND DAD",
        text = {
            "This Joker has a {C:jane_RGB,E:1}strange",
            "{C:jane_RGB,E:1}reaction {}to scored {C:attention}7{}s",
        }
    },
    config = {},
    pos = {x = 0, y = 0},
    soul_pos = {x = 1, y = 0},
    cost = 12,
    atlas = "jane7granddad",
    blueprint_compat = true,
    rarity = Cryptid and exotic or 3,
    loc_vars = function(_, _, center)
        return {vars = {center.ability.shopslots}}
    end,
    add_to_deck = function(_, card, _)
        grand_dad(card)
    end,
    remove_from_deck = function(_, card, _)
        grand_dad(card)
    end,
    calculate = function(_, card, context)
        if context.cardarea == G.play then
            local function scj(c)
                return c.cardarea and c.cardarea == G.play and not c.before and not c.after and not c.repetition
            end

            if context.other_card and context.other_card:get_id() == 7 and scj(context) then
                grand_dad(card)
                local palette = granddad_palette[math.random(#granddad_palette)]
                local rnd = pseudorandom(pseudoseed("granddad"), 1, Cryptid and 7 or 5)

                if rnd == 1 then
                    return {
                        message = "+777",
                        chips = 777,
                        colour = palette,
                        card = card
                    }, true
                elseif rnd == 2 then
                    return {
                        message = "+777 Mult",
                        mult = 777,
                        colour = palette,
                        card = card
                    }, true
                elseif rnd == 3 then
                    return {
                        message = "+$7",
                        dollars = 7,
                        colour = palette,
                        card = card
                    }, true
                elseif rnd == 4 then
                    return {
                        message = "x7",
                        x_chips = 7,
                        colour = palette,
                        card = card
                    }, true
                elseif rnd == 5 then
                    return {
                        message = "x7 Mult",
                        x_mult = 7,
                        colour = palette,
                        card = card
                    }, true
                elseif rnd == 6 then
                    return {
                        message = "^1.77",
                        e_chips = 1.77,
                        colour = palette,
                        card = card
                    }, true
                else
                    return {
                        message = "^1.77 Mult",
                        e_mult = 1.77,
                        colour = palette,
                        card = card
                    }, true
                end
            end
        end
    end
}

local operator = Cryptid and "^" or "x"

SMODS.Joker {
    key = "betmma",
    atlas = "janebetmma",
    loc_txt = {
        name = "Betmma",
        text = {
            "{X:dark_edition,C:chips}+" .. operator .. "#1#{C:chips} Chips{} for every",
            "{C:attention}unique Voucher redeemed",
            "{C:inactive}(Currently {X:dark_edition,C:chips}" .. operator .. "#2#{C:inactive})",
        }
    },
    config = {big_num_scaler = true, extra = {tet = 0.1}},
    pos = {x = 0, y = 0},
    soul_pos = {x = 1, y = 0},
    cost = 50,
    rarity = exotic,
    blueprint_compat = true,
    loc_vars = function(_, _, center)
        return {vars = {center.ability.extra.tet, 1 + (voucher_count() * center.ability.extra.tet)}}
    end,
    calculate = function(_, card, context)
        if not context.joker_main then
            return
        end

        local v = voucher_count()

        if v > 0 then
            local num = 1 + (v * card.ability.extra.tet)

            return {
                card = card,
                colour = G.C.jane_RGB,
                message = operator .. number_format(num),
                [Cryptid and "Echips_mod" or "xchips_mod"] = num,
            }, true
        end
    end
}

SMODS.Joker {
    key = "peppino",
    atlas = "janepeppino",
    loc_txt = {
        name = "Peppino Spaghetti",
        text = {
            "{X:dark_edition,C:red}" .. operator .. "2^x{C:red} Mult{} for every",
            "{C:attention}food or Peppino Joker",
            "in your possession",
            "{C:inactive}(Currently {X:dark_edition,C:red}" .. operator .. "#1#{C:red} Mult{C:inactive})",
        }
    },
    pos = {x = 0, y = 0},
    soul_pos = {x = 1, y = 0},
    cost = 50,
    rarity = exotic,
    blueprint_compat = true,
    loc_vars = function(_, _, _)
        return {vars = {2 ^ food_jokers_count()}}
    end,
    calculate = function(_, _, context)
        local count = food_jokers_count()

        if context.joker_main and count > 0 then
            return {
                colour = G.C.DARK_EDITION,
                message = "^" .. 2 ^ count .. " Mult",
                [Cryptid and "Emult_mod" or "xmult_mod"] = 2 ^ count,
            }, true
        end
    end
}
