Skip to content

Commit

Permalink
individual joker effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Eremel committed Dec 29, 2024
1 parent 5551b96 commit 351f11d
Show file tree
Hide file tree
Showing 4 changed files with 185 additions and 51 deletions.
120 changes: 118 additions & 2 deletions lovely/better_calc.toml
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,36 @@ local seals = not card.ability.extra_enhancement and card:calculate_seal(context
if seals then
ret.seals = seals
end"""

[[patches]]
[patches.pattern]
target = "functions/common_events.lua"
pattern = '''
if context.cardarea == G.jokers or context.card == G.consumeables then
local jokers = nil
if context.edition then
jokers = card:get_edition(context)
elseif context.other_joker then
jokers = context.other_joker:calculate_joker(context)
else
jokers = card:calculate_joker(context)
end
if jokers then
ret.jokers = jokers
end'''
match_indent = true
position = "at"
payload = """
if card.ability.set == 'Joker' or card.ability.consumeable then
local jokers = nil
if context.other_joker then
jokers = context.other_joker:calculate_joker(context)
else
jokers = card:calculate_joker(context)
end
if jokers then
ret.jokers = jokers
end
"""


[[patches]]
Expand Down Expand Up @@ -423,8 +452,95 @@ for key, effect in pairs(effects[ii]) do
if calculated then effects.calculated = true end
end
end'''
# Joker Effects
# Edition effects
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = '''
--calculate the joker edition effects
local edition_effects = eval_card(_card, {cardarea = G.jokers, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, edition = true})
if edition_effects.jokers then
edition_effects.jokers.edition = true
if edition_effects.jokers.chip_mod then
hand_chips = mod_chips(hand_chips + edition_effects.jokers.chip_mod)
update_hand_text({delay = 0}, {chips = hand_chips})
card_eval_status_text(_card, 'jokers', nil, percent, nil, {
message = localize{type='variable',key='a_chips',vars={edition_effects.jokers.chip_mod}},
chip_mod = edition_effects.jokers.chip_mod,
colour = G.C.EDITION,
edition = true})
end
if edition_effects.jokers.mult_mod then
mult = mod_mult(mult + edition_effects.jokers.mult_mod)
update_hand_text({delay = 0}, {mult = mult})
card_eval_status_text(_card, 'jokers', nil, percent, nil, {
message = localize{type='variable',key='a_mult',vars={edition_effects.jokers.mult_mod}},
mult_mod = edition_effects.jokers.mult_mod,
colour = G.C.DARK_EDITION,
edition = true})
end
percent = percent+percent_delta
end'''
match_indent = true
position = "at"
payload = '''
-- remove base game joker edition calc
local edition_eval = eval_card(_card, {cardarea = G.jokers, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, edition = true})
for type, effect in pairs(edition_eval) do
if type == 'edition' then SMODS.calculate_effect(effect, _card, 1, true, true) end
end'''
# Edition mult effects
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = '''
if edition_effects.jokers then
if edition_effects.jokers.x_mult_mod then
mult = mod_mult(mult*edition_effects.jokers.x_mult_mod)
update_hand_text({delay = 0}, {mult = mult})
card_eval_status_text(_card, 'jokers', nil, percent, nil, {
message = localize{type='variable',key='a_xmult',vars={edition_effects.jokers.x_mult_mod}},
x_mult_mod = edition_effects.jokers.x_mult_mod,
colour = G.C.EDITION,
edition = true})
end
percent = percent+percent_delta
end'''
match_indent = true
position = "at"
payload = '''
-- calculate edition multipliers
for type, effect in pairs(edition_eval) do
if type == 'edition' then SMODS.calculate_effect(effect, _card, 1, true, false) end
end'''
# Joker effects
[[patches]]
[patches.pattern]
target = "functions/state_events.lua"
pattern = '''
--calculate the joker effects
local effects = eval_card(_card, {cardarea = G.jokers, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, joker_main = true})
G.GAME.selected_back:trigger_effect({context = 'joker_main', joker = _card, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands})

--Any Joker effects
if effects.jokers then
local extras = {mult = false, hand_chips = false}
if effects.jokers.mult_mod then mult = mod_mult(mult + effects.jokers.mult_mod);extras.mult = true end
if effects.jokers.chip_mod then hand_chips = mod_chips(hand_chips + effects.jokers.chip_mod);extras.hand_chips = true end
if effects.jokers.Xmult_mod then mult = mod_mult(mult*effects.jokers.Xmult_mod);extras.mult = true end
update_hand_text({delay = 0}, {chips = extras.hand_chips and hand_chips, mult = extras.mult and mult})
card_eval_status_text(_card, 'jokers', nil, percent, nil, effects.jokers)
percent = percent+percent_delta
end'''
match_indent = true
position = "at"
payload = '''
-- Calculate context.joker_main
local effects = eval_card(_card, {cardarea = G.jokers, full_hand = G.play.cards, scoring_hand = scoring_hand, scoring_name = text, poker_hands = poker_hands, joker_main = true})
for type, effect in pairs(effects) do
if type ~= 'edition' then SMODS.calculate_effect(effect, _card, 1) end
end'''

## Fix other evaluations
# Discarding cards
Expand Down
14 changes: 7 additions & 7 deletions lovely/sticker.toml
Original file line number Diff line number Diff line change
Expand Up @@ -209,13 +209,13 @@ 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.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]
Expand Down
6 changes: 3 additions & 3 deletions src/game_object.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2978,7 +2978,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
return { vars = { self.config.chips } }
end,
calculate = function(self, card, context)
if context.joker_main or (context.main_scoring and context.cardarea == G.play) then
if context.edition or (context.main_scoring and context.cardarea == G.play) then
return {
chips = card.edition.chips
}
Expand Down Expand Up @@ -3009,7 +3009,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
return { vars = { self.config.mult } }
end,
calculate = function(self, card, context)
if context.joker_main or (context.main_scoring and context.cardarea == G.play) then
if context.edition or (context.main_scoring and context.cardarea == G.play) then
return {
mult = card.edition.mult
}
Expand Down Expand Up @@ -3040,7 +3040,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
return { vars = { self.config.x_mult } }
end,
calculate = function(self, card, context)
if context.joker_main or (context.main_scoring and context.cardarea == G.play) then
if context.edition or (context.main_scoring and context.cardarea == G.play) then
return {
x_mult = card.edition.x_mult
}
Expand Down
96 changes: 57 additions & 39 deletions src/utils.lua
Original file line number Diff line number Diff line change
Expand Up @@ -919,61 +919,93 @@ end

-- This function handles the calculation of each effect returned to evaluate play.
-- Can easily be hooked to add more calculation effects ala Talisman
SMODS.calculate_individual_effect = function(effect, scored_card, percent, key, amount)
if key == 'chips' or key == 'h_chips' or key == 'chip_mod' and amount then
SMODS.calculate_individual_effect = function(effect, scored_card, percent, key, amount, from_edition, no_x)
if (key == 'chips' or key == 'h_chips' or key == 'chip_mod') and amount and (not from_edition or no_x) then
if effect.card then juice_card(effect.card) end
hand_chips = mod_chips(hand_chips + amount)
update_hand_text({delay = 0}, {chips = hand_chips})
if not effect.remove_default_message then card_eval_status_text(scored_card, 'chips', amount, percent) end
update_hand_text({delay = 0}, {chips = hand_chips, mult = mult})
if not effect.remove_default_message then
if from_edition then
card_eval_status_text(scored_card, 'jokers', nil, percent, nil, {
message = localize{type = 'variable', key = 'a_chips', vars = {amount}},
chip_mod = amount,
colour = G.C.EDITION,
edition = true
})
else
if key ~= 'chip_mod' then card_eval_status_text(scored_card, 'chips', amount, percent) end
end
end
return true
end

if key == 'mult' or key == 'h_mult' or key == 'mult_mod' and amount then
if (key == 'mult' or key == 'h_mult' or key == 'mult_mod') and amount and (not from_edition or no_x) then
if effect.card then juice_card(effect.card) end
mult = mod_mult(mult + amount)
update_hand_text({delay = 0}, {mult = mult})
if not effect.remove_default_message then card_eval_status_text(scored_card, key, amount, percent) end
update_hand_text({delay = 0}, {chips = hand_chips, mult = mult})
if not effect.remove_default_message then
if from_edition then
card_eval_status_text(scored_card, 'jokers', nil, percent, nil, {
message = localize{type = 'variable', key = 'a_mult', vars = {amount}},
mult_mod = amount,
colour = G.C.DARK_EDITION,
edition = true
})
else
if key ~= 'mult_mod' then card_eval_status_text(scored_card, key, amount, percent) end
end
end
return true
end

if key == 'p_dollars' or key == 'dollars' and amount then
if (key == 'p_dollars' or key == 'dollars') and amount and (not from_edition or no_x) then
if effect.card then juice_card(effect.card) end
ease_dollars(amount)
if not effect.remove_default_message then card_eval_status_text(scored_card, 'dollars', amount, percent) end
return true
end

if key == 'x_mult' or key == 'xmult' and amount ~= 1 then
if (key == 'x_mult' or key == 'xmult' or key == 'x_mult_mod' or key == 'Xmult_mod') and amount ~= 1 and (not from_edition or not no_x) then
if effect.card then juice_card(effect.card) end
mult = mod_mult(mult * amount)
update_hand_text({delay = 0}, {mult = mult})
if not effect.remove_default_message then card_eval_status_text(scored_card, 'x_mult', amount, percent) end
update_hand_text({delay = 0}, {chips = hand_chips, mult = mult})
if not effect.remove_default_message then
if from_edition then
card_eval_status_text(scored_card, 'jokers', nil, percent, nil, {
message = localize{type='variable',key='a_xmult',vars={amount}},
x_mult_mod = amount,
colour = G.C.EDITION,
edition = true})
else
if key ~= 'Xmult_mod' then card_eval_status_text(scored_card, 'x_mult', amount, percent) end
end
end
return true
end

if key == 'message' then
if key == 'message' and (not from_edition or no_x) then
card_eval_status_text(effect.card or effect.focus or scored_card, 'extra', nil, percent, nil, effect)
return true
end

if key == 'func' then
if key == 'func' and (not from_edition or no_x) then
effect.func()
return true
end

if key == 'swap' then
if key == 'swap' and (not from_edition or no_x) then
local old_mult = mult
mult = mod_mult(hand_chips)
hand_chips = mod_chips(old_mult)
update_hand_text({delay = 0}, {chips = hand_chips, mult = mult})
return true
end

if key == 'level_up' then
if key == 'level_up' and (not from_edition or no_x) then
level_up_hand(scored_card, G.GAME.last_hand_played, effect.instant, type(amount) == 'number' and amount or 1)
end

if key == 'extra' then
if key == 'extra' and (not from_edition or no_x) then
local extra_calc = false
for key_ex, amount_ex in pairs(amount) do
extra_calc = SMODS.calculate_individual_effect(amount, scored_card, percent, key_ex, amount_ex)
Expand All @@ -982,11 +1014,18 @@ SMODS.calculate_individual_effect = function(effect, scored_card, percent, key,
end
end

SMODS.calculate_effect = function(effect, scored_card, percent)
SMODS.calculate_effect = function(effect, scored_card, percent, from_edition, no_x)
local calculated = false
local message = false
for key, amount in pairs(effect) do
calculated = SMODS.calculate_individual_effect(effect, scored_card, percent, key, amount)
if key == 'message' then
message = true
else
calculated = SMODS.calculate_individual_effect(effect, scored_card, percent, key, amount, from_edition, no_x)
percent = percent+0.08
end
end
if message then calculated = SMODS.calculate_individual_effect(effect, scored_card, percent, 'message', effect.message, from_edition, no_x) end

return calculated
end
Expand Down Expand Up @@ -1027,25 +1066,4 @@ function Card:calculate_edition(context)
if o then return o end
end
end
end


function Card:get_edition()

if self.edition then
local ret = {card = self}
if self.edition.p_dollars then
ret.p_dollars_mod = self.edition.p_dollars
end
if self.edition.x_mult then
ret.x_mult_mod = self.edition.x_mult
end
if self.edition.mult then
ret.mult_mod = self.edition.mult
end
if self.edition.chips then
ret.chip_mod = self.edition.chips
end
return ret
end
end

0 comments on commit 351f11d

Please sign in to comment.