--- STEAMODDED HEADER
--- MOD_NAME: Silksong News
--- MOD_ID: silksong_news
--- MOD_AUTHOR: [Skyball]
--- MOD_DESCRIPTION: New Jokers and other stuff related to Silksong
--- DEPENDENCIES: [Steamodded>=1.0.0~ALPHA-0812d]

-- 2025-03-28
-- local DAYS_SINCE_NEWS = 463

local DAYS_SINCE_NEWS = 1542 - 25

SMODS.Atlas {
    key = "silksong_watch",
    path = "silksong_watch.png",
    px = 71,
    py = 95
}

SMODS.Atlas {
    object_type = "Atlas",
    atlas_table = "ANIMATION_ATLAS",
    key = "silksong_bosses",
    path = "silksong_bosses.png",
	px = 34,
	py = 34,
	frames = 21,
}

-- text = {
--    "Adds {C:mult}+1{} Mult for every day with {C:mult}NO News{},",
--    "resets when {C:attention}there are YES news{C:inactive}.",
--    "{C:inactive}(Currently {C:mult}+" .. DAYS_SINCE_NEWS .. "{}{C:inactive} Mult){}",
-- }

SMODS.Joker {
    key = 'silksong_no_news',
    loc_txt = {
        name = 'NO News',
        text = {
            "Adds {C:mult}+1{} Mult for every day",
            "with {C:mult}NO News{} on DSN.",
            "{C:inactive}(Currently {C:mult}+" .. DAYS_SINCE_NEWS .. "{}{C:inactive} Mult){}",
        }
    },
    config = { extra = {} },
    rarity = 2,
    atlas = 'silksong_watch',
    pos = { x = 0, y = 0 },
    cost = math.floor(DAYS_SINCE_NEWS / 10),
    calculate = function(self, card, context)
        if context.joker_main then
            return {
                mult_mod = DAYS_SINCE_NEWS,
                message = "+" .. DAYS_SINCE_NEWS .. " Mult",
                colour = G.C.MULT
            }
        end
    end
}

SMODS.Joker {
    key = 'crumb_trail',
    loc_txt = {
        name = 'Crumb Trail',
        text = {
            "This Joker gains {C:chips}+1{} Chips",
            "per discarded card.",
            "{C:inactive}(Currently {C:chips}+#1#{C:inactive} Chips){}"
        }
    },
    config = {
        extra = {
            chips = 0
        }
    },
    rarity = 2,
    atlas = 'silksong_watch',
    pos = { x = 1, y = 0 },
    cost = 5,
    loc_vars = function(self, info_queue, card)
        return { vars = { card.ability.extra.chips } }
    end,
    calculate = function(self, card, context)
        -- Initialize extra if not exists (safety check)
        if not card.ability.extra then
            card.ability.extra = { chips = 0 }
        end

        -- When a card is discarded
        if context.discard and not context.other_card.debuff then
            card.ability.extra.chips = card.ability.extra.chips + 1
            return {
                message = "+1 Chips",
                colour = G.C.CHIPS,
                card = card
            }
        end

        -- Apply the chip bonus during scoring
        if context.joker_main and card.ability.extra.chips > 0 then
            return {
                chip_mod = card.ability.extra.chips,
                message = localize { type = 'variable', key = 'a_chips', vars = { card.ability.extra.chips } },
                colour = G.C.CHIPS
            }
        end
    end
}

SMODS.Joker {
    key = 'belief',
    loc_txt = {
        name = 'Belief',
        text = {
            "{C:green}#1# in #2#{} chance to",
            "give {X:mult,C:white} X#3# {} Mult when scored.",
            "Failed attempts increase odds and",
            "resets to {C:green}1 in #2#{} after success."
        }
    },
    config = {
        extra = {
            current_prob = 1,
            max_prob = 10,
            base_xmult = 4
        }
    },
    rarity = 3,
    atlas = 'silksong_watch',
    pos = { x = 2, y = 0 },
    cost = 8,
    loc_vars = function(self, info_queue, card)
        return { vars = { card.ability.extra.current_prob, card.ability.extra.max_prob, card.ability.extra.base_xmult } }
    end,
    calculate = function(self, card, context)
        if context.joker_main then
            -- Check if we trigger the bonus
            if math.random() < (card.ability.extra.current_prob / card.ability.extra.max_prob) then
                -- Success - apply bonus and reset probability
                card.ability.extra.current_prob = 1
                return {
                    Xmult_mod = card.ability.extra.base_xmult,
                    message = localize { type = 'variable', key = 'a_xmult', vars = { card.ability.extra.base_xmult } },
                    colour = G.C.MULT
                }
            else
                -- Failure - increase probability for next time
                card.ability.extra.current_prob = math.min(card.ability.extra.current_prob + 1, card.ability.extra.max_prob)
                return {
                    message = card.ability.extra.current_prob.."/"..card.ability.extra.max_prob,
                    colour = G.C.GREEN,
                    card = card
                }
            end
        end
    end
}


SMODS.Blind {
    object_type = "Blind",
    key = "shade_lord",
    name = "P5 AB Hitless",
    loc_txt = {
        name = "P5 AB Hitless",
        text = {
            "{C:red}Extremely high blind{}",
            "Defeat to get Silksong News"
        }
    },
    atlas = "silksong_bosses",
    pos = { x = 0, y = 0 },
    boss = {
        min = 1,
        max = 10
    },
    mult = 920340,
    dollars = 10,
    boss_colour = HEX("4a4a4a"),
    discovered = true,
    unlocked = true,
    alert = true,
    apply = function(self, game_obj)
    end
}
