name: Kairyu-Shin's
card_text: Send 1 face-up "Umi" you control to the GY; Special Summon up to 2 monsters with different names from your hand and/or Deck, that mention "Umi" or are WATER Normal Monsters, in Defense Position, then if your opponent controls a monster, you can Special Summon any number of Level 6 or lower WATER Normal Monsters from your hand and/or Deck. Until the end of your next turn after this card resolves, you cannot Special Summon monsters, except WATER monsters. You can only activate 1 "Kairyu-Shin's Dark Reef" per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 22702055 --Umi
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 22702055 --Umi
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsCode(CARD_ID_1) and c:IsAbleToGraveAsCost() and c:IsFaceup()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return (aux.IsCodeListed(c, CARD_ID_1) or (c:IsType(TYPE_NORMAL) and c:IsAttribute(ATTRIBUTE_WATER))) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.spfilter1(c, e, tp)
  	return c:IsType(TYPE_NORMAL) and c:IsAttribute(ATTRIBUTE_WATER) and c:IsLevelBelow(6) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(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 + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ft = math.min(2, (Duel.GetLocationCount(tp, LOCATION_MZONE)))
  	if ft > 0 then
  		if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		local tg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, nil, e, tp)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g1 = tg:SelectSubGroup(tp, aux.dncheck, false, 1, ft)
  		if g1 then
  			Duel.SpecialSummon(g1, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  		end
  		local ft1 = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		local g2 = Duel.GetMatchingGroup(s.spfilter1, tp, LOCATION_HAND + LOCATION_DECK, 0, nil, e, tp)
  		if ft1 > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		if ft1 > 0 and Duel.IsExistingMatchingCard(nil, tp, 0, LOCATION_MZONE, 1, nil) and #g2 > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local g3 = g2:Select(tp, 1, ft1, nil)
  			if g3 then
  				Duel.SpecialSummon(g3, 0, tp, tp, false, false, POS_FACEUP)
  			end
  		end
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  		e1:SetTargetRange(1, 0)
  		e1:SetTarget(s.splimit)
  		if Duel.GetTurnPlayer() == tp then
  			e1:SetReset(RESET_PHASE + PHASE_END + RESET_SELF_TURN, 2)
  		else
  			e1:SetReset(RESET_PHASE + PHASE_END + RESET_SELF_TURN, 1)
  		end
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.splimit(e, c)
  	return not c:IsAttribute(ATTRIBUTE_WATER)
  end
  
  
source_text: Kairyu-Shin's
  Send 1 face-up "Umi" you control to the GY; Special Summon up to 2 monsters with different names from your hand and/or Deck, that mention "Umi" or are WATER Normal Monsters, in Defense Position, then if your opponent controls a monster, you can Special Summon any number of Level 6 or lower WATER Normal Monsters from your hand and/or Deck. Until the end of your next turn after this card resolves, you cannot Special Summon monsters, except WATER monsters. You can only activate 1 "Kairyu-Shin's Dark Reef" per turn.
target_text: -- Kairyu-Shin's
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_1 = 22702055 --Umi
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_1)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c)
  	return c:IsCode(CARD_ID_1) and c:IsAbleToGraveAsCost() and c:IsFaceup()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_ONFIELD, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_ONFIELD, 0, 1, 1, nil)
  	Duel.SendtoGrave(g, REASON_COST)
  end
  function s.spfilter(c, e, tp)
  	return (aux.IsCodeListed(c, CARD_ID_1) or (c:IsType(TYPE_NORMAL) and c:IsAttribute(ATTRIBUTE_WATER))) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE)
  end
  function s.spfilter1(c, e, tp)
  	return c:IsType(TYPE_NORMAL) and c:IsAttribute(ATTRIBUTE_WATER) and c:IsLevelBelow(6) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(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 + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local ft = math.min(2, (Duel.GetLocationCount(tp, LOCATION_MZONE)))
  	if ft > 0 then
  		if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		local tg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, nil, e, tp)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g1 = tg:SelectSubGroup(tp, aux.dncheck, false, 1, ft)
  		if g1 then
  			Duel.SpecialSummon(g1, 0, tp, tp, false, false, POS_FACEUP_DEFENSE)
  		end
  		local ft1 = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		local g2 = Duel.GetMatchingGroup(s.spfilter1, tp, LOCATION_HAND + LOCATION_DECK, 0, nil, e, tp)
  		if ft1 > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  			ft = 1
  		end
  		if ft1 > 0 and Duel.IsExistingMatchingCard(nil, tp, 0, LOCATION_MZONE, 1, nil) and #g2 > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  			local g3 = g2:Select(tp, 1, ft1, nil)
  			if g3 then
  				Duel.SpecialSummon(g3, 0, tp, tp, false, false, POS_FACEUP)
  			end
  		end
  	end
  	if e:IsHasType(EFFECT_TYPE_ACTIVATE) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_FIELD)
  		e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  		e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  		e1:SetTargetRange(1, 0)
  		e1:SetTarget(s.splimit)
  		if Duel.GetTurnPlayer() == tp then
  			e1:SetReset(RESET_PHASE + PHASE_END + RESET_SELF_TURN, 2)
  		else
  			e1:SetReset(RESET_PHASE + PHASE_END + RESET_SELF_TURN, 1)
  		end
  		Duel.RegisterEffect(e1, tp)
  	end
  end
  function s.splimit(e, c)
  	return not c:IsAttribute(ATTRIBUTE_WATER)
  end
  
  