--センサー万別
function c114514963.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetHintTiming(0,TIMINGS_CHECK_MONSTER)
	c:RegisterEffect(e1)
	--adjust
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e2:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE)
	e2:SetCode(EVENT_ADJUST)
	e2:SetRange(LOCATION_SZONE)
	e2:SetOperation(c114514963.adjustop)
	c:RegisterEffect(e2)
	--cannot summon,spsummon,flipsummon
	local e4=Effect.CreateEffect(c)
	e4:SetType(EFFECT_TYPE_FIELD)
	e4:SetRange(LOCATION_SZONE)
	e4:SetCode(EFFECT_LIMIT_SPECIAL_SUMMON_POSITION)
	e4:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
	e4:SetTargetRange(1,1)
	e4:SetTarget(c114514963.sumlimit)
	c:RegisterEffect(e4)
	local e5=e4:Clone()
	e5:SetCode(EFFECT_CANNOT_SUMMON)
	c:RegisterEffect(e5)
	local e6=e4:Clone()
	e6:SetCode(EFFECT_CANNOT_FLIP_SUMMON)
	c:RegisterEffect(e6)
	if not c114514963.global_check then
		c114514963.global_check=true
		c114514963[0]={}
		c114514963[1]={}
		local attribute=1
		while attribute<ATTRIBUTE_ALL do
			c114514963[0][attribute]=Group.CreateGroup()
			c114514963[0][attribute]:KeepAlive()
			c114514963[1][attribute]=Group.CreateGroup()
			c114514963[1][attribute]:KeepAlive()
			attribute=attribute<<1
		end
	end
end
function c114514963.rmfilter(c,rc)
	return c:IsFaceup() and c:IsAttribute(rc) and c:IsStatus(STATUS_EFFECT_ENABLED)
end
function c114514963.sumlimit(e,c,sump,sumtype,sumpos,targetp)
	if sumtype==SUMMON_TYPE_DUAL then return false end
	if sumpos and bit.band(sumpos,POS_FACEDOWN)>0 then return false end
	local tp=sump
	if targetp then tp=targetp end
	return Duel.IsExistingMatchingCard(c114514963.rmfilter,tp,LOCATION_MZONE,0,1,nil,c:GetAttribute())
end
function c114514963.adjustop(e,tp,eg,ep,ev,re,r,rp)
	local phase=Duel.GetCurrentPhase()
	if (phase==PHASE_DAMAGE and not Duel.IsDamageCalculated()) or phase==PHASE_DAMAGE_CAL then return end
	local sg=Group.CreateGroup()
	for p=0,1 do
		local g=Duel.GetMatchingGroup(Card.IsFaceup,p,LOCATION_MZONE,0,nil)
		local attribute=1
		while attribute<ATTRIBUTE_ALL do
			local rg=g:Filter(Card.IsAttribute,nil,attribute)
			local rc=rg:GetCount()
			if rc>1 then
				rg:Sub(c114514963[p][attribute]:Filter(Card.IsAttribute,nil,attribute))
				Duel.Hint(HINT_SELECTMSG,p,HINTMSG_TOGRAVE)
				local dg=rg:Select(p,rc-1,rc-1,nil)
				sg:Merge(dg)
			end
			attribute=attribute<<1
		end
	end
	if sg:GetCount()>0 then
		Duel.SendtoGrave(sg,REASON_RULE)
		Duel.Readjust()
	end
	for p=0,1 do
		local g=Duel.GetMatchingGroup(Card.IsFaceup,p,LOCATION_MZONE,0,nil)
		local attribute=1
		while attribute<ATTRIBUTE_ALL do
			c114514963[p][attribute]:Clear()
			c114514963[p][attribute]:Merge(g:Filter(Card.IsAttribute,nil,attribute))
			attribute=attribute<<1
		end
	end
end
