[manifest]
version = "1.0.0"
dump_lua = true
priority = -1

# initiate variables
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "rental_rate = 3,"
position = "after"
payload = '''
cry_voucher_perishable_rounds = 8,
cry_voucher_rental_rate = 2,
cry_consumeable_rental_rate = 2,
cry_voucher_banana_odds = 12,
cry_consumeable_banana_odds = 4,
cry_pinned_consumeables = 0,
cry_shop_joker_price_modifier = 1,
'''
match_indent = true

# check for pinned
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "G.GAME.current_round.voucher = SMODS.get_next_vouchers()"
position = "at"
payload = '''
if G.GAME.current_round.cry_voucher_stickers.pinned == false then
	G.GAME.current_round.voucher = SMODS.get_next_vouchers()
end
'''
match_indent = true

# remove stickers if voucher is redeemed
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "self:apply_to_run()"
position = "before"
payload = '''
G.GAME.current_round.cry_voucher_edition = nil
G.GAME.current_round.cry_voucher_stickers = {eternal = false, perishable = false, rental = false, pinned = false, banana = false}
'''
match_indent = true

# consumeable sticker checking
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "local used_tarot = copier or self"
position = "after"
payload = '''
if self.ability.rental then
	G.E_MANAGER:add_event(Event({
		trigger = 'immediate',
		blocking = false,
		blockable = false,
		func = (function()
			ease_dollars(-G.GAME.cry_consumeable_rental_rate)
		return true
	end)}))
end
local gone = false
if self.ability.banana then
    if not self.ability.extinct then
        if SMODS.pseudorandom_probability(self, "oops_it_banana", 1, G.GAME.cry_consumeable_banana_odds, "Banana Sticker") then
	    local gone = true
            self.ability.extinct = true
            G.E_MANAGER:add_event(Event({
                func = function()
                    play_sound('tarot1')
                    self.T.r = -0.2
                    self:juice_up(0.3, 0.4)
                    self.states.drag.is = true
                    self.children.center.pinch.x = true
                    G.E_MANAGER:add_event(Event({trigger = 'after', delay = 0.3, blockable = false,
                        func = function()
                                if self.area then self.area:remove_card(self) end
                                self:remove()
                                self = nil
                            return true; end}))
                    return true
                end
            }))
            card_eval_status_text(self, 'jokers', nil, nil, nil, {message = localize('k_extinct_ex'), delay = 0.1})
            return true
        end
    end
end
if gone == false then
'''
match_indent = true

# end the wrap
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "function Card:can_use_consumeable(any_state, skip_check)"
position = "before"
payload = '''
end
'''
match_indent = true

# check for pinned
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "if G.STATE ~= G.STATES.HAND_PLAYED and G.STATE ~= G.STATES.DRAW_TO_HAND and G.STATE ~= G.STATES.PLAY_TAROT or any_state then"
position = "before"
payload = '''
if G.GAME.cry_pinned_consumeables > 0 and not self.pinned then
	return false
end
'''
match_indent = true

# pinned consumeable remove, counterpart is in cryptid's create_card
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "if self.joker_added_to_deck_but_debuffed then"
position = "before"
payload = '''
if self.ability.consumeable and self.pinned and (G.GAME.cry_pinned_consumeables > 0) then
	G.GAME.cry_pinned_consumeables = G.GAME.cry_pinned_consumeables - 1
end
'''
match_indent = true

# rental jank
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "if self.ability.rental then self.cost = 1 end"
position = "at"
payload = '''
if self.ability.rental and (not (self.ability.set == "Planet" and #find_joker('Astronomer') > 0) and self.ability.set ~= "Booster") then self.cost = 1 end
'''
match_indent = true

# apply stickers to packs
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "card.ability.booster_pos = i"
position = "before"
payload = '''
local stickers = Cryptid.next_voucher_stickers(true)	-- don't mind the name
for k, v in pairs(stickers) do
	card.ability[k] = v
end
'''
match_indent = true
