name: Wattrain
card_text: Add "Watt" cards with different names from your Deck to your hand, except "Wattrain", up to the number of Thunder monsters you control with different names. During your Main Phase, except the turn this card was sent to the GY: You can banish this card from your GY; Special Summon as many "Watt" monsters as possible with different names from your hand. You can only use each effect of "Wattrain" once per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0xe --Watt
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0xe --Watt
  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)
  	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)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.ctfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_THUNDER)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.ctfilter, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g1 = Duel.GetMatchingGroup(s.ctfilter, tp, LOCATION_MZONE, 0, nil)
  	local g2 = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g1:GetCount() == 0 or g2:GetCount() == 0 then
  		return
  	end
  	local ct = g1:GetClassCount(Card.GetCode)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = g2:SelectSubGroup(tp, aux.dncheck, false, 1, ct)
  	if sg and sg:GetCount() > 0 then
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND, 0, nil, e, tp)
  	if ct <= 0 or g:GetCount() == 0 then
  		return
  	end
  	ct = math.min(ct, g:GetClassCount(Card.GetCode))
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ct = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = g:SelectSubGroup(tp, aux.dncheck, false, ct, ct)
  	if sg and sg:GetCount() > 0 then
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Wattrain
  Add "Watt" cards with different names from your Deck to your hand, except "Wattrain", up to the number of Thunder monsters you control with different names. During your Main Phase, except the turn this card was sent to the GY: You can banish this card from your GY; Special Summon as many "Watt" monsters as possible with different names from your hand. You can only use each effect of "Wattrain" once per turn.
target_text: -- Wattrain
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0xe --Watt
  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)
  	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)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(aux.exccon)
  	e2:SetCost(aux.bfgcost)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  end
  function s.ctfilter(c)
  	return c:IsFaceup() and c:IsRace(RACE_THUNDER)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and not c:IsCode(id) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.ctfilter, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local g1 = Duel.GetMatchingGroup(s.ctfilter, tp, LOCATION_MZONE, 0, nil)
  	local g2 = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g1:GetCount() == 0 or g2:GetCount() == 0 then
  		return
  	end
  	local ct = g1:GetClassCount(Card.GetCode)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = g2:SelectSubGroup(tp, aux.dncheck, false, 1, ct)
  	if sg and sg:GetCount() > 0 then
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, sg)
  	end
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ct = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_HAND, 0, nil, e, tp)
  	if ct <= 0 or g:GetCount() == 0 then
  		return
  	end
  	ct = math.min(ct, g:GetClassCount(Card.GetCode))
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ct = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local sg = g:SelectSubGroup(tp, aux.dncheck, false, ct, ct)
  	if sg and sg:GetCount() > 0 then
  		Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  