name: Cycle
card_text: This card is used to Ritual Summon "Ruin, Queen of Oblivion" or "Demise, King of Armageddon". You must also Tribute monsters from your field whose total Levels equal or exceed the Level of the Ritual Monster you Ritual Summon. During your Main Phase, except the turn this card was sent to the GY: You can shuffle this card into the Deck; add 1 "End of the World" from your Deck to your hand, then, you can add 1 "Ruin, Queen of Oblivion" or "Demise, King of Armageddon" from your GY to your hand.
external_ids: local CARD_ID_0 = 46427957 --Ruin, Queen of Oblivion
  local CARD_ID_1 = 72426662 --Demise, King of Armageddon
  local CARD_ID_2 = 8198712 --End of the World
  
lua: local CARD_ID_0 = 46427957 --Ruin, Queen of Oblivion
  local CARD_ID_1 = 72426662 --Demise, King of Armageddon
  local CARD_ID_2 = 8198712 --End of the World
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddRitualProcGreater2Code2(c, CARD_ID_0, CARD_ID_1, nil, nil, s.mfilter)
  	--salvage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.mfilter(c)
  	return not c:IsLocation(LOCATION_HAND)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToDeckAsCost()
  	end
  	Duel.SendtoDeck(e:GetHandler(), nil, SEQ_DECKSHUFFLE, REASON_COST)
  end
  function s.filter(c)
  	return c:IsCode(CARD_ID_2) and c:IsAbleToHand()
  end
  function s.filter2(c)
  	return c:IsCode(CARD_ID_0, CARD_ID_1) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  		local mg = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.filter2), tp, LOCATION_GRAVE, 0, nil)
  		if mg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local sg = mg:Select(tp, 1, 1, nil)
  			Duel.SendtoHand(sg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sg)
  		end
  	end
  end
  
  
source_text: Cycle
  This card is used to Ritual Summon "Ruin, Queen of Oblivion" or "Demise, King of Armageddon". You must also Tribute monsters from your field whose total Levels equal or exceed the Level of the Ritual Monster you Ritual Summon. During your Main Phase, except the turn this card was sent to the GY: You can shuffle this card into the Deck; add 1 "End of the World" from your Deck to your hand, then, you can add 1 "Ruin, Queen of Oblivion" or "Demise, King of Armageddon" from your GY to your hand.
target_text: -- Cycle
  local CARD_ID_0 = 46427957 --Ruin, Queen of Oblivion
  local CARD_ID_1 = 72426662 --Demise, King of Armageddon
  local CARD_ID_2 = 8198712 --End of the World
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddRitualProcGreater2Code2(c, CARD_ID_0, CARD_ID_1, nil, nil, s.mfilter)
  	--salvage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(s.thcost)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.mfilter(c)
  	return not c:IsLocation(LOCATION_HAND)
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToDeckAsCost()
  	end
  	Duel.SendtoDeck(e:GetHandler(), nil, SEQ_DECKSHUFFLE, REASON_COST)
  end
  function s.filter(c)
  	return c:IsCode(CARD_ID_2) and c:IsAbleToHand()
  end
  function s.filter2(c)
  	return c:IsCode(CARD_ID_0, CARD_ID_1) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  		local mg = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.filter2), tp, LOCATION_GRAVE, 0, nil)
  		if mg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 1)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			local sg = mg:Select(tp, 1, 1, nil)
  			Duel.SendtoHand(sg, nil, REASON_EFFECT)
  			Duel.ConfirmCards(1 - tp, sg)
  		end
  	end
  end
  
  