[manifest]
version = "1.0.0"
dump_lua = true
priority = 0

[[patches]]
[patches.pattern]
target = "functions/ui_definitions.lua"
pattern = '''
local discard_button = {n=G.UIT.C, config={id = 'discard_button',align = "tm", padding = 0.3, r = 0.1, minw = 2.5, minh = button_height, hover = true, colour = G.C.RED, button = "discard_cards_from_highlighted", one_press = true, shadow = true, func = 'can_discard'}, nodes={
    {n=G.UIT.R, config={align = "cm", padding = 0}, nodes={
    {n=G.UIT.T, config={text = localize('b_discard'), scale = text_scale, colour = G.C.UI.TEXT_LIGHT, focus_args = {button = 'y', orientation = 'bm'}, func = 'set_button_pip'}}
    }}
}}
'''
position = "at"
payload = '''
local discard_button = {n=G.UIT.C, config={id = 'discard_button',align = "tm", padding = 0.3, r = 0.1, minw = 2.5, minh = button_height, hover = true, colour = G.C.RED, button = "discard_cards_from_highlighted", shadow = true, func = 'can_discard'}, nodes={
    {n=G.UIT.R, config={align = "cm", padding = 0}, nodes={
    {n=G.UIT.T, config={text = localize('b_discard'), scale = text_scale, colour = G.C.UI.TEXT_LIGHT, focus_args = {button = 'y', orientation = 'bm'}, func = 'set_button_pip'}}
    }}
}}
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = '''
func = (function()  update_hand_text({delay = 0, immediate = true}, {mult = 0, chips = 0, chip_total = G.GAME.blind.cry_cap_score and G.GAME.blind:cry_cap_score(math.floor(hand_chips*mult)) or math.floor(hand_chips*mult), level = '', handname = ''});play_sound('button', 0.9, 0.6);return true end)
'''
position = "at"
payload = '''
func = (function()

if G.GAME.hands["cry_None"].visible then
update_hand_text({delay = 0, immediate = true}, {mult = 0, chips = 0, chip_total = G.GAME.blind.cry_cap_score and G.GAME.blind:cry_cap_score(math.floor(hand_chips*mult)) or math.floor(hand_chips*mult), level = '', handname = ''});
    G.reset_to_none = true

else
    update_hand_text({delay = 0, immediate = true}, {mult = 0, chips = 0, chip_total = G.GAME.blind.cry_cap_score and G.GAME.blind:cry_cap_score(math.floor(hand_chips*mult)) or math.floor(hand_chips*mult), level = '', handname = ''});
end
play_sound('button', 0.9, 0.6);return true end)
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''
level_up_hand(context.blueprint_card or self, text, nil, 1)
update_hand_text({sound = 'button', volume = 0.7, pitch = 1.1, delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
return nil, true
'''
position = "at"
payload = '''
                level_up_hand(context.blueprint_card or self, text, nil, 1)
                if G.GAME.hands["cry_None"].visible then
                    Cryptid.reset_to_none()

                else
                    update_hand_text({delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
                end
                return nil, true
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''
level_up_hand(used_tarot, self.ability.consumeable.hand_type)
update_hand_text({sound = 'button', volume = 0.7, pitch = 1.1, delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
'''
position = "at"
payload = '''
level_up_hand(used_tarot, self.ability.consumeable.hand_type)
update_hand_text({sound = 'button', volume = 0.7, pitch = 1.1, delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
if G.GAME.current_round.current_hand.handname ~= "" then
    G.E_MANAGER:add_event(Event({
        trigger = 'after',
        func = function()
            G.hand:parse_highlighted()
            return true
        end
    }))
end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''
for k, v in pairs(G.GAME.hands) do
    level_up_hand(self, k, true)
end
update_hand_text({sound = 'button', volume = 0.7, pitch = 1.1, delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
'''
position = "at"
payload = '''
        for k, v in pairs(G.GAME.hands) do
            level_up_hand(self, k, true)
        end
        if G.GAME.hands["cry_None"].visible then
            Cryptid.reset_to_none()

        else
            update_hand_text({delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
        end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''
if self.ability.consumeable.max_highlighted then
    update_hand_text({immediate = true, nopulse = true, delay = 0}, {mult = 0, chips = 0, level = '', handname = ''})
end
'''
position = "at"
payload = '''
if self.ability.consumeable.max_highlighted then
    if G.GAME.hands["cry_None"].visible then
        Cryptid.reset_to_none()
                
    else
        update_hand_text({delay = 0}, {mult = 0, chips = 0, handname = '', level = ''})
    end
end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = '''
G.E_MANAGER:add_event(Event({
    trigger = 'immediate',
    func = (function() G.GAME.current_round.current_hand.handname = '';return true end)
    }))
'''
position = "at"
payload = '''
G.E_MANAGER:add_event(Event({
    trigger = 'immediate',
    func = (function()
        if G.GAME.current_round.current_hand.handname ~= localize('cry_None', "poker_hands") or not G.GAME.hands["cry_None"].visible then
            G.GAME.current_round.current_hand.handname = ''
        end
        return true end)
    }))
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = '''
    G.E_MANAGER:add_event(Event({
      trigger = 'immediate',
      	func = (function()
            if G.GAME.current_round.current_hand.handname ~= localize('cry_None', "poker_hands") or not G.GAME.hands["cry_None"].visible then
                G.GAME.current_round.current_hand.handname = ''
            end
            return true end)
      }))
      delay(0.3)
'''
position = "at"
payload = '''
    G.E_MANAGER:add_event(Event({
      trigger = 'immediate',
      	func = (function()
            if text ~= "cry_None" or not G.GAME.hands["cry_None"].visible then
                G.GAME.current_round.current_hand.handname = ''
            end
            return true end)
      }))
      delay(0.3)
delay(0.3)
if not (SMODS.Mods["Talisman"] or {}).can_load then
    evaluate_play_after(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
end
return text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta
end
function evaluate_play_after(text, disp_text, poker_hands, scoring_hand, non_loc_disp_text, percent, percent_delta)
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = '''
G.GAME.hands[text].played = G.GAME.hands[text].played + 1
'''
position = "at"
payload = '''
local hand = (G.GAME.hands[text])
if not hand then text = "cry_None"; disp_text = localize("cry_None", "poker_hands") end
hand = G.GAME.hands[text]
if text == "cry_None" then G.GAME.hands["cry_None"].visible = true end
hand.played = hand.played + 1
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = '''
G.GAME.hands[hand].level = math.max(0, G.GAME.hands[hand].level + amount)
G.GAME.hands[hand].mult = math.max(G.GAME.hands[hand].mult + G.GAME.hands[hand].l_mult*amount, 1)
G.GAME.hands[hand].chips = math.max(G.GAME.hands[hand].chips + G.GAME.hands[hand].l_chips*amount, 1)
'''
position = "at"
payload = '''
G.GAME.hands[hand].level = math.max(0, G.GAME.hands[hand].level + amount)
G.GAME.hands[hand].mult = G.GAME.hands[hand].mult + G.GAME.hands[hand].l_mult*amount
G.GAME.hands[hand].chips = G.GAME.hands[hand].chips + G.GAME.hands[hand].l_chips*amount
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "game.lua"
pattern = '''
if #G.hand.cards < 1 and #G.deck.cards < 1 and #G.play.cards < 1 then
    end_round()
end
'''
position = "at"
payload = '''
if #G.hand.cards < 1 and #G.deck.cards < 1 and #G.play.cards < 1 and not G.PROFILES[G.SETTINGS.profile].cry_none then
    end_round()
end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "game.lua"
pattern = '''
if #G.hand.cards < 1 and #G.deck.cards < 1 then
    end_round()
else
    save_run()
    G.CONTROLLER:recall_cardarea_focus('hand')
end
'''
position = "at"
payload = '''
if #G.hand.cards < 1 and #G.deck.cards < 1 and not G.PROFILES[G.SETTINGS.profile].cry_none then
    end_round()
else
    save_run()
    G.CONTROLLER:recall_cardarea_focus('hand')
end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = '''
G.hand.config.card_limit <= 0 and #G.hand.cards == 0 then
'''
position = "at"
payload = '''
G.hand.config.card_limit <= 0 and #G.hand.cards == 0 and not G.PROFILES[G.SETTINGS.profile].cry_none then
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "card.lua"
pattern = '''
local text,disp_text = G.FUNCS.get_poker_hand_info(G.hand.highlighted)
'''
position = "after"
payload = '''
if not text or text == "NULL" then 
    G.GAME.hands["cry_None"].visible = true
    text = "cry_None" 
end
'''
match_indent = true

[[patches]]
[patches.pattern]
target = "game.lua"
pattern = '''
            if (not G.hand.cards[1]) and G.deck.cards[1] then 
                G.STATE = G.STATES.DRAW_TO_HAND
                G.STATE_COMPLETE = false
            else
'''
position = "at"
payload = '''
            if (not G.hand.cards[1]) and G.deck.cards[1] and G.hand.config.card_limit > 0 then 
                G.STATE = G.STATES.DRAW_TO_HAND
                G.STATE_COMPLETE = false
            else
'''
match_indent = true

# Fix a crash with Cerlulean bell if there are no cards in hand 1/2
[[patches]]
[patches.pattern]
target = "blind.lua"
pattern = '''
forced_card.ability.forced_selection = true
'''
position = "before"
payload = '''
if forced_card then
'''
match_indent = true

# Fix a crash with Cerlulean bell if there are no cards in hand 2/2
[[patches]]
[patches.pattern]
target = "blind.lua"
pattern = '''
G.hand:add_to_highlighted(forced_card)
'''
position = "after"
payload = '''
end
'''
match_indent = true
