name: Imperial
card_text: If you control no other monsters: You can Tribute this card; take 2 different monsters from your Deck among "Queen's Knight", "King's Knight", and/or "Jack's Knight", and either add to your hand or Special Summon each monster. You can only use this effect of "Imperial Bower" once per turn.
external_ids: local CARD_ID_0 = 64788463 --King's Knight
  local CARD_ID_1 = 90876561 --Jack's Knight
  local CARD_ID_2 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_3 = 25652259 --Queen's Knight
  
lua: local CARD_ID_0 = 64788463 --King's Knight
  local CARD_ID_1 = 90876561 --Jack's Knight
  local CARD_ID_2 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_3 = 25652259 --Queen's Knight
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_3, CARD_ID_0, CARD_ID_1)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_SPECIAL_SUMMON + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 1
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.opfilter(c, e, tp, ft)
  	return (c:IsAbleToHand() or c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and ft > 0) and c:IsCode(CARD_ID_0, CARD_ID_3, CARD_ID_1)
  end
  function s.opcheck(g, e, tp, ft)
  	if g:GetClassCount(Card.GetCode) < 2 then
  		return false
  	end
  	local thct = g:FilterCount(Card.IsAbleToHand, nil)
  	local spct = g:FilterCount(Card.IsCanBeSpecialSummoned, nil, e, 0, tp, false, false)
  	return thct + math.min(spct, ft) >= 2
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ft = Duel.GetMZoneCount(tp, e:GetHandler())
  		if ft < 0 then
  			ft = 0
  		end
  		if ft > 0 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_2) then
  			ft = 1
  		end
  		local g = Duel.GetMatchingGroup(s.opfilter, tp, LOCATION_DECK, 0, nil, e, tp, ft)
  		return g:CheckSubGroup(s.opcheck, 2, 2, e, tp, ft)
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft < 0 then
  		ft = 0
  	end
  	if ft > 0 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_2) then
  		ft = 1
  	end
  	local g = Duel.GetMatchingGroup(s.opfilter, tp, LOCATION_DECK, 0, nil, e, tp, ft)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local sg = g:SelectSubGroup(tp, s.opcheck, false, 2, 2, e, tp, ft)
  	if not sg then
  		return
  	end
  	local thsg = Group.CreateGroup()
  	local spsg = Group.CreateGroup()
  	local thct = sg:FilterCount(Card.IsAbleToHand, nil)
  	local spct = sg:FilterCount(Card.IsCanBeSpecialSummoned, nil, e, 0, tp, false, false)
  	if thct == 0 then
  		spsg = sg
  	elseif spct == 0 or ft == 0 then
  		thsg = sg
  	else
  		if Duel.SelectYesNo(tp, aux.Stringid(id, 1)) or ft < 2 then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			thsg = sg:FilterSelect(tp, Card.IsAbleToHand, 1, thct, nil)
  			spsg = sg - thsg
  		else
  			spsg = sg
  		end
  	end
  	if #thsg > 0 then
  		Duel.SendtoHand(thsg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, thsg)
  	end
  	if #spsg > 0 then
  		Duel.SpecialSummon(spsg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Imperial
  If you control no other monsters: You can Tribute this card; take 2 different monsters from your Deck among "Queen's Knight", "King's Knight", and/or "Jack's Knight", and either add to your hand or Special Summon each monster. You can only use this effect of "Imperial Bower" once per turn.
target_text: -- Imperial
  local CARD_ID_0 = 64788463 --King's Knight
  local CARD_ID_1 = 90876561 --Jack's Knight
  local CARD_ID_2 = 59822133 --Blue-Eyes Spirit Dragon
  local CARD_ID_3 = 25652259 --Queen's Knight
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, CARD_ID_3, CARD_ID_0, CARD_ID_1)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SEARCH + CATEGORY_SPECIAL_SUMMON + CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetCost(s.spcost)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 1
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsReleasable()
  	end
  	Duel.Release(e:GetHandler(), REASON_COST)
  end
  function s.opfilter(c, e, tp, ft)
  	return (c:IsAbleToHand() or c:IsCanBeSpecialSummoned(e, 0, tp, false, false) and ft > 0) and c:IsCode(CARD_ID_0, CARD_ID_3, CARD_ID_1)
  end
  function s.opcheck(g, e, tp, ft)
  	if g:GetClassCount(Card.GetCode) < 2 then
  		return false
  	end
  	local thct = g:FilterCount(Card.IsAbleToHand, nil)
  	local spct = g:FilterCount(Card.IsCanBeSpecialSummoned, nil, e, 0, tp, false, false)
  	return thct + math.min(spct, ft) >= 2
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ft = Duel.GetMZoneCount(tp, e:GetHandler())
  		if ft < 0 then
  			ft = 0
  		end
  		if ft > 0 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_2) then
  			ft = 1
  		end
  		local g = Duel.GetMatchingGroup(s.opfilter, tp, LOCATION_DECK, 0, nil, e, tp, ft)
  		return g:CheckSubGroup(s.opcheck, 2, 2, e, tp, ft)
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft < 0 then
  		ft = 0
  	end
  	if ft > 0 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_2) then
  		ft = 1
  	end
  	local g = Duel.GetMatchingGroup(s.opfilter, tp, LOCATION_DECK, 0, nil, e, tp, ft)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_OPERATECARD)
  	local sg = g:SelectSubGroup(tp, s.opcheck, false, 2, 2, e, tp, ft)
  	if not sg then
  		return
  	end
  	local thsg = Group.CreateGroup()
  	local spsg = Group.CreateGroup()
  	local thct = sg:FilterCount(Card.IsAbleToHand, nil)
  	local spct = sg:FilterCount(Card.IsCanBeSpecialSummoned, nil, e, 0, tp, false, false)
  	if thct == 0 then
  		spsg = sg
  	elseif spct == 0 or ft == 0 then
  		thsg = sg
  	else
  		if Duel.SelectYesNo(tp, aux.Stringid(id, 1)) or ft < 2 then
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  			thsg = sg:FilterSelect(tp, Card.IsAbleToHand, 1, thct, nil)
  			spsg = sg - thsg
  		else
  			spsg = sg
  		end
  	end
  	if #thsg > 0 then
  		Duel.SendtoHand(thsg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, thsg)
  	end
  	if #spsg > 0 then
  		Duel.SpecialSummon(spsg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  