Skip to content

Commit

Permalink
Merge pull request #358 from Steamopollys/sticker-calc
Browse files Browse the repository at this point in the history
[WIP] sticker calc
  • Loading branch information
Eremel authored Dec 28, 2024
2 parents 7e4f6ae + c546d68 commit e0ad003
Show file tree
Hide file tree
Showing 6 changed files with 137 additions and 22 deletions.
10 changes: 7 additions & 3 deletions lovely/back.toml
Original file line number Diff line number Diff line change
Expand Up @@ -172,11 +172,15 @@ payload = '''G.GAME.selected_back:trigger_effect({context = 'reroll_shop'})'''
[[patches]]
[patches.pattern]
target = 'functions/state_events.lua'
pattern = '''G.jokers.cards[i]:calculate_perishable()
pattern = '''
G.jokers.cards[i]:calculate_rental()
G.jokers.cards[i]:calculate_perishable()
end'''
position = 'after'
position = 'at'
match_indent = true
payload = '''G.GAME.selected_back:trigger_effect({context = 'end_of_round', game_over = game_over})'''
payload = '''
end
G.GAME.selected_back:trigger_effect({context = 'end_of_round', game_over = game_over})'''

[[patches]]
[patches.pattern]
Expand Down
20 changes: 20 additions & 0 deletions lovely/enhancement.toml
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,12 @@ local enhancement = card:calculate_enhancement(context)
if enhancement then
ret.enhancement = enhancement
end
for k,v in pairs(SMODS.Stickers) do
local sticker = card:calculate_sticker(context, k)
if sticker then
ret[v] = sticker
end
end
"""
[[patches]]
[patches.pattern]
Expand All @@ -443,6 +449,20 @@ if seals then
ret.seals = seals
end"""

[[patches]]
[patches.regex]
target = 'functions/common_events.lua'
position = 'after'
pattern = '( ){4}if context\.cardarea == G\.jokers or context\.card == G\.consumeables then(\n.*)*?\n( ){4}end'
payload = '''
for k,v in pairs(SMODS.Stickers) do
local sticker = card:calculate_sticker(context, k)
if sticker then
ret[v] = sticker
end
end
'''

# G.FUNCS.evaluate_play()
# handle scoring
[[patches]]
Expand Down
8 changes: 4 additions & 4 deletions lovely/joker_retrigger.toml
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ payload = ''' }) end
target = "functions/state_events.lua"
pattern = "eval = G.jokers.cards[i]:calculate_joker({end_of_round = true, game_over = game_over})"
position = "at"
payload = "eval = G.jokers.cards[i]:calculate_joker({end_of_round = true, game_over = game_over, callback = function(card, eval)"
payload = "eval = eval_card(G.jokers.cards[i], {cardarea = G.jokers, end_of_round = true, game_over = game_over, callback = function(card, eval)"
match_indent = true

# End of round held in hand effects
Expand All @@ -138,16 +138,16 @@ match_indent = true
target = "functions/state_events.lua"
pattern = "local eval = G.jokers.cards[k]:calculate_joker({cardarea = G.hand, other_card = G.hand.cards[i], individual = true, end_of_round = true})"
position = "at"
payload = "local eval = G.jokers.cards[k]:calculate_joker({cardarea = G.hand, other_card = G.hand.cards[i], individual = true, end_of_round = true, callback = function(card, eval, retrigger)"
payload = "local eval = eval_card(G.jokers.cards[k], {cardarea = G.hand, other_card = G.hand.cards[i], individual = true, end_of_round = true, callback = function(card, eval, retrigger)"
match_indent = true

# Played hand effects
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = "local eval = G.jokers.cards[k]:calculate_joker({cardarea = G.play, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, other_card = scoring_hand[i], individual = true})"
payload = "local eval = eval_card(G.jokers.cards[k], {cardarea = G.play, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, other_card = scoring_hand[i], individual = true, callback = function(card, eval, retrigger)"
position = "at"
payload = "local eval = G.jokers.cards[k]:calculate_joker({cardarea = G.play, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, other_card = scoring_hand[i], individual = true, callback = function(card, eval, retrigger)"
match_indent = true

# Held in hand effects
Expand All @@ -156,7 +156,7 @@ match_indent = true
target = "functions/state_events.lua"
pattern = "local eval = G.jokers.cards[k]:calculate_joker({cardarea = G.hand, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, other_card = G.hand.cards[i], individual = true})"
position = "at"
payload = "local eval = G.jokers.cards[k]:calculate_joker({cardarea = G.hand, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, other_card = G.hand.cards[i], individual = true, callback = function(card, eval, retrigger)"
payload = "local eval = eval_card(G.jokers.cards[k], {cardarea = G.hand, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, other_card = G.hand.cards[i], individual = true, callback = function(card, eval, retrigger)"
match_indent = true

