name: Meizen
card_text: 2 "Ninja" monsters with different Types
  Must first be either Fusion Summoned, or Special Summoned from your Extra Deck by Tributing the above cards you control. Your "Ninja" monsters can attack directly. While you control a face-down Defense Position monster, your opponent's monsters cannot target this card for attacks. When your opponent activates a card or effect (Quick Effect): You can Special Summon 1 "Ninja" monster from your Deck in face-up or face-down Defense Position. You can only use this effect of "Meizen the Battle Ninja" 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)
  	c:EnableReviveLimit()
  	--fusion summon
  	aux.AddFusionProcFunRep(c, s.ffilter, 2, true)
  	aux.AddContactFusionProcedure(c, aux.FilterBoolFunction(Card.IsReleasable, REASON_SPSUMMON), LOCATION_MZONE, 0, Duel.Release, REASON_SPSUMMON + REASON_MATERIAL)
  	--splimit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(s.splimit)
  	c:RegisterEffect(e1)
  	--direct attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DIRECT_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	c:RegisterEffect(e2)
  	--acn't be attacked
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_CANNOT_BE_BATTLE_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetCondition(s.atkcon)
  	e3:SetValue(aux.imval1)
  	c:RegisterEffect(e3)
  	--spsummon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_CHAINING)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.ffilter(c, fc, sub, mg, sg)
  	return c:IsFusionSetCard(SETCARD_ID_0) and (not sg or not sg:IsExists(Card.IsRace, 1, c, c:GetRace()))
  end
  function s.splimit(e, se, sp, st)
  	return not e:GetHandler():IsLocation(LOCATION_EXTRA) or aux.fuslimit(e, se, sp, st)
  end
  function s.atkcon(e)
  	return Duel.IsExistingMatchingCard(Card.IsPosition, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil, POS_FACEDOWN_DEFENSE)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_DEFENSE)
  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_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 1 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_DEFENSE)
  		if g:GetFirst():IsFacedown() then
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  
  
source_text: Meizen
  2 "Ninja" monsters with different Types
  Must first be either Fusion Summoned, or Special Summoned from your Extra Deck by Tributing the above cards you control. Your "Ninja" monsters can attack directly. While you control a face-down Defense Position monster, your opponent's monsters cannot target this card for attacks. When your opponent activates a card or effect (Quick Effect): You can Special Summon 1 "Ninja" monster from your Deck in face-up or face-down Defense Position. You can only use this effect of "Meizen the Battle Ninja" once per turn.
target_text: -- Meizen
  local SETCARD_ID_0 = 0x2b --Ninja
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--fusion summon
  	aux.AddFusionProcFunRep(c, s.ffilter, 2, true)
  	aux.AddContactFusionProcedure(c, aux.FilterBoolFunction(Card.IsReleasable, REASON_SPSUMMON), LOCATION_MZONE, 0, Duel.Release, REASON_SPSUMMON + REASON_MATERIAL)
  	--splimit
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(s.splimit)
  	c:RegisterEffect(e1)
  	--direct attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DIRECT_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	c:RegisterEffect(e2)
  	--acn't be attacked
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE)
  	e3:SetCode(EFFECT_CANNOT_BE_BATTLE_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e3:SetCondition(s.atkcon)
  	e3:SetValue(aux.imval1)
  	c:RegisterEffect(e3)
  	--spsummon
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_CHAINING)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.spcon)
  	e4:SetTarget(s.sptg)
  	e4:SetOperation(s.spop)
  	c:RegisterEffect(e4)
  end
  function s.ffilter(c, fc, sub, mg, sg)
  	return c:IsFusionSetCard(SETCARD_ID_0) and (not sg or not sg:IsExists(Card.IsRace, 1, c, c:GetRace()))
  end
  function s.splimit(e, se, sp, st)
  	return not e:GetHandler():IsLocation(LOCATION_EXTRA) or aux.fuslimit(e, se, sp, st)
  end
  function s.atkcon(e)
  	return Duel.IsExistingMatchingCard(Card.IsPosition, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil, POS_FACEDOWN_DEFENSE)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_DEFENSE)
  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_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) < 1 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_DEFENSE)
  		if g:GetFirst():IsFacedown() then
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  
  