name: Eye
card_text: If you control an Illusion or Spellcaster monster: Activate 1 of these effects;
  ● Your Illusion and Spellcaster monsters cannot be destroyed by battle this turn.
  ● During your opponent's turn: Target 1 face-up monster your opponent controls; take control of it until the End Phase.
  ● When an opponent's monster declares an attack: Target 1 face-up monster your opponent controls, except the attacking monster; change the attack target to it and perform damage calculation.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_ILLUSION + RACE_SPELLCASTER)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.tfilter(c)
  	return c:IsFaceup() and c:IsControlerCanBeChanged()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local a = Duel.GetAttacker()
  	if chkc then
  		local f = { false, s.tfilter(chkc), chkc:IsFaceup() and chkc ~= a }
  		return f[e:GetLabel()] and chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp)
  	end
  	if chk == 0 then
  		return true
  	end
  	local b2 = Duel.GetTurnPlayer() == 1 - tp and Duel.IsExistingTarget(s.tfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	local b3 = Duel.GetTurnPlayer() == 1 - tp and Duel.CheckEvent(EVENT_ATTACK_ANNOUNCE) and Duel.IsExistingTarget(Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, a)
  	local op = aux.SelectFromOptions(tp, { true, aux.Stringid(id, 1) }, { b2, aux.Stringid(id, 2) }, { b3, aux.Stringid(id, 3) })
  	e:SetLabel(op)
  	if op == 1 then
  		e:SetCategory(0)
  		e:SetProperty(0)
  		e:SetOperation(s.protect)
  	elseif op == 2 then
  		e:SetCategory(CATEGORY_CONTROL)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		e:SetOperation(s.control)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  		local g = Duel.SelectTarget(tp, s.tfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  		Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  	else
  		e:SetCategory(0)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		e:SetOperation(s.tattack)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		Duel.SelectTarget(tp, Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, 1, a)
  	end
  end
  function s.protect(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_ILLUSION + RACE_SPELLCASTER))
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetValue(1)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.control(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsRelateToEffect(e) then
  		Duel.GetControl(tc, tp, PHASE_END, 1)
  	end
  end
  function s.tattack(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsRelateToEffect(e) and a:IsAttackable() and not a:IsImmuneToEffect(e) then
  		Duel.CalculateDamage(a, tc)
  	end
  end
  
  
source_text: Eye
  If you control an Illusion or Spellcaster monster: Activate 1 of these effects;
  ● Your Illusion and Spellcaster monsters cannot be destroyed by battle this turn.
  ● During your opponent's turn: Target 1 face-up monster your opponent controls; take control of it until the End Phase.
  ● When an opponent's monster declares an attack: Target 1 face-up monster your opponent controls, except the attacking monster; change the attack target to it and perform damage calculation.
target_text: -- Eye
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_ILLUSION + RACE_SPELLCASTER)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.tfilter(c)
  	return c:IsFaceup() and c:IsControlerCanBeChanged()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local a = Duel.GetAttacker()
  	if chkc then
  		local f = { false, s.tfilter(chkc), chkc:IsFaceup() and chkc ~= a }
  		return f[e:GetLabel()] and chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp)
  	end
  	if chk == 0 then
  		return true
  	end
  	local b2 = Duel.GetTurnPlayer() == 1 - tp and Duel.IsExistingTarget(s.tfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	local b3 = Duel.GetTurnPlayer() == 1 - tp and Duel.CheckEvent(EVENT_ATTACK_ANNOUNCE) and Duel.IsExistingTarget(Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, a)
  	local op = aux.SelectFromOptions(tp, { true, aux.Stringid(id, 1) }, { b2, aux.Stringid(id, 2) }, { b3, aux.Stringid(id, 3) })
  	e:SetLabel(op)
  	if op == 1 then
  		e:SetCategory(0)
  		e:SetProperty(0)
  		e:SetOperation(s.protect)
  	elseif op == 2 then
  		e:SetCategory(CATEGORY_CONTROL)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		e:SetOperation(s.control)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  		local g = Duel.SelectTarget(tp, s.tfilter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  		Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  	else
  		e:SetCategory(0)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		e:SetOperation(s.tattack)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  		Duel.SelectTarget(tp, Card.IsFaceup, tp, 0, LOCATION_MZONE, 1, 1, a)
  	end
  end
  function s.protect(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsRace, RACE_ILLUSION + RACE_SPELLCASTER))
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	e1:SetValue(1)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.control(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsRelateToEffect(e) then
  		Duel.GetControl(tc, tp, PHASE_END, 1)
  	end
  end
  function s.tattack(e, tp, eg, ep, ev, re, r, rp)
  	local a = Duel.GetAttacker()
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsRelateToEffect(e) and a:IsAttackable() and not a:IsImmuneToEffect(e) then
  		Duel.CalculateDamage(a, tc)
  	end
  end
  
  