name: Ground
card_text: Add 1 Dinosaur Tuner or Dinosaur Normal Monster from your Deck to your hand, then destroy 1 card in your hand. You can banish this card from your GY; Fusion Summon 1 Dinosaur Fusion Monster from your Extra Deck, using monsters from your hand or field as material. You can only use each effect of "Ground Xeno" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--fusion
  	local e2 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  	})
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetCost(aux.bfgcost)
  	c:RegisterEffect(e2)
  end
  
  function s.filter(c)
  	return c:IsRace(RACE_DINOSAUR) and c:IsType(TYPE_TUNER + TYPE_NORMAL) and c:IsAbleToHand()
  end
  
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, nil, 1, tp, LOCATION_HAND)
  end
  
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if #g == 0 then
  		return false
  	end
  	local tc = g:GetFirst()
  	if Duel.SendtoHand(tc, nil, REASON_EFFECT) > 0 and tc:IsLocation(LOCATION_HAND) then
  		Duel.ConfirmCards(1 - tp, tc)
  		Duel.BreakEffect()
  		Duel.ShuffleHand(tp)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local dg = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_HAND, 0, 1, 1, nil)
  		Duel.Destroy(dg, REASON_EFFECT)
  	end
  end
  
  function s.fusfilter(c)
  	return c:IsRace(RACE_DINOSAUR)
  end
  
  
source_text: Ground
  Add 1 Dinosaur Tuner or Dinosaur Normal Monster from your Deck to your hand, then destroy 1 card in your hand. You can banish this card from your GY; Fusion Summon 1 Dinosaur Fusion Monster from your Extra Deck, using monsters from your hand or field as material. You can only use each effect of "Ground Xeno" once per turn.
target_text: -- Ground
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_DESTROY)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--fusion
  	local e2 = FusionSpell.CreateSummonEffect(c, {
  		fusfilter = s.fusfilter,
  	})
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + o)
  	e2:SetCost(aux.bfgcost)
  	c:RegisterEffect(e2)
  end
  
  function s.filter(c)
  	return c:IsRace(RACE_DINOSAUR) and c:IsType(TYPE_TUNER + TYPE_NORMAL) and c:IsAbleToHand()
  end
  
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, nil, 1, tp, LOCATION_HAND)
  end
  
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if #g == 0 then
  		return false
  	end
  	local tc = g:GetFirst()
  	if Duel.SendtoHand(tc, nil, REASON_EFFECT) > 0 and tc:IsLocation(LOCATION_HAND) then
  		Duel.ConfirmCards(1 - tp, tc)
  		Duel.BreakEffect()
  		Duel.ShuffleHand(tp)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  		local dg = Duel.SelectMatchingCard(tp, nil, tp, LOCATION_HAND, 0, 1, 1, nil)
  		Duel.Destroy(dg, REASON_EFFECT)
  	end
  end
  
  function s.fusfilter(c)
  	return c:IsRace(RACE_DINOSAUR)
  end
  
  