Skip to content

Commit ba3e270

Browse files
committed
fix(lua.endpoints): fix pack with mega packs with double target selection
1 parent 6d5187f commit ba3e270

1 file changed

Lines changed: 27 additions & 10 deletions

File tree

src/lua/endpoints/pack.lua

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -196,12 +196,12 @@ return {
196196

197197
-- Highlight the target cards in hand
198198
if args.targets and #args.targets > 0 then
199-
-- Clear existing highlights
200-
for _, hand_card in ipairs(G.hand.cards) do
201-
hand_card.highlighted = false
199+
-- Clear existing highlights using proper CardArea method
200+
for i = #G.hand.highlighted, 1, -1 do
201+
G.hand:remove_from_highlighted(G.hand.highlighted[i], true)
202202
end
203203

204-
-- Highlight target cards
204+
-- Highlight target cards using proper CardArea method
205205
for _, target_idx in ipairs(args.targets) do
206206
local hand_pos = target_idx + 1 -- Convert 0-based to 1-based
207207
if not G.hand.cards[hand_pos] then
@@ -211,8 +211,7 @@ return {
211211
})
212212
return true
213213
end
214-
G.hand.cards[hand_pos].highlighted = true
215-
G.hand.highlighted[#G.hand.highlighted + 1] = G.hand.cards[hand_pos]
214+
G.hand:add_to_highlighted(G.hand.cards[hand_pos], true)
216215
end
217216
end
218217
end
@@ -320,17 +319,35 @@ return {
320319
trigger = "condition",
321320
blocking = false,
322321
func = function()
323-
-- Calculate expected hand size
324-
-- If deck has fewer cards than hand limit, hand will only have deck_size cards
322+
-- Wait for state transition to complete (ensures hand is fully dealt)
323+
if not G.STATE_COMPLETE then
324+
return false
325+
end
326+
327+
-- Calculate expected hand size for initial load
328+
-- After cards are destroyed (mega packs), hand may have fewer cards
325329
local hand_limit = G.hand.config and G.hand.config.card_limit or 8
326330
local deck_size = G.deck and G.deck.config and G.deck.config.card_count or 52
327331
local expected_hand_size = math.min(deck_size, hand_limit)
328332

329-
-- Wait for hand to be fully loaded and positioned
333+
-- Calculate minimum required cards based on target indices
334+
local min_required = 1
335+
if args.targets and #args.targets > 0 then
336+
for _, target_idx in ipairs(args.targets) do
337+
local required = target_idx + 1 -- 0-based to 1-based
338+
if required > min_required then
339+
min_required = required
340+
end
341+
end
342+
end
343+
344+
-- Wait for hand to be ready:
345+
-- - At least expected_hand_size cards (initial load), OR
346+
-- - At least min_required cards (for mega packs after cards destroyed)
330347
local hand_ready = G.hand
331348
and not G.hand.REMOVED
332349
and G.hand.cards
333-
and #G.hand.cards == expected_hand_size
350+
and (#G.hand.cards >= expected_hand_size or #G.hand.cards >= min_required)
334351
and G.hand.T -- Table area exists
335352
and G.hand.T.x -- Positioned
336353

0 commit comments

Comments
 (0)