-- if this slot has a unique_by, wrap its filter to exclude collided keys
-- if this slot has a unique_by, wrap its filter to exclude collided keys
localnew_filter=slot.group.filter
localnew_filter=slot.group.filter
ifslot.group.unique_bythen
ifslot.group.unique_bythen
...
@@ -4145,14 +4054,14 @@ function Fusion.CanCompleteFromMappings(e,sel,eg,slots,mat_filter,fgoalcheck,tc,
...
@@ -4145,14 +4054,14 @@ function Fusion.CanCompleteFromMappings(e,sel,eg,slots,mat_filter,fgoalcheck,tc,
-- if this slot has a has_same, wrap its filter to include only sames
-- if this slot has a has_same, wrap its filter to include only sames
ifslot.group.has_samethen
ifslot.group.has_samethen
-- only if there is at least one already‐selected card for this slot…
-- only if there is at least one already‐selected card for this slot…
local has_sel = false
localhas_sel=false
for_,mapped_iinpairs(mapping)do
for_,mapped_iinpairs(mapping)do
ifmapped_i==ithen
ifmapped_i==ithen
has_sel=true
has_sel=true
break
break
end
end
end
end
if has_sel then
ifhas_selthen
-- precompute, for each fn in has_same, the overlap of already-mapped cards
-- precompute, for each fn in has_same, the overlap of already-mapped cards
localused_overlap={}-- fn → (number mask) or (table of keys)
localused_overlap={}-- fn → (number mask) or (table of keys)
for_,fninipairs(slot.group.has_same)do
for_,fninipairs(slot.group.has_same)do
...
@@ -4181,12 +4090,12 @@ function Fusion.CanCompleteFromMappings(e,sel,eg,slots,mat_filter,fgoalcheck,tc,
...
@@ -4181,12 +4090,12 @@ function Fusion.CanCompleteFromMappings(e,sel,eg,slots,mat_filter,fgoalcheck,tc,
localprev=new_filter
localprev=new_filter
new_filter=function(mc,p_tc)
new_filter=function(mc,p_tc)
-- original criteria
-- original criteria
if prev and not prev(mc,tc) then
ifprevandnotprev(mc,p_tc)then
returnfalse
returnfalse
end
end
-- for each fn in has_same, check against the precomputed overlap
-- for each fn in has_same, check against the precomputed overlap
forfn,overlapinpairs(used_overlap)do
forfn,overlapinpairs(used_overlap)do
local v=fn(mc,tc)
localv=fn(mc,p_tc)
iftype(overlap)=="number"then
iftype(overlap)=="number"then
-- bitmask path
-- bitmask path
if(overlap&v)==0then
if(overlap&v)==0then
...
@@ -4222,35 +4131,35 @@ function Fusion.CanCompleteFromMappings(e,sel,eg,slots,mat_filter,fgoalcheck,tc,
...
@@ -4222,35 +4131,35 @@ function Fusion.CanCompleteFromMappings(e,sel,eg,slots,mat_filter,fgoalcheck,tc,
}
}
})
})
end
end
else
else
if not filled_single[i] then
ifnotfilled_single[i]then
-- single‐slot still unfilled
-- single‐slot still unfilled
table.insert(rem_slots,slot)
table.insert(rem_slots,slot)
end
end
end
end
end
end
-- if nothing remains, we exhausted slots, check fgoal
-- if nothing remains, we exhausted slots, check fgoal
if #rem_slots==0 then
if#rem_slots==0then
if (fgoalcheck==nil or fgoalcheck(sel)==true) and (aux.FGoalCheckAdditional==nil or aux.FGoalCheckAdditional(tc:GetOwner(),sel,tc)) and aux.TuneMagicianCheckAdditionalX(EFFECT_TUNE_MAGICIAN_F)(sel) then
ifFusion.FinalCheck(e,sel,tc,fgoalcheck,chkf)then
Fusion.LockedCodes=old_locked
Fusion.LockedCodes=old_locked
returntrue
returntrue
else
else
Fusion.LockedCodes=old_locked
Fusion.LockedCodes=old_locked
returnfalse
returnfalse
end
end
end
end
-- delegate to FusionCondition (allow_extras = true)
-- delegate to FusionCondition (allow_extras=true)
local search_cond=Fusion.BasicCondition(tc,rem_slots,mat_filter,fgoalcheck,true,sel)