D
If this card is Normal Summoned: It is also treated as a "Destiny HERO" monster while face-up on the field. You can only use each of the following effects of "D Cubed" once per turn.
● You can discard up to 2 cards; Special Summon "D Cubed" from your hand, Deck, and/or GY, equal to the number discarded, also for the rest of this turn, you cannot Normal or Special Summon other monsters, except "Destiny HERO" monsters.
● If this card is destroyed by battle or card effect: You can send 1 "Destiny HERO" monster from your Deck to the GY.
local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
local SETCARD_ID_0 = 0xc008 --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)
	--setcode
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
	e1:SetCode(EVENT_SUMMON_SUCCESS)
	e1:SetOperation(s.scop)
	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:SetCountLimit(1, id)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCost(s.spcost)
	e2:SetTarget(s.sptg)
	e2:SetOperation(s.spop)
	c:RegisterEffect(e2)
	--to grave
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 2))
	e3:SetCategory(CATEGORY_TOGRAVE)
	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
	e3:SetProperty(EFFECT_FLAG_DELAY)
	e3:SetCode(EVENT_DESTROYED)
	e3:SetCountLimit(1, id + 1)
	e3:SetCondition(s.tgcon)
	e3:SetTarget(s.tgtg)
	e3:SetOperation(s.tgop)
	c:RegisterEffect(e3)
end
function s.scop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsRelateToEffect(e) and c:IsFaceup() then
		local e1 = Effect.CreateEffect(c)
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetCode(EFFECT_ADD_SETCODE)
		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
		e1:SetValue(0xc008)
		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
		c:RegisterEffect(e1)
	end
end
function s.spfilter(c, e, tp)
	return c:IsCode(id) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
	end
	local ct = 2
	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
		ct = 1
	end
	ct = math.min(ct, (Duel.GetLocationCount(tp, LOCATION_MZONE)), Duel.GetMatchingGroupCount(s.spfilter, tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK, 0, nil, e, tp))
	local cg = Duel.DiscardHand(tp, Card.IsDiscardable, 1, ct, REASON_COST + REASON_DISCARD, nil)
	e:SetLabel(cg)
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 + LOCATION_GRAVE + LOCATION_DECK, 0, 1, nil, e, tp)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, e:GetLabel(), tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local ct = e:GetLabel()
	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
	if ft >= ct then
		if ct == 1 or not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
			local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK, 0, ct, ct, nil, e, tp)
			if g:GetCount() > 0 then
				Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
			end
		end
	end
	local e1 = Effect.CreateEffect(e:GetHandler())
	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)
	local e2 = e1:Clone()
	e2:SetCode(EFFECT_CANNOT_SUMMON)
	Duel.RegisterEffect(e2, tp)
end
function s.splimit(e, c)
	return not c:IsSetCard(SETCARD_ID_0)
end
function s.tgcon(e, tp, eg, ep, ev, re, r, rp)
	return bit.band(r, REASON_EFFECT + REASON_BATTLE) ~= 0
end
function s.tgfilter(c)
	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGrave()
end
function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil)
	end
	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
end
function s.tgop(e, tp, eg, ep, ev, re, r, rp)
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
	if g:GetCount() > 0 then
		Duel.SendtoGrave(g, REASON_EFFECT)
	end
end


D
If this card is Normal Summoned: It is also treated as a "Destiny HERO" monster while face-up on the field. You can only use each of the following effects of "D Cubed" once per turn.
● You can discard up to 2 cards; Special Summon "D Cubed" from your hand, Deck, and/or GY, equal to the number discarded, also for the rest of this turn, you cannot Normal or Special Summon other monsters, except "Destiny HERO" monsters.
● If this card is destroyed by battle or card effect: You can send 1 "Destiny HERO" monster from your Deck to the GY.
-- D
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)
	--setcode
	local e1 = Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id, 0))
	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_F)
	e1:SetCode(EVENT_SUMMON_SUCCESS)
	e1:SetOperation(s.scop)
	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:SetCountLimit(1, id)
	e2:SetRange(LOCATION_MZONE)
	e2:SetCost(s.spcost)
	e2:SetTarget(s.sptg)
	e2:SetOperation(s.spop)
	c:RegisterEffect(e2)
	--to grave
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 2))
	e3:SetCategory(CATEGORY_TOGRAVE)
	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
	e3:SetProperty(EFFECT_FLAG_DELAY)
	e3:SetCode(EVENT_DESTROYED)
	e3:SetCountLimit(1, id + 1)
	e3:SetCondition(s.tgcon)
	e3:SetTarget(s.tgtg)
	e3:SetOperation(s.tgop)
	c:RegisterEffect(e3)
end
function s.scop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	if c:IsRelateToEffect(e) and c:IsFaceup() then
		local e1 = Effect.CreateEffect(c)
		e1:SetType(EFFECT_TYPE_SINGLE)
		e1:SetCode(EFFECT_ADD_SETCODE)
		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
		e1:SetValue(0xc008)
		e1:SetReset(RESET_EVENT + RESETS_STANDARD)
		c:RegisterEffect(e1)
	end
end
function s.spfilter(c, e, tp)
	return c:IsCode(id) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
end
function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(Card.IsDiscardable, tp, LOCATION_HAND, 0, 1, nil)
	end
	local ct = 2
	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
		ct = 1
	end
	ct = math.min(ct, (Duel.GetLocationCount(tp, LOCATION_MZONE)), Duel.GetMatchingGroupCount(s.spfilter, tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK, 0, nil, e, tp))
	local cg = Duel.DiscardHand(tp, Card.IsDiscardable, 1, ct, REASON_COST + REASON_DISCARD, nil)
	e:SetLabel(cg)
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 + LOCATION_GRAVE + LOCATION_DECK, 0, 1, nil, e, tp)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, e:GetLabel(), tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local ct = e:GetLabel()
	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
	if ft >= ct then
		if ct == 1 or not Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
			local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.spfilter), tp, LOCATION_HAND + LOCATION_GRAVE + LOCATION_DECK, 0, ct, ct, nil, e, tp)
			if g:GetCount() > 0 then
				Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
			end
		end
	end
	local e1 = Effect.CreateEffect(e:GetHandler())
	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)
	local e2 = e1:Clone()
	e2:SetCode(EFFECT_CANNOT_SUMMON)
	Duel.RegisterEffect(e2, tp)
end
function s.splimit(e, c)
	return not c:IsSetCard(SETCARD_ID_0)
end
function s.tgcon(e, tp, eg, ep, ev, re, r, rp)
	return bit.band(r, REASON_EFFECT + REASON_BATTLE) ~= 0
end
function s.tgfilter(c)
	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGrave()
end
function s.tgtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_DECK, 0, 1, nil)
	end
	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
end
function s.tgop(e, tp, eg, ep, ev, re, r, rp)
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
	if g:GetCount() > 0 then
		Duel.SendtoGrave(g, REASON_EFFECT)
	end
end

