Skip to content

Commit cae688a

Browse files
authored
feat: Add weights to every object and SMODS.Attribute (#1284)
1 parent b253d68 commit cae688a

File tree

9 files changed

+1101
-14
lines changed

9 files changed

+1101
-14
lines changed

lovely/card_limit.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ position = "at"
286286
payload = """local hand_space = e
287287
local cards_to_draw = {}
288288
local space_taken = 0
289-
local limit = G.hand.config.card_limit - #G.hand.cards - (SMODS.cards_to_draw or 0)
289+
local limit = (G.hand.config.card_limit - #G.hand.cards - (SMODS.cards_to_draw or 0))
290290
local flags = SMODS.calculate_context({drawing_cards = true, amount = limit})
291291
limit = flags.cards_to_draw or flags.modify or limit
292292
local unfixed = not G.hand.config.fixed_limit

lovely/weights.toml

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
[manifest]
2+
version = "1.0.0"
3+
dump_lua = true
4+
priority = -10
5+
6+
# Bypass get_new_boss()
7+
[[patches]]
8+
[patches.pattern]
9+
target = 'functions/common_events.lua'
10+
match_indent = true
11+
position = 'after'
12+
pattern = '''
13+
function get_new_boss()
14+
'''
15+
payload = '''
16+
-- Use SMODS object weight system when enabled
17+
if SMODS.optional_features.object_weights then return SMODS.poll_object({type = 'Blind'}) end
18+
'''
19+
20+
# Bypass create_card_for_shop()
21+
[[patches]]
22+
[patches.pattern]
23+
target = 'functions/UI_definitions.lua'
24+
match_indent = true
25+
position = 'after'
26+
pattern = '''
27+
function create_card_for_shop(area)
28+
'''
29+
payload = '''
30+
-- Use SMODS object weight system when enabled
31+
if SMODS.optional_features.object_weights then return SMODS.create_shop_card(area) end
32+
'''
33+
34+
# Bypass create_card key selection
35+
[[patches]]
36+
[patches.pattern]
37+
target = 'functions/common_events.lua'
38+
match_indent = true
39+
position = 'before'
40+
pattern = '''
41+
if forced_key and not G.GAME.banned_keys[forced_key] then
42+
'''
43+
payload = '''
44+
-- Use SMODS object weight system when enabled
45+
if not forced_key and SMODS.optional_features.object_weights then forced_key = SMODS.poll_object({type = _type, guaranteed = true}) end
46+
47+
'''
48+
49+
# These patches add functionality for polling blinds, but are a precursor for full support of modded small and big blinds
50+
# TODO: move to blind related toml
51+
# Adjust vanilla blinds max ante property
52+
[[patches]]
53+
[patches.pattern]
54+
target = 'game.lua'
55+
match_indent = true
56+
position = 'before'
57+
pattern = '''
58+
self.b_undiscovered = {name = 'Undiscovered', debuff_text = 'Defeat this blind to discover', pos = {x=0,y=30}}
59+
'''
60+
payload = '''
61+
for key, blind in pairs(self.P_BLINDS) do
62+
if blind.boss and blind.boss.max then
63+
blind.boss.max = nil
64+
if blind.boss.showdown then
65+
blind.boss.min = nil
66+
end
67+
end
68+
if key == 'bl_small' then blind.small = {min = 1} end
69+
if key == 'bl_big' then blind.big = {min = 1} end
70+
end
71+
'''
72+
73+
# Add custom small/big blinds to `G.GAME.bosses_used`
74+
[[patches]]
75+
[patches.pattern]
76+
target = 'game.lua'
77+
match_indent = true
78+
position = 'after'
79+
pattern = '''
80+
if v.boss then bosses_used[k] = 0 end
81+
'''
82+
payload = '''
83+
if v.small or v.big then bosses_used[k] = 0 end
84+
'''

src/core.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ for _, path in ipairs {
66
"src/overrides.lua",
77
"src/game_object.lua",
88
"src/compat_0_9_8.lua",
9+
"src/utils/weights.lua"
910
} do
1011
assert(load(SMODS.NFS.read(SMODS.path..path), ('=[SMODS _ "%s"]'):format(path)))()
1112
end

src/game_object.lua

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,10 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
115115
-- Checked on __call but not take_ownership. For take_ownership, the key must exist
116116
function SMODS.GameObject:check_duplicate_key()
117117
if self.obj_table[self.key] or (self.get_obj and self:get_obj(self.key)) then
118+
if self.set == 'Attribute' then
119+
SMODS.Attributes[self.key].keys = SMODS.merge_lists({SMODS.Attributes[self.key].keys, self.keys})
120+
return true
121+
end
118122
sendWarnMessage(('Object %s has the same key as an existing object, not registering.'):format(self.key), self.set)
119123
sendWarnMessage('If you want to modify an existing object, use take_ownership()', self.set)
120124
return true
@@ -389,6 +393,12 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
389393
end,
390394
}
391395

396+
-------------------------------------------------------------------------------------------------
397+
----- API CODE GameObject.Attribute
398+
-------------------------------------------------------------------------------------------------
399+
400+
assert(load(SMODS.NFS.read(SMODS.path..'src/game_objects/attributes.lua'), ('=[SMODS _ "src/game_objects/attributes.lua"]')))()
401+
392402
-------------------------------------------------------------------------------------------------
393403
----- INTERNAL API CODE GameObject._Loc_Pre
394404
-------------------------------------------------------------------------------------------------
@@ -1188,6 +1198,13 @@ Set `prefix_config.key = false` on your object instead.]]):format(obj.key), obj.
11881198
v:inject_card(self)
11891199
end
11901200
end
1201+
if self.attributes then
1202+
for _, attribute in ipairs(self.attributes) do
1203+
if SMODS.Attributes[attribute] then
1204+
SMODS.Attributes[attribute].keys = SMODS.merge_lists({SMODS.Attributes[attribute].keys or {}, {self.key}})
1205+
end
1206+
end
1207+
end
11911208
end,
11921209
delete = function(self)
11931210
G.P_CENTERS[self.key] = nil

0 commit comments

Comments
 (0)