name: Gunkan
card_text: (When you activate this card, you can also reveal 1 "Gunkan Suship Shari" in your hand.) Reveal 3 "Gunkan" monsters from your Deck, your opponent chooses 1 of them for you to add to your hand, also shuffle the rest into your Deck. If you revealed "Gunkan Suship Shari" in your hand at activation, you can choose the card to add to your hand, instead of your opponent choosing. If this card is in your GY, except the turn it was sent there: You can banish this card, then target 3 "Gunkan" monsters in your GY; shuffle them into the Deck, then draw 1 card.
external_ids: local CARD_ID_0 = 24639891 --Gunkan Suship Shari
  local SETCARD_ID_0 = 0x166 --Gunkan
  
lua: local CARD_ID_0 = 24639891 --Gunkan Suship Shari
  local SETCARD_ID_0 = 0x166 --Gunkan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to deck & draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_DRAW)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsCode(CARD_ID_0) and not c:IsPublic()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_HAND, 0, nil)
  	if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.ConfirmCards(1 - tp, sg)
  		Duel.ShuffleHand(tp)
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if chk == 0 then
  		return g:GetCount() >= 3
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, 0, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() >= 3 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local sg = g:Select(tp, 3, 3, nil)
  		Duel.ConfirmCards(1 - tp, sg)
  		local p = 1 - tp
  		if e:GetLabel() == 1 then
  			p = tp
  		end
  		Duel.Hint(HINT_SELECTMSG, p, HINTMSG_ATOHAND)
  		local tg = sg:Select(p, 1, 1, nil)
  		tg:GetFirst():SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  	end
  end
  function s.tdfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) 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.IsPlayerCanDraw(tp, 1) and Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 3, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 3, 3, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #tg == 0 then
  		return
  	end
  	Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local g = Duel.GetOperatedGroup()
  	if g:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK) then
  		Duel.ShuffleDeck(tp)
  	end
  	local ct = g:FilterCount(Card.IsLocation, nil, LOCATION_DECK + LOCATION_EXTRA)
  	if ct > 0 then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  
  
source_text: Gunkan
  (When you activate this card, you can also reveal 1 "Gunkan Suship Shari" in your hand.) Reveal 3 "Gunkan" monsters from your Deck, your opponent chooses 1 of them for you to add to your hand, also shuffle the rest into your Deck. If you revealed "Gunkan Suship Shari" in your hand at activation, you can choose the card to add to your hand, instead of your opponent choosing. If this card is in your GY, except the turn it was sent there: You can banish this card, then target 3 "Gunkan" monsters in your GY; shuffle them into the Deck, then draw 1 card.
target_text: -- Gunkan
  local CARD_ID_0 = 24639891 --Gunkan Suship Shari
  local SETCARD_ID_0 = 0x166 --Gunkan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--to deck & draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK + CATEGORY_DRAW)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsCode(CARD_ID_0) and not c:IsPublic()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_HAND, 0, nil)
  	if g:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local sg = g:Select(tp, 1, 1, nil)
  		Duel.ConfirmCards(1 - tp, sg)
  		Duel.ShuffleHand(tp)
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if chk == 0 then
  		return g:GetCount() >= 3
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, 0, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetCount() >= 3 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local sg = g:Select(tp, 3, 3, nil)
  		Duel.ConfirmCards(1 - tp, sg)
  		local p = 1 - tp
  		if e:GetLabel() == 1 then
  			p = tp
  		end
  		Duel.Hint(HINT_SELECTMSG, p, HINTMSG_ATOHAND)
  		local tg = sg:Select(p, 1, 1, nil)
  		tg:GetFirst():SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  	end
  end
  function s.tdfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) 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.IsPlayerCanDraw(tp, 1) and Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 3, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 3, 3, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local tg = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #tg == 0 then
  		return
  	end
  	Duel.SendtoDeck(tg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local g = Duel.GetOperatedGroup()
  	if g:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK) then
  		Duel.ShuffleDeck(tp)
  	end
  	local ct = g:FilterCount(Card.IsLocation, nil, LOCATION_DECK + LOCATION_EXTRA)
  	if ct > 0 then
  		Duel.BreakEffect()
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	end
  end
  
  