name: Ancient
card_text: Cannot be Normal Summoned/Set. Must be Special Summoned (from your hand) by controlling the highest ATK "Ancient Warriors" monster on the field (even if it's tied). You can only Special Summon "Ancient Warriors - Rebellious Lu Feng" once per turn this way. Once per turn, during the Main Phase (Quick Effect): You can destroy the 1 face-up monster your opponent controls with the highest ATK (your choice, if tied), also you cannot activate monster effects the turn you activate this effect, except "Ancient Warriors" monsters'. Once per turn, during the End Phase, if your opponent controls a monster with the highest ATK on the field (even if tied): Give control of this card to your opponent.
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)
  	c:EnableReviveLimit()
  	--special summon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_SPSUMMON_PROC)
  	e2:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e2:SetCondition(s.spcon)
  	c:RegisterEffect(e2)
  	--Destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetCountLimit(1)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetHintTiming(0, TIMING_MAIN_END)
  	e3:SetCost(s.descost)
  	e3:SetCondition(s.descon)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  	--control
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCategory(CATEGORY_CONTROL)
  	e4:SetCode(EVENT_PHASE + PHASE_END)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.ctlcon)
  	e4:SetTarget(s.ctltg)
  	e4:SetOperation(s.ctlop)
  	c:RegisterEffect(e4)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
  end
  function s.chainfilter(re, tp, cid)
  	local rc = re:GetHandler()
  	return rc:IsSetCard(SETCARD_ID_0) or not re:IsActiveType(TYPE_MONSTER)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	if g:GetCount() == 0 then
  		return false
  	end
  	local tg = g:GetMaxGroup(Card.GetAttack)
  	return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and tg:IsExists(Card.IsControler, 1, nil, tp)
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetCustomActivityCount(id, tp, ACTIVITY_CHAIN) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e1:SetTargetRange(1, 0)
  	e1:SetValue(s.aclimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.aclimit(e, re, tp)
  	return not re:GetHandler():IsSetCard(SETCARD_ID_0) and re:IsActiveType(TYPE_MONSTER)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsMainPhase() and e:GetHandler():IsSetCard(SETCARD_ID_0)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	local tg = g:GetMaxGroup(Card.GetAttack)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, tg, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	if #g > 0 then
  		local tg = g:GetMaxGroup(Card.GetAttack)
  		if #tg > 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local sg = tg:Select(tp, 1, 1, nil)
  			Duel.HintSelection(sg)
  			Duel.Destroy(sg, REASON_EFFECT)
  		else
  			Duel.Destroy(tg, REASON_EFFECT)
  		end
  	end
  end
  function s.ctlcon(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	if g:GetCount() == 0 then
  		return false
  	end
  	local tg = g:GetMaxGroup(Card.GetAttack)
  	return tg:IsExists(Card.IsControler, 1, nil, 1 - tp)
  end
  function s.ctltg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, e:GetHandler(), 1, 0, 0)
  end
  function s.ctlop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.GetControl(c, 1 - tp)
  	end
  end
  
  
source_text: Ancient
  Cannot be Normal Summoned/Set. Must be Special Summoned (from your hand) by controlling the highest ATK "Ancient Warriors" monster on the field (even if it's tied). You can only Special Summon "Ancient Warriors - Rebellious Lu Feng" once per turn this way. Once per turn, during the Main Phase (Quick Effect): You can destroy the 1 face-up monster your opponent controls with the highest ATK (your choice, if tied), also you cannot activate monster effects the turn you activate this effect, except "Ancient Warriors" monsters'. Once per turn, during the End Phase, if your opponent controls a monster with the highest ATK on the field (even if tied): Give control of this card to your opponent.
target_text: -- Ancient
  local SETCARD_ID_0 = 0x137 --Ancient
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_SPSUMMON_PROC)
  	e2:SetProperty(EFFECT_FLAG_UNCOPYABLE)
  	e2:SetRange(LOCATION_HAND)
  	e2:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e2:SetCondition(s.spcon)
  	c:RegisterEffect(e2)
  	--Destroy
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_DESTROY)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetCountLimit(1)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetHintTiming(0, TIMING_MAIN_END)
  	e3:SetCost(s.descost)
  	e3:SetCondition(s.descon)
  	e3:SetTarget(s.destg)
  	e3:SetOperation(s.desop)
  	c:RegisterEffect(e3)
  	--control
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCategory(CATEGORY_CONTROL)
  	e4:SetCode(EVENT_PHASE + PHASE_END)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1)
  	e4:SetCondition(s.ctlcon)
  	e4:SetTarget(s.ctltg)
  	e4:SetOperation(s.ctlop)
  	c:RegisterEffect(e4)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
  end
  function s.chainfilter(re, tp, cid)
  	local rc = re:GetHandler()
  	return rc:IsSetCard(SETCARD_ID_0) or not re:IsActiveType(TYPE_MONSTER)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	if g:GetCount() == 0 then
  		return false
  	end
  	local tg = g:GetMaxGroup(Card.GetAttack)
  	return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and tg:IsExists(Card.IsControler, 1, nil, tp)
  end
  function s.descost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetCustomActivityCount(id, tp, ACTIVITY_CHAIN) == 0
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET + EFFECT_FLAG_OATH)
  	e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  	e1:SetTargetRange(1, 0)
  	e1:SetValue(s.aclimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.aclimit(e, re, tp)
  	return not re:GetHandler():IsSetCard(SETCARD_ID_0) and re:IsActiveType(TYPE_MONSTER)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsMainPhase() and e:GetHandler():IsSetCard(SETCARD_ID_0)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	local tg = g:GetMaxGroup(Card.GetAttack)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, tg, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, 0, LOCATION_MZONE, nil)
  	if #g > 0 then
  		local tg = g:GetMaxGroup(Card.GetAttack)
  		if #tg > 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local sg = tg:Select(tp, 1, 1, nil)
  			Duel.HintSelection(sg)
  			Duel.Destroy(sg, REASON_EFFECT)
  		else
  			Duel.Destroy(tg, REASON_EFFECT)
  		end
  	end
  end
  function s.ctlcon(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, nil)
  	if g:GetCount() == 0 then
  		return false
  	end
  	local tg = g:GetMaxGroup(Card.GetAttack)
  	return tg:IsExists(Card.IsControler, 1, nil, 1 - tp)
  end
  function s.ctltg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, e:GetHandler(), 1, 0, 0)
  end
  function s.ctlop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.GetControl(c, 1 - tp)
  	end
  end
  
  