name: Cosmic
card_text: 1 Tuner Synchro Monster + 2+ non-Tuner Synchro Monsters
  Must be Synchro Summoned. (Quick Effect): You can banish this card until the End Phase to activate 1 of these effects;
  ● When your opponent activates a card or effect: Negate the activation, and if you do, destroy that card.
  ● When your opponent would Summon a monster(s): Negate the Summon, and if you do, destroy that monster(s).
  ● When an opponent's monster declares an attack: Negate the attack, then end the Battle Phase.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsSynchroType, TYPE_SYNCHRO), aux.NonTuner(Card.IsSynchroType, TYPE_SYNCHRO), 2)
  	c:EnableReviveLimit()
  	--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:SetCountLimit(1)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.discon)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  	--disable spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DISABLE_SUMMON + CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EVENT_SUMMON)
  	e3:SetCondition(s.dscon)
  	e3:SetCost(s.cost)
  	e3:SetTarget(s.dstg)
  	e3:SetOperation(s.dsop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_FLIP_SUMMON)
  	c:RegisterEffect(e4)
  	local e5 = e3:Clone()
  	e5:SetCode(EVENT_SPSUMMON)
  	c:RegisterEffect(e5)
  	--negate attack
  	local e6 = Effect.CreateEffect(c)
  	e6:SetDescription(aux.Stringid(id, 2))
  	e6:SetType(EFFECT_TYPE_QUICK_O)
  	e6:SetRange(LOCATION_MZONE)
  	e6:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e6:SetCountLimit(1)
  	e6:SetCondition(s.negcon)
  	e6:SetCost(s.cost)
  	e6:SetOperation(s.negop)
  	c:RegisterEffect(e6)
  end
  s.material_type = TYPE_SYNCHRO
  s.cosmic_quasar_dragon_summon = true
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToRemoveAsCost()
  	end
  	if Duel.Remove(c, 0, REASON_COST + REASON_TEMPORARY) ~= 0 and c:GetOriginalCode() == id then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_END)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		e1:SetLabelObject(c)
  		e1:SetCountLimit(1)
  		e1:SetOperation(s.retop)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.distg(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.disop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  function s.dscon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == 1 - tp and Duel.GetCurrentChain() == 0
  end
  function s.dstg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE_SUMMON, eg, eg:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, eg:GetCount(), 0, 0)
  end
  function s.dsop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateSummon(eg)
  	Duel.Destroy(eg, REASON_EFFECT)
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateAttack() then
  		Duel.BreakEffect()
  		Duel.SkipPhase(1 - tp, PHASE_BATTLE, RESET_PHASE + PHASE_BATTLE_STEP, 1)
  	end
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ReturnToField(e:GetLabelObject())
  end
  
  
source_text: Cosmic
  1 Tuner Synchro Monster + 2+ non-Tuner Synchro Monsters
  Must be Synchro Summoned. (Quick Effect): You can banish this card until the End Phase to activate 1 of these effects;
  ● When your opponent activates a card or effect: Negate the activation, and if you do, destroy that card.
  ● When your opponent would Summon a monster(s): Negate the Summon, and if you do, destroy that monster(s).
  ● When an opponent's monster declares an attack: Negate the attack, then end the Battle Phase.
target_text: -- Cosmic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsSynchroType, TYPE_SYNCHRO), aux.NonTuner(Card.IsSynchroType, TYPE_SYNCHRO), 2)
  	c:EnableReviveLimit()
  	--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:SetCountLimit(1)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.discon)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  	--disable spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DISABLE_SUMMON + CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCode(EVENT_SUMMON)
  	e3:SetCondition(s.dscon)
  	e3:SetCost(s.cost)
  	e3:SetTarget(s.dstg)
  	e3:SetOperation(s.dsop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_FLIP_SUMMON)
  	c:RegisterEffect(e4)
  	local e5 = e3:Clone()
  	e5:SetCode(EVENT_SPSUMMON)
  	c:RegisterEffect(e5)
  	--negate attack
  	local e6 = Effect.CreateEffect(c)
  	e6:SetDescription(aux.Stringid(id, 2))
  	e6:SetType(EFFECT_TYPE_QUICK_O)
  	e6:SetRange(LOCATION_MZONE)
  	e6:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e6:SetCountLimit(1)
  	e6:SetCondition(s.negcon)
  	e6:SetCost(s.cost)
  	e6:SetOperation(s.negop)
  	c:RegisterEffect(e6)
  end
  s.material_type = TYPE_SYNCHRO
  s.cosmic_quasar_dragon_summon = true
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToRemoveAsCost()
  	end
  	if Duel.Remove(c, 0, REASON_COST + REASON_TEMPORARY) ~= 0 and c:GetOriginalCode() == id then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		e1:SetCode(EVENT_PHASE + PHASE_END)
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		e1:SetLabelObject(c)
  		e1:SetCountLimit(1)
  		e1:SetOperation(s.retop)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.distg(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.disop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  function s.dscon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == 1 - tp and Duel.GetCurrentChain() == 0
  end
  function s.dstg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DISABLE_SUMMON, eg, eg:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, eg:GetCount(), 0, 0)
  end
  function s.dsop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateSummon(eg)
  	Duel.Destroy(eg, REASON_EFFECT)
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetAttacker():IsControler(1 - tp)
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateAttack() then
  		Duel.BreakEffect()
  		Duel.SkipPhase(1 - tp, PHASE_BATTLE, RESET_PHASE + PHASE_BATTLE_STEP, 1)
  	end
  end
  function s.retop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.ReturnToField(e:GetLabelObject())
  end
  
  