name: Ancient
card_text: You can target 1 Continuous Spell/Trap you control; send it to the GY, and if you do, halve the ATK of 2 face-up monsters on the field, until the end of this turn. If a card(s) your opponent controls is destroyed by battle or card effect: You can target 1 "Ancient Warriors" card in your GY, except "Ancient Warriors - Deceptive Jia Wen"; add it to your hand. You can only use each effect of "Ancient Warriors - Deceptive Jia Wen" once per turn.
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)
  	--atk
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOGRAVE + CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.tgfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsType(TYPE_CONTINUOUS) and c:IsAbleToGrave() and Duel.IsExistingMatchingCard(Card.IsFaceup, 0, LOCATION_MZONE, LOCATION_MZONE, 2, c)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(tp) and s.tgfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tgfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectTarget(tp, s.tgfilter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, 1, 0, 0)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoGrave(tc, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_GRAVE) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  		local g = Duel.SelectMatchingCard(tp, Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 2, 2, nil)
  		if g:GetCount() == 2 then
  			Duel.HintSelection(g)
  			local tc1 = g:GetFirst()
  			local tc2 = g:GetNext()
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetValue(math.ceil(tc1:GetAttack() / 2))
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc1:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetValue(math.ceil(tc2:GetAttack() / 2))
  			tc2:RegisterEffect(e2)
  		end
  	end
  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.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Ancient
  You can target 1 Continuous Spell/Trap you control; send it to the GY, and if you do, halve the ATK of 2 face-up monsters on the field, until the end of this turn. If a card(s) your opponent controls is destroyed by battle or card effect: You can target 1 "Ancient Warriors" card in your GY, except "Ancient Warriors - Deceptive Jia Wen"; add it to your hand. You can only use each effect of "Ancient Warriors - Deceptive Jia Wen" once per turn.
target_text: -- Ancient
  local SETCARD_ID_0 = 0x137 --Ancient
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOGRAVE + CATEGORY_ATKCHANGE)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_CARD_TARGET)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.tgfilter(c)
  	return c:IsFaceup() and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsType(TYPE_CONTINUOUS) and c:IsAbleToGrave() and Duel.IsExistingMatchingCard(Card.IsFaceup, 0, LOCATION_MZONE, LOCATION_MZONE, 2, c)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsOnField() and chkc:IsControler(tp) and s.tgfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tgfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectTarget(tp, s.tgfilter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, g, 1, 0, 0)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoGrave(tc, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_GRAVE) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  		local g = Duel.SelectMatchingCard(tp, Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 2, 2, nil)
  		if g:GetCount() == 2 then
  			Duel.HintSelection(g)
  			local tc1 = g:GetFirst()
  			local tc2 = g:GetNext()
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetCode(EFFECT_SET_ATTACK_FINAL)
  			e1:SetValue(math.ceil(tc1:GetAttack() / 2))
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			tc1:RegisterEffect(e1)
  			local e2 = e1:Clone()
  			e2:SetValue(math.ceil(tc2:GetAttack() / 2))
  			tc2:RegisterEffect(e2)
  		end
  	end
  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.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  