name: Torrential
card_text: When a face-up WATER monster you control is destroyed by battle or by a card effect and sent to the Graveyard: Special Summon the monsters destroyed and sent from the field to your Graveyard at that time, then inflict 500 damage to your opponent for each of those Special Summoned monsters. You can only activate 1 "Torrential Reborn" per turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, tp)
  	return c:IsReason(REASON_DESTROY)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsPreviousControler(tp)
  		and c:IsPreviousPosition(POS_FACEUP)
  		and c:IsAttribute(ATTRIBUTE_WATER)
  		and bit.band(c:GetPreviousAttributeOnField(), ATTRIBUTE_WATER) ~= 0
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.spfilter(c, e, tp)
  	return c:IsPreviousLocation(LOCATION_MZONE) and c:IsControler(tp) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ct = eg:FilterCount(s.spfilter, nil, e, tp)
  		return ct > 0 and (ct == 1 or not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) and Duel.GetLocationCount(tp, LOCATION_MZONE) >= ct
  	end
  	Duel.SetTargetCard(eg)
  	local g = eg:Filter(s.spfilter, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, g:GetCount(), 0, 0)
  end
  function s.spfilter2(c, e, tp)
  	return c:IsPreviousLocation(LOCATION_MZONE) and c:IsControler(tp) and c:IsRelateToEffect(e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	local sg = eg:Filter(s.spfilter2, nil, e, tp)
  	if ft < sg:GetCount() then
  		return
  	end
  	local ct = Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  	if ct == 0 then
  		return
  	end
  	Duel.BreakEffect()
  	Duel.Damage(1 - tp, ct * 500, REASON_EFFECT)
  end
  
  
source_text: Torrential
  When a face-up WATER monster you control is destroyed by battle or by a card effect and sent to the Graveyard: Special Summon the monsters destroyed and sent from the field to your Graveyard at that time, then inflict 500 damage to your opponent for each of those Special Summoned monsters. You can only activate 1 "Torrential Reborn" per turn.
target_text: -- Torrential
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetProperty(EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, tp)
  	return c:IsReason(REASON_DESTROY)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  		and c:IsPreviousControler(tp)
  		and c:IsPreviousPosition(POS_FACEUP)
  		and c:IsAttribute(ATTRIBUTE_WATER)
  		and bit.band(c:GetPreviousAttributeOnField(), ATTRIBUTE_WATER) ~= 0
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.spfilter(c, e, tp)
  	return c:IsPreviousLocation(LOCATION_MZONE) and c:IsControler(tp) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local ct = eg:FilterCount(s.spfilter, nil, e, tp)
  		return ct > 0 and (ct == 1 or not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) and Duel.GetLocationCount(tp, LOCATION_MZONE) >= ct
  	end
  	Duel.SetTargetCard(eg)
  	local g = eg:Filter(s.spfilter, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, g:GetCount(), 0, 0)
  end
  function s.spfilter2(c, e, tp)
  	return c:IsPreviousLocation(LOCATION_MZONE) and c:IsControler(tp) and c:IsRelateToEffect(e) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	local sg = eg:Filter(s.spfilter2, nil, e, tp)
  	if ft < sg:GetCount() then
  		return
  	end
  	local ct = Duel.SpecialSummon(sg, 0, tp, tp, false, false, POS_FACEUP)
  	if ct == 0 then
  		return
  	end
  	Duel.BreakEffect()
  	Duel.Damage(1 - tp, ct * 500, REASON_EFFECT)
  end
  
  