Five-Headed
5 monsters
Must be Link Summoned. If this card is Link Summoned using DARK, EARTH, WATER, FIRE, and WIND Attributes: You can destroy all cards your opponent controls. Cannot be destroyed by battle with a DARK, EARTH, WATER, FIRE, or WIND monster. Unaffected by other cards' effects. Once per turn, during your opponent's End Phase: You must banish 5 cards from your GY face-down (this is not optional), or send this card to the GY.
local s, id, o = GetID()
function s.initial_effect(c)
	--link summon
	c:EnableReviveLimit()
	aux.AddLinkProcedure(c, nil, 5, 5)
	--spsummon condition
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
	e1:SetValue(aux.linklimit)
	c:RegisterEffect(e1)
	--mat check
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_MATERIAL_CHECK)
	e2:SetValue(s.matcheck)
	c:RegisterEffect(e2)
	--destroy
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 0))
	e3:SetCategory(CATEGORY_DESTROY)
	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
	e3:SetProperty(EFFECT_FLAG_DELAY)
	e3:SetCondition(s.descon)
	e3:SetTarget(s.destg)
	e3:SetOperation(s.desop)
	e3:SetLabelObject(e2)
	c:RegisterEffect(e3)
	--immume
	local e4 = Effect.CreateEffect(c)
	e4:SetType(EFFECT_TYPE_SINGLE)
	e4:SetCode(EFFECT_IMMUNE_EFFECT)
	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e4:SetRange(LOCATION_MZONE)
	e4:SetValue(s.efilter)
	c:RegisterEffect(e4)
	--indes battle
	local e5 = e4:Clone()
	e5:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
	e5:SetValue(s.indes)
	c:RegisterEffect(e5)
	--remove
	local e6 = Effect.CreateEffect(c)
	e6:SetDescription(aux.Stringid(id, 1))
	e6:SetCategory(CATEGORY_REMOVE + CATEGORY_TOGRAVE)
	e6:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e6:SetCode(EVENT_PHASE + PHASE_END)
	e6:SetRange(LOCATION_MZONE)
	e6:SetCountLimit(1)
	e6:SetCondition(s.rmcon)
	e6:SetTarget(s.rmtg)
	e6:SetOperation(s.rmop)
	c:RegisterEffect(e6)
end
function s.matcheck(e, c)
	local g = c:GetMaterial()
	local att = 0
	local tc = g:GetFirst()
	while tc do
		att = att | tc:GetLinkAttribute()
		tc = g:GetNext()
	end
	e:SetLabel(att)
end
function s.descon(e, tp, eg, ep, ev, re, r, rp)
	local att = e:GetLabelObject():GetLabel()
	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
		and att & ATTRIBUTE_DARK > 0
		and att & ATTRIBUTE_EARTH > 0
		and att & ATTRIBUTE_WATER > 0
		and att & ATTRIBUTE_FIRE > 0
		and att & ATTRIBUTE_WIND > 0
end
function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
	end
	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
	Duel.Destroy(g, REASON_EFFECT)
end
function s.efilter(e, te)
	return te:GetOwner() ~= e:GetOwner()
end
function s.indes(e, c)
	return c:IsAttribute(ATTRIBUTE_DARK + ATTRIBUTE_EARTH + ATTRIBUTE_WATER + ATTRIBUTE_FIRE + ATTRIBUTE_WIND)
end
function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetTurnPlayer() == 1 - tp
end
function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 5, tp, LOCATION_GRAVE)
	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, e:GetHandler(), 1, 0, 0)
end
function s.rmop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local res = false
	local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, LOCATION_GRAVE, 0, nil, tp, POS_FACEDOWN)
	if g:GetCount() >= 5 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
		local sg = Duel.SelectMatchingCard(tp, Card.IsAbleToRemove, tp, LOCATION_GRAVE, 0, 5, 5, nil, tp, POS_FACEDOWN)
		Duel.Remove(sg, POS_FACEDOWN, REASON_EFFECT)
		if Duel.GetOperatedGroup():FilterCount(Card.IsLocation, nil, LOCATION_REMOVED) == 5 then
			res = true
		end
	end
	if not res and c:IsRelateToEffect(e) then
		Duel.SendtoGrave(c, REASON_EFFECT)
	end
end


