name: Gunkan
card_text: Once per turn: You can reveal 1 "Gunkan Suship Shari" in your hand; place 1 counter on this card, and if you do, reveal 1 "Gunkan" Xyz Monster from your Extra Deck, and your opponent declares 1 "Gunkan" monster's card name, except "Gunkan Suship Shari", that is mentioned on any "Gunkan" Xyz Monster, then, you add that declared card from your Deck to your hand. If you cannot add, shuffle this card into the Deck. If this card in its owner's possession is destroyed by an opponent's card: Your opponent pays exactly 500 LP for each counter on this card.
external_ids: local CARD_ID_0 = 24639891 --Gunkan Suship Shari
  local CARD_ID_1 = 42377643 --Gunkan Suship Uni
  local CARD_ID_2 = 61027400 --Gunkan Suship Ikura
  local CARD_ID_3 = 78362751 --Gunkan Suship Shirauo
  local SETCARD_ID_0 = 0x166 --Gunkan
  local COUNTER_ID_0 = 0x66 --Counter(Gunkan
  
lua: local CARD_ID_0 = 24639891 --Gunkan Suship Shari
  local CARD_ID_1 = 42377643 --Gunkan Suship Uni
  local CARD_ID_2 = 61027400 --Gunkan Suship Ikura
  local CARD_ID_3 = 78362751 --Gunkan Suship Shirauo
  local SETCARD_ID_0 = 0x166 --Gunkan
  local COUNTER_ID_0 = 0x66 --Counter(Gunkan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x66)
  	aux.SushipMentionsTable = aux.SushipMentionsTable or { CARD_ID_2, CARD_ID_3, CARD_ID_1 }
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--add
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_COUNTER + CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	--pay lp
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_LEAVE_FIELD_P)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetOperation(s.regop)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_DESTROYED)
  	e4:SetCondition(s.plpcon)
  	e4:SetOperation(s.plpop)
  	c:RegisterEffect(e4)
  	e3:SetLabelObject(e4)
  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 Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	Duel.ConfirmCards(1 - tp, g)
  	Duel.ShuffleHand(tp)
  end
  function s.rfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ) and not c:IsPublic()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.rfilter, tp, LOCATION_EXTRA, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_COUNTER, e:GetHandler(), 1, tp, 0x66)
  end
  function s.filter(c, code)
  	return c:IsCode(code) and c:IsAbleToHand()
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:AddCounter(COUNTER_ID_0, 1) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  	local g = Duel.SelectMatchingCard(tp, s.rfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil)
  	if #g == 0 then
  		return
  	end
  	Duel.ConfirmCards(1 - tp, g)
  	local nt = {}
  	for i, n in ipairs(aux.SushipMentionsTable) do
  		table.insert(nt, n)
  		table.insert(nt, OPCODE_ISCODE)
  		if i > 1 then
  			table.insert(nt, OPCODE_OR)
  		end
  	end
  	local code = Duel.AnnounceCard(1 - tp, table.unpack(nt))
  	Duel.Hint(HINT_CARD, tp, code)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local tc = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, code):GetFirst()
  	if tc then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tc)
  	elseif c:IsRelateToEffect(e) then
  		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = e:GetHandler():GetCounter(COUNTER_ID_0)
  	e:GetLabelObject():SetLabel(ct)
  end
  function s.plpcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousControler(tp) and c:IsReason(REASON_DESTROY) and c:GetReasonPlayer() == 1 - tp
  end
  function s.plpop(e, tp, eg, ep, ev, re, r, rp)
  	local val = e:GetLabel() * 500
  	if val > 0 and Duel.GetLP(1 - tp) >= val then
  		Duel.PayLPCost(1 - tp, val)
  	end
  end
  
  
source_text: Gunkan
  Once per turn: You can reveal 1 "Gunkan Suship Shari" in your hand; place 1 counter on this card, and if you do, reveal 1 "Gunkan" Xyz Monster from your Extra Deck, and your opponent declares 1 "Gunkan" monster's card name, except "Gunkan Suship Shari", that is mentioned on any "Gunkan" Xyz Monster, then, you add that declared card from your Deck to your hand. If you cannot add, shuffle this card into the Deck. If this card in its owner's possession is destroyed by an opponent's card: Your opponent pays exactly 500 LP for each counter on this card.
target_text: -- Gunkan
  local CARD_ID_0 = 24639891 --Gunkan Suship Shari
  local CARD_ID_1 = 42377643 --Gunkan Suship Uni
  local CARD_ID_2 = 61027400 --Gunkan Suship Ikura
  local CARD_ID_3 = 78362751 --Gunkan Suship Shirauo
  local SETCARD_ID_0 = 0x166 --Gunkan
  local COUNTER_ID_0 = 0x66 --Counter(Gunkan
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x66)
  	aux.SushipMentionsTable = aux.SushipMentionsTable or { CARD_ID_2, CARD_ID_3, CARD_ID_1 }
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--add
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_COUNTER + CATEGORY_SEARCH + CATEGORY_TOHAND + CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	--pay lp
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EVENT_LEAVE_FIELD_P)
  	e3:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e3:SetOperation(s.regop)
  	c:RegisterEffect(e3)
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
  	e4:SetCode(EVENT_DESTROYED)
  	e4:SetCondition(s.plpcon)
  	e4:SetOperation(s.plpop)
  	c:RegisterEffect(e4)
  	e3:SetLabelObject(e4)
  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 Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_HAND, 0, 1, 1, nil)
  	Duel.ConfirmCards(1 - tp, g)
  	Duel.ShuffleHand(tp)
  end
  function s.rfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ) and not c:IsPublic()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.rfilter, tp, LOCATION_EXTRA, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_COUNTER, e:GetHandler(), 1, tp, 0x66)
  end
  function s.filter(c, code)
  	return c:IsCode(code) and c:IsAbleToHand()
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if not c:AddCounter(COUNTER_ID_0, 1) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  	local g = Duel.SelectMatchingCard(tp, s.rfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil)
  	if #g == 0 then
  		return
  	end
  	Duel.ConfirmCards(1 - tp, g)
  	local nt = {}
  	for i, n in ipairs(aux.SushipMentionsTable) do
  		table.insert(nt, n)
  		table.insert(nt, OPCODE_ISCODE)
  		if i > 1 then
  			table.insert(nt, OPCODE_OR)
  		end
  	end
  	local code = Duel.AnnounceCard(1 - tp, table.unpack(nt))
  	Duel.Hint(HINT_CARD, tp, code)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local tc = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, code):GetFirst()
  	if tc then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tc)
  	elseif c:IsRelateToEffect(e) then
  		Duel.SendtoDeck(c, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = e:GetHandler():GetCounter(COUNTER_ID_0)
  	e:GetLabelObject():SetLabel(ct)
  end
  function s.plpcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsPreviousControler(tp) and c:IsReason(REASON_DESTROY) and c:GetReasonPlayer() == 1 - tp
  end
  function s.plpop(e, tp, eg, ep, ev, re, r, rp)
  	local val = e:GetLabel() * 500
  	if val > 0 and Duel.GetLP(1 - tp) >= val then
  		Duel.PayLPCost(1 - tp, val)
  	end
  end
  
  