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

## Booster Pack API

# Card:open
[[patches]]
[patches.regex]
target = "card.lua"
pattern = '''(?<indent>[\t ]*)if self\.ability\.name:find\('Arcana'\) then \n[\s\S]{12}G\.STATE'''
position = "before"
payload = '''
booster_obj = self.config.center
if booster_obj and SMODS.Centers[booster_obj.key] then
    G.STATE = G.STATES.SMODS_BOOSTER_OPENED
    SMODS.OPENED_BOOSTER = self
end'''
line_prepend = '$indent'

# Card:open
[[patches]]
[patches.regex]
target = "card.lua"
pattern = '''(?<indent>[\t ]*)if self\.ability\.name:find\('Arcana'\) then[\t\n ]*if G\.GAME\.used_vouchers\.v_omen_globe and pseudorandom\('omen_globe'\) > 0\.8 then''' # Possibly try to target something else
position = "at"
payload = '''if booster_obj.create_card and type(booster_obj.create_card) == "function" then 
    local _card_to_spawn = booster_obj:create_card(self, i)
    if type((_card_to_spawn or {}).is) == 'function' and _card_to_spawn:is(Card) then
        card = _card_to_spawn
    else
        card = SMODS.create_card(_card_to_spawn)
    end
elseif self.ability.name:find('Arcana') then
    if G.GAME.used_vouchers.v_omen_globe and pseudorandom('omen_globe') > 0.8 then'''
line_prepend = '$indent'

## Stop cards from boosters getting double emplaced
# Card:open
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "G.pack_cards:emplace(v)"
position = "at"
payload = "--G.pack_cards:emplace(v)"
match_indent = true

# Game:set_globals
[[patches]]
[patches.regex]
target = "globals.lua"
pattern = '''(?<indent>[\t ]*)self\.STATES = \{'''
position = "after"
payload = '''

    SMODS_BOOSTER_OPENED = 999,'''
line_prepend = '$indent'

# Game:update
[[patches]]
[patches.regex]
target = "game.lua"
pattern = '''(?<indent>[\t ]*)if self\.STATE == self\.STATES\.TAROT_PACK then'''
position = "before"
payload = '''
if G.STATE == G.STATES.SMODS_BOOSTER_OPENED then
    SMODS.OPENED_BOOSTER.config.center:update_pack(dt)
end

'''
line_prepend = '$indent'

# G.FUNC.can_skip_booster
# TODO customize whether pack can be skipped
[[patches]]
[patches.regex]
target = "functions/button_callbacks.lua"
pattern = '''(?<indent>[\t ]*)\(G\.STATE == G\.STATES\.PLANET_PACK or G\.STATE == G\.STATES\.STANDARD_PACK'''
position = "at"
payload = '''(G.STATE == G.STATES.SMODS_BOOSTER_OPENED or G.STATE == G.STATES.PLANET_PACK or G.STATE == G.STATES.STANDARD_PACK'''

# CardArea:draw()
[[patches]]
[patches.pattern]
target = "cardarea.lua"
pattern = "(self.config.type == 'deck' and self ~= G.deck) or"
position = "before"
payload = '''
(self.config.type == 'hand' and state == G.STATES.SMODS_BOOSTER_OPENED) or'''
match_indent = true

# G.FUNCS.use_card
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "prev_state == G.STATES.SPECTRAL_PACK or prev_state == G.STATES.STANDARD_PACK or"
position = "after"
payload = '''
prev_state == G.STATES.SMODS_BOOSTER_OPENED or'''
match_indent = true

# CardArea:align_cards()
[[patches]]
[patches.pattern]
target = "cardarea.lua"
pattern = "if self.config.type == 'hand' and (G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK  or G.STATE == G.STATES.PLANET_PACK) then"
position = "at"
payload = "if self.config.type == 'hand' and (G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.PLANET_PACK or G.STATE == G.STATES.SMODS_BOOSTER_OPENED) then"
match_indent = true

# CardArea:align_cards()
[[patches]]
[patches.pattern]
target = "cardarea.lua"
pattern = "if self.config.type == 'hand' and not (G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.PLANET_PACK) then"
position = "at"
payload = "if self.config.type == 'hand' and not (G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.PLANET_PACK or G.STATE == G.STATES.SMODS_BOOSTER_OPENED) then"
match_indent = true

# Card:can_use_consumable()
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "if G.STATE == G.STATES.SELECTING_HAND or G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.PLANET_PACK then"
position = "at"
payload = "if G.STATE == G.STATES.SELECTING_HAND or G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.PLANET_PACK or G.STATE == G.STATES.SMODS_BOOSTER_OPENED then"
match_indent = true

# G.FUNC.use_card()
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "if G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.PLANET_PACK or G.STATE == G.STATES.SPECTRAL_PACK then"
position = "at"
payload = "if G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.PLANET_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.SMODS_BOOSTER_OPENED then"
match_indent = true

# G.FUNC.use_card()
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "(G.STATE == G.STATES.BUFFOON_PACK and G.STATES.BUFFOON_PACK) or"
position = "before"
payload = "(G.STATE == G.STATES.SMODS_BOOSTER_OPENED and G.STATES.SMODS_BOOSTER_OPENED) or"
match_indent = true

# G.FUNC.use_card()
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "if not (G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK) and"
position = "at"
payload = "if not (G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.SMODS_BOOSTER_OPENED) and"
match_indent = true

# Card:use_consumeable()
[[patches]]
[patches.regex]
target = "card.lua"
pattern = '''(?<indent>[\t ]*)align = \(G\.STATE[\s\S]*and -0\.2 or 0},'''
position = "at"
payload = '''
align = (G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.SMODS_BOOSTER_OPENED) and 'tm' or 'cm',
offset = {x = 0, y = (G.STATE == G.STATES.TAROT_PACK or G.STATE == G.STATES.SPECTRAL_PACK or G.STATE == G.STATES.SMODS_BOOSTER_OPENED) and -0.2 or 0},'''
line_prepend = '$indent'

# G.FUNCS.use_card()
[[patches]]
[patches.pattern]
target = "functions/button_callbacks.lua"
pattern = "e.config.ref_table:redeem()"
position = "before"
payload = "if area == G.pack_cards then e.config.ref_table.cost = 0 end"
match_indent = true

## Stopping ease_dollars anim from playing when voucher is free
# Card:redeem()
[[patches]]
[patches.regex]
target = "card.lua"
pattern = '''(?<indent>[\t ]*)ease_dollars\(-self\.cost\)\n[\s\S]{8}inc_career_stat\('c_shop_dollars_spent', self\.cost\)'''
position = "at"
payload = '''
if self.cost ~= 0 then
    ease_dollars(-self.cost)
    inc_career_stat('c_shop_dollars_spent', self.cost)
end'''
line_prepend = '$indent'
