name: Ancient
card_text: All other "Ancient Warriors" monsters you control cannot be destroyed by battle. You can only use each of the following effects of "Ancient Warriors - Fearsome Zhang Yuan" once per turn.
  ● At the start of the Damage Step, when your "Ancient Warriors" monster battles an opponent's face-up monster: You can Special Summon this card from your hand, and if you do, that opponent's monster loses 1000 ATK.
  ● If a card(s) your opponent controls is destroyed by battle or card effect: You can target 1 card your opponent controls; destroy it.
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)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_BATTLE_START)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.indtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.descon)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local d = a:GetBattleTarget()
  	if not d then
  		return false
  	end
  	if a:IsControler(1 - tp) then
  		a, d = d, a
  	end
  	e:SetLabelObject(d)
  	return a:IsFaceup() and a:IsControler(tp) and a:IsSetCard(SETCARD_ID_0) and d:IsFaceup() and d:IsControler(1 - tp)
  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 e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		local tc = e:GetLabelObject()
  		if tc:IsRelateToBattle() and tc:IsFaceup() and tc:IsControler(1 - tp) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(-1000)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  		end
  	end
  end
  function s.indtg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c ~= e:GetHandler()
  end
  function s.cfilter(c, tp)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT) and c:IsPreviousControler(1 - tp) and c:IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsOnField()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(nil, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, nil, 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: Ancient
  All other "Ancient Warriors" monsters you control cannot be destroyed by battle. You can only use each of the following effects of "Ancient Warriors - Fearsome Zhang Yuan" once per turn.
  ● At the start of the Damage Step, when your "Ancient Warriors" monster battles an opponent's face-up monster: You can Special Summon this card from your hand, and if you do, that opponent's monster loses 1000 ATK.
  ● If a card(s) your opponent controls is destroyed by battle or card effect: You can target 1 card your opponent controls; destroy it.
target_text: -- Ancient
  local SETCARD_ID_0 = 0x137 --Ancient
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_BATTLE_START)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.indtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_CARD_TARGET)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCondition(s.descon)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local d = a:GetBattleTarget()
  	if not d then
  		return false
  	end
  	if a:IsControler(1 - tp) then
  		a, d = d, a
  	end
  	e:SetLabelObject(d)
  	return a:IsFaceup() and a:IsControler(tp) and a:IsSetCard(SETCARD_ID_0) and d:IsFaceup() and d:IsControler(1 - tp)
  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 e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
  		local tc = e:GetLabelObject()
  		if tc:IsRelateToBattle() and tc:IsFaceup() and tc:IsControler(1 - tp) then
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(-1000)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  		end
  	end
  end
  function s.indtg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c ~= e:GetHandler()
  end
  function s.cfilter(c, tp)
  	return c:IsReason(REASON_BATTLE + REASON_EFFECT) and c:IsPreviousControler(1 - tp) and c:IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsOnField()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(nil, tp, 0, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, nil, 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
  
  