name: Ninjitsu
card_text: Special Summon up to 2 Level 4 or lower Insect monsters from your hand (with the same Level, if Summoning 2). If you control "Number 2: Ninja Shadow Mosquito": You can banish this card from your GY, then target face-up monsters your opponent controls up to the number of Insect monsters you control; place 1 Hallucination Counter on each of those monsters. (The effects, if any, of monsters with Hallucination Counters are negated.) You can only use each effect of "Ninjitsu Art of Mosquito Marching" once per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 32453837 --Number 2: Ninja Shadow Mosquito
  local COUNTER_ID_0 = 0x1063 --Hallucination
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 32453837 --Number 2: Ninja Shadow Mosquito
  local COUNTER_ID_0 = 0x1063 --Hallucination
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--counter
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_COUNTER)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.countercond)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.countertg)
  	e2:SetOperation(s.counterop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c, e, tp)
  	return c:IsLevelBelow(4) and c:IsRace(RACE_INSECT) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND, 0, nil, e, tp)
  	local ft = math.min((Duel.GetLocationCount(tp, LOCATION_MZONE)), #g, 2)
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = g:SelectSubGroup(tp, s.spcheck, false, 1, ft)
  	if sg then
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.spcheck(sg)
  	return sg:GetClassCount(Card.GetLevel) == 1
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_1)
  end
  function s.countercond(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  end
  function s.ctfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_INSECT)
  end
  function s.tgfilter(c)
  	return c:IsFaceup() and c:IsCanAddCounter(COUNTER_ID_0, 1)
  end
  function s.countertg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and chkc:IsFaceup()
  	end
  	local ct = Duel.GetMatchingGroupCount(s.ctfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return ct > 0 and Duel.IsExistingTarget(s.tgfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_COUNTER)
  	local g = Duel.SelectTarget(tp, s.tgfilter, tp, 0, LOCATION_MZONE, 1, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_COUNTER, nil, 0, 0, 0)
  end
  function s.ctcon(e)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) > 0
  end
  function s.counterop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #g == 0 then
  		return
  	end
  	local c = e:GetHandler()
  	for tc in aux.Next(g) do
  		if tc:AddCounter(COUNTER_ID_0, 1) then
  			--Negate its effects
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DISABLE)
  			e1:SetCondition(s.ctcon)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  		end
  	end
  end
  
  
source_text: Ninjitsu
  Special Summon up to 2 Level 4 or lower Insect monsters from your hand (with the same Level, if Summoning 2). If you control "Number 2: Ninja Shadow Mosquito": You can banish this card from your GY, then target face-up monsters your opponent controls up to the number of Insect monsters you control; place 1 Hallucination Counter on each of those monsters. (The effects, if any, of monsters with Hallucination Counters are negated.) You can only use each effect of "Ninjitsu Art of Mosquito Marching" once per turn.
target_text: -- Ninjitsu
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 32453837 --Number 2: Ninja Shadow Mosquito
  local COUNTER_ID_0 = 0x1063 --Hallucination
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--counter
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_COUNTER)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.countercond)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.countertg)
  	e2:SetOperation(s.counterop)
  	c:RegisterEffect(e2)
  end
  function s.spfilter(c, e, tp)
  	return c:IsLevelBelow(4) and c:IsRace(RACE_INSECT) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND, 0, nil, e, tp)
  	local ft = math.min((Duel.GetLocationCount(tp, LOCATION_MZONE)), #g, 2)
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = g:SelectSubGroup(tp, s.spcheck, false, 1, ft)
  	if sg then
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.spcheck(sg)
  	return sg:GetClassCount(Card.GetLevel) == 1
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsCode(CARD_ID_1)
  end
  function s.countercond(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  end
  function s.ctfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_INSECT)
  end
  function s.tgfilter(c)
  	return c:IsFaceup() and c:IsCanAddCounter(COUNTER_ID_0, 1)
  end
  function s.countertg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(1 - tp) and chkc:IsFaceup()
  	end
  	local ct = Duel.GetMatchingGroupCount(s.ctfilter, tp, LOCATION_MZONE, 0, nil)
  	if chk == 0 then
  		return ct > 0 and Duel.IsExistingTarget(s.tgfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_COUNTER)
  	local g = Duel.SelectTarget(tp, s.tgfilter, tp, 0, LOCATION_MZONE, 1, ct, nil)
  	Duel.SetOperationInfo(0, CATEGORY_COUNTER, nil, 0, 0, 0)
  end
  function s.ctcon(e)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) > 0
  end
  function s.counterop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #g == 0 then
  		return
  	end
  	local c = e:GetHandler()
  	for tc in aux.Next(g) do
  		if tc:AddCounter(COUNTER_ID_0, 1) then
  			--Negate its effects
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_DISABLE)
  			e1:SetCondition(s.ctcon)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  		end
  	end
  end
  
  