name: Ursarctic
card_text: Special Summon 1 "Ultimate Flagship Ursatron" from your Extra Deck by banishing 1 "Ursarctic Big Dipper" and 1 "Drytron Fafnir" from your hand and/or field, although you can banish 1 of them from your Deck instead if "Ursarctic Polari" or "Drytron Alpha Thuban" is on the field. If you would Tribute a monster(s) to activate an "Ursarctic" or "Drytron" monster's effect, you can banish this card from your GY instead. You can only use this effect of "Ursarctic Drytron" once per turn.
external_ids: local CARD_ID_0 = 58793369 --Drytron Fafnir
  local CARD_ID_1 = 97148796 --Drytron Alpha Thuban
  local CARD_ID_2 = 89264428 --Ursarctic Big Dipper
  local CARD_ID_3 = 27693363 --Ursarctic Polari
  local CARD_ID_4 = 33250142 --Ultimate Flagship Ursatron
  
lua: local CARD_ID_0 = 58793369 --Drytron Fafnir
  local CARD_ID_1 = 97148796 --Drytron Alpha Thuban
  local CARD_ID_2 = 89264428 --Ursarctic Big Dipper
  local CARD_ID_3 = 27693363 --Ursarctic Polari
  local CARD_ID_4 = 33250142 --Ultimate Flagship Ursatron
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_2, CARD_ID_0, CARD_ID_1, CARD_ID_3)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetCode(id)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(16471775)
  	c:RegisterEffect(e3)
  end
  function s.deckconfilter(c)
  	return c:IsCode(CARD_ID_1, CARD_ID_3) and c:IsFaceup()
  end
  function s.deckcon(tp)
  	return Duel.IsExistingMatchingCard(s.deckconfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  end
  function s.cfilter(c)
  	return c:IsCode(CARD_ID_2, CARD_ID_0) and c:IsAbleToRemove()
  end
  function s.fselect(g, e, tp)
  	return g:GetClassCount(Card.GetCode) == 2 and g:FilterCount(Card.IsLocation, nil, LOCATION_DECK) <= 1 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, g)
  end
  function s.spfilter(c, e, tp, g)
  	return c:IsCode(CARD_ID_4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, true) and Duel.GetLocationCountFromEx(tp, tp, g, c) > 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local loc = LOCATION_HAND + LOCATION_ONFIELD
  	if s.deckcon(tp) then
  		loc = loc | LOCATION_DECK
  	end
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, loc, 0, nil)
  	if chk == 0 then
  		return g:CheckSubGroup(s.fselect, 2, 2, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 2, tp, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local loc = LOCATION_HAND + LOCATION_ONFIELD
  	if s.deckcon(tp) then
  		loc = loc | LOCATION_DECK
  	end
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, loc, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local rg = g:SelectSubGroup(tp, s.fselect, false, 2, 2, e, tp)
  	if rg and Duel.Remove(rg, POS_FACEUP, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, nil)
  		if #sg > 0 then
  			Duel.SpecialSummon(sg, 0, tp, tp, false, true, POS_FACEUP)
  			sg:GetFirst():CompleteProcedure()
  		end
  	end
  end
  
  
source_text: Ursarctic
  Special Summon 1 "Ultimate Flagship Ursatron" from your Extra Deck by banishing 1 "Ursarctic Big Dipper" and 1 "Drytron Fafnir" from your hand and/or field, although you can banish 1 of them from your Deck instead if "Ursarctic Polari" or "Drytron Alpha Thuban" is on the field. If you would Tribute a monster(s) to activate an "Ursarctic" or "Drytron" monster's effect, you can banish this card from your GY instead. You can only use this effect of "Ursarctic Drytron" once per turn.
target_text: -- Ursarctic
  local CARD_ID_0 = 58793369 --Drytron Fafnir
  local CARD_ID_1 = 97148796 --Drytron Alpha Thuban
  local CARD_ID_2 = 89264428 --Ursarctic Big Dipper
  local CARD_ID_3 = 27693363 --Ursarctic Polari
  local CARD_ID_4 = 33250142 --Ultimate Flagship Ursatron
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_2, CARD_ID_0, CARD_ID_1, CARD_ID_3)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetCode(id)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(16471775)
  	c:RegisterEffect(e3)
  end
  function s.deckconfilter(c)
  	return c:IsCode(CARD_ID_1, CARD_ID_3) and c:IsFaceup()
  end
  function s.deckcon(tp)
  	return Duel.IsExistingMatchingCard(s.deckconfilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  end
  function s.cfilter(c)
  	return c:IsCode(CARD_ID_2, CARD_ID_0) and c:IsAbleToRemove()
  end
  function s.fselect(g, e, tp)
  	return g:GetClassCount(Card.GetCode) == 2 and g:FilterCount(Card.IsLocation, nil, LOCATION_DECK) <= 1 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_EXTRA, 0, 1, nil, e, tp, g)
  end
  function s.spfilter(c, e, tp, g)
  	return c:IsCode(CARD_ID_4) and c:IsCanBeSpecialSummoned(e, 0, tp, false, true) and Duel.GetLocationCountFromEx(tp, tp, g, c) > 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local loc = LOCATION_HAND + LOCATION_ONFIELD
  	if s.deckcon(tp) then
  		loc = loc | LOCATION_DECK
  	end
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, loc, 0, nil)
  	if chk == 0 then
  		return g:CheckSubGroup(s.fselect, 2, 2, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 2, tp, LOCATION_HAND + LOCATION_ONFIELD + LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_EXTRA)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local loc = LOCATION_HAND + LOCATION_ONFIELD
  	if s.deckcon(tp) then
  		loc = loc | LOCATION_DECK
  	end
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, loc, 0, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local rg = g:SelectSubGroup(tp, s.fselect, false, 2, 2, e, tp)
  	if rg and Duel.Remove(rg, POS_FACEUP, REASON_EFFECT) ~= 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local sg = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_EXTRA, 0, 1, 1, nil, e, tp, nil)
  		if #sg > 0 then
  			Duel.SpecialSummon(sg, 0, tp, tp, false, true, POS_FACEUP)
  			sg:GetFirst():CompleteProcedure()
  		end
  	end
  end
  
  