Miracle
Fusion Summon 1 Fusion Monster from your Extra Deck that lists a Synchro Monster as material, by banishing Fusion Materials listed on it from your field or GY. If this Set card is destroyed by your opponent's card effect and sent to your GY: Draw 1 card.
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = FusionSpell.CreateSummonEffect(c, {
		fusfilter = s.fusfilter,
		pre_select_mat_location = LOCATION_MZONE | LOCATION_GRAVE,
		mat_operation_code_map = {
			{ [LOCATION_REMOVED] = FusionSpell.FUSION_OPERATION_GRAVE },
			{ [0xff] = FusionSpell.FUSION_OPERATION_BANISH },
		},
		extra_target = s.extra_target,
		additional_fcheck = s.fcheck,
	})
	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
	c:RegisterEffect(e1)
	--draw
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 1))
	e2:SetCategory(CATEGORY_DRAW)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_PLAYER_TARGET)
	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetCondition(s.drcon)
	e2:SetTarget(s.drtg)
	e2:SetOperation(s.drop)
	c:RegisterEffect(e2)
end

function s.fusfilter(c)
	return aux.IsMaterialListType(c, TYPE_SYNCHRO) == true
end

function s.fcheck(tp, mg, fc, mg_all)
	if fc.synchro_fusion_check ~= nil then
		if fc.synchro_fusion_check(tp, mg_all, fc) == false then
			return false
		end
	elseif not mg_all:IsExists(function(c)
		return c:IsFusionType(TYPE_SYNCHRO)
	end, 1, nil) then
		return false
	end
	return true
end

function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, tp, LOCATION_ONFIELD + LOCATION_GRAVE)
end

function s.drcon(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	return bit.band(r, 0x41) == 0x41 and rp == 1 - tp and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousPosition(POS_FACEDOWN)
end

function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetTargetPlayer(tp)
	Duel.SetTargetParam(1)
	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
end

function s.drop(e, tp, eg, ep, ev, re, r, rp)
	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
	Duel.Draw(p, d, REASON_EFFECT)
end


Miracle
Fusion Summon 1 Fusion Monster from your Extra Deck that lists a Synchro Monster as material, by banishing Fusion Materials listed on it from your field or GY. If this Set card is destroyed by your opponent's card effect and sent to your GY: Draw 1 card.
-- Miracle
local s, id, o = GetID()
function s.initial_effect(c)
	--Activate
	local e1 = FusionSpell.CreateSummonEffect(c, {
		fusfilter = s.fusfilter,
		pre_select_mat_location = LOCATION_MZONE | LOCATION_GRAVE,
		mat_operation_code_map = {
			{ [LOCATION_REMOVED] = FusionSpell.FUSION_OPERATION_GRAVE },
			{ [0xff] = FusionSpell.FUSION_OPERATION_BANISH },
		},
		extra_target = s.extra_target,
		additional_fcheck = s.fcheck,
	})
	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_SPECIAL_SUMMON + CATEGORY_FUSION_SUMMON)
	c:RegisterEffect(e1)
	--draw
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 1))
	e2:SetCategory(CATEGORY_DRAW)
	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_PLAYER_TARGET)
	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
	e2:SetCode(EVENT_TO_GRAVE)
	e2:SetCondition(s.drcon)
	e2:SetTarget(s.drtg)
	e2:SetOperation(s.drop)
	c:RegisterEffect(e2)
end

function s.fusfilter(c)
	return aux.IsMaterialListType(c, TYPE_SYNCHRO) == true
end

function s.fcheck(tp, mg, fc, mg_all)
	if fc.synchro_fusion_check ~= nil then
		if fc.synchro_fusion_check(tp, mg_all, fc) == false then
			return false
		end
	elseif not mg_all:IsExists(function(c)
		return c:IsFusionType(TYPE_SYNCHRO)
	end, 1, nil) then
		return false
	end
	return true
end

function s.extra_target(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, tp, LOCATION_ONFIELD + LOCATION_GRAVE)
end

function s.drcon(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	return bit.band(r, 0x41) == 0x41 and rp == 1 - tp and c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_ONFIELD) and c:IsPreviousPosition(POS_FACEDOWN)
end

function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetTargetPlayer(tp)
	Duel.SetTargetParam(1)
	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
end

function s.drop(e, tp, eg, ep, ev, re, r, rp)
	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
	Duel.Draw(p, d, REASON_EFFECT)
end

