Commit 172f6105 authored by Vury Leo's avatar Vury Leo

Add 幻影王 ハイド・ライド

parent 116bed88
......@@ -3377,15 +3377,21 @@ Synchro = {}
-- Use this as the "infinite" maximum count
Synchro.Infinite=math.huge
-- a tiny enum for clarity
Synchro.Role={
TUNER=1,
NON_TUNER=2,
}
--- Add Synchro procedure effect to a card using a single params table
--- @param c Card -- the Synchro monster card
--- @param params? table -- parameters table with keys: f1,f2,minc,maxc
function Synchro.AddSynchroProcedure(c,params)
params=params or {}
local tuner_race=params.tuner_race or RACE_ALL
local tuner_filter=params.tuner_filter or function(mc,tc) return mc:IsType(TYPE_TUNER) end
local tuner_filter=params.tuner_filter or Synchro.DefaultTunerFilter
local non_tuner_race=params.non_tuner_race or RACE_ALL
local non_tuner_filter=params.non_tuner_filter or function(mc,tc) return not mc:IsType(TYPE_TUNER) end
local non_tuner_filter=params.non_tuner_filter or Synchro.DefaultNonTunerFilter
local tuner_min=params.tuner_min or 1
local tuner_max=params.tuner_max or 1
local non_tuner_min=params.non_tuner_min or 1
......@@ -3474,6 +3480,7 @@ function Synchro.FindValidSelection(candidates,target_level,
hand_count=0,
genomix_race=nil,
material_limit_filter=aux.TRUE,
selected_roles={}
},
{
level_prune_index=level_prune_index,
......@@ -3540,15 +3547,25 @@ function Synchro.CanCompleteSelection(candidates,target_level,tuner_race,tuner_f
end
end
--- one time prune on selected materials considering race
--- onetime prune on selected materials considering race
if index==prune_indexes.race_prune_index+1 then
for _,sc in ipairs(selected) do
if not (prune_tuner_filter(sc) or prune_non_tuner_filter(sc)) then
return false
for i,sc in ipairs(selected) do
local role=state.selected_roles[i]
if role==Synchro.Role.TUNER then
if not prune_tuner_filter(sc,tc) then
return false
end
elseif role==Synchro.Role.NON_TUNER then
if not prune_non_tuner_filter(sc,tc) then
return false
end
else
error("Synchro.CanCompleteSelection: unknown role for selected["..i.."]")
end
end
end
if index>#candidates then
-- check if target_level achievable exactly
if state.possible_sums[target_level] and
......@@ -3571,7 +3588,7 @@ function Synchro.CanCompleteSelection(candidates,target_level,tuner_race,tuner_f
--- include branch
if can_include then
for _,diff in ipairs(Synchro.GenerateVariantForCard(
state,mc,#selected+1,tc,prune_tuner_filter,prune_non_tuner_filter
state,mc,#selected+1,tc,tuner_race,prune_tuner_filter,non_tuner_race,prune_non_tuner_filter
)) do
-- apply diff
local branch_state=Synchro.ApplyVariantState(
......@@ -3614,15 +3631,6 @@ function Synchro.SynCondition(tuner_race,tuner_filter,non_tuner_race,non_tuner_f
local smat_states=nil
local smat_arr=nil
if smat~=nil then
if not mg:IsContains(smat) then
return false
end
smat_arr={}
table.insert(smat_arr,smat)
smat_states=Synchro.BuildStatesFromSelection(smat_arr,tuner_race,tuner_filter,non_tuner_race,non_tuner_filter,base_mapper,c,math.huge)
end
local candidates={}
for mc in aux.Next(mg) do
if mc~=smat then
......@@ -3631,6 +3639,13 @@ function Synchro.SynCondition(tuner_race,tuner_filter,non_tuner_race,non_tuner_f
end
if smat~=nil then
if not mg:IsContains(smat) then
return false
end
smat_arr={}
table.insert(smat_arr,smat)
smat_states=Synchro.BuildStatesFromSelection(smat_arr,tuner_race,tuner_filter,non_tuner_race,non_tuner_filter,base_mapper,c,math.huge)
for _,state in ipairs(smat_states) do
if Synchro.FindValidSelection(candidates,target_level,tuner_race,tuner_filter,non_tuner_race,non_tuner_filter,c,tuner_min,tuner_max,non_tuner_min,non_tuner_max,base_mapper,smat_arr,state) then
return true
......@@ -3836,6 +3851,25 @@ function Synchro.LevelMapper(card,tc)
return levels
end
function Synchro.DefaultTunerFilter(mc,tc)
return mc:IsType(TYPE_TUNER)
end
function Synchro.DefaultNonTunerFilter(mc,tc)
-- if this card has EFFECT_NONTUNER, always count it as a non-Tuner
for _,e in ipairs({mc:IsHasEffect(EFFECT_NONTUNER)}) do
local v=e:GetValue()
if type(v)=="function" then
if v(e,tc) then
return true
end
elseif v then
return true
end
end
return not mc:IsType(TYPE_TUNER)
end
function Synchro.UpdatepossibleSums(possible_sums,card_levels,prune_level)
local new_sums={}
for sum, _ in pairs(possible_sums) do
......@@ -3861,6 +3895,7 @@ function Synchro.BuildStatesFromSelection(selection,tuner_race,tuner_filter,non_
hand_count=0,
genomix_race=nil,
material_limit_filter=aux.TRUE,
selected_roles={}
}
}
......@@ -3961,12 +3996,12 @@ end
-- Helper to generate only the variant-specific diffs for a card
function Synchro.GenerateVariantForCard(st,card,selected_count,tc,tuner_race,tuner_filter,non_tuner_race,non_tuner_filter)
local variants = {}
local base_variants = {}
-- MonoSynchron first/second
if Synchro.IsMono(card) then
if st.level_mapper_priority<2 then
local firstMono = card
table.insert(variants,{
table.insert(base_variants,{
possible_sums={[(selected_count-1)+card:GetLevel()]=true},
level_mapper=function(c)
return (c==firstMono) and {c:GetLevel()} or {1}
......@@ -3974,7 +4009,7 @@ function Synchro.GenerateVariantForCard(st,card,selected_count,tc,tuner_race,tun
level_mapper_priority=2,
})
elseif st.level_mapper_priority==2 then
table.insert(variants,{
table.insert(base_variants,{
possible_sums={[selected_count]=true},
level_mapper=function() return {1} end,
})
......@@ -3985,20 +4020,20 @@ function Synchro.GenerateVariantForCard(st,card,selected_count,tc,tuner_race,tun
local declared_race=card:IsHasEffect(42155488):GetLabel()
if st.genomix_race~=nil then
assert(declared_race==st.genomix_race,"we activated 2 Genomix Fighter with 2 different races but we still have monster to summon")
table.insert(variants,{})
table.insert(base_variants,{})
else
table.insert(variants,{genomix_race=declared_race})
table.insert(base_variants,{genomix_race=declared_race})
end
end
-- Normal branch
if not (Synchro.IsMandatory(card) or Synchro.IsNoHarm(card)) then
table.insert(variants,{})
table.insert(base_variants,{})
end
-- Flower Cardian override
if Synchro.IsFlower(card) and st.level_mapper_priority < 1 then
table.insert(variants,{
table.insert(base_variants,{
possible_sums={[2*selected_count]=true},
level_mapper=function() return {2} end,
level_mapper_priority=1,
......@@ -4007,11 +4042,48 @@ function Synchro.GenerateVariantForCard(st,card,selected_count,tc,tuner_race,tun
-- Tatsunoko effect
if Synchro.IsTatsunoko(card) then
table.insert(variants,{
table.insert(base_variants,{
hand_count_limit=1,
})
end
-- now wrap each base_variant in role‐specific diffs
local variants={}
local can_be_tuner=tuner_filter(card,tc)
local can_be_non_tuner=non_tuner_filter(card,tc)
for _, base in ipairs(base_variants) do
-- tuner branch
if can_be_tuner then
table.insert(variants,{
possible_sums=base.possible_sums,
level_mapper=base.level_mapper,
level_mapper_priority=base.level_mapper_priority,
hand_count_limit=base.hand_count_limit,
append_material_limit_filter=base.append_material_limit_filter,
genomix_race=base.genomix_race,
-- role-specific
tuner_delta=1,
non_tuner_delta=0,
role=Synchro.Role.TUNER,
})
end
-- non-tuner branch
if can_be_non_tuner then
table.insert(variants,{
possible_sums=base.possible_sums,
level_mapper=base.level_mapper,
level_mapper_priority=base.level_mapper_priority,
hand_count_limit=base.hand_count_limit,
append_material_limit_filter=base.append_material_limit_filter,
genomix_race=base.genomix_race,
tuner_delta=0,
non_tuner_delta=1,
role=Synchro.Role.NON_TUNER,
})
end
end
return variants
end
......@@ -4019,9 +4091,11 @@ end
-- Helper to apply a diff to a base state
function Synchro.ApplyVariantState(st,card,diff,tuner_race,tuner_filter,non_tuner_race,non_tuner_filter,tc,prune_level,append_material_limit_filter)
-- compute increments using provided filters
local tuner_inc=tuner_filter(card,tc) and 1 or 0
local non_tuner_inc=non_tuner_filter(card,tc) and 1 or 0
local tuner_inc=diff.tuner_delta
local non_tuner_inc=diff.non_tuner_delta
local hand_inc=card:IsLocation(LOCATION_HAND) and 1 or 0
local new_selected_roles={ table.unpack(st.selected_roles) }
table.insert(new_selected_roles,diff.role)
local possible_sums=Synchro.UpdatepossibleSums(
st.possible_sums,
st.level_mapper(card,tc),
......@@ -4041,6 +4115,7 @@ function Synchro.ApplyVariantState(st,card,diff,tuner_race,tuner_filter,non_tune
hand_count=st.hand_count+hand_inc,
genomix_race=diff.genomix_race or st.genomix_race,
material_limit_filter=new_material_limit_filter,
selected_roles=new_selected_roles,
}
end
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment