name: Sky
card_text: Activate this card only if you control no monsters in your Main Monster Zones. The equipped monster cannot attack directly. It can make a second attack on monsters during each Battle Phase. If the equipped monster destroys a monster by its attack while you have 3 or more Spells in your GY: Draw 1 card. If this card is sent from the field to the GY by a card effect: You can target up to 3 "Sky Striker" cards in your GY, except "Sky Striker Mecharmory - Hercules Base"; shuffle them into the Deck.
external_ids: local SETCARD_ID_0 = 0x115 --Sky
  
lua: local SETCARD_ID_0 = 0x115 --Sky
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--cannot direct attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_EQUIP)
  	e2:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	c:RegisterEffect(e2)
  	--extra attack
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_EQUIP)
  	e3:SetCode(EFFECT_EXTRA_ATTACK_MONSTER)
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  	--draw
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_DRAW)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e4:SetCode(EVENT_BATTLE_DESTROYING)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCondition(s.drcon)
  	e4:SetTarget(s.drtg)
  	e4:SetOperation(s.drop)
  	c:RegisterEffect(e4)
  	--todeck
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_TODECK)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_TO_GRAVE)
  	e5:SetCondition(s.tdcon)
  	e5:SetTarget(s.tdtg)
  	e5:SetOperation(s.tdop)
  	c:RegisterEffect(e5)
  	--Equip limit
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_SINGLE)
  	e6:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e6:SetCode(EFFECT_EQUIP_LIMIT)
  	e6:SetValue(1)
  	c:RegisterEffect(e6)
  end
  function s.cfilter(c)
  	return c:GetSequence() < 5
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return not Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if e:GetHandler():IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, e:GetHandler(), tc)
  	end
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	local ec = e:GetHandler():GetEquipTarget()
  	return Duel.GetMatchingGroupCount(Card.IsType, tp, LOCATION_GRAVE, 0, nil, TYPE_SPELL) >= 3 and eg:GetFirst() == ec and Duel.GetAttacker() == ec
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_EFFECT) and c:IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.tdfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 3, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() > 0 then
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  
source_text: Sky
  Activate this card only if you control no monsters in your Main Monster Zones. The equipped monster cannot attack directly. It can make a second attack on monsters during each Battle Phase. If the equipped monster destroys a monster by its attack while you have 3 or more Spells in your GY: Draw 1 card. If this card is sent from the field to the GY by a card effect: You can target up to 3 "Sky Striker" cards in your GY, except "Sky Striker Mecharmory - Hercules Base"; shuffle them into the Deck.
target_text: -- Sky
  local SETCARD_ID_0 = 0x115 --Sky
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_EQUIP)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_CONTINUOUS_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--cannot direct attack
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_EQUIP)
  	e2:SetCode(EFFECT_CANNOT_DIRECT_ATTACK)
  	c:RegisterEffect(e2)
  	--extra attack
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_EQUIP)
  	e3:SetCode(EFFECT_EXTRA_ATTACK_MONSTER)
  	e3:SetValue(1)
  	c:RegisterEffect(e3)
  	--draw
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_DRAW)
  	e4:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e4:SetCode(EVENT_BATTLE_DESTROYING)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCondition(s.drcon)
  	e4:SetTarget(s.drtg)
  	e4:SetOperation(s.drop)
  	c:RegisterEffect(e4)
  	--todeck
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_TODECK)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_TO_GRAVE)
  	e5:SetCondition(s.tdcon)
  	e5:SetTarget(s.tdtg)
  	e5:SetOperation(s.tdop)
  	c:RegisterEffect(e5)
  	--Equip limit
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_SINGLE)
  	e6:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e6:SetCode(EFFECT_EQUIP_LIMIT)
  	e6:SetValue(1)
  	c:RegisterEffect(e6)
  end
  function s.cfilter(c)
  	return c:GetSequence() < 5
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return not Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_EQUIP)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_EQUIP, e:GetHandler(), 1, 0, 0)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if e:GetHandler():IsRelateToEffect(e) and tc:IsRelateToEffect(e) and tc:IsFaceup() then
  		Duel.Equip(tp, e:GetHandler(), tc)
  	end
  end
  function s.drcon(e, tp, eg, ep, ev, re, r, rp)
  	local ec = e:GetHandler():GetEquipTarget()
  	return Duel.GetMatchingGroupCount(Card.IsType, tp, LOCATION_GRAVE, 0, nil, TYPE_SPELL) >= 3 and eg:GetFirst() == ec and Duel.GetAttacker() == ec
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  function s.tdcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_EFFECT) and c:IsPreviousLocation(LOCATION_ONFIELD)
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.tdfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 3, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if g:GetCount() > 0 then
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  
  