name: T.G.
card_text: 2+ Effect Monsters, including a "T.G." Tuner
  If this card is Link Summoned, you can: Special Summon 3 "T.G." monsters (1 from your hand, 1 from your Deck, and 1 from your GY) in Defense Position to your zones this card points to, also you cannot Special Summon monsters for the rest of this turn, except "T.G." monsters. You can only use this effect of "T.G. Trident Launcher" once per turn. Your opponent cannot target "T.G." Synchro Monsters this card points to with card effects.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x27 --T.G.
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x27 --T.G.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 2, 99, s.lcheck)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--cannot be target/battle indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetTarget(s.tgtg)
  	e2:SetValue(aux.tgoval)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:IsExists(s.mzfilter, 1, nil)
  end
  function s.mzfilter(c)
  	return c:IsLinkSetCard(SETCARD_ID_0) and c:IsLinkType(TYPE_TUNER)
  end
  function s.tgtg(e, c)
  	return e:GetHandler():GetLinkedGroup():IsContains(c) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SYNCHRO)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.spfilter(c, e, tp, zone)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE, tp, zone)
  end
  function s.spcheck(sg, e, tp, mg)
  	return sg:GetClassCount(Card.GetLocation) == #sg
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local zone = e:GetHandler():GetLinkedZone(tp) & 0x1f
  		local ct = Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone)
  		return ct > 2
  			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp, zone)
  			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp, zone)
  			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp, zone)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 3, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		local zone = c:GetLinkedZone(tp) & 0x1f
  		local ct = Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone)
  		if ct >= 3 then
  			local g1 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND, 0, nil, e, tp, zone)
  			local g2 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK, 0, nil, e, tp, zone)
  			local g3 = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, nil, e, tp, zone)
  			if #g1 > 0 and #g2 > 0 and #g3 > 0 then
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local sg1 = g1:Select(tp, 1, 1, nil)
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local sg2 = g2:Select(tp, 1, 1, nil)
  				sg1:Merge(sg2)
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local sg3 = g3:Select(tp, 1, 1, nil)
  				sg1:Merge(sg3)
  				Duel.SpecialSummon(sg1, 0, tp, tp, false, false, POS_FACEUP_DEFENSE, zone)
  			end
  		end
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	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:IsSetCard(SETCARD_ID_0)
  end
  
  
source_text: T.G.
  2+ Effect Monsters, including a "T.G." Tuner
  If this card is Link Summoned, you can: Special Summon 3 "T.G." monsters (1 from your hand, 1 from your Deck, and 1 from your GY) in Defense Position to your zones this card points to, also you cannot Special Summon monsters for the rest of this turn, except "T.G." monsters. You can only use this effect of "T.G. Trident Launcher" once per turn. Your opponent cannot target "T.G." Synchro Monsters this card points to with card effects.
target_text: -- T.G.
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0x27 --T.G.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 2, 99, s.lcheck)
  	--spsummon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--cannot be target/battle indestructable
  	local e2 = Effect.CreateEffect(c)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e2:SetTarget(s.tgtg)
  	e2:SetValue(aux.tgoval)
  	c:RegisterEffect(e2)
  end
  function s.lcheck(g, lc)
  	return g:IsExists(s.mzfilter, 1, nil)
  end
  function s.mzfilter(c)
  	return c:IsLinkSetCard(SETCARD_ID_0) and c:IsLinkType(TYPE_TUNER)
  end
  function s.tgtg(e, c)
  	return e:GetHandler():GetLinkedGroup():IsContains(c) and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SYNCHRO)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.spfilter(c, e, tp, zone)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP_DEFENSE, tp, zone)
  end
  function s.spcheck(sg, e, tp, mg)
  	return sg:GetClassCount(Card.GetLocation) == #sg
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local zone = e:GetHandler():GetLinkedZone(tp) & 0x1f
  		local ct = Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone)
  		return ct > 2
  			and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)
  			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp, zone)
  			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp, zone)
  			and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK, 0, 1, nil, e, tp, zone)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 3, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		local zone = c:GetLinkedZone(tp) & 0x1f
  		local ct = Duel.GetLocationCount(tp, LOCATION_MZONE, tp, LOCATION_REASON_TOFIELD, zone)
  		if ct >= 3 then
  			local g1 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND, 0, nil, e, tp, zone)
  			local g2 = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_DECK, 0, nil, e, tp, zone)
  			local g3 = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.spfilter), tp, LOCATION_GRAVE, 0, nil, e, tp, zone)
  			if #g1 > 0 and #g2 > 0 and #g3 > 0 then
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local sg1 = g1:Select(tp, 1, 1, nil)
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local sg2 = g2:Select(tp, 1, 1, nil)
  				sg1:Merge(sg2)
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  				local sg3 = g3:Select(tp, 1, 1, nil)
  				sg1:Merge(sg3)
  				Duel.SpecialSummon(sg1, 0, tp, tp, false, false, POS_FACEUP_DEFENSE, zone)
  			end
  		end
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_SPECIAL_SUMMON)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	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:IsSetCard(SETCARD_ID_0)
  end
  
  