name: Hidden
card_text: If a "Ninja" monster is Summoned to your field (except during the Damage Step): You can target 1 "Ninja" monster or 1 "Ninjitsu Art" card in your GY; add it to your hand, but for the rest of this turn, you cannot activate cards, or the effects of cards, with the same name as the added card. If a "Ninja" monster(s) or "Ninjitsu Art" card(s) you control would be destroyed by battle or an opponent's card effect, you can banish 1 "Ninja" monster from your GY instead. You can only use each effect of "Hidden Village of Ninjitsu Arts" once per turn.
external_ids: local SETCARD_ID_0 = 0x2b --Ninja
  
lua: local SETCARD_ID_0 = 0x2b --Ninja
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_FLIP_SUMMON_SUCCESS)
  	c:RegisterEffect(e3)
  	local e4 = e2:Clone()
  	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e4)
  	--destroy replace
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e5:SetCode(EFFECT_DESTROY_REPLACE)
  	e5:SetRange(LOCATION_FZONE)
  	e5:SetCountLimit(1, id + 1)
  	e5:SetTarget(s.reptg)
  	e5:SetValue(s.repval)
  	e5:SetOperation(s.repop)
  	c:RegisterEffect(e5)
  end
  function s.thcfilter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.thcfilter, 1, nil, tp)
  end
  function s.thfilter(c)
  	return (c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) or c:IsSetCard(0x61)) 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 c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and Duel.SendtoHand(tc, nil, REASON_EFFECT) > 0 and tc:IsLocation(LOCATION_HAND) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  		e1:SetTargetRange(1, 0)
  		e1:SetValue(s.aclimit)
  		e1:SetLabel(tc:GetCode())
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.aclimit(e, re, tp)
  	return re:GetHandler():IsCode(e:GetLabel())
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and (c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) or c:IsSetCard(0x61))
  		and c:IsOnField()
  		and c:IsControler(tp)
  		and not c:IsReason(REASON_REPLACE)
  		and (c:IsReason(REASON_BATTLE) or c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp)
  end
  function s.rmfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp) and Duel.IsExistingMatchingCard(s.rmfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESREPLACE)
  		local tg = Duel.SelectMatchingCard(tp, s.rmfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		e:SetLabelObject(tg:GetFirst())
  		return true
  	end
  	return false
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_CARD, 0, id)
  	local tc = e:GetLabelObject()
  	Duel.Remove(tc, POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  end
  
  
source_text: Hidden
  If a "Ninja" monster is Summoned to your field (except during the Damage Step): You can target 1 "Ninja" monster or 1 "Ninjitsu Art" card in your GY; add it to your hand, but for the rest of this turn, you cannot activate cards, or the effects of cards, with the same name as the added card. If a "Ninja" monster(s) or "Ninjitsu Art" card(s) you control would be destroyed by battle or an opponent's card effect, you can banish 1 "Ninja" monster from your GY instead. You can only use each effect of "Hidden Village of Ninjitsu Arts" once per turn.
target_text: -- Hidden
  local SETCARD_ID_0 = 0x2b --Ninja
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_FLIP_SUMMON_SUCCESS)
  	c:RegisterEffect(e3)
  	local e4 = e2:Clone()
  	e4:SetCode(EVENT_SPSUMMON_SUCCESS)
  	c:RegisterEffect(e4)
  	--destroy replace
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e5:SetCode(EFFECT_DESTROY_REPLACE)
  	e5:SetRange(LOCATION_FZONE)
  	e5:SetCountLimit(1, id + 1)
  	e5:SetTarget(s.reptg)
  	e5:SetValue(s.repval)
  	e5:SetOperation(s.repop)
  	c:RegisterEffect(e5)
  end
  function s.thcfilter(c, tp)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.thcfilter, 1, nil, tp)
  end
  function s.thfilter(c)
  	return (c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) or c:IsSetCard(0x61)) 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 c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if c:IsRelateToEffect(e) and tc:IsRelateToEffect(e) and Duel.SendtoHand(tc, nil, REASON_EFFECT) > 0 and tc:IsLocation(LOCATION_HAND) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetCode(EFFECT_CANNOT_ACTIVATE)
  		e1:SetTargetRange(1, 0)
  		e1:SetValue(s.aclimit)
  		e1:SetLabel(tc:GetCode())
  		e1:SetReset(RESET_PHASE + PHASE_END)
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.aclimit(e, re, tp)
  	return re:GetHandler():IsCode(e:GetLabel())
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup()
  		and (c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) or c:IsSetCard(0x61))
  		and c:IsOnField()
  		and c:IsControler(tp)
  		and not c:IsReason(REASON_REPLACE)
  		and (c:IsReason(REASON_BATTLE) or c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp)
  end
  function s.rmfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemoveAsCost()
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return eg:IsExists(s.repfilter, 1, nil, tp) and Duel.IsExistingMatchingCard(s.rmfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	if Duel.SelectEffectYesNo(tp, e:GetHandler(), 96) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESREPLACE)
  		local tg = Duel.SelectMatchingCard(tp, s.rmfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		e:SetLabelObject(tg:GetFirst())
  		return true
  	end
  	return false
  end
  function s.repop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_CARD, 0, id)
  	local tc = e:GetLabelObject()
  	Duel.Remove(tc, POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  end
  
  