name: Cubic
card_text: You take no battle damage from attacks involving your "Cubic" monsters. You can only use each of the following effects of "Cubic Dharma" once per turn, during your Main Phase:
  ● You can send 1 "Cubic" card from your hand to the GY, and if you do, draw 1 card.
  ● You can banish this card from your GY, then target 1 "Cubic" monster in your GY; add it to your hand.
external_ids: local SETCARD_ID_0 = 0xe3 --Cubic
  
lua: 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)
  	c:RegisterEffect(e1)
  	--Avoid battle damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.filter)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--Draw
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_HANDES + CATEGORY_DRAW)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.drawtg)
  	e3:SetOperation(s.drawop)
  	c:RegisterEffect(e3)
  	--To hand
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_TOHAND)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetRange(LOCATION_GRAVE)
  	e4:SetCountLimit(1, id + 1)
  	e4:SetCost(aux.bfgcost)
  	e4:SetTarget(s.thtg)
  	e4:SetOperation(s.thop)
  	c:RegisterEffect(e4)
  end
  function s.filter(e, c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.drawtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_HAND)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drawop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.DiscardHand(tp, s.cfilter, 1, 1, REASON_EFFECT) > 0 then
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	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, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tc)
  	end
  end
  
  
source_text: Cubic
  You take no battle damage from attacks involving your "Cubic" monsters. You can only use each of the following effects of "Cubic Dharma" once per turn, during your Main Phase:
  ● You can send 1 "Cubic" card from your hand to the GY, and if you do, draw 1 card.
  ● You can banish this card from your GY, then target 1 "Cubic" monster in your GY; add it to your hand.
target_text: -- Cubic
  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)
  	c:RegisterEffect(e1)
  	--Avoid battle damage
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.filter)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	--Draw
  	local e3 = Effect.CreateEffect(c)
  	e3:SetCategory(CATEGORY_HANDES + CATEGORY_DRAW)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetTarget(s.drawtg)
  	e3:SetOperation(s.drawop)
  	c:RegisterEffect(e3)
  	--To hand
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_TOHAND)
  	e4:SetType(EFFECT_TYPE_IGNITION)
  	e4:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e4:SetRange(LOCATION_GRAVE)
  	e4:SetCountLimit(1, id + 1)
  	e4:SetCost(aux.bfgcost)
  	e4:SetTarget(s.thtg)
  	e4:SetOperation(s.thop)
  	c:RegisterEffect(e4)
  end
  function s.filter(e, c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0)
  end
  function s.drawtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1) and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, nil, 1, tp, LOCATION_HAND)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drawop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.DiscardHand(tp, s.cfilter, 1, 1, REASON_EFFECT) > 0 then
  		Duel.Draw(tp, 1, REASON_EFFECT)
  	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, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tc)
  	end
  end
  
  