name: Ancient
card_text: If your "Ancient Warriors" monster battles, your opponent cannot activate any Spell/Trap Cards until the end of the Damage Step. You can only use 1 of the following effects of "Ancient Warriors Saga - Defense of Changban" per turn, and only once that turn.
  ● At the start of your opponent's Battle Phase: You can send this face-up card from your Spell & Trap Zone to the GY; monsters your opponent controls cannot target "Ancient Warriors" monsters for attacks this turn.
  ● When an opponent's monster declares an attack: You can banish this card from your GY; Special Summon 1 "Ancient Warriors" monster from your Deck.
external_ids: local SETCARD_ID_0 = 0x137 --Ancient
  
lua: local SETCARD_ID_0 = 0x137 --Ancient
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	e0:SetHintTiming(0, TIMING_MAIN_END + TIMING_END_PHASE)
  	c:RegisterEffect(e0)
  	--actlimit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetTargetRange(0, 1)
  	e1:SetValue(s.aclimit)
  	e1:SetCondition(s.actcon)
  	c:RegisterEffect(e1)
  	--can not be attack target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE_START)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.atcon)
  	e2:SetCost(s.atcost)
  	e2:SetOperation(s.atop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.spcon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp)
  end
  function s.aclimit(e, re, tp)
  	return re:IsHasType(EFFECT_TYPE_ACTIVATE)
  end
  function s.actcon(e)
  	local tp = e:GetHandlerPlayer()
  	local a = Duel.GetAttacker()
  	local d = Duel.GetAttackTarget()
  	return (a and s.cfilter(a, tp)) or (d and s.cfilter(d, tp))
  end
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == 1 - tp
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToGraveAsCost() and c:IsStatus(STATUS_EFFECT_ENABLED)
  	end
  	Duel.SendtoGrave(c, REASON_COST)
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e1:SetTargetRange(0, LOCATION_MZONE)
  	e1:SetValue(s.atlimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.atlimit(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsFaceup()
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer()
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(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 g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Ancient
  If your "Ancient Warriors" monster battles, your opponent cannot activate any Spell/Trap Cards until the end of the Damage Step. You can only use 1 of the following effects of "Ancient Warriors Saga - Defense of Changban" per turn, and only once that turn.
  ● At the start of your opponent's Battle Phase: You can send this face-up card from your Spell & Trap Zone to the GY; monsters your opponent controls cannot target "Ancient Warriors" monsters for attacks this turn.
  ● When an opponent's monster declares an attack: You can banish this card from your GY; Special Summon 1 "Ancient Warriors" monster from your Deck.
target_text: -- Ancient
  local SETCARD_ID_0 = 0x137 --Ancient
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_ACTIVATE)
  	e0:SetCode(EVENT_FREE_CHAIN)
  	e0:SetHintTiming(0, TIMING_MAIN_END + TIMING_END_PHASE)
  	c:RegisterEffect(e0)
  	--actlimit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetRange(LOCATION_SZONE)
  	e1:SetTargetRange(0, 1)
  	e1:SetValue(s.aclimit)
  	e1:SetCondition(s.actcon)
  	c:RegisterEffect(e1)
  	--can not be attack target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_PHASE + PHASE_BATTLE_START)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.atcon)
  	e2:SetCost(s.atcost)
  	e2:SetOperation(s.atop)
  	c:RegisterEffect(e2)
  	--spsummon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_ATTACK_ANNOUNCE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.spcon)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp)
  end
  function s.aclimit(e, re, tp)
  	return re:IsHasType(EFFECT_TYPE_ACTIVATE)
  end
  function s.actcon(e)
  	local tp = e:GetHandlerPlayer()
  	local a = Duel.GetAttacker()
  	local d = Duel.GetAttackTarget()
  	return (a and s.cfilter(a, tp)) or (d and s.cfilter(d, tp))
  end
  function s.atcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == 1 - tp
  end
  function s.atcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsAbleToGraveAsCost() and c:IsStatus(STATUS_EFFECT_ENABLED)
  	end
  	Duel.SendtoGrave(c, REASON_COST)
  end
  function s.atop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e1:SetTargetRange(0, LOCATION_MZONE)
  	e1:SetValue(s.atlimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.atlimit(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsFaceup()
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return tp ~= Duel.GetTurnPlayer()
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(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 g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  