--Sp-骷髅骑手的复活
function c87593004.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetTarget(c87593004.target)
	e1:SetOperation(c87593004.activate)
	c:RegisterEffect(e1)
end
function c87593004.filter(c,e,tp,f)
	if f:GetControler()==tp then cou=0x871 else cou=0x872 end
	if bit.band(c:GetType(),0x81)~=0x81
	or not c:IsCanBeSpecialSummoned(e,SUMMON_TYPE_RITUAL,tp,false,true) then return false end
	return f:IsCanRemoveCounter(tp,cou,c:GetLevel(),REASON_EFFECT)
end
function c87593004.target(e,tp,eg,ep,ev,re,r,rp,chk)
	local f=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_SZONE,LOCATION_SZONE,nil,87593200):GetFirst()
	if chk==0 then
		return Duel.GetLocationCount(tp,LOCATION_MZONE)>0
			and Duel.IsExistingMatchingCard(c87593004.filter,tp,LOCATION_GRAVE,0,1,nil,e,tp,f)
	end
	Duel.SetOperationInfo(0,CATEGORY_SPECIAL_SUMMON,nil,1,tp,LOCATION_GRAVE)
end
function c87593004.activate(e,tp,eg,ep,ev,re,r,rp)
	local f=Duel.GetMatchingGroup(Card.IsCode,tp,LOCATION_SZONE,LOCATION_SZONE,nil,87593200):GetFirst()
	if f:GetControler()==tp then cou=0x871 else cou=0x872 end
	if Duel.GetLocationCount(tp,LOCATION_MZONE)<=0 then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_SPSUMMON)
	local tc=Duel.SelectMatchingCard(tp,c87593004.filter,tp,LOCATION_GRAVE,0,1,1,nil,e,tp,f):GetFirst()
	if tc then
		f:RemoveCounter(tp,cou,tc:GetLevel(),REASON_EFFECT)
		tc:SetMaterial(Group.CreateGroup())
		Duel.SpecialSummon(tc,SUMMON_TYPE_RITUAL,tp,tp,false,true,POS_FACEUP)
		tc:CompleteProcedure()
	end
end
