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

### Rarity API

# get_badge_colour
[[patches]]
[patches.pattern]
target = 'functions/UI_definitions.lua'
pattern = 'return G.BADGE_COL[key] or {1, 0, 0, 1}'
position = 'before'
match_indent = true
payload = '''
for k, v in pairs(SMODS.Rarity.obj_buffer) do
    G.BADGE_COL[k] = G.C.RARITY[v]
end'''

# G.UIDEF.card_h_popup
[[patches]]
[patches.pattern]
target = "functions/UI_definitions.lua"
pattern = "if AUT.card_type == 'Joker' or (AUT.badges and AUT.badges.force_rarity) then card_type = ({localize('k_common'), localize('k_uncommon'), localize('k_rare'), localize('k_legendary')})[card.config.center.rarity] end"
position = "at"
payload = "if AUT.card_type == 'Joker' or (AUT.badges and AUT.badges.force_rarity) then card_type = SMODS.Rarity:get_rarity_badge(card.config.center.rarity) end"
match_indent = true

# Game:update
[[patches]]
[patches.pattern]
target = "game.lua"
pattern = "self.C.EDITION[2] = 0.7+0.2*(1+math.sin(self.TIMERS.REAL*1.5 + 6))"
position = "after"
payload = '''
for k, v in pairs(SMODS.Rarities) do
    if v.gradient and type(v.gradient) == "function" then v:gradient(dt) end
end'''
match_indent = true

# get_current_pool
[[patches]]
[patches.regex]
target = "functions/common_events.lua"
pattern = '''(?<indent>[\t ]*)local rarity = _rarity or pseudorandom\('rarity'\.\.G\.GAME\.round_resets\.ante\.\.\(_append or ''\)\) \n[\s\S]{12}rarity = \(_legendary and 4\) or \(rarity > 0\.95 and 3\) or \(rarity > 0\.7 and 2\) or 1'''
position = "at"
payload = '''
_rarity = (_legendary and 4) or (type(_rarity) == "number" and ((_rarity > 0.95 and 3) or (_rarity > 0.7 and 2) or 1)) or _rarity
_rarity = ({Common = 1, Uncommon = 2, Rare = 3, Legendary = 4})[_rarity] or _rarity
local rarity = _rarity or SMODS.poll_rarity("Joker", 'rarity'..G.GAME.round_resets.ante..(_append or ''))
'''

## Ensure that other cards set to string rarity work the same as set for int rarity
# Card:calculate_joker
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "if self.ability.name == 'Baseball Card' and context.other_joker.config.center.rarity == 2 and self ~= context.other_joker then"
position = "at"
payload = '''if self.ability.name == 'Baseball Card' and (context.other_joker.config.center.rarity == 2 or context.other_joker.config.center.rarity == "Uncommon") and self ~= context.other_joker then'''
match_indent = true
