name: Gigarays
card_text: Cannot be Normal Summoned/Set. Must first be Special Summoned (from your hand) by sending 2 other monsters from your hand and/or field to the GY. Gains 300 ATK for each banished card. Once per turn: You can pay half your LP; apply 1 of these effects, depending on the number of "Gandora" monsters with different names in your GY.
  ● 1: Destroy all other cards on the field.
  ● 2: Banish all other cards on the field.
  ● 3+: Banish all other cards on the field and in the GYs.
external_ids: local SETCARD_ID_0 = 0xf5 --Gandora
  
lua: local SETCARD_ID_0 = 0xf5 --Gandora
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon rule
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--atk gain
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(s.value)
  	c:RegisterEffect(e2)
  	--variable effect
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCost(s.cost)
  	e3:SetTarget(s.target)
  	e3:SetOperation(s.operation)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToGraveAsCost()
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_MZONE + LOCATION_HAND, 0, c)
  	return g:CheckSubGroup(aux.mzctcheck, 2, 2, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_MZONE + LOCATION_HAND, 0, c)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:SelectSubGroup(tp, aux.mzctcheck, true, 2, 2, tp)
  	if sg then
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = e:GetLabelObject()
  	Duel.SendtoGrave(g, REASON_SPSUMMON)
  	g:DeleteGroup()
  end
  function s.value(e, c)
  	return Duel.GetFieldGroupCount(c:GetControler(), LOCATION_REMOVED, LOCATION_REMOVED) * 300
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.PayLPCost(tp, math.floor(Duel.GetLP(tp) / 2))
  end
  function s.filter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local gc = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil):GetClassCount(Card.GetCode)
  	if chk == 0 then
  		local b1 = Duel.IsExistingMatchingCard(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, c)
  		local b2 = Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, c)
  		local b3 = Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, LOCATION_ONFIELD + LOCATION_GRAVE, LOCATION_ONFIELD + LOCATION_GRAVE, 1, c)
  		return (gc == 1 and b1) or (gc == 2 and b2) or (gc > 2 and b3)
  	end
  	if gc == 1 then
  		e:SetCategory(CATEGORY_DESTROY)
  		local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, c)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	else
  		e:SetCategory(CATEGORY_REMOVE)
  		local loc = LOCATION_ONFIELD
  		if gc > 2 then
  			loc = LOCATION_ONFIELD + LOCATION_GRAVE
  		end
  		local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, loc, loc, c)
  		Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, g:GetCount(), 0, 0)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local gc = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil):GetClassCount(Card.GetCode)
  	if gc == 1 then
  		local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, aux.ExceptThisCard(e))
  		Duel.Destroy(g, REASON_EFFECT)
  	elseif gc >= 2 then
  		local loc = LOCATION_ONFIELD
  		if gc > 2 then
  			loc = LOCATION_ONFIELD + LOCATION_GRAVE
  		end
  		local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, loc, loc, aux.ExceptThisCard(e))
  		Duel.Remove(g, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  
source_text: Gigarays
  Cannot be Normal Summoned/Set. Must first be Special Summoned (from your hand) by sending 2 other monsters from your hand and/or field to the GY. Gains 300 ATK for each banished card. Once per turn: You can pay half your LP; apply 1 of these effects, depending on the number of "Gandora" monsters with different names in your GY.
  ● 1: Destroy all other cards on the field.
  ● 2: Banish all other cards on the field.
  ● 3+: Banish all other cards on the field and in the GYs.
target_text: -- Gigarays
  local SETCARD_ID_0 = 0xf5 --Gandora
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--special summon rule
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetCode(EFFECT_SPSUMMON_PROC)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  	--atk gain
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetValue(s.value)
  	c:RegisterEffect(e2)
  	--variable effect
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1)
  	e3:SetCost(s.cost)
  	e3:SetTarget(s.target)
  	e3:SetOperation(s.operation)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsAbleToGraveAsCost()
  end
  function s.spcon(e, c)
  	if c == nil then
  		return true
  	end
  	local tp = c:GetControler()
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_MZONE + LOCATION_HAND, 0, c)
  	return g:CheckSubGroup(aux.mzctcheck, 2, 2, tp)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk, c)
  	local g = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_MZONE + LOCATION_HAND, 0, c)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:SelectSubGroup(tp, aux.mzctcheck, true, 2, 2, tp)
  	if sg then
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp, c)
  	local g = e:GetLabelObject()
  	Duel.SendtoGrave(g, REASON_SPSUMMON)
  	g:DeleteGroup()
  end
  function s.value(e, c)
  	return Duel.GetFieldGroupCount(c:GetControler(), LOCATION_REMOVED, LOCATION_REMOVED) * 300
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.PayLPCost(tp, math.floor(Duel.GetLP(tp) / 2))
  end
  function s.filter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local gc = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil):GetClassCount(Card.GetCode)
  	if chk == 0 then
  		local b1 = Duel.IsExistingMatchingCard(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, c)
  		local b2 = Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, 1, c)
  		local b3 = Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, LOCATION_ONFIELD + LOCATION_GRAVE, LOCATION_ONFIELD + LOCATION_GRAVE, 1, c)
  		return (gc == 1 and b1) or (gc == 2 and b2) or (gc > 2 and b3)
  	end
  	if gc == 1 then
  		e:SetCategory(CATEGORY_DESTROY)
  		local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, c)
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	else
  		e:SetCategory(CATEGORY_REMOVE)
  		local loc = LOCATION_ONFIELD
  		if gc > 2 then
  			loc = LOCATION_ONFIELD + LOCATION_GRAVE
  		end
  		local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, loc, loc, c)
  		Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, g:GetCount(), 0, 0)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local gc = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil):GetClassCount(Card.GetCode)
  	if gc == 1 then
  		local g = Duel.GetMatchingGroup(nil, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, aux.ExceptThisCard(e))
  		Duel.Destroy(g, REASON_EFFECT)
  	elseif gc >= 2 then
  		local loc = LOCATION_ONFIELD
  		if gc > 2 then
  			loc = LOCATION_ONFIELD + LOCATION_GRAVE
  		end
  		local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, loc, loc, aux.ExceptThisCard(e))
  		Duel.Remove(g, POS_FACEUP, REASON_EFFECT)
  	end
  end
  
  