name: Destiny
card_text: When a "Destiny HERO" monster you control is destroyed and sent to the Graveyard by an opponent's card effect: Special Summon, to your side of the field, all "Destiny HERO" monsters that were destroyed and sent to either Graveyard this turn.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0xc008 --Destiny
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0xc008 --Destiny
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousSetCard(SETCARD_ID_0) and c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousControler(tp)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(r, REASON_EFFECT) ~= 0 and rp == 1 - tp and eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.spfilter(c, e, tp)
  	return c:IsReason(REASON_DESTROY) and c:GetTurnID() == Duel.GetTurnCount() and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, nil, e, tp)
  	if chk == 0 then
  		return g:GetCount() > 0 and Duel.GetLocationCount(tp, LOCATION_MZONE) >= g:GetCount()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, g:GetCount(), 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, nil, e, tp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 or ft < g:GetCount() or (g:GetCount() > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) then
  		return
  	end
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Destiny
  When a "Destiny HERO" monster you control is destroyed and sent to the Graveyard by an opponent's card effect: Special Summon, to your side of the field, all "Destiny HERO" monsters that were destroyed and sent to either Graveyard this turn.
target_text: -- Destiny
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local SETCARD_ID_0 = 0xc008 --Destiny
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetCode(EVENT_TO_GRAVE)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousSetCard(SETCARD_ID_0) and c:IsPreviousPosition(POS_FACEUP) and c:IsPreviousLocation(LOCATION_MZONE) and c:IsPreviousControler(tp)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return bit.band(r, REASON_EFFECT) ~= 0 and rp == 1 - tp and eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.spfilter(c, e, tp)
  	return c:IsReason(REASON_DESTROY) and c:GetTurnID() == Duel.GetTurnCount() and c:IsSetCard(SETCARD_ID_0) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, nil, e, tp)
  	if chk == 0 then
  		return g:GetCount() > 0 and Duel.GetLocationCount(tp, LOCATION_MZONE) >= g:GetCount()
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, g:GetCount(), 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_GRAVE, LOCATION_GRAVE, nil, e, tp)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if ft <= 0 or ft < g:GetCount() or (g:GetCount() > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0)) then
  		return
  	end
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  