name: Zexal
card_text: Special Summon 1 "ZW -" or "ZS -" monster from your hand, then, if you control a "Utopia" monster, you can make all monsters you currently control become all Level 4 or all Level 5. During your Main Phase, except the turn this card was sent to the GY: You can banish 1 "ZW -" or "ZS -" monster and this card from your GY, then target 1 card your opponent controls; destroy it. You can only use each effect of "Zexal Catapult" once per turn.
external_ids: local SETCARD_ID_0 = 0x107f --Utopia
  local SETCARD_ID_1 = 0x107e --ZW
  
lua: local SETCARD_ID_0 = 0x107f --Utopia
  local SETCARD_ID_1 = 0x107e --ZW
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	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_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(s.descost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1, 0x207e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1)
  end
  function s.lvfilter(c)
  	return c:IsFaceup() and c:IsLevelAbove(0) and (not c:IsLevel(4) or not c:IsLevel(5))
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	if
  		sg:GetCount() > 0
  		and Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP) > 0
  		and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  		and Duel.IsExistingMatchingCard(s.lvfilter, tp, LOCATION_MZONE, 0, 1, nil)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  	then
  		Duel.BreakEffect()
  		local g = Duel.GetMatchingGroup(s.lvfilter, tp, LOCATION_MZONE, 0, nil)
  		local lv = 0
  		if g:FilterCount(Card.IsLevel, nil, 5) == #g then
  			lv = 4
  		end
  		if g:FilterCount(Card.IsLevel, nil, 4) == #g then
  			lv = 5
  		end
  		if lv == 0 then
  			lv = Duel.AnnounceNumber(tp, 4, 5)
  		end
  		local lc = g:GetFirst()
  		while lc do
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_CHANGE_LEVEL)
  			e1:SetValue(lv)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			lc:RegisterEffect(e1)
  			lc = g:GetNext()
  		end
  	end
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_1, 0x207e) and c:IsAbleToRemoveAsCost()
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, c)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, c)
  	g:AddCard(c)
  	Duel.Remove(g, POS_FACEUP, 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: Zexal
  Special Summon 1 "ZW -" or "ZS -" monster from your hand, then, if you control a "Utopia" monster, you can make all monsters you currently control become all Level 4 or all Level 5. During your Main Phase, except the turn this card was sent to the GY: You can banish 1 "ZW -" or "ZS -" monster and this card from your GY, then target 1 card your opponent controls; destroy it. You can only use each effect of "Zexal Catapult" once per turn.
target_text: -- Zexal
  local SETCARD_ID_0 = 0x107f --Utopia
  local SETCARD_ID_1 = 0x107e --ZW
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	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_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(s.descost)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_1, 0x207e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_1)
  end
  function s.lvfilter(c)
  	return c:IsFaceup() and c:IsLevelAbove(0) and (not c:IsLevel(4) or not c:IsLevel(5))
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_HAND, 0, 1, 1, nil, e, tp)
  	if
  		sg:GetCount() > 0
  		and Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP) > 0
  		and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  		and Duel.IsExistingMatchingCard(s.lvfilter, tp, LOCATION_MZONE, 0, 1, nil)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  	then
  		Duel.BreakEffect()
  		local g = Duel.GetMatchingGroup(s.lvfilter, tp, LOCATION_MZONE, 0, nil)
  		local lv = 0
  		if g:FilterCount(Card.IsLevel, nil, 5) == #g then
  			lv = 4
  		end
  		if g:FilterCount(Card.IsLevel, nil, 4) == #g then
  			lv = 5
  		end
  		if lv == 0 then
  			lv = Duel.AnnounceNumber(tp, 4, 5)
  		end
  		local lc = g:GetFirst()
  		while lc do
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_CHANGE_LEVEL)
  			e1:SetValue(lv)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			lc:RegisterEffect(e1)
  			lc = g:GetNext()
  		end
  	end
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_1, 0x207e) and c:IsAbleToRemoveAsCost()
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, c)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, c)
  	g:AddCard(c)
  	Duel.Remove(g, POS_FACEUP, 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
  
  