name: Runick
card_text: You can activate "Runick" Quick-Play Spell Cards from your hand during your opponent's turn. Once per turn, if you activate a "Runick" Quick-Play Spell Card: You can target up to 3 "Runick" Quick-Play Spells in your GY; place them on the bottom of your Deck in any order, then draw the same number of cards.
external_ids: local SETCARD_ID_0 = 0x17f --Runick
  
lua: local SETCARD_ID_0 = 0x17f --Runick
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--act qp in hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_QP_ACT_IN_NTPHAND)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetTargetRange(LOCATION_HAND, 0)
  	c:RegisterEffect(e2)
  	--control
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_TODECK + CATEGORY_DRAW)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.condition)
  	e3:SetTarget(s.target)
  	e3:SetOperation(s.operation)
  	c:RegisterEffect(e3)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return rp == tp and re:IsActiveType(TYPE_SPELL) and re:IsActiveType(TYPE_QUICKPLAY) and re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:GetHandler():IsSetCard(SETCARD_ID_0)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_QUICKPLAY) and c:IsAbleToDeck()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp) and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 3, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, #g, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, #g)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local sg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #sg == 0 then
  		return
  	end
  	Duel.SendtoDeck(sg, nil, SEQ_DECKTOP, REASON_EFFECT)
  	local og = Duel.GetOperatedGroup()
  	local ct = og:FilterCount(Card.IsLocation, nil, LOCATION_DECK)
  	if ct == 0 then
  		return
  	end
  	Duel.SortDecktop(tp, tp, ct)
  	for i = 1, ct do
  		local mg = Duel.GetDecktopGroup(tp, 1)
  		Duel.MoveSequence(mg:GetFirst(), 1)
  	end
  	Duel.BreakEffect()
  	Duel.Draw(tp, ct, REASON_EFFECT)
  end
  
  
source_text: Runick
  You can activate "Runick" Quick-Play Spell Cards from your hand during your opponent's turn. Once per turn, if you activate a "Runick" Quick-Play Spell Card: You can target up to 3 "Runick" Quick-Play Spells in your GY; place them on the bottom of your Deck in any order, then draw the same number of cards.
target_text: -- Runick
  local SETCARD_ID_0 = 0x17f --Runick
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--act qp in hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_QP_ACT_IN_NTPHAND)
  	e2:SetRange(LOCATION_FZONE)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetTargetRange(LOCATION_HAND, 0)
  	c:RegisterEffect(e2)
  	--control
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_TODECK + CATEGORY_DRAW)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetProperty(EFFECT_FLAG_DELAY + EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_FZONE)
  	e3:SetCountLimit(1)
  	e3:SetCondition(s.condition)
  	e3:SetTarget(s.target)
  	e3:SetOperation(s.operation)
  	c:RegisterEffect(e3)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return rp == tp and re:IsActiveType(TYPE_SPELL) and re:IsActiveType(TYPE_QUICKPLAY) and re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:GetHandler():IsSetCard(SETCARD_ID_0)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_QUICKPLAY) and c:IsAbleToDeck()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp) and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 3, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, #g, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, #g)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local sg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #sg == 0 then
  		return
  	end
  	Duel.SendtoDeck(sg, nil, SEQ_DECKTOP, REASON_EFFECT)
  	local og = Duel.GetOperatedGroup()
  	local ct = og:FilterCount(Card.IsLocation, nil, LOCATION_DECK)
  	if ct == 0 then
  		return
  	end
  	Duel.SortDecktop(tp, tp, ct)
  	for i = 1, ct do
  		local mg = Duel.GetDecktopGroup(tp, 1)
  		Duel.MoveSequence(mg:GetFirst(), 1)
  	end
  	Duel.BreakEffect()
  	Duel.Draw(tp, ct, REASON_EFFECT)
  end
  
  