name: De-Fusion
card_text: Target 1 Fusion Monster on the field; return that target to the Extra Deck, then, if all the materials that were used for its Fusion Summon are in your GY, you can Special Summon all of them.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOEXTRA + CATEGORY_SPECIAL_SUMMON + CATEGORY_GRAVE_SPSUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_FUSION) and c:IsAbleToExtra()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, g, 1, 0, 0)
  end
  function s.mgfilter(c, e, tp, fusc, mg)
  	return c:IsControler(tp)
  		and c:IsLocation(LOCATION_GRAVE)
  		and c:GetReason() & (REASON_FUSION + REASON_MATERIAL) == (REASON_FUSION + REASON_MATERIAL)
  		and c:GetReasonCard() == fusc
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and fusc:CheckFusionMaterial(mg, c, PLAYER_NONE, true)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not (tc:IsRelateToEffect(e) and tc:IsFaceup()) then
  		return
  	end
  	local mg = tc:GetMaterial()
  	local ct = mg:GetCount()
  	if
  		Duel.SendtoDeck(tc, nil, SEQ_DECKTOP, REASON_EFFECT) ~= 0
  		and tc:IsLocation(LOCATION_EXTRA)
  		and tc:IsSummonType(SUMMON_TYPE_FUSION)
  		and ct > 0
  		and ct <= Duel.GetLocationCount(tp, LOCATION_MZONE)
  		and (not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) or ct == 1)
  		and mg:FilterCount(aux.NecroValleyFilter(s.mgfilter), nil, e, tp, tc, mg) == ct
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 0))
  	then
  		Duel.BreakEffect()
  		Duel.SpecialSummon(mg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: De-Fusion
  Target 1 Fusion Monster on the field; return that target to the Extra Deck, then, if all the materials that were used for its Fusion Summon are in your GY, you can Special Summon all of them.
target_text: -- De-Fusion
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOEXTRA + CATEGORY_SPECIAL_SUMMON + CATEGORY_GRAVE_SPSUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_FUSION) and c:IsAbleToExtra()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, g, 1, 0, 0)
  end
  function s.mgfilter(c, e, tp, fusc, mg)
  	return c:IsControler(tp)
  		and c:IsLocation(LOCATION_GRAVE)
  		and c:GetReason() & (REASON_FUSION + REASON_MATERIAL) == (REASON_FUSION + REASON_MATERIAL)
  		and c:GetReasonCard() == fusc
  		and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  		and fusc:CheckFusionMaterial(mg, c, PLAYER_NONE, true)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not (tc:IsRelateToEffect(e) and tc:IsFaceup()) then
  		return
  	end
  	local mg = tc:GetMaterial()
  	local ct = mg:GetCount()
  	if
  		Duel.SendtoDeck(tc, nil, SEQ_DECKTOP, REASON_EFFECT) ~= 0
  		and tc:IsLocation(LOCATION_EXTRA)
  		and tc:IsSummonType(SUMMON_TYPE_FUSION)
  		and ct > 0
  		and ct <= Duel.GetLocationCount(tp, LOCATION_MZONE)
  		and (not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) or ct == 1)
  		and mg:FilterCount(aux.NecroValleyFilter(s.mgfilter), nil, e, tp, tc, mg) == ct
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 0))
  	then
  		Duel.BreakEffect()
  		Duel.SpecialSummon(mg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  