Cubic
When an opponent's monster declares an attack: Special Summon 1 "Vijam the Cubic Seed" from your Deck, and if you do, change the attack target to it, and perform damage calculation. If your opponent's LP are at least 2000 higher than yours: You can banish this card from your GY; Special Summon 1 "Vijam the Cubic Seed" from your hand, Deck, or GY, then, if only your opponent controlled a monster when this effect was activated, you can Special Summon up to 2 more "Vijam the Cubic Seed". You can only use this effect of "Cubic Ascension" once per turn.
local CARD_ID_0 = 15610297 --Vijam the Cubic Seed
local CARD_ID_1 = 59822133 --Blue-Eyes Spirit Dragon

local CARD_ID_0 = 15610297 --Vijam the Cubic Seed
local CARD_ID_1 = 59822133 --Blue-Eyes Spirit Dragon
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_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
	e1:SetCondition(s.condition)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	--Activate
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 1))
	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_FREE_CHAIN)
	e2:SetRange(LOCATION_GRAVE)
	e2:SetCountLimit(1, id)
	e2:SetCost(aux.bfgcost)
	e2:SetCondition(s.spcon)
	e2:SetTarget(s.sptg)
	e2:SetOperation(s.spop)
	c:RegisterEffect(e2)
end
function s.condition(e, tp, eg, ep, ev, re, r, rp)
	local a = Duel.GetAttacker()
	return a:IsControler(1 - tp)
end
function s.filter(c, e, tp)
	return c:IsCode(CARD_ID_0) 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
		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
		return
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
	local tc = g:GetFirst()
	if tc and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
		local at = Duel.GetAttacker()
		if at:IsAttackable() and not at:IsImmuneToEffect(e) then
			Duel.CalculateDamage(at, tc)
		end
	end
end
function s.spcon(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetLP(tp) <= Duel.GetLP(1 - tp) - 2000
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.filter, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, e, tp)
	end
	if Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 0 then
		e:SetLabel(1)
	else
		e:SetLabel(0)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
	if ft <= 0 then
		return
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
	if g:GetCount() <= 0 then
		return
	end
	Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
	ft = ft - 1
	local sg = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.filter), tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, nil, e, tp)
	if e:GetLabel() == 1 and sg:GetCount() > 0 and ft > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
		Duel.BreakEffect()
		ft = math.min(ft, sg:GetCount(), 2)
		if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1) then
			ft = 1
		end
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
		local tg = sg:Select(tp, 1, ft, nil)
		Duel.SpecialSummon(tg, 0, tp, tp, false, false, POS_FACEUP)
	end
end


Cubic
When an opponent's monster declares an attack: Special Summon 1 "Vijam the Cubic Seed" from your Deck, and if you do, change the attack target to it, and perform damage calculation. If your opponent's LP are at least 2000 higher than yours: You can banish this card from your GY; Special Summon 1 "Vijam the Cubic Seed" from your hand, Deck, or GY, then, if only your opponent controlled a monster when this effect was activated, you can Special Summon up to 2 more "Vijam the Cubic Seed". You can only use this effect of "Cubic Ascension" once per turn.
-- Cubic
local CARD_ID_0 = 15610297 --Vijam the Cubic Seed
local CARD_ID_1 = 59822133 --Blue-Eyes Spirit Dragon
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_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_ATTACK_ANNOUNCE)
	e1:SetCondition(s.condition)
	e1:SetTarget(s.target)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
	--Activate
	local e2 = Effect.CreateEffect(c)
	e2:SetDescription(aux.Stringid(id, 1))
	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e2:SetType(EFFECT_TYPE_QUICK_O)
	e2:SetCode(EVENT_FREE_CHAIN)
	e2:SetRange(LOCATION_GRAVE)
	e2:SetCountLimit(1, id)
	e2:SetCost(aux.bfgcost)
	e2:SetCondition(s.spcon)
	e2:SetTarget(s.sptg)
	e2:SetOperation(s.spop)
	c:RegisterEffect(e2)
end
function s.condition(e, tp, eg, ep, ev, re, r, rp)
	local a = Duel.GetAttacker()
	return a:IsControler(1 - tp)
end
function s.filter(c, e, tp)
	return c:IsCode(CARD_ID_0) 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
		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil, e, tp)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK)
end
function s.activate(e, tp, eg, ep, ev, re, r, rp)
	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
		return
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local g = Duel.SelectMatchingCard(tp, s.filter, tp, LOCATION_DECK, 0, 1, 1, nil, e, tp)
	local tc = g:GetFirst()
	if tc and Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP) ~= 0 then
		local at = Duel.GetAttacker()
		if at:IsAttackable() and not at:IsImmuneToEffect(e) then
			Duel.CalculateDamage(at, tc)
		end
	end
end
function s.spcon(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetLP(tp) <= Duel.GetLP(1 - tp) - 2000
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.filter, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil, e, tp)
	end
	if Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) == 0 and Duel.GetFieldGroupCount(tp, 0, LOCATION_MZONE) > 0 then
		e:SetLabel(1)
	else
		e:SetLabel(0)
	end
	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE)
end
function s.spop(e, tp, eg, ep, ev, re, r, rp)
	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
	if ft <= 0 then
		return
	end
	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.filter), tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
	if g:GetCount() <= 0 then
		return
	end
	Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
	ft = ft - 1
	local sg = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.filter), tp, LOCATION_HAND + LOCATION_DECK + LOCATION_GRAVE, 0, nil, e, tp)
	if e:GetLabel() == 1 and sg:GetCount() > 0 and ft > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
		Duel.BreakEffect()
		ft = math.min(ft, sg:GetCount(), 2)
		if ft > 1 and Duel.IsPlayerAffectedByEffect(tp, CARD_ID_1) then
			ft = 1
		end
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
		local tg = sg:Select(tp, 1, ft, nil)
		Duel.SpecialSummon(tg, 0, tp, tp, false, false, POS_FACEUP)
	end
end

