--无限的轮回
function c60150813.initial_effect(c)
	c:EnableCounterPermit(0x1b)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	c:RegisterEffect(e1)
	--add counter
	local e2=Effect.CreateEffect(c)
	e2:SetType(EFFECT_TYPE_FIELD+EFFECT_TYPE_CONTINUOUS)
	e2:SetRange(LOCATION_SZONE)
	e2:SetCode(EVENT_REMOVE)
	e2:SetOperation(c60150813.ctop)
	c:RegisterEffect(e2)
	--atkup
	local e3=Effect.CreateEffect(c)
	e3:SetType(EFFECT_TYPE_FIELD)
	e3:SetCode(EFFECT_UPDATE_ATTACK)
	e3:SetRange(LOCATION_SZONE)
	e3:SetTargetRange(LOCATION_MZONE,LOCATION_MZONE)
	e3:SetTarget(aux.TargetBoolFunction(Card.IsSetCard,0x3b23))
	e3:SetValue(c60150813.atkval)
	c:RegisterEffect(e3)
	local e4=e3:Clone()
	e4:SetCode(EFFECT_UPDATE_DEFENSE)
	c:RegisterEffect(e4)
	--special summon
	local e5=Effect.CreateEffect(c)
	e5:SetCategory(CATEGORY_TOHAND)
	e5:SetDescription(aux.Stringid(60150813,1))
	e5:SetType(EFFECT_TYPE_IGNITION)
	e5:SetRange(LOCATION_SZONE)
	e5:SetCountLimit(1,60150813)
	e5:SetCost(c60150813.cost3)
	e5:SetOperation(c60150813.op3)
	c:RegisterEffect(e5)
end
function c60150813.ctfilter(c)
	return not c:IsType(TYPE_TOKEN)
end
function c60150813.ctop(e,tp,eg,ep,ev,re,r,rp)
	local ct=eg:FilterCount(c60150813.ctfilter,nil)
	if ct>0 then
		e:GetHandler():AddCounter(0x1b,1)
	end
end
function c60150813.atkval(e,c)
	return e:GetHandler():GetCounter(0x1b)*50
end
function c60150813.cfilter(c)
	return ((c:IsFaceup() and c:IsType(TYPE_MONSTER)) or c:IsFacedown()) and (c:IsAbleToDeckAsCost() or c:IsAbleToExtraAsCost())
end
function c60150813.cost3(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return e:GetHandler():IsCanRemoveCounter(tp,0x1b,3,REASON_COST)
		and Duel.IsExistingMatchingCard(c60150813.cfilter,tp,LOCATION_REMOVED,LOCATION_REMOVED,3,nil) 
		and Duel.IsExistingMatchingCard(c60150813.filter2,tp,LOCATION_DECK,0,1,nil) end
	Duel.Hint(HINT_OPSELECTED,1-tp,e:GetDescription())
	e:GetHandler():RemoveCounter(tp,0x1b,3,REASON_COST)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_TODECK)
	local g=Duel.SelectMatchingCard(tp,c60150813.cfilter,tp,LOCATION_REMOVED,LOCATION_REMOVED,3,3,nil)
	Duel.SendtoDeck(g,nil,2,REASON_COST)
end
function c60150813.filter2(c)
	return c:IsSetCard(0x3b23) and c:IsAttribute(ATTRIBUTE_DARK) and c:IsAbleToHand()
end
function c60150813.op3(e,tp,eg,ep,ev,re,r,rp)
	if not e:GetHandler():IsRelateToEffect(e) then return end
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
	local g=Duel.SelectMatchingCard(tp,c60150813.filter2,tp,LOCATION_DECK,0,1,1,nil)
	if g:GetCount()>0 then
		Duel.SendtoHand(g,nil,REASON_EFFECT)
		Duel.ConfirmCards(1-tp,g)
	end
end