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

### Per-mod functions

# end_round()
[[patches]]
[patches.regex]
target = 'functions/state_events.lua'
pattern = '''(?<indent>[\t ]*)reset_castle_card\(\)'''
line_prepend = '$indent'
position = 'after'
payload = '''

for _, mod in ipairs(SMODS.mod_list) do
	if mod.reset_game_globals and type(mod.reset_game_globals) == 'function' then
		mod.reset_game_globals(false)
	end
end'''

# Game:start_run()
[[patches]]
[patches.regex]
target = 'game.lua'
pattern = '''(?<indent>[\t ]*)reset_castle_card\(\)'''
line_prepend = '$indent'
position = 'after'
payload = '''

for _, mod in ipairs(SMODS.mod_list) do
	if mod.reset_game_globals and type(mod.reset_game_globals) == 'function' then
		mod.reset_game_globals(true)
	end
end'''

# Card:set_debuff()
[[patches]]
[patches.pattern]
target = 'card.lua'
pattern = "function Card:set_debuff(should_debuff)"
position = 'after'
match_indent = true
payload = '''
	for _, mod in ipairs(SMODS.mod_list) do
		if mod.set_debuff and type(mod.set_debuff) == 'function' then
            local res = mod.set_debuff(self)
            if res == 'prevent_debuff' then
                if self.debuff then
                    self.debuff = false
                    if self.area == G.jokers then self:add_to_deck(true) end
					self.debuffed_by_blind = false
                end
                return
            end
			should_debuff = should_debuff or res
		end
	end
	for k, v in pairs(self.ability.debuff_sources or {}) do
		if v == 'prevent_debuff' then
			if self.debuff then
				self.debuff = false
				if self.area == G.jokers then self:add_to_deck(true) end
			end
			self.debuffed_by_blind = false
			return
		end
		should_debuff = should_debuff or v
	end
	
'''
