name: Crystal
card_text: 2+ Tuners or 1 Tuner Synchro Monster + "Clear Wing Synchro Dragon"
  Must be Synchro Summoned. Once per turn, when another card, or its effect, is activated (Quick Effect): You can negate the activation, and if you do, destroy that card, and if you destroyed a monster, this card gains ATK equal to that monster's original ATK until the end of this turn. If this face-up Synchro Summoned card in its owner's control leaves the field by an opponent's card: You can Special Summon 1 "Clear Wing" monster from your Extra Deck.
external_ids: local CARD_ID_0 = 82044279 --Clear Wing Synchro Dragon
  local SETCARD_ID_0 = 0xff --Clear
  
lua: local CARD_ID_0 = 82044279 --Clear Wing Synchro Dragon
  local SETCARD_ID_0 = 0xff --Clear
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--material
  	aux.AddSynchroMixProcedure(c, aux.FilterBoolFunction(Card.IsCode, CARD_ID_0), nil, nil, aux.Tuner(nil), 1, 99, s.syncheck)
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.synlimit)
  	c:RegisterEffect(e1)
  	--negate
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.negcon)
  	e2:SetTarget(s.negtg)
  	e2:SetOperation(s.negop)
  	c:RegisterEffect(e2)
  	--special summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.mgcheck(c, mg)
  	local rg = mg - c
  	if c:IsCode(CARD_ID_0) then
  		return (rg:IsExists(Card.IsType, 1, nil, TYPE_SYNCHRO) or #rg >= 2) and not rg:IsExists(s.chkfilter, 1, nil)
  	else
  		return false
  	end
  end
  function s.chkfilter(c)
  	return not c:IsTuner(c)
  end
  function s.syncheck(g)
  	return g:IsExists(s.mgcheck, 1, nil, g)
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev)
  end
  function s.negtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local rc = re:GetHandler()
  	if
  		Duel.NegateActivation(ev)
  		and rc:IsRelateToEffect(re)
  		and Duel.Destroy(rc, REASON_EFFECT) ~= 0
  		and rc:GetBaseAttack() >= 0
  		and not rc:IsPreviousLocation(LOCATION_SZONE)
  		and (rc:IsPreviousLocation(LOCATION_MZONE) or rc:GetOriginalType() & TYPE_MONSTER ~= 0)
  		and c:IsRelateToEffect(e)
  		and c:IsFaceup()
  	then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END)
  		e1:SetValue(rc:GetBaseAttack())
  		c:RegisterEffect(e1)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsSummonType(SUMMON_TYPE_SYNCHRO) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousControler(tp) and c:GetReasonPlayer() == 1 - tp
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Crystal
  2+ Tuners or 1 Tuner Synchro Monster + "Clear Wing Synchro Dragon"
  Must be Synchro Summoned. Once per turn, when another card, or its effect, is activated (Quick Effect): You can negate the activation, and if you do, destroy that card, and if you destroyed a monster, this card gains ATK equal to that monster's original ATK until the end of this turn. If this face-up Synchro Summoned card in its owner's control leaves the field by an opponent's card: You can Special Summon 1 "Clear Wing" monster from your Extra Deck.
target_text: -- Crystal
  local CARD_ID_0 = 82044279 --Clear Wing Synchro Dragon
  local SETCARD_ID_0 = 0xff --Clear
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--material
  	aux.AddSynchroMixProcedure(c, aux.FilterBoolFunction(Card.IsCode, CARD_ID_0), nil, nil, aux.Tuner(nil), 1, 99, s.syncheck)
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.synlimit)
  	c:RegisterEffect(e1)
  	--negate
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.negcon)
  	e2:SetTarget(s.negtg)
  	e2:SetOperation(s.negop)
  	c:RegisterEffect(e2)
  	--special summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_LEAVE_FIELD)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.mgcheck(c, mg)
  	local rg = mg - c
  	if c:IsCode(CARD_ID_0) then
  		return (rg:IsExists(Card.IsType, 1, nil, TYPE_SYNCHRO) or #rg >= 2) and not rg:IsExists(s.chkfilter, 1, nil)
  	else
  		return false
  	end
  end
  function s.chkfilter(c)
  	return not c:IsTuner(c)
  end
  function s.syncheck(g)
  	return g:IsExists(s.mgcheck, 1, nil, g)
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev)
  end
  function s.negtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local rc = re:GetHandler()
  	if
  		Duel.NegateActivation(ev)
  		and rc:IsRelateToEffect(re)
  		and Duel.Destroy(rc, REASON_EFFECT) ~= 0
  		and rc:GetBaseAttack() >= 0
  		and not rc:IsPreviousLocation(LOCATION_SZONE)
  		and (rc:IsPreviousLocation(LOCATION_MZONE) or rc:GetOriginalType() & TYPE_MONSTER ~= 0)
  		and c:IsRelateToEffect(e)
  		and c:IsFaceup()
  	then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE + RESET_PHASE + PHASE_END)
  		e1:SetValue(rc:GetBaseAttack())
  		c:RegisterEffect(e1)
  	end
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsSummonType(SUMMON_TYPE_SYNCHRO) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousControler(tp) and c:GetReasonPlayer() == 1 - tp
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  