name: Cosmic
card_text: "Alien Ammonite" + 1 or more non-Tuner "Alien" monsters
  Once per turn, you can select any number of face-up Spell or Trap Cards. Return those cards to their owners' hands, and distribute new A-Counters among monsters on the field equal to the number of cards returned. Once per turn, you can remove 2 A-Counters from anywhere on the field to destroy 1 card your opponent controls.
external_ids: local CARD_ID_0 = 652362 --Alien Ammonite
  local SETCARD_ID_0 = 0xc --Alien
  local COUNTER_ID_0 = 0x100e --A-Counter
  
lua: local CARD_ID_0 = 652362 --Alien Ammonite
  local SETCARD_ID_0 = 0xc --Alien
  local COUNTER_ID_0 = 0x100e --A-Counter
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddMaterialCodeList(c, CARD_ID_0)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsCode, CARD_ID_0), aux.NonTuner(Card.IsSetCard, SETCARD_ID_0), 1)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_COUNTER)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCountLimit(1)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCost(s.descost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  s.counter_add_list = { 0x100e }
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  			and Duel.IsExistingMatchingCard(Card.IsCanAddCounter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, 0x100e, 1)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 16, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, g:GetCount(), 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local rg = tg:Filter(Card.IsRelateToEffect, nil, e)
  	Duel.SendtoHand(rg, nil, REASON_EFFECT)
  	local ct = rg:FilterCount(Card.IsLocation, nil, LOCATION_HAND)
  	local g = Duel.GetMatchingGroup(Card.IsCanAddCounter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, 0x100e, 1)
  	if ct == 0 or g:GetCount() == 0 then
  		return
  	end
  	for i = 1, ct do
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_COUNTER)
  		local sg = g:Select(tp, 1, 1, nil)
  		sg:GetFirst():AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsCanRemoveCounter(tp, 1, 1, COUNTER_ID_0, 2, REASON_COST)
  	end
  	Duel.RemoveCounter(tp, 1, 1, COUNTER_ID_0, 2, REASON_COST)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  
  
source_text: Cosmic
  "Alien Ammonite" + 1 or more non-Tuner "Alien" monsters
  Once per turn, you can select any number of face-up Spell or Trap Cards. Return those cards to their owners' hands, and distribute new A-Counters among monsters on the field equal to the number of cards returned. Once per turn, you can remove 2 A-Counters from anywhere on the field to destroy 1 card your opponent controls.
target_text: -- Cosmic
  local CARD_ID_0 = 652362 --Alien Ammonite
  local SETCARD_ID_0 = 0xc --Alien
  local COUNTER_ID_0 = 0x100e --A-Counter
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddMaterialCodeList(c, CARD_ID_0)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsCode, CARD_ID_0), aux.NonTuner(Card.IsSetCard, SETCARD_ID_0), 1)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_COUNTER)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetCountLimit(1)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCost(s.descost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  s.counter_add_list = { 0x100e }
  function s.filter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  			and Duel.IsExistingMatchingCard(Card.IsCanAddCounter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, 0x100e, 1)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 16, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, g:GetCount(), 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS)
  	local rg = tg:Filter(Card.IsRelateToEffect, nil, e)
  	Duel.SendtoHand(rg, nil, REASON_EFFECT)
  	local ct = rg:FilterCount(Card.IsLocation, nil, LOCATION_HAND)
  	local g = Duel.GetMatchingGroup(Card.IsCanAddCounter, tp, LOCATION_MZONE, LOCATION_MZONE, nil, 0x100e, 1)
  	if ct == 0 or g:GetCount() == 0 then
  		return
  	end
  	for i = 1, ct do
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_COUNTER)
  		local sg = g:Select(tp, 1, 1, nil)
  		sg:GetFirst():AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsCanRemoveCounter(tp, 1, 1, COUNTER_ID_0, 2, REASON_COST)
  	end
  	Duel.RemoveCounter(tp, 1, 1, COUNTER_ID_0, 2, REASON_COST)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(1 - tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.Destroy(tc, REASON_EFFECT)
  	end
  end
  
  