name: Shiranui
card_text: 1 Zombie Tuner + 1+ non-Tuner Zombie monsters
  If this card is Special Summoned: You can return any number of your Zombie Synchro Monsters, that are banished or are in your GY, to the Extra Deck, then you can destroy cards your opponent controls, equal to the number of cards returned. If a Zombie monster(s) you control would be destroyed by battle or card effect, you can banish 1 "Shiranui" monster from your GY instead. You can only Special Summon "Shiranui Sunsaga(s)" once per turn.
external_ids: local SETCARD_ID_0 = 0xd9 --Shiranui
  
lua: local SETCARD_ID_0 = 0xd9 --Shiranui
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetSPSummonOnce(id)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsRace, RACE_ZOMBIE), aux.NonTuner(Card.IsRace, RACE_ZOMBIE), 1)
  	c:EnableReviveLimit()
  	--to deck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOEXTRA + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetTarget(s.tdtg)
  	e1:SetOperation(s.tdop)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	c:RegisterEffect(e2)
  end
  function s.tdfilter(c)
  	return (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsType(TYPE_SYNCHRO) and c:IsRace(RACE_ZOMBIE) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, nil, 1, tp, LOCATION_GRAVE + LOCATION_REMOVED)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, nil)
  	if g:GetCount() == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local sg = g:Select(tp, 1, g:GetCount(), nil)
  	Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local ct = Duel.GetOperatedGroup():FilterCount(Card.IsLocation, nil, LOCATION_EXTRA)
  	local dg = Duel.GetMatchingGroup(nil, tp, 0, LOCATION_ONFIELD, nil)
  	if ct > 0 and dg:GetCount() >= ct and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local sg2 = dg:Select(tp, ct, ct, nil)
  		Duel.Destroy(sg2, REASON_EFFECT)
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsLocation(LOCATION_MZONE) and c:IsRace(RACE_ZOMBIE) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.rmfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
  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_REMOVE)
  		local g = Duel.SelectMatchingCard(tp, s.rmfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		Duel.Remove(g, POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  		return true
  	end
  	return false
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  
  
source_text: Shiranui
  1 Zombie Tuner + 1+ non-Tuner Zombie monsters
  If this card is Special Summoned: You can return any number of your Zombie Synchro Monsters, that are banished or are in your GY, to the Extra Deck, then you can destroy cards your opponent controls, equal to the number of cards returned. If a Zombie monster(s) you control would be destroyed by battle or card effect, you can banish 1 "Shiranui" monster from your GY instead. You can only Special Summon "Shiranui Sunsaga(s)" once per turn.
target_text: -- Shiranui
  local SETCARD_ID_0 = 0xd9 --Shiranui
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetSPSummonOnce(id)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsRace, RACE_ZOMBIE), aux.NonTuner(Card.IsRace, RACE_ZOMBIE), 1)
  	c:EnableReviveLimit()
  	--to deck
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOEXTRA + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetTarget(s.tdtg)
  	e1:SetOperation(s.tdop)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTarget(s.reptg)
  	e2:SetValue(s.repval)
  	c:RegisterEffect(e2)
  end
  function s.tdfilter(c)
  	return (c:IsLocation(LOCATION_GRAVE) or c:IsFaceup()) and c:IsType(TYPE_SYNCHRO) and c:IsRace(RACE_ZOMBIE) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, nil, 1, tp, LOCATION_GRAVE + LOCATION_REMOVED)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.tdfilter, tp, LOCATION_GRAVE + LOCATION_REMOVED, 0, nil)
  	if g:GetCount() == 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local sg = g:Select(tp, 1, g:GetCount(), nil)
  	Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local ct = Duel.GetOperatedGroup():FilterCount(Card.IsLocation, nil, LOCATION_EXTRA)
  	local dg = Duel.GetMatchingGroup(nil, tp, 0, LOCATION_ONFIELD, nil)
  	if ct > 0 and dg:GetCount() >= ct and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local sg2 = dg:Select(tp, ct, ct, nil)
  		Duel.Destroy(sg2, REASON_EFFECT)
  	end
  end
  function s.repfilter(c, tp)
  	return c:IsFaceup() and c:IsControler(tp) and c:IsLocation(LOCATION_MZONE) and c:IsRace(RACE_ZOMBIE) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.rmfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
  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_REMOVE)
  		local g = Duel.SelectMatchingCard(tp, s.rmfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		Duel.Remove(g, POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  		return true
  	end
  	return false
  end
  function s.repval(e, c)
  	return s.repfilter(c, e:GetHandlerPlayer())
  end
  
  