name: Jurrac
card_text: During your Main Phase: You can destroy 1 card you control, and if you do, send 1 Dinosaur monster from your Deck to the GY, then you can Special Summon "Jurrac" monster(s) from your hand and/or Deck, except "Jurrac Stego", whose total Levels equal the sent monster's Level, ignoring their Summoning conditions, also for the rest of this turn, you cannot Special Summon, except Dinosaur monsters. You can only use this effect of "Jurrac Stego" once per turn. When this card is destroyed by battle: You can return 1 face-up card on the field to the hand.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x22 --Jurrac
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x22 --Jurrac
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, id)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY | CATEGORY_TOGRAVE | CATEGORY_SPECIAL_SUMMON | CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYED)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.tgfilter(c, e, tp)
  	return c:IsLevelAbove(1) and c:IsRace(RACE_DINOSAUR) and c:IsAbleToGrave()
  end
  function s.spfilter(c, e, tp)
  	return not c:IsCode(id) and c:IsSetCard(SETCARD_ID_0) and c:IsLevelAbove(1) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.gcheck(g, lv)
  	return g:GetSum(Card.GetLevel) == lv
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, 0, nil, e, tp)
  	if chk == 0 then
  		return #g > 0 and Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_ONFIELD, 0, 1, 1, nil, e, tp)
  	Duel.HintSelection(g)
  	if Duel.Destroy(g, REASON_EFFECT) > 0 then
  		local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local sg = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  		local gc = sg:GetFirst()
  		if gc and Duel.SendtoGrave(gc, REASON_EFFECT) ~= 0 and gc:IsLocation(LOCATION_GRAVE) and ft > 0 then
  			local lv = gc:GetLevel()
  			if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  				ft = 1
  			end
  			local tg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, nil, e, tp)
  			if tg:CheckSubGroup(s.gcheck, 1, ft, lv) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local ssg = tg:SelectSubGroup(tp, s.gcheck, false, 1, ft, lv)
  				if ssg:GetCount() > 0 then
  					Duel.BreakEffect()
  					Duel.SpecialSummon(ssg, 0, tp, tp, true, false, POS_FACEUP)
  				end
  			end
  		end
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.splimit(e, c)
  	return not c:IsRace(RACE_DINOSAUR)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceup, Card.IsAbleToHand), tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_ONFIELD)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.AND(Card.IsFaceup, Card.IsAbleToHand), tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Jurrac
  During your Main Phase: You can destroy 1 card you control, and if you do, send 1 Dinosaur monster from your Deck to the GY, then you can Special Summon "Jurrac" monster(s) from your hand and/or Deck, except "Jurrac Stego", whose total Levels equal the sent monster's Level, ignoring their Summoning conditions, also for the rest of this turn, you cannot Special Summon, except Dinosaur monsters. You can only use this effect of "Jurrac Stego" once per turn. When this card is destroyed by battle: You can return 1 face-up card on the field to the hand.
target_text: -- Jurrac
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x22 --Jurrac
  local s, id, o = GetID()
  function s.initial_effect(c)
  	aux.AddCodeList(c, id)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY | CATEGORY_TOGRAVE | CATEGORY_SPECIAL_SUMMON | CATEGORY_DECKDES)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_BATTLE_DESTROYED)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.tgfilter(c, e, tp)
  	return c:IsLevelAbove(1) and c:IsRace(RACE_DINOSAUR) and c:IsAbleToGrave()
  end
  function s.spfilter(c, e, tp)
  	return not c:IsCode(id) and c:IsSetCard(SETCARD_ID_0) and c:IsLevelAbove(1) and c:IsType(TYPE_MONSTER) and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  end
  function s.gcheck(g, lv)
  	return g:GetSum(Card.GetLevel) == lv
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, 0, nil, e, tp)
  	if chk == 0 then
  		return #g > 0 and Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_ONFIELD, 0, 1, 1, nil, e, tp)
  	Duel.HintSelection(g)
  	if Duel.Destroy(g, REASON_EFFECT) > 0 then
  		local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  		local sg = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
  		local gc = sg:GetFirst()
  		if gc and Duel.SendtoGrave(gc, REASON_EFFECT) ~= 0 and gc:IsLocation(LOCATION_GRAVE) and ft > 0 then
  			local lv = gc:GetLevel()
  			if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  				ft = 1
  			end
  			local tg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, nil, e, tp)
  			if tg:CheckSubGroup(s.gcheck, 1, ft, lv) and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local ssg = tg:SelectSubGroup(tp, s.gcheck, false, 1, ft, lv)
  				if ssg:GetCount() > 0 then
  					Duel.BreakEffect()
  					Duel.SpecialSummon(ssg, 0, tp, tp, true, false, POS_FACEUP)
  				end
  			end
  		end
  	end
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetTargetRange(1, 0)
  	e1:SetTarget(s.splimit)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.splimit(e, c)
  	return not c:IsRace(RACE_DINOSAUR)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(aux.AND(Card.IsFaceup, Card.IsAbleToHand), tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_ONFIELD)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.AND(Card.IsFaceup, Card.IsAbleToHand), tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.HintSelection(g)
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  	end
  end
  
  