Skip to content

Commit bf0e79a

Browse files
feat: score modification effect (#1167)
* feat: score modification effect * chore: add LSP * chore: resolve merge conflict * chore: change all add_score to just score * Feature parity: (x)score_message, remove_default_message + loc key consistency --------- Co-authored-by: Casimir Eisenach <casimirusenormus@hotmail.de>
1 parent c0db6f1 commit bf0e79a

File tree

8 files changed

+247
-0
lines changed

8 files changed

+247
-0
lines changed

assets/sounds/xscore.ogg

46.4 KB
Binary file not shown.

localization/en-us.lua

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,46 @@ return {
142142
"card {C:attention}#1#{} #2#",
143143
},
144144
},
145+
card_score = {
146+
text = {
147+
"{C:purple}#1#{} Score",
148+
},
149+
},
150+
card_h_score = {
151+
text = {
152+
"{C:purple}#1#{} Score when held",
153+
},
154+
},
155+
card_x_score = {
156+
text = {
157+
"{X:purple,C:white}X#1#{} Score",
158+
},
159+
},
160+
card_h_x_score = {
161+
text = {
162+
"{X:purple,C:white}X#1#{} Score when held",
163+
},
164+
},
165+
card_extra_score = {
166+
text = {
167+
"{C:purple}#1#{} extra Score",
168+
},
169+
},
170+
card_extra_h_score = {
171+
text = {
172+
"{C:purple}#1#{} extra Score when held",
173+
},
174+
},
175+
card_extra_x_score = {
176+
text = {
177+
"{X:purple,C:white}X#1#{} extra Score",
178+
},
179+
},
180+
card_extra_h_x_score = {
181+
text = {
182+
"{X:purple,C:white}X#1#{} extra Score when held",
183+
},
184+
},
145185
artist = {
146186
text = {
147187
"{C:inactive}Artist",
@@ -300,6 +340,9 @@ return {
300340
cashout_hidden = '...and #1# more',
301341
a_xchips = "X#1# Chips",
302342
a_xchips_minus = "-X#1# Chips",
343+
a_score="#1# Score",
344+
a_xscore="X#1# Score",
345+
a_xscore_minus="-X#1# Score",
303346
smods_version_mismatch = {
304347
"Your Steamodded version has changed",
305348
"since this run was started!",

lovely/better_calc.toml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,14 @@ if context.cardarea == G.play and context.main_scoring then
116116
ret.playing_card.x_chips = x_chips
117117
end
118118
119+
local score = card:get_bonus_score()
120+
if score ~= 0 then
121+
ret.playing_card.score = score
122+
end
123+
local x_score = card:get_bonus_x_score()
124+
if x_score ~= 1 then
125+
ret.playing_card.x_score = x_score
126+
end
119127
-- TARGET: main scoring on played cards
120128
end
121129
if context.end_of_round and context.cardarea == G.hand and context.playing_card_end_of_round then
@@ -170,6 +178,15 @@ if context.cardarea == G.hand and context.main_scoring then
170178
ret.playing_card.x_chips = h_x_chips
171179
end
172180
181+
local h_score = card:get_bonus_h_score()
182+
if h_score ~= 0 then
183+
ret.playing_card.score = h_score
184+
end
185+
local h_x_score = card:get_bonus_h_x_score()
186+
if h_x_score ~= 1 then
187+
ret.playing_card.h_x_score = h_x_score
188+
end
189+
173190
-- TARGET: main scoring on held cards
174191
"""
175192

lovely/perma_bonus.toml

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,10 @@ bonus_h_x_mult = self.ability.perma_h_x_mult ~= 0 and (self.ability.perma_h_x_mu
9999
bonus_p_dollars = self.ability.perma_p_dollars ~= 0 and self.ability.perma_p_dollars or nil,
100100
bonus_h_dollars = self.ability.perma_h_dollars ~= 0 and self.ability.perma_h_dollars or nil,
101101
total_h_dollars = total_h_dollars ~= 0 and total_h_dollars or nil,
102+
perma_score = self.ability.perma_score ~= 0 and (self.ability.perma_score) or nil,
103+
perma_h_score = self.ability.perma_h_score ~= 0 and (self.ability.perma_h_score) or nil,
104+
perma_x_score = self.ability.perma_x_score ~= 1 and (self.ability.perma_x_score) or nil,
105+
perma_h_x_score = self.ability.perma_h_x_score ~= 1 and (self.ability.perma_h_x_score) or nil,
102106
bonus_chips = bonus_chips ~= 0 and bonus_chips or nil,
103107
bonus_repetitions = self.ability.perma_repetitions ~= 0 and self.ability.perma_repetitions or nil,'''
104108
match_indent = true
@@ -140,6 +144,10 @@ perma_h_dollars = self.ability and self.ability.perma_h_dollars or 0,
140144
perma_repetitions = self.ability and self.ability.perma_repetitions or 0,
141145
card_limit = self.ability and self.ability.card_limit or 0,
142146
extra_slots_used = self.ability and self.ability.extra_slots_used or 0,
147+
perma_score = self.ability and self.ability.perma_score or 0,
148+
perma_h_score = self.ability and self.ability.perma_h_score or 0,
149+
perma_x_score = self.ability and self.ability.perma_x_score or 1,
150+
perma_h_x_score = self.ability and self.ability.perma_h_x_score or 1,
143151
'''
144152
match_indent = true
145153
overwrite = false
@@ -257,6 +265,34 @@ function Card:get_h_dollars()
257265
-- TARGET: get_h_dollars
258266
return ret
259267
end
268+
269+
function Card:get_bonus_score()
270+
if self.debuff then return 0 end
271+
local ret = (self.ability.perma_score or 0)
272+
-- TARGET: get_bonus_score
273+
return ret
274+
end
275+
276+
function Card:get_bonus_x_score()
277+
if self.debuff then return 1 end
278+
local ret = (self.ability.perma_x_score or 1)
279+
-- TARGET: get_bonus_x_score
280+
return ret
281+
end
282+
283+
function Card:get_bonus_h_score()
284+
if self.debuff then return 0 end
285+
local ret = (self.ability.perma_h_score or 0)
286+
-- TARGET: get_bonus_h_score
287+
return ret
288+
end
289+
290+
function Card:get_bonus_h_x_score()
291+
if self.debuff then return 1 end
292+
local ret = (self.ability.perma_h_x_score or 1)
293+
-- TARGET: get_bonus_h_x_score
294+
return ret
295+
end
260296
'''
261297

262298
# Card:get_p_dollars

lovely/score_mod.toml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
[manifest]
2+
version = "1.0.0"
3+
dump_lua = true
4+
priority = -10
5+
6+
# Score Modification!
7+
8+
9+
[[patches]]
10+
[patches.pattern]
11+
target = "functions/common_events.lua"
12+
pattern = """ if extra.edition then """
13+
position = "before"
14+
payload = """
15+
if extra.sound_override then
16+
sound = extra.sound_override
17+
end
18+
if extra.update_score then
19+
G.CARD_EVAL_TRIGGERED = nil
20+
update_score = true
21+
end
22+
"""
23+
overwrite = true
24+
match_indent = true
25+
26+
27+
28+
[[patches]]
29+
[patches.pattern]
30+
target = "functions/common_events.lua"
31+
pattern = """ local trigger = 'before'"""
32+
position = "before"
33+
payload = """
34+
local update_score = nil
35+
"""
36+
overwrite = true
37+
match_indent = true
38+
39+
40+
41+
[[patches]]
42+
[patches.pattern]
43+
target = "functions/common_events.lua"
44+
pattern = """play_sound(sound, 0.8+percent*0.2, volume)"""
45+
position = "before"
46+
payload = """
47+
if update_score then
48+
G.SCORE_DISPLAY_QUEUE = G.SCORE_DISPLAY_QUEUE or {}
49+
table.remove(G.SCORE_DISPLAY_QUEUE, 1)
50+
G.HUD:get_UIE_by_ID('chip_UI_count'):juice_up(0.3, 0.3)
51+
end
52+
"""
53+
overwrite = true
54+
match_indent = true
55+
56+
57+
[[patches]]
58+
[patches.pattern]
59+
target = 'functions/button_callbacks.lua'
60+
pattern = """ local new_chips_text = number_format(G.GAME.chips)"""
61+
position = "after"
62+
payload = """if G.SCORE_DISPLAY_QUEUE and G.SCORE_DISPLAY_QUEUE[1] then
63+
new_chips_text = number_format(G.SCORE_DISPLAY_QUEUE[1])
64+
if G.GAME.chips_text ~= new_chips_text then
65+
e.config.scale = math.min(0.8, scale_number(G.SCORE_DISPLAY_QUEUE[1], 1.1))
66+
G.GAME.chips_text = new_chips_text
67+
end
68+
return
69+
end
70+
"""
71+
overwrite = true
72+
match_indent = true

lsp_def/utils.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,3 +810,14 @@ function SMODS.get_card_type_text_colour(type, center, card) end
810810
---@param key string
811811
---@return table?
812812
function SMODS.get_badge_text_colour(key) end
813+
814+
---Check if `challenge` is unlocked.
815+
---@param mod_score Score_Mod_Parameter Score modification parameter
816+
function SMODS.mod_score(mod_score) end
817+
818+
---@class Score_Mod_Parameter
819+
---@field add? number Add this number to score
820+
---@field mult? number Multiply score by this number
821+
---@field card? Card Card responsible for score modification action, crucial for score display to work properly
822+
---@field effect? table Table of effects that were calculated
823+
---@field from_edition? boolean

src/game_object.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -617,6 +617,7 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
617617
end
618618

619619
SMODS.Sound{ key = 'xchips', path = 'xchips.ogg'}
620+
SMODS.Sound{ key = 'xscore', path = 'xscore.ogg'}
620621

621622
-------------------------------------------------------------------------------------------------
622623
------- API CODE GameObject.Gradient

src/utils.lua

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1245,6 +1245,16 @@ SMODS.calculate_individual_effect = function(effect, scored_card, key, amount, f
12451245
})
12461246
return true
12471247
end
1248+
if (key == 'xscore' or key == 'h_xscore' or key == 'x_score' or key == 'h_x_score') and amount ~= 1 then
1249+
if effect.card and effect.card ~= scored_card then juice_card(effect.card) end
1250+
SMODS.mod_score({ mult = amount, card = effect.message_card or effect.juice_card or scored_card or effect.card or effect.focus, effect = effect, from_edition = from_edition })
1251+
return true
1252+
end
1253+
if (key == 'score' or key == 'h_score') and amount ~= 0 then
1254+
if effect.card and effect.card ~= scored_card then juice_card(effect.card) end
1255+
SMODS.mod_score({ add = amount, card = effect.message_card or effect.juice_card or scored_card or effect.card or effect.focus, effect = effect, from_edition = from_edition })
1256+
return true
1257+
end
12481258

12491259
if key == 'message' and not SMODS.no_resolve then
12501260
if effect.card and effect.card ~= scored_card then juice_card(effect.card) end
@@ -1466,6 +1476,8 @@ SMODS.scoring_parameter_keys = {
14661476
}
14671477
SMODS.other_calculation_keys = {
14681478
'p_dollars', 'dollars', 'h_dollars',
1479+
'score', 'h_score',
1480+
'xscore', 'x_score', 'h_x_score', 'h_xscore',
14691481
'swap', 'balance',
14701482
'saved', 'effect', 'remove',
14711483
'debuff', 'prevent_debuff', 'debuff_text',
@@ -3126,6 +3138,18 @@ function SMODS.localize_perma_bonuses(specific_vars, desc_nodes)
31263138
if specific_vars and specific_vars.bonus_h_dollars then
31273139
localize{type = 'other', key = 'card_extra_h_dollars', nodes = desc_nodes, vars = {SMODS.signed_dollars(specific_vars.bonus_h_dollars)}}
31283140
end
3141+
if specific_vars and specific_vars.perma_score then
3142+
localize{type = 'other', key = 'card_extra_score', nodes = desc_nodes, vars = {SMODS.signed(specific_vars.perma_score)}}
3143+
end
3144+
if specific_vars and specific_vars.perma_h_score then
3145+
localize{type = 'other', key = 'card_extra_h_score', nodes = desc_nodes, vars = {SMODS.signed(specific_vars.perma_h_score)}}
3146+
end
3147+
if specific_vars and specific_vars.perma_x_score then
3148+
localize{type = 'other', key = 'card_extra_x_score', nodes = desc_nodes, vars = {(specific_vars.perma_x_score)}}
3149+
end
3150+
if specific_vars and specific_vars.perma_h_x_score then
3151+
localize{type = 'other', key = 'card_extra_h_x_score', nodes = desc_nodes, vars = {(specific_vars.perma_h_x_score)}}
3152+
end
31293153
if specific_vars and specific_vars.bonus_repetitions then
31303154
localize{type = 'other', key = 'card_extra_repetitions', nodes = desc_nodes, vars = {specific_vars.bonus_repetitions, localize(specific_vars.bonus_repetitions > 1 and 'b_retrigger_plural' or 'b_retrigger_single')}}
31313155
end
@@ -3578,4 +3602,47 @@ function SMODS.get_badge_text_colour(key)
35783602
for k, v in pairs(SMODS.Seals) do
35793603
if k:lower()..'_seal' == key and v.text_colour then return v.text_colour end
35803604
end
3605+
end
3606+
-- function to modify score: normally accepts add and mult argument and additionally card argument
3607+
SMODS.mod_score = function(score_mod)
3608+
score_mod = score_mod or {}
3609+
local score_fx = {}
3610+
local score_cal = score_mod.set or G.GAME.chips
3611+
local old = G.GAME.chips
3612+
G.SCORE_DISPLAY_QUEUE = G.SCORE_DISPLAY_QUEUE or {}
3613+
-- TARGET: higher priority score operation
3614+
if score_mod.mult then
3615+
local absoluted = math.abs(score_mod.mult)
3616+
score_cal = score_cal * score_mod.mult
3617+
table.insert(G.SCORE_DISPLAY_QUEUE, old)
3618+
score_fx[#score_fx+1] = {key = score_mod.mult < 0 and "a_xscore_minus" or "a_xscore", value = absoluted, sound = "xscore", message_key = "xscore_message"}
3619+
end
3620+
if score_mod.add and score_mod.add ~= 0 then
3621+
local absoluted = math.abs(score_mod.add)
3622+
score_cal = score_cal + score_mod.add
3623+
table.insert(G.SCORE_DISPLAY_QUEUE, old)
3624+
score_fx[#score_fx+1] = { key = "a_score", value = score_mod.add, sound = "gong", message_key = 'score_message'}
3625+
end
3626+
-- TARGET: lower priority score operation
3627+
G.GAME.chips = score_cal
3628+
3629+
if not (score_mod.effect and score_mod.effect.remove_default_message) and score_mod.card then
3630+
for _,v in ipairs(score_fx) do
3631+
if score_mod.from_edition then
3632+
card_eval_status_text(score_mod.card, 'jokers', nil, percent, nil, {message = localize{type = 'variable', key = v.key, vars = {v.value}}, update_score = true, colour = G.C.EDITION, edition = true, sound = v.sound, volume = 0.5 })
3633+
elseif score_mod.effect and score_mod.effect[v.message_key] then
3634+
score_mod.effect[v.message_key].update_score = true
3635+
card_eval_status_text(score_mod.card, 'extra', v.value, percent, nil, score_mod.effect[v.message_key])
3636+
else
3637+
card_eval_status_text(score_mod.card, 'jokers', nil, percent, nil, {message = localize{type='variable',key= v.key,vars={v.value}}, update_score = true, volume = 0.5, sound_override = v.sound, colour = G.C.PURPLE})
3638+
end
3639+
end
3640+
-- this check is in case some skip animation mods is there, may be removed in the future
3641+
if G.CARD_EVAL_TRIGGERED then
3642+
G.SCORE_DISPLAY_QUEUE = nil
3643+
end
3644+
elseif score_mod.effect then
3645+
score_mod.effect.update_score = true
3646+
end
3647+
delay(0.2)
35813648
end

0 commit comments

Comments
 (0)