name: Thunder
card_text: "Thunder Dragon" + 1 Thunder monster
  Must be either Fusion Summoned, or Special Summoned during the turn a Thunder monster's effect was activated in the hand, by Tributing 1 Thunder Effect non-Fusion Monster (in which case you do not use "Polymerization"). Cards cannot be added from the Main Deck to your opponent's hand except by drawing them. If this card would be destroyed by battle or card effect, you can banish 1 Thunder monster from your GY instead.
external_ids: local CARD_ID_0 = 31786629 --Thunder Dragon
  
lua: local CARD_ID_0 = 31786629 --Thunder Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcCodeFun(c, CARD_ID_0, aux.FilterBoolFunction(Card.IsRace, RACE_THUNDER), 1, true, true)
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.fuslimit)
  	c:RegisterEffect(e1)
  	--special summon rule
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_SPSUMMON_PROC)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e2:SetRange(LOCATION_EXTRA)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--disable search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_TO_HAND)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetTargetRange(0, 1)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsLocation, LOCATION_DECK))
  	c:RegisterEffect(e3)
  	--destroy replace
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCode(EFFECT_DESTROY_REPLACE)
  	e4:SetTarget(s.reptg)
  	c:RegisterEffect(e4)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
  end
  function s.chainfilter(re, tp, cid)
  	return not (re:GetHandler():IsRace(RACE_THUNDER) and re:IsActiveType(TYPE_MONSTER) and Duel.GetChainInfo(cid, CHAININFO_TRIGGERING_LOCATION) == LOCATION_HAND)
  end
  function s.spfilter(c, fc, tp)
  	return c:IsRace(RACE_THUNDER)
  		and c:IsFusionType(TYPE_EFFECT)
  		and not c:IsFusionType(TYPE_FUSION)
  		and Duel.GetLocationCountFromEx(tp, tp, c, fc) > 0
  		and c:IsCanBeFusionMaterial(fc, SUMMON_TYPE_SPECIAL)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	return (Duel.GetCustomActivityCount(id, tp, ACTIVITY_CHAIN) ~= 0 or Duel.GetCustomActivityCount(id, 1 - tp, ACTIVITY_CHAIN) ~= 0)
  		and Duel.CheckReleaseGroupEx(tp, s.spfilter, 1, REASON_SPSUMMON, false, nil, c, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetReleaseGroup(tp, false, REASON_SPSUMMON):Filter(s.spfilter, nil, c, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
  	local tc = g:SelectUnselect(nil, tp, false, true, 1, 1)
  	if tc then
  		e:SetLabelObject(tc)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local tc = e:GetLabelObject()
  	c:SetMaterial(Group.FromCards(tc))
  	Duel.Release(tc, REASON_SPSUMMON)
  end
  function s.repfilter(c)
  	return c:IsRace(RACE_THUNDER) and c:IsAbleToRemove()
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE) and Duel.IsExistingMatchingCard(s.repfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	if Duel.SelectEffectYesNo(tp, c, 96) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESREPLACE)
  		local g = Duel.SelectMatchingCard(tp, s.repfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		Duel.Remove(g, POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  		return true
  	else
  		return false
  	end
  end
  
  
source_text: Thunder
  "Thunder Dragon" + 1 Thunder monster
  Must be either Fusion Summoned, or Special Summoned during the turn a Thunder monster's effect was activated in the hand, by Tributing 1 Thunder Effect non-Fusion Monster (in which case you do not use "Polymerization"). Cards cannot be added from the Main Deck to your opponent's hand except by drawing them. If this card would be destroyed by battle or card effect, you can banish 1 Thunder monster from your GY instead.
target_text: -- Thunder
  local CARD_ID_0 = 31786629 --Thunder Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--fusion material
  	c:EnableReviveLimit()
  	aux.AddFusionProcCodeFun(c, CARD_ID_0, aux.FilterBoolFunction(Card.IsRace, RACE_THUNDER), 1, true, true)
  	--spsummon condition
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	e1:SetValue(aux.fuslimit)
  	c:RegisterEffect(e1)
  	--special summon rule
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_SPSUMMON_PROC)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e2:SetRange(LOCATION_EXTRA)
  	e2:SetCondition(s.spcon)
  	e2:SetTarget(s.sptg)
  	e2:SetOperation(s.spop)
  	c:RegisterEffect(e2)
  	--disable search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_TO_HAND)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e3:SetTargetRange(0, 1)
  	e3:SetTarget(aux.TargetBoolFunction(Card.IsLocation, LOCATION_DECK))
  	c:RegisterEffect(e3)
  	--destroy replace
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_SINGLE)
  	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetCode(EFFECT_DESTROY_REPLACE)
  	e4:SetTarget(s.reptg)
  	c:RegisterEffect(e4)
  	Duel.AddCustomActivityCounter(id, ACTIVITY_CHAIN, s.chainfilter)
  end
  function s.chainfilter(re, tp, cid)
  	return not (re:GetHandler():IsRace(RACE_THUNDER) and re:IsActiveType(TYPE_MONSTER) and Duel.GetChainInfo(cid, CHAININFO_TRIGGERING_LOCATION) == LOCATION_HAND)
  end
  function s.spfilter(c, fc, tp)
  	return c:IsRace(RACE_THUNDER)
  		and c:IsFusionType(TYPE_EFFECT)
  		and not c:IsFusionType(TYPE_FUSION)
  		and Duel.GetLocationCountFromEx(tp, tp, c, fc) > 0
  		and c:IsCanBeFusionMaterial(fc, SUMMON_TYPE_SPECIAL)
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	return (Duel.GetCustomActivityCount(id, tp, ACTIVITY_CHAIN) ~= 0 or Duel.GetCustomActivityCount(id, 1 - tp, ACTIVITY_CHAIN) ~= 0)
  		and Duel.CheckReleaseGroupEx(tp, s.spfilter, 1, REASON_SPSUMMON, false, nil, c, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetReleaseGroup(tp, false, REASON_SPSUMMON):Filter(s.spfilter, nil, c, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RELEASE)
  	local tc = g:SelectUnselect(nil, tp, false, true, 1, 1)
  	if tc then
  		e:SetLabelObject(tc)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local tc = e:GetLabelObject()
  	c:SetMaterial(Group.FromCards(tc))
  	Duel.Release(tc, REASON_SPSUMMON)
  end
  function s.repfilter(c)
  	return c:IsRace(RACE_THUNDER) and c:IsAbleToRemove()
  end
  function s.reptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE) and Duel.IsExistingMatchingCard(s.repfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	if Duel.SelectEffectYesNo(tp, c, 96) then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESREPLACE)
  		local g = Duel.SelectMatchingCard(tp, s.repfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  		Duel.Remove(g, POS_FACEUP, REASON_EFFECT + REASON_REPLACE)
  		return true
  	else
  		return false
  	end
  end
  
  