name: Cubic
card_text: When this card is activated: You can target 1 "Cubic" monster you control, except "Vijam the Cubic Seed"; send any number of "Vijam the Cubic Seed" from your hand and/or Deck to the Graveyard, then that monster gains 800 ATK for each (even if this card leaves the field). During your opponent's turn, if "Vijam the Cubic Seed" is Special Summoned by the effect of a "Cubic" monster: Send this card to the Graveyard, and if you do, halve your opponent's LP. You can banish this card from your Graveyard; add 1 "Cubic" monster from your Deck to your hand.
external_ids: local CARD_ID_0 = 15610297 --Vijam the Cubic Seed
  local SETCARD_ID_0 = 0xe3 --Cubic
  
lua: local CARD_ID_0 = 15610297 --Vijam the Cubic Seed
  local SETCARD_ID_0 = 0xe3 --Cubic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  	--lp halve
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(s.lpcon)
  	e2:SetOperation(s.lpop)
  	c:RegisterEffect(e2)
  	--to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.tgfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToGrave()
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and not c:IsCode(CARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return true
  	end
  	if
  		Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  		and Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 0))
  	then
  		e:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_TOGRAVE)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		e:SetOperation(s.activate)
  		Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  		Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  	else
  		e:SetCategory(0)
  		e:SetProperty(0)
  		e:SetOperation(nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 99, nil)
  	if Duel.SendtoGrave(g, REASON_EFFECT) ~= 0 then
  		local og = Duel.GetOperatedGroup()
  		local n = og:FilterCount(Card.IsLocation, nil, LOCATION_GRAVE)
  		local tc = Duel.GetFirstTarget()
  		if tc:IsRelateToEffect(e) and tc:IsFaceup() and n > 0 then
  			Duel.BreakEffect()
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(n * 800)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  		end
  	end
  end
  function s.lpcon(e, tp, eg, ep, ev, re, r, rp)
  	local rc = re:GetHandler()
  	return Duel.GetTurnPlayer() ~= tp and re:IsActiveType(TYPE_MONSTER) and rc and rc:IsSetCard(SETCARD_ID_0) and eg:IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.lpop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SendtoGrave(c, REASON_EFFECT) ~= 0 and c:IsLocation(LOCATION_GRAVE) then
  		Duel.SetLP(1 - tp, math.ceil(Duel.GetLP(1 - tp) / 2))
  	end
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Cubic
  When this card is activated: You can target 1 "Cubic" monster you control, except "Vijam the Cubic Seed"; send any number of "Vijam the Cubic Seed" from your hand and/or Deck to the Graveyard, then that monster gains 800 ATK for each (even if this card leaves the field). During your opponent's turn, if "Vijam the Cubic Seed" is Special Summoned by the effect of a "Cubic" monster: Send this card to the Graveyard, and if you do, halve your opponent's LP. You can banish this card from your Graveyard; add 1 "Cubic" monster from your Deck to your hand.
target_text: -- Cubic
  local CARD_ID_0 = 15610297 --Vijam the Cubic Seed
  local SETCARD_ID_0 = 0xe3 --Cubic
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  	--lp halve
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCondition(s.lpcon)
  	e2:SetOperation(s.lpop)
  	c:RegisterEffect(e2)
  	--to hand
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 2))
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCost(aux.bfgcost)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  end
  function s.tgfilter(c)
  	return c:IsCode(CARD_ID_0) and c:IsAbleToGrave()
  end
  function s.filter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and not c:IsCode(CARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return true
  	end
  	if
  		Duel.IsExistingTarget(s.filter, tp, LOCATION_MZONE, 0, 1, nil)
  		and Duel.IsExistingMatchingCard(s.tgfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 0))
  	then
  		e:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_TOGRAVE)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		e:SetOperation(s.activate)
  		Duel.SelectTarget(tp, s.filter, tp, LOCATION_MZONE, 0, 1, 1, nil)
  		Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_DECK)
  	else
  		e:SetCategory(0)
  		e:SetProperty(0)
  		e:SetOperation(nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local g = Duel.SelectMatchingCard(tp, s.tgfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 99, nil)
  	if Duel.SendtoGrave(g, REASON_EFFECT) ~= 0 then
  		local og = Duel.GetOperatedGroup()
  		local n = og:FilterCount(Card.IsLocation, nil, LOCATION_GRAVE)
  		local tc = Duel.GetFirstTarget()
  		if tc:IsRelateToEffect(e) and tc:IsFaceup() and n > 0 then
  			Duel.BreakEffect()
  			local e1 = Effect.CreateEffect(e:GetHandler())
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(n * 800)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  		end
  	end
  end
  function s.lpcon(e, tp, eg, ep, ev, re, r, rp)
  	local rc = re:GetHandler()
  	return Duel.GetTurnPlayer() ~= tp and re:IsActiveType(TYPE_MONSTER) and rc and rc:IsSetCard(SETCARD_ID_0) and eg:IsExists(Card.IsCode, 1, nil, CARD_ID_0)
  end
  function s.lpop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) and Duel.SendtoGrave(c, REASON_EFFECT) ~= 0 and c:IsLocation(LOCATION_GRAVE) then
  		Duel.SetLP(1 - tp, math.ceil(Duel.GetLP(1 - tp) / 2))
  	end
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  