name: Divine
card_text: 2 Level 12 monsters
  Once per turn, if an Xyz Monster battled this turn, you can also Xyz Summon "Divine Arsenal AA-ZEUS - Sky Thunder" by using 1 Xyz Monster you control as material. (Transfer its materials to this card.) (Quick Effect): You can detach 2 materials from this card; send all other cards from the field to the GY. Once per turn, if another card(s) you control is destroyed by battle or an opponent's card effect: You can attach 1 card from your hand, Deck, or Extra Deck to this card as material.
external_ids: local CARD_ID_0 = 90448280 --Divine Arsenal AA-ZEUS - Sky Thunder
  
lua: local CARD_ID_0 = 90448280 --Divine Arsenal AA-ZEUS - Sky Thunder
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 12, 2, s.ovfilter, aux.Stringid(id, 0), 2, s.xyzop)
  	c:EnableReviveLimit()
  	--to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetCategory(CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCost(s.tgcost)
  	e1:SetTarget(s.tgtg)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--overlay
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.ovcon)
  	e2:SetTarget(s.ovtg)
  	e2:SetOperation(s.ovop)
  	c:RegisterEffect(e2)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.GlobalEffect()
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_BATTLED)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.ovfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ)
  end
  function s.xyzop(e, tp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) > 0 and Duel.GetFlagEffect(tp, id + 1) == 0
  	end
  	Duel.RegisterFlagEffect(tp, id + 1, RESET_PHASE + PHASE_END, EFFECT_FLAG_OATH, 1)
  end
  function s.check(c)
  	return c and c:IsType(TYPE_XYZ)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if s.check(Duel.GetAttacker()) or s.check(Duel.GetAttackTarget()) then
  		Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  		Duel.RegisterFlagEffect(1 - tp, id, RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  function s.tgcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 2, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 2, 2, REASON_COST)
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGrave, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, e:GetHandler())
  	if chk == 0 then
  		return #g > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, #g, 0, 0)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGrave, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, aux.ExceptThisCard(e))
  	if #g > 0 then
  		Duel.SendtoGrave(g, REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_ONFIELD) and (c:IsReason(REASON_BATTLE) or c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp)
  end
  function s.ovcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp) and not eg:IsContains(e:GetHandler())
  end
  function s.ofilter(c, e)
  	return c:IsCanOverlay() and (not e or not c:IsImmuneToEffect(e))
  end
  function s.ovtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsType(TYPE_XYZ) and Duel.IsExistingMatchingCard(s.ofilter, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_EXTRA, 0, 1, nil)
  	end
  end
  function s.ovop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local g = Duel.SelectMatchingCard(tp, s.ofilter, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_EXTRA, 0, 1, 1, nil, e)
  		local tc = g:GetFirst()
  		if tc then
  			Duel.Overlay(c, tc)
  		end
  		Duel.ShuffleDeck(tp)
  	end
  end
  
  
source_text: Divine
  2 Level 12 monsters
  Once per turn, if an Xyz Monster battled this turn, you can also Xyz Summon "Divine Arsenal AA-ZEUS - Sky Thunder" by using 1 Xyz Monster you control as material. (Transfer its materials to this card.) (Quick Effect): You can detach 2 materials from this card; send all other cards from the field to the GY. Once per turn, if another card(s) you control is destroyed by battle or an opponent's card effect: You can attach 1 card from your hand, Deck, or Extra Deck to this card as material.
target_text: -- Divine
  local CARD_ID_0 = 90448280 --Divine Arsenal AA-ZEUS - Sky Thunder
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, nil, 12, 2, s.ovfilter, aux.Stringid(id, 0), 2, s.xyzop)
  	c:EnableReviveLimit()
  	--to grave
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 1))
  	e1:SetCategory(CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_QUICK_O)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e1:SetCost(s.tgcost)
  	e1:SetTarget(s.tgtg)
  	e1:SetOperation(s.tgop)
  	c:RegisterEffect(e1)
  	--overlay
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 2))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.ovcon)
  	e2:SetTarget(s.ovtg)
  	e2:SetOperation(s.ovop)
  	c:RegisterEffect(e2)
  	if not s.global_check then
  		s.global_check = true
  		local ge1 = Effect.GlobalEffect()
  		ge1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  		ge1:SetCode(EVENT_BATTLED)
  		ge1:SetOperation(s.checkop)
  		Duel.RegisterEffect(ge1, 0)
  	end
  end
  function s.ovfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_XYZ)
  end
  function s.xyzop(e, tp, chk)
  	if chk == 0 then
  		return Duel.GetFlagEffect(tp, id) > 0 and Duel.GetFlagEffect(tp, id + 1) == 0
  	end
  	Duel.RegisterFlagEffect(tp, id + 1, RESET_PHASE + PHASE_END, EFFECT_FLAG_OATH, 1)
  end
  function s.check(c)
  	return c and c:IsType(TYPE_XYZ)
  end
  function s.checkop(e, tp, eg, ep, ev, re, r, rp)
  	if s.check(Duel.GetAttacker()) or s.check(Duel.GetAttackTarget()) then
  		Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  		Duel.RegisterFlagEffect(1 - tp, id, RESET_PHASE + PHASE_END, 0, 1)
  	end
  end
  function s.tgcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 2, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 2, 2, REASON_COST)
  end
  function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGrave, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, e:GetHandler())
  	if chk == 0 then
  		return #g > 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, #g, 0, 0)
  end
  function s.tgop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsAbleToGrave, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, aux.ExceptThisCard(e))
  	if #g > 0 then
  		Duel.SendtoGrave(g, REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousControler(tp) and c:IsPreviousLocation(LOCATION_ONFIELD) and (c:IsReason(REASON_BATTLE) or c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp)
  end
  function s.ovcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp) and not eg:IsContains(e:GetHandler())
  end
  function s.ofilter(c, e)
  	return c:IsCanOverlay() and (not e or not c:IsImmuneToEffect(e))
  end
  function s.ovtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsType(TYPE_XYZ) and Duel.IsExistingMatchingCard(s.ofilter, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_EXTRA, 0, 1, nil)
  	end
  end
  function s.ovop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_XMATERIAL)
  		local g = Duel.SelectMatchingCard(tp, s.ofilter, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_EXTRA, 0, 1, 1, nil, e)
  		local tc = g:GetFirst()
  		if tc then
  			Duel.Overlay(c, tc)
  		end
  		Duel.ShuffleDeck(tp)
  	end
  end
  
  