name: Ni-Ni
card_text: If this card is not equipped with an Equip Card, you take no damage from battles involving this card. If this card is equipped with an Equip Card, it cannot be destroyed by battle and your opponent takes any battle damage you would have taken from battles involving this card. During your opponent's turn, while this card is equipped with an Equip Card (Quick Effect): You can target 1 face-up monster your opponent controls; take control of it until the End Phase. You can only use this effect of "Ni-Ni the Mirror Mikanko" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--no damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.ndcon)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--battle indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	e2:SetCondition(s.indcon)
  	c:RegisterEffect(e2)
  	--reflect battle damage
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_REFLECT_BATTLE_DAMAGE)
  	c:RegisterEffect(e3)
  	--control
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_CONTROL)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.ctcon)
  	e4:SetTarget(s.cttg)
  	e4:SetOperation(s.ctop)
  	c:RegisterEffect(e4)
  end
  function s.ndcon(e)
  	return e:GetHandler():GetEquipCount() == 0
  end
  function s.indcon(e)
  	return e:GetHandler():GetEquipCount() > 0
  end
  function s.ctcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetEquipCount() > 0 and Duel.GetTurnPlayer() == 1 - tp
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsControlerCanBeChanged()
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.GetControl(tc, tp, PHASE_END, 1)
  	end
  end
  
  
source_text: Ni-Ni
  If this card is not equipped with an Equip Card, you take no damage from battles involving this card. If this card is equipped with an Equip Card, it cannot be destroyed by battle and your opponent takes any battle damage you would have taken from battles involving this card. During your opponent's turn, while this card is equipped with an Equip Card (Quick Effect): You can target 1 face-up monster your opponent controls; take control of it until the End Phase. You can only use this effect of "Ni-Ni the Mirror Mikanko" once per turn.
target_text: -- Ni-Ni
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--no damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCondition(s.ndcon)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	--battle indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetValue(1)
  	e2:SetCondition(s.indcon)
  	c:RegisterEffect(e2)
  	--reflect battle damage
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_REFLECT_BATTLE_DAMAGE)
  	c:RegisterEffect(e3)
  	--control
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_CONTROL)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetHintTiming(0, TIMINGS_CHECK_MONSTER)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.ctcon)
  	e4:SetTarget(s.cttg)
  	e4:SetOperation(s.ctop)
  	c:RegisterEffect(e4)
  end
  function s.ndcon(e)
  	return e:GetHandler():GetEquipCount() == 0
  end
  function s.indcon(e)
  	return e:GetHandler():GetEquipCount() > 0
  end
  function s.ctcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetEquipCount() > 0 and Duel.GetTurnPlayer() == 1 - tp
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsControlerCanBeChanged()
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONTROL)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_CONTROL, g, 1, 0, 0)
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.GetControl(tc, tp, PHASE_END, 1)
  	end
  end
  
  