Five-Headed
5 monsters
Must be Link Summoned. If this card is Link Summoned using DARK, EARTH, WATER, FIRE, and WIND Attributes: You can destroy all cards your opponent controls. Cannot be destroyed by battle with a DARK, EARTH, WATER, FIRE, or WIND monster. Unaffected by other cards' effects. Once per turn, during your opponent's End Phase: You must banish 5 cards from your GY face-down (this is not optional), or send this card to the GY.
-- Five-Headed
local s, id, o = GetID()
function s.initial_effect(c)
	--link summon
	c:EnableReviveLimit()
	aux.AddLinkProcedure(c, nil, 5, 5)
	--spsummon condition
	local e1 = Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_SINGLE)
	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
	e1:SetValue(aux.linklimit)
	c:RegisterEffect(e1)
	--mat check
	local e2 = Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_SINGLE)
	e2:SetCode(EFFECT_MATERIAL_CHECK)
	e2:SetValue(s.matcheck)
	c:RegisterEffect(e2)
	--destroy
	local e3 = Effect.CreateEffect(c)
	e3:SetDescription(aux.Stringid(id, 0))
	e3:SetCategory(CATEGORY_DESTROY)
	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
	e3:SetCode(EVENT_SPSUMMON_SUCCESS)
	e3:SetProperty(EFFECT_FLAG_DELAY)
	e3:SetCondition(s.descon)
	e3:SetTarget(s.destg)
	e3:SetOperation(s.desop)
	e3:SetLabelObject(e2)
	c:RegisterEffect(e3)
	--immume
	local e4 = Effect.CreateEffect(c)
	e4:SetType(EFFECT_TYPE_SINGLE)
	e4:SetCode(EFFECT_IMMUNE_EFFECT)
	e4:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
	e4:SetRange(LOCATION_MZONE)
	e4:SetValue(s.efilter)
	c:RegisterEffect(e4)
	--indes battle
	local e5 = e4:Clone()
	e5:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
	e5:SetValue(s.indes)
	c:RegisterEffect(e5)
	--remove
	local e6 = Effect.CreateEffect(c)
	e6:SetDescription(aux.Stringid(id, 1))
	e6:SetCategory(CATEGORY_REMOVE + CATEGORY_TOGRAVE)
	e6:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
	e6:SetCode(EVENT_PHASE + PHASE_END)
	e6:SetRange(LOCATION_MZONE)
	e6:SetCountLimit(1)
	e6:SetCondition(s.rmcon)
	e6:SetTarget(s.rmtg)
	e6:SetOperation(s.rmop)
	c:RegisterEffect(e6)
end
function s.matcheck(e, c)
	local g = c:GetMaterial()
	local att = 0
	local tc = g:GetFirst()
	while tc do
		att = att | tc:GetLinkAttribute()
		tc = g:GetNext()
	end
	e:SetLabel(att)
end
function s.descon(e, tp, eg, ep, ev, re, r, rp)
	local att = e:GetLabelObject():GetLabel()
	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
		and att & ATTRIBUTE_DARK > 0
		and att & ATTRIBUTE_EARTH > 0
		and att & ATTRIBUTE_WATER > 0
		and att & ATTRIBUTE_FIRE > 0
		and att & ATTRIBUTE_WIND > 0
end
function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return Duel.IsExistingMatchingCard(aux.TRUE, tp, 0, LOCATION_ONFIELD, 1, nil)
	end
	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
end
function s.desop(e, tp, eg, ep, ev, re, r, rp)
	local g = Duel.GetMatchingGroup(aux.TRUE, tp, 0, LOCATION_ONFIELD, nil)
	Duel.Destroy(g, REASON_EFFECT)
end
function s.efilter(e, te)
	return te:GetOwner() ~= e:GetOwner()
end
function s.indes(e, c)
	return c:IsAttribute(ATTRIBUTE_DARK + ATTRIBUTE_EARTH + ATTRIBUTE_WATER + ATTRIBUTE_FIRE + ATTRIBUTE_WIND)
end
function s.rmcon(e, tp, eg, ep, ev, re, r, rp)
	return Duel.GetTurnPlayer() == 1 - tp
end
function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
	if chk == 0 then
		return true
	end
	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 5, tp, LOCATION_GRAVE)
	Duel.SetOperationInfo(0, CATEGORY_TOGRAVE, e:GetHandler(), 1, 0, 0)
end
function s.rmop(e, tp, eg, ep, ev, re, r, rp)
	local c = e:GetHandler()
	local res = false
	local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, LOCATION_GRAVE, 0, nil, tp, POS_FACEDOWN)
	if g:GetCount() >= 5 then
		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
		local sg = Duel.SelectMatchingCard(tp, Card.IsAbleToRemove, tp, LOCATION_GRAVE, 0, 5, 5, nil, tp, POS_FACEDOWN)
		Duel.Remove(sg, POS_FACEDOWN, REASON_EFFECT)
		if Duel.GetOperatedGroup():FilterCount(Card.IsLocation, nil, LOCATION_REMOVED) == 5 then
			res = true
		end
	end
	if not res and c:IsRelateToEffect(e) then
		Duel.SendtoGrave(c, REASON_EFFECT)
	end
end

