Commit e28927ef authored by Vury Leo's avatar Vury Leo

new fusion check for necrovalley

parent 0c3fc674
...@@ -89,7 +89,7 @@ function s.thop(e,tp,eg,ep,ev,re,r,rp) ...@@ -89,7 +89,7 @@ function s.thop(e,tp,eg,ep,ev,re,r,rp)
e1:SetTargetRange(LOCATION_GRAVE,0) e1:SetTargetRange(LOCATION_GRAVE,0)
e1:SetTarget(function(_,c) return c:IsAbleToRemove() and c:IsType(TYPE_MONSTER) end) e1:SetTarget(function(_,c) return c:IsAbleToRemove() and c:IsType(TYPE_MONSTER) end)
e1:SetOperation(function() return FusionSpell.FUSION_OPERATION_BANISH end) e1:SetOperation(function() return FusionSpell.FUSION_OPERATION_BANISH end)
e1:SetValue(function(fusion_effect,c) return c and c:IsSetCard(0xdf) and c:IsControler(fusion_effect:GetHandlerPlayer()) end) e1:SetValue(function(extra_material_effect,c) return c and c:IsSetCard(0xdf) and c:IsControler(extra_material_effect:GetHandlerPlayer()) end)
e1:SetReset(RESET_PHASE|PHASE_END) e1:SetReset(RESET_PHASE|PHASE_END)
Duel.RegisterEffect(e1,tp) Duel.RegisterEffect(e1,tp)
end end
......
...@@ -64,7 +64,7 @@ function s.thop(e,tp,eg,ep,ev,re,r,rp) ...@@ -64,7 +64,7 @@ function s.thop(e,tp,eg,ep,ev,re,r,rp)
e2:SetCountLimit(1) e2:SetCountLimit(1)
e2:SetTarget(s.mttg) e2:SetTarget(s.mttg)
e2:SetOperation(function() return FusionSpell.FUSION_OPERATION_BANISH end) e2:SetOperation(function() return FusionSpell.FUSION_OPERATION_BANISH end)
e2:SetValue(function(fusion_effect,c) return c and c:IsControler(fusion_effect:GetHandlerPlayer()) end) e2:SetValue(function(extra_material_effect,c) return c and c:IsControler(extra_material_effect:GetHandlerPlayer()) end)
e2:SetReset(RESET_PHASE+PHASE_END) e2:SetReset(RESET_PHASE+PHASE_END)
Duel.RegisterEffect(e2,tp) Duel.RegisterEffect(e2,tp)
end end
......
...@@ -12,7 +12,8 @@ function s.initial_effect(c) ...@@ -12,7 +12,8 @@ function s.initial_effect(c)
{ [LOCATION_DECK] = FusionSpell.FUSION_OPERATION_GRAVE }, { [LOCATION_DECK] = FusionSpell.FUSION_OPERATION_GRAVE },
{ [0xff] = FusionSpell.FUSION_OPERATION_SHUFFLE } { [0xff] = FusionSpell.FUSION_OPERATION_SHUFFLE }
}, },
extra_target=s.extra_target extra_target=s.extra_target,
stage_x_operation=s.stage_x_operation
}) })
e1:SetDescription(aux.Stringid(id,0)) e1:SetDescription(aux.Stringid(id,0))
e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O) e1:SetType(EFFECT_TYPE_SINGLE+EFFECT_TYPE_TRIGGER_O)
...@@ -49,3 +50,30 @@ function s.extra_target(e,tp,eg,ep,ev,re,r,rp,chk) ...@@ -49,3 +50,30 @@ function s.extra_target(e,tp,eg,ep,ev,re,r,rp,chk)
end end
Duel.SetOperationInfo(0,CATEGORY_TODECK,nil,1,tp,LOCATION_ONFIELD+LOCATION_GRAVE+LOCATION_REMOVED) Duel.SetOperationInfo(0,CATEGORY_TODECK,nil,1,tp,LOCATION_ONFIELD+LOCATION_GRAVE+LOCATION_REMOVED)
end end
---@type FUSION_SPELL_STAGE_X_CALLBACK_FUNCTION
function s.stage_x_operation(e,tc,tp,stage)
if stage==FusionSpell.STAGE_AT_ALL_OPERATION_FINISH then
local c=e:GetHandler()
if c:IsRelateToChain() then
local e1=Effect.CreateEffect(c)
e1:SetType(EFFECT_TYPE_SINGLE)
e1:SetCode(EFFECT_CANNOT_ATTACK)
e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
e1:SetReset(RESET_EVENT+RESETS_STANDARD+RESET_PHASE+PHASE_END)
c:RegisterEffect(e1)
end
local e2=Effect.CreateEffect(c)
e2:SetType(EFFECT_TYPE_FIELD)
e2:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
e2:SetTargetRange(1,0)
e2:SetReset(RESET_PHASE+PHASE_END)
e2:SetTarget(s.splimit)
Duel.RegisterEffect(e2,tp)
end
end
function s.splimit(e,c)
return not c:IsType(TYPE_FUSION) and c:IsLocation(LOCATION_EXTRA)
end
\ No newline at end of file
...@@ -36,7 +36,7 @@ function s.initial_effect(c) ...@@ -36,7 +36,7 @@ function s.initial_effect(c)
e4:SetTarget(function(_,mc) return mc:IsFaceup() and mc:IsType(TYPE_MONSTER) end) e4:SetTarget(function(_,mc) return mc:IsFaceup() and mc:IsType(TYPE_MONSTER) end)
e4:SetCost(s.extra_material_cost) e4:SetCost(s.extra_material_cost)
e4:SetOperation(function() return FusionSpell.FUSION_OPERATION_INHERIT end) e4:SetOperation(function() return FusionSpell.FUSION_OPERATION_INHERIT end)
e4:SetValue(function(fusion_effect,tc) return tc and tc:IsSetCard(0x9d) and tc:IsControler(fusion_effect:GetHandlerPlayer()) end) e4:SetValue(function(extra_material_effect,tc) return tc and tc:IsSetCard(0x9d) and tc:IsControler(extra_material_effect:GetHandlerPlayer()) end)
e4:SetLabel(1) --- at most 1 material per fusion effect e4:SetLabel(1) --- at most 1 material per fusion effect
c:RegisterEffect(e4) c:RegisterEffect(e4)
end end
......
...@@ -32,7 +32,7 @@ function s.fusop(e,tp,eg,ep,ev,re,r,rp) ...@@ -32,7 +32,7 @@ function s.fusop(e,tp,eg,ep,ev,re,r,rp)
e1:SetTargetRange(LOCATION_EXTRA,0) e1:SetTargetRange(LOCATION_EXTRA,0)
e1:SetTarget(function(_,c) return c:IsAbleToGrave() and c:IsType(TYPE_MONSTER) and c:IsSetCard(0x4) end) e1:SetTarget(function(_,c) return c:IsAbleToGrave() and c:IsType(TYPE_MONSTER) and c:IsSetCard(0x4) end)
e1:SetOperation(function() return FusionSpell.FUSION_OPERATION_GRAVE end) e1:SetOperation(function() return FusionSpell.FUSION_OPERATION_GRAVE end)
e1:SetValue(function(fusion_effect,c) return c and c:IsSetCard(0x4) and c:IsControler(fusion_effect:GetHandlerPlayer()) end) e1:SetValue(function(extra_material_effect,c) return c and c:IsSetCard(0x4) and c:IsControler(extra_material_effect:GetHandlerPlayer()) end)
e1:SetLabel(1) --- at most 1 material per fusion effect e1:SetLabel(1) --- at most 1 material per fusion effect
e1:SetReset(RESET_PHASE|PHASE_END) e1:SetReset(RESET_PHASE|PHASE_END)
Duel.RegisterEffect(e1,tp) Duel.RegisterEffect(e1,tp)
......
...@@ -2467,7 +2467,7 @@ function FusionSpell.GetSummonTarget( ...@@ -2467,7 +2467,7 @@ function FusionSpell.GetSummonTarget(
end end
-- --- check for chain material targets -- --- check for chain material targets
if sumtype&SUMMON_TYPE_FUSION~=0 then if sumtype&SUMMON_TYPE_FUSION~=0 then
local ce_sg=FusionSpell.IsExistsChainMaterialSummonTargets(e,tp,fusfilter,additional_fcheck,additional_fgoalcheck,fuslocation,sumtype,sumpos,gc) local ce_sg=FusionSpell.IsExistsChainMaterialSummonTargets(e,tp,fusfilter,matfilter,additional_fcheck,additional_fgoalcheck,fuslocation,sumtype,sumpos,gc)
if ce_sg==true then if ce_sg==true then
return true return true
end end
...@@ -2480,7 +2480,7 @@ function FusionSpell.GetSummonTarget( ...@@ -2480,7 +2480,7 @@ function FusionSpell.GetSummonTarget(
end end
---@param fusfilter fun(c:Card):boolean filter for the monster to be Fusion Summoned ---@param fusfilter fun(c:Card):boolean filter for the monster to be Fusion Summoned
---@param matfilter fun(c:Card):boolean filter for the materials, use it only under very strong limitation like D-Fusion. ---@param matfilter fun(c:Card):boolean filter for the materials, use it only under very strong limitation like D-フュージョン.
---@param pre_select_mat_location integer|FUSION_SPELL_PRE_SELECT_MAT_LOCATION_FUNCTION location where to find the materials before known the materials ---@param pre_select_mat_location integer|FUSION_SPELL_PRE_SELECT_MAT_LOCATION_FUNCTION location where to find the materials before known the materials
---@param mat_operation_code_map {[integer]:FUSION_OPERATION_CODE}[] operation code to do for the materials, it will be check in order ---@param mat_operation_code_map {[integer]:FUSION_OPERATION_CODE}[] operation code to do for the materials, it will be check in order
---@param post_select_mat_location integer? location where to find the materials after known the materials ---@param post_select_mat_location integer? location where to find the materials after known the materials
...@@ -2508,35 +2508,31 @@ function FusionSpell.GetSummonOperation( ...@@ -2508,35 +2508,31 @@ function FusionSpell.GetSummonOperation(
gc gc
) )
return function(e,tp,eg,ep,ev,re,r,rp) return function(e,tp,eg,ep,ev,re,r,rp)
local fusion_targets=Group.CreateGroup()
local sg=Duel.GetMatchingGroup( local sg=Duel.GetMatchingGroup(
FusionSpell.SummonTargetFilter,tp,fuslocation,0,nil, FusionSpell.SummonTargetFilter,tp,fuslocation,0,nil,
--- FusionSpell.SummonTargetFilter param --- FusionSpell.SummonTargetFilter param
fusfilter,matfilter,e,tp,pre_select_mat_location,mat_operation_code_map,post_select_mat_location,additional_fcheck,additional_fgoalcheck,sumtype,sumpos,pre_select_mat_opponent_location,gc) fusfilter,aux.NecroValleyFilter(matfilter),e,tp,pre_select_mat_location,mat_operation_code_map,post_select_mat_location,additional_fcheck,additional_fgoalcheck,sumtype,sumpos,pre_select_mat_opponent_location,gc)
fusion_targets:Merge(sg)
--- check for chain material targets --- check for chain material targets
local ce_sgs={} local ce_sgs={}
local can_chain_material=false
if sumtype&SUMMON_TYPE_FUSION~=0 then if sumtype&SUMMON_TYPE_FUSION~=0 then
ce_sgs=FusionSpell.ListChainMaterialSummonTargets(e,tp,fusfilter,additional_fcheck,additional_fgoalcheck,fuslocation,sumtype,sumpos,gc) ce_sgs=FusionSpell.ListChainMaterialSummonTargets(e,tp,fusfilter,aux.NecroValleyFilter(matfilter),additional_fcheck,additional_fgoalcheck,fuslocation,sumtype,sumpos,gc)
--- if there's any chain material effect has valid target --- add chain material targets
for _ in pairs(ce_sgs) do for _,ce_sg in pairs(ce_sgs) do
can_chain_material=true fusion_targets:Merge(ce_sg)
break
end end
end end
local tc=nil local tc=nil
if #sg>0 or can_chain_material==true then if #fusion_targets>0 then
local materials=Group.CreateGroup() local materials=Group.CreateGroup()
local fusion_effect=nil local fusion_effect=nil
local fusion_succeeded=false local fusion_succeeded=false
while #materials==0 do while #materials==0 do
Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON) Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
---@type Group
local fusion_targets=sg:Clone()
for _, ce_sg in pairs(ce_sgs) do
fusion_targets:Merge(ce_sg)
end
tc=fusion_targets:Select(tp,1,1,nil):GetFirst() tc=fusion_targets:Select(tp,1,1,nil):GetFirst()
...@@ -2561,7 +2557,7 @@ function FusionSpell.GetSummonOperation( ...@@ -2561,7 +2557,7 @@ function FusionSpell.GetSummonOperation(
tc, tc,
tp, tp,
e, e,
matfilter, aux.NecroValleyFilter(matfilter),
pre_select_mat_location, pre_select_mat_location,
mat_operation_code_map, mat_operation_code_map,
post_select_mat_location, post_select_mat_location,
...@@ -2576,7 +2572,7 @@ function FusionSpell.GetSummonOperation( ...@@ -2576,7 +2572,7 @@ function FusionSpell.GetSummonOperation(
--- use chain material effect --- use chain material effect
---@type function ---@type function
local chain_material_filter=fusion_effect:GetTarget() local chain_material_filter=fusion_effect:GetTarget()
local chain_mg=chain_material_filter(fusion_effect,e,tp) local chain_mg=chain_material_filter(fusion_effect,e,tp):Filter(aux.NecroValleyFilter(matfilter),nil)
assert(#chain_mg>0, "we are trying to apply a chain material, but it has no possible material") assert(#chain_mg>0, "we are trying to apply a chain material, but it has no possible material")
aux.FCheckAdditional=FusionSpell.GetFusionSpellFCheckAdditionalFunctionForChainMaterial(additional_fcheck) aux.FCheckAdditional=FusionSpell.GetFusionSpellFCheckAdditionalFunctionForChainMaterial(additional_fcheck)
aux.FGoalCheckAdditional=FusionSpell.GetFusionSpellFGoalCheckAdditionalFunctionForChainMaterial(additional_fgoalcheck) aux.FGoalCheckAdditional=FusionSpell.GetFusionSpellFGoalCheckAdditionalFunctionForChainMaterial(additional_fgoalcheck)
...@@ -2678,7 +2674,7 @@ function FusionSpell.GetSummonOperation( ...@@ -2678,7 +2674,7 @@ function FusionSpell.GetSummonOperation(
end end
-- before do the operations to the materials, hint the opponent selected materials -- before do the operations to the materials, hint the opponent selected materials
local confirm_materials=materials:Filter(Card.IsLocation,nil,LOCATION_HAND|LOCATION_EXTRA|LOCATION_DECK) local confirm_materials=materials:Filter(function(c) return c:IsLocation(LOCATION_HAND|LOCATION_EXTRA|LOCATION_DECK) or c:IsFacedown() end,nil)
if #confirm_materials>0 then if #confirm_materials>0 then
Duel.ConfirmCards(1-tp,confirm_materials) Duel.ConfirmCards(1-tp,confirm_materials)
end end
...@@ -2848,14 +2844,15 @@ end ...@@ -2848,14 +2844,15 @@ end
---@return {[Effect]:Group} effect_targets_map Return a map of different chain material to potiential fusion targets ---@return {[Effect]:Group} effect_targets_map Return a map of different chain material to potiential fusion targets
---@param gc fun(e:Effect):Card|nil ---@param gc fun(e:Effect):Card|nil
function FusionSpell.ListChainMaterialSummonTargets(e,tp,fusfilter,additional_fcheck,additional_fgoalcheck,fuslocation,sumtype,sumpos,gc) function FusionSpell.ListChainMaterialSummonTargets(e,tp,fusfilter,matfilter,additional_fcheck,additional_fgoalcheck,fuslocation,sumtype,sumpos,gc)
local chain_material_effects={Duel.IsPlayerAffectedByEffect(tp,EFFECT_CHAIN_MATERIAL)} local chain_material_effects={Duel.IsPlayerAffectedByEffect(tp,EFFECT_CHAIN_MATERIAL)}
---@type {[Effect]:Group} ---@type {[Effect]:Group}
local chain_material_targets={} local chain_material_targets={}
for _,ce in ipairs(chain_material_effects) do for _,ce in ipairs(chain_material_effects) do
---@type function ---@type function
local chain_material_filter=ce:GetTarget() local chain_material_filter=ce:GetTarget()
local chain_mg=chain_material_filter(ce,e,tp) ---@type Group
local chain_mg=chain_material_filter(ce,e,tp):Filter(matfilter,nil)
if #chain_mg>0 then if #chain_mg>0 then
local ce_fusfilter=ce:GetValue() local ce_fusfilter=ce:GetValue()
local ce_sg=Duel.GetMatchingGroup(FusionSpell.ChainMaterialSummonTargetFilter,tp,fuslocation,0,nil, local ce_sg=Duel.GetMatchingGroup(FusionSpell.ChainMaterialSummonTargetFilter,tp,fuslocation,0,nil,
...@@ -2871,13 +2868,13 @@ end ...@@ -2871,13 +2868,13 @@ end
---@return boolean res return whether there is a valid target for any chain material effect ---@return boolean res return whether there is a valid target for any chain material effect
---@param gc fun(e:Effect):Card|nil ---@param gc fun(e:Effect):Card|nil
function FusionSpell.IsExistsChainMaterialSummonTargets(e,tp,fusfilter,additional_fcheck,additional_fgoalcheck,fuslocation,sumtype,sumpos,gc) function FusionSpell.IsExistsChainMaterialSummonTargets(e,tp,fusfilter,matfilter,additional_fcheck,additional_fgoalcheck,fuslocation,sumtype,sumpos,gc)
local chain_material_effects={Duel.IsPlayerAffectedByEffect(tp,EFFECT_CHAIN_MATERIAL)} local chain_material_effects={Duel.IsPlayerAffectedByEffect(tp,EFFECT_CHAIN_MATERIAL)}
---@type {[Effect]:Group} ---@type {[Effect]:Group}
for _,ce in ipairs(chain_material_effects) do for _,ce in ipairs(chain_material_effects) do
---@type function ---@type function
local chain_material_filter=ce:GetTarget() local chain_material_filter=ce:GetTarget()
local chain_mg=chain_material_filter(ce,e,tp) local chain_mg=chain_material_filter(ce,e,tp):Filter(matfilter)
if #chain_mg>0 then if #chain_mg>0 then
local ce_fusfilter=ce:GetValue() local ce_fusfilter=ce:GetValue()
local res=Duel.IsExistingMatchingCard(FusionSpell.ChainMaterialSummonTargetFilter,tp,fuslocation,0,1,nil, local res=Duel.IsExistingMatchingCard(FusionSpell.ChainMaterialSummonTargetFilter,tp,fuslocation,0,1,nil,
......
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