name: Ryu-Ge
card_text: You can only control 1 "Ryu-Ge Realm - Sea Spires". Your "Ryu-Ge" monsters cannot be destroyed by battle. "Ryu-Ge" Pendulum Monsters, and Level 10 or higher monsters whose original Type is Sea Serpent, that you control, gain this effect.
  ● Once per opponent's turn (Quick Effect): You can place 1 "Ryu-Ge" Continuous Spell you control on the bottom of the Deck, then target 1 card on the field; return it to the hand.
external_ids: local SETCARD_ID_0 = 0x1c0 --Ryu-Ge
  
lua: local SETCARD_ID_0 = 0x1c0 --Ryu-Ge
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetUniqueOnField(1, 0, id)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.thcon)
  	e3:SetCost(s.thcost)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_GRANT)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, 0)
  	e4:SetTarget(s.eftg)
  	e4:SetLabelObject(e3)
  	c:RegisterEffect(e4)
  	--change type
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetCode(EFFECT_ADD_TYPE)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetTargetRange(LOCATION_MZONE, 0)
  	e5:SetTarget(s.eftg)
  	e5:SetValue(TYPE_EFFECT)
  	c:RegisterEffect(e5)
  	local e6 = e5:Clone()
  	e6:SetCode(EFFECT_REMOVE_TYPE)
  	e6:SetValue(TYPE_NORMAL)
  	c:RegisterEffect(e6)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == 1 - tp
  end
  function s.costfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsAbleToDeckAsCost()
  		and bit.band(c:GetType(), TYPE_SPELL + TYPE_CONTINUOUS) == TYPE_SPELL + TYPE_CONTINUOUS
  		and Duel.IsExistingMatchingCard(Card.IsAbleToHand, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, c)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_ONFIELD, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_ONFIELD, 0, 1, 1, nil, tp)
  	Duel.HintSelection(g)
  	Duel.SendtoDeck(g, nil, SEQ_DECKBOTTOM, REASON_COST)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsAbleToHand()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToHand, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToHand, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 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 tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.eftg(e, c)
  	return c:IsLevelAbove(10) and c:GetOriginalRace() == RACE_SEASERPENT or c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM)
  end
  
  
source_text: Ryu-Ge
  You can only control 1 "Ryu-Ge Realm - Sea Spires". Your "Ryu-Ge" monsters cannot be destroyed by battle. "Ryu-Ge" Pendulum Monsters, and Level 10 or higher monsters whose original Type is Sea Serpent, that you control, gain this effect.
  ● Once per opponent's turn (Quick Effect): You can place 1 "Ryu-Ge" Continuous Spell you control on the bottom of the Deck, then target 1 card on the field; return it to the hand.
target_text: -- Ryu-Ge
  local SETCARD_ID_0 = 0x1c0 --Ryu-Ge
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetUniqueOnField(1, 0, id)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_FREE_CHAIN)
  	e3:SetHintTiming(0, TIMINGS_CHECK_MONSTER + TIMING_END_PHASE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.thcon)
  	e3:SetCost(s.thcost)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_GRANT)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, 0)
  	e4:SetTarget(s.eftg)
  	e4:SetLabelObject(e3)
  	c:RegisterEffect(e4)
  	--change type
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_FIELD)
  	e5:SetCode(EFFECT_ADD_TYPE)
  	e5:SetRange(LOCATION_SZONE)
  	e5:SetTargetRange(LOCATION_MZONE, 0)
  	e5:SetTarget(s.eftg)
  	e5:SetValue(TYPE_EFFECT)
  	c:RegisterEffect(e5)
  	local e6 = e5:Clone()
  	e6:SetCode(EFFECT_REMOVE_TYPE)
  	e6:SetValue(TYPE_NORMAL)
  	c:RegisterEffect(e6)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetTurnPlayer() == 1 - tp
  end
  function s.costfilter(c, tp)
  	return c:IsFaceup()
  		and c:IsSetCard(SETCARD_ID_0)
  		and c:IsAbleToDeckAsCost()
  		and bit.band(c:GetType(), TYPE_SPELL + TYPE_CONTINUOUS) == TYPE_SPELL + TYPE_CONTINUOUS
  		and Duel.IsExistingMatchingCard(Card.IsAbleToHand, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, c)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_ONFIELD, 0, 1, nil, tp)
  	end
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_ONFIELD, 0, 1, 1, nil, tp)
  	Duel.HintSelection(g)
  	Duel.SendtoDeck(g, nil, SEQ_DECKBOTTOM, REASON_COST)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsOnField() and chkc:IsAbleToHand()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsAbleToHand, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToHand, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 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 tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.eftg(e, c)
  	return c:IsLevelAbove(10) and c:GetOriginalRace() == RACE_SEASERPENT or c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_PENDULUM)
  end
  
  