name: Radiant
card_text: Activate 1 of these effects (but you can only use each effect of "Radiant Typhoon Summoning Technique" once per turn);
  ● Send 1 "Radiant Typhoon" monster from your Deck to the GY.
  ● Add 1 "Mystical Space Typhoon" from your Deck or GY to your hand. 
  If this card is destroyed by the effect of "Mystical Space Typhoon": You can Set this card.
external_ids: local CARD_ID_0 = 5318639 --Mystical Space Typhoon
  local SETCARD_ID_0 = 0x1d1 --Radiant
  
lua: local CARD_ID_0 = 5318639 --Mystical Space Typhoon
  local SETCARD_ID_0 = 0x1d1 --Radiant
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCondition(s.setcon)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  end
  function s.tgfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToGrave()
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil) and (not e:IsCostChecked() or Duel.GetFlagEffect(tp, id) == 0)
  	local b2 = Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil) and (not e:IsCostChecked() or Duel.GetFlagEffect(tp, id + o) == 0)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	if b1 or b2 then
  		op = aux.SelectFromOptions(tp, { b1, aux.Stringid(id, 2), 1 }, { b2, aux.Stringid(id, 3), 2 })
  	end
  	e:SetLabel(op)
  	if op == 1 then
  		if e:IsCostChecked() then
  			e:SetCategory(CATEGORY_TOGRAVE)
  			Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  		end
  		Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  	elseif op == 2 then
  		if e:IsCostChecked() then
  			e:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  			Duel.RegisterFlagEffect(tp, id + o, RESET_PHASE + PHASE_END, 0, 1)
  		end
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.SendtoGrave(g, REASON_EFFECT)
  		end
  	elseif e:GetLabel() == 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_EFFECT) and re:GetHandler():IsCode(CARD_ID_0)
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToChain() and aux.NecroValleyFilter()(c) then
  		Duel.SSet(tp, c)
  	end
  end
  
  
source_text: Radiant
  Activate 1 of these effects (but you can only use each effect of "Radiant Typhoon Summoning Technique" once per turn);
  ● Send 1 "Radiant Typhoon" monster from your Deck to the GY.
  ● Add 1 "Mystical Space Typhoon" from your Deck or GY to your hand. 
  If this card is destroyed by the effect of "Mystical Space Typhoon": You can Set this card.
target_text: -- Radiant
  local CARD_ID_0 = 5318639 --Mystical Space Typhoon
  local SETCARD_ID_0 = 0x1d1 --Radiant
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_0)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_TOGRAVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(0, TIMING_END_PHASE)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--set
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetCondition(s.setcon)
  	e2:SetTarget(s.settg)
  	e2:SetOperation(s.setop)
  	c:RegisterEffect(e2)
  end
  function s.tgfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToGrave()
  end
  function s.thfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local b1 = Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil) and (not e:IsCostChecked() or Duel.GetFlagEffect(tp, id) == 0)
  	local b2 = Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil) and (not e:IsCostChecked() or Duel.GetFlagEffect(tp, id + o) == 0)
  	if chk == 0 then
  		return b1 or b2
  	end
  	local op = 0
  	if b1 or b2 then
  		op = aux.SelectFromOptions(tp, { b1, aux.Stringid(id, 2), 1 }, { b2, aux.Stringid(id, 3), 2 })
  	end
  	e:SetLabel(op)
  	if op == 1 then
  		if e:IsCostChecked() then
  			e:SetCategory(CATEGORY_TOGRAVE)
  			Duel.RegisterFlagEffect(tp, id, RESET_PHASE + PHASE_END, 0, 1)
  		end
  		Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  	elseif op == 2 then
  		if e:IsCostChecked() then
  			e:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  			Duel.RegisterFlagEffect(tp, id + o, RESET_PHASE + PHASE_END, 0, 1)
  		end
  		Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetLabel() == 1 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.SendtoGrave(g, REASON_EFFECT)
  		end
  	elseif e:GetLabel() == 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  		if g:GetCount() > 0 then
  			Duel.SendtoHand(g, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, g)
  		end
  	end
  end
  function s.setcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_EFFECT) and re:GetHandler():IsCode(CARD_ID_0)
  end
  function s.settg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsSSetable()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.setop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToChain() and aux.NecroValleyFilter()(c) then
  		Duel.SSet(tp, c)
  	end
  end
  
  