Skip to content

Commit

Permalink
fix retriggers finally
Browse files Browse the repository at this point in the history
  • Loading branch information
Eremel committed Dec 31, 2024
1 parent 8c8d6c5 commit 53837dd
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 29 deletions.
20 changes: 12 additions & 8 deletions lovely/better_calc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -64,11 +64,7 @@ end
'''
position = 'at'
match_indent = true
payload = '''
if reps[j] == 1 and next(effects) then
reps = SMODS.calculate_repetitions(G.hand.cards[i], {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], repetition = true, card_effects = effects}, {})
end
'''
payload = ''''''

# Handle retrigger messages
[[patches]]
Expand Down Expand Up @@ -127,7 +123,10 @@ if next(effects) then
local eval = eval_card(_card, {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})
if next(eval) then
mod_percent = true
table.insert(effects, eval)
for rt = 1, ((eval.retriggers and #eval.retriggers or 0) + 1) do
table.insert(effects, eval)
end
-- if eval.jokers then print('Added '..((eval.retriggers and #eval.retriggers or 0) + 1)..' retriggers for '.._card.config.center_key) end
end
end
end
Expand Down Expand Up @@ -330,7 +329,7 @@ if card.ability.set == 'Joker' or card.ability.consumeable then
if jokers then
ret.jokers = jokers
if not context.retrigger_joker_check then
local retriggers = SMODS.calculate_retriggers(card, context)
local retriggers = SMODS.calculate_retriggers(card, context, ret)
if next(retriggers) then
ret.retriggers = retriggers
end
Expand Down Expand Up @@ -503,7 +502,12 @@ match_indent = true
position = "at"
payload = '''
-- Base game calculation removed 2
SMODS.trigger_effects(effects, G.hand.cards[i], percent)'''
SMODS.trigger_effects(effects, G.hand.cards[i], percent)
if reps[j] == 1 and effects.calculated then
SMODS.calculate_repetitions(G.hand.cards[i], {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], repetition = true, card_effects = effects}, reps)
end
'''
# Joker Effects
# Edition effects
[[patches]]
Expand Down
28 changes: 7 additions & 21 deletions src/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1039,20 +1039,8 @@ end

SMODS.trigger_effects = function(effects, card, percent)
for i, effect_table in ipairs(effects) do
if effect_table.retriggers and effect_table.retriggers.calculated then SMODS.calculate_effect(effect_table.retriggers, card, percent); effect_table.retriggers = nil end
for key, effect in pairs(effect_table) do
if key ~= 'smods' then
if key == 'retriggers' and not effect.calculated then
for rt = 1, #effect do
effect_table.smods.context.retrigger_check = true
local eval = eval_card(effect_table.smods.card, effect_table.smods.context)
if eval then
eval.retriggers = effect[rt]
eval.retriggers.calculated = true
table.insert(effects, eval)
end
end
end
if type(effect) == 'table' then
local calc = SMODS.calculate_effect(effect, card, percent, effect_table.smods and effect_table.smods.edition, effect_table.smods and effect_table.smods.no_x)
if calc then effects.calculated = true end
Expand Down Expand Up @@ -1083,14 +1071,11 @@ SMODS.calculate_repetitions = function(card, context, reps)
--From Red seal
context.repetition_only = true
local eval = eval_card(card, context)
local retriggers = eval and eval.retriggers and #eval.retriggers or 1
for key, value in pairs(eval) do
if value.repetitions then
for h=1, value.repetitions do
value.card = value.card or card
for i=1, retriggers do
reps[#reps+1] = {key = value}
end
reps[#reps+1] = {key = value}
end
end
end
Expand All @@ -1100,14 +1085,16 @@ SMODS.calculate_repetitions = function(card, context, reps)
local _card = G.jokers.cards[k] or G.consumeables.cards[k - #G.jokers.cards]
--calculate the joker effects
local eval = eval_card(_card, context)
local retriggers = eval and eval.retriggers and #eval.retriggers or 1
local rt = (eval and eval.retriggers and #eval.retriggers or 0) + 1
for key, value in pairs(eval) do
if value.repetitions then
if value.repetitions and key ~= 'retriggers' then

for h=1, value.repetitions do
value.card = value.card or _card
for i=1, retriggers do
for i=1, rt do
reps[#reps+1] = {key = value}
end
-- print('Added '..rt..' repetitions from '.._card.config.center_key)
end
end
end
Expand All @@ -1119,8 +1106,7 @@ SMODS.calculate_retriggers = function(card, context, _ret)
local retriggers = {}
for k=1, #G.jokers.cards + #G.consumeables.cards do
local _card = G.jokers.cards[k] or G.consumeables.cards[k - #G.jokers.cards]
context.retrigger_joker_check = true
local eval = eval_card(_card, context)
local eval = eval_card(_card, {retrigger_joker_check = true, other_card = card, other_context = context, other_ret = _ret})
for key, value in pairs(eval) do
if value.repetitions then
for h=1, value.repetitions do
Expand Down

0 comments on commit 53837dd

Please sign in to comment.