# Fix syntax of last 3 patches
Expand Down
97 changes: 83 additions & 14 deletions lovely/sticker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,22 +109,18 @@ for k, v in pairs(SMODS.Stickers) do
end
'''

# Card:calculate_joker()
# end_round()
[[patches]]
[patches.pattern]
target = "card.lua"
pattern = "function Card:calculate_joker(context)"
position = 'after'
payload = '''
for k, v in pairs(SMODS.Stickers) do
if self.ability[v.key] then
if v.calculate and type(v.calculate) == 'function' then
local override_card = v:calculate(self, context)
if override_card then return override_card end
end
end
end'''
target = 'functions/state_events.lua'
match_indent = true
position = 'before'
pattern = "if G.GAME.round_resets.ante == G.GAME.win_ante and G.GAME.blind:get_type() == 'Boss' then"
payload = '''
for i, v in ipairs(G.hand.cards) do
eval_card(G.hand.cards[i], {cardarea = G.hand, end_of_round = true, game_over = game_over })
end
'''

# get_badge_colour()
[[patches]]
Expand All @@ -146,4 +142,77 @@ target = 'cardarea.lua'
pattern = '''table.sort(self.cards, function (a, b) return a.T.x + a.T.w/2 - 100*(a.pinned and a.sort_id or 0) < b.T.x + b.T.w/2 - 100*(b.pinned and b.sort_id or 0) end)'''
position = 'at'
match_indent = true
payload = '''table.sort(self.cards, function (a, b) return a.T.x + a.T.w/2 - 100*((a.pinned and not a.ignore_pinned) and a.sort_id or 0) < b.T.x + b.T.w/2 - 100*((b.pinned and not b.ignore_pinned) and b.sort_id or 0) end)'''
payload = '''table.sort(self.cards, function (a, b) return a.T.x + a.T.w/2 - 100*((a.pinned and not a.ignore_pinned) and a.sort_id or 0) < b.T.x + b.T.w/2 - 100*((b.pinned and not b.ignore_pinned) and b.sort_id or 0) end)'''


[[patches]]
[patches.regex]
target = 'functions/state_events.lua'
pattern = 'G\.jokers\.cards\[i\]:calculate_joker\('
position = 'at'
payload = 'eval_card(G.jokers.cards[i], '

[[patches]]
[patches.regex]
target = 'functions/state_events.lua'
pattern = 'G\.jokers\.cards\[j\]:calculate_joker\('
position = 'at'
payload = 'eval_card(G.jokers.cards[j], '

[[patches]]
[patches.regex]
target = 'functions/state_events.lua'
pattern = 'v:calculate_joker\('
position = 'at'
payload = 'eval_card(v, '

[[patches]]
[patches.regex]
target = 'card.lua'
pattern = 'G\.jokers\.cards\[i\]:calculate_joker\('
position = 'at'
payload = 'eval_card(G.jokers.cards[i], '

[[patches]]
[patches.regex]
target = 'functions/misc_functions.lua'
pattern = 'G\.jokers\.cards\[i\]:calculate_joker\('
position = 'at'
payload = 'eval_card(G.jokers.cards[i], '

[[patches]]
[patches.regex]
target = 'functions/button_callbacks.lua'
pattern = 'G\.jokers\.cards\[i\]:calculate_joker\('
position = 'at'
payload = 'eval_card(G.jokers.cards[i], '

[[patches]]
[patches.regex]
target = 'functions/button_callbacks.lua'
pattern = 'c1:calculate_joker\(\{buying_card = true, card = c1\}\)'
position = 'at'
payload = 'eval_card(c1, {buying_card = true, card = c1})'

[[patches]]
[patches.pattern]
target = 'card.lua'
pattern = 'self:calculate_joker{selling_self = true}'
position = 'at'
match_indent = true
payload = 'eval_card(self, {selling_self = true})'

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = "if context.cardarea == G.jokers or context.card == G.consumeables then"
match_indent = true
position = "at"
payload = "if card.ability.set == 'Joker' or card.ability.consumeable then"

[[patches]]
[patches.regex]
target = 'game.lua'
pattern = 'G\.jokers\.cards\[i\]:calculate_joker\('
position = 'at'
payload = 'eval_card(G.jokers.cards[i], '
17 changes: 16 additions & 1 deletion src/game_object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2708,7 +2708,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
inject = function(self)
SMODS.Sticker.inject(self)
G.shared_sticker_eternal = self.sticker_sprite
end
end,
}

SMODS.Sticker{
Expand All @@ -2729,6 +2729,11 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
inject = function(self)
SMODS.Sticker.inject(self)
G.shared_sticker_perishable = self.sticker_sprite
end,
calculate = function(self, card, context)
if context.end_of_round and not context.repetition then
card:calculate_perishable()
end
end
}

Expand All @@ -2750,6 +2755,16 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
inject = function(self)
SMODS.Sticker.inject(self)
G.shared_sticker_rental = self.sticker_sprite
end,
calculate = function(self, card, context)
if context.end_of_round and not context.repetition and not context.individual then
card:calculate_rental()
end
if context.skipping_booster then
ease_dollars(G.GAME.rental_rate)
card_eval_status_text(card, 'dollars', G.GAME.rental_rate)
end
if context.joker_main then return { mult_mod = 10 } end
end
}

Expand Down
7 changes: 7 additions & 0 deletions src/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,13 @@ function time(func, ...)
return 1000*(end_time-start_time)
end

function Card:calculate_sticker(context, key)
local sticker = SMODS.Stickers[key]
if self.ability[key] and type(sticker.calculate) == 'function' then
return sticker:calculate(self, context)
end
end

function Card:calculate_enhancement(context)
if self.debuff or self.ability.set ~= 'Enhanced' then return nil end
local center = self.config.center
Expand Down

0 comments on commit e0ad003

Please sign in to comment.