--磁石偏向
local s,id,o=GetID()
function s.initial_effect(c)
	--activate
	local e1=Effect.CreateEffect(c)
	e1:SetDescription(aux.Stringid(id,0))
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_CHAINING)
	e1:SetCondition(s.con)
	e1:SetTarget(s.tg)
	e1:SetOperation(s.activate)
	c:RegisterEffect(e1)
end
function s.filter(c)
	return c:IsFaceup() and c:IsSetCard(0x2066)
end
function s.con(e,tp,eg,ep,ev,re,r,rp)
	return Duel.IsExistingMatchingCard(s.filter,tp,LOCATION_MZONE,0,1,nil) and s.check(ev,tp)
end
function s.check(chainc,tp)
	local check=0
	for i=1,chainc do
		if Duel.GetChainInfo(i,CHAININFO_TRIGGERING_PLAYER)==1-tp then
			check=1
			break
		end
	end
	return check==1
end
function s.tg(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(Card.IsAbleToGrave,tp,LOCATION_MZONE,0,1,nil) end
end
function s.activate(e,tp,eg,ep,ev,re,r,rp)
	local t={}
	local j=0
	for i=1,ev do
		if Duel.GetChainInfo(i,CHAININFO_TRIGGERING_PLAYER)==1-tp then
			t[j]=i
			j=j+1
		end
	end
	for key,v in pairs(t) do
		local g=Group.CreateGroup()
		Duel.ChangeTargetCard(v,g)
		Duel.ChangeChainOperation(v,s.repop)
	end
end
function s.repop(e,tp,eg,ep,ev,re,r,rp)
	local g=Duel.GetMatchingGroup(Card.IsAbleToGrave,tp,LOCATION_MZONE,0,nil)
	if g:GetCount()>0 then 
		local sg=Duel.SelectMatchingCard(tp,Card.IsAbleToGrave,tp,LOCATION_MZONE,0,1,1,nil)
		Duel.SendtoGrave(sg,REASON_EFFECT)
	end
end