--魔力統轄
--
--Script by JoyJ and mercury233
function c100308022.initial_effect(c)
	--Activate
	local e1=Effect.CreateEffect(c)
	e1:SetCategory(CATEGORY_TOHAND+CATEGORY_SEARCH)
	e1:SetType(EFFECT_TYPE_ACTIVATE)
	e1:SetCode(EVENT_FREE_CHAIN)
	e1:SetCountLimit(1,100308022+EFFECT_COUNT_CODE_OATH)
	e1:SetTarget(c100308022.target)
	e1:SetOperation(c100308022.operation)
	c:RegisterEffect(e1)
end
function c100308022.filter(c)
	return c:IsSetCard(0x230) and c:IsAbleToHand()
end
function c100308022.target(e,tp,eg,ep,ev,re,r,rp,chk)
	if chk==0 then return Duel.IsExistingMatchingCard(c100308022.filter,tp,LOCATION_DECK,0,1,nil) end
	Duel.SetOperationInfo(0,CATEGORY_TOHAND,nil,1,tp,LOCATION_DECK)
end
function c100308022.cfilter(c)
	return c:IsCode(100308022,75014062) and (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE))
end
function c100308022.operation(e,tp,eg,ep,ev,re,r,rp)
	Duel.Hint(HINT_SELECTMSG,tp,HINTMSG_ATOHAND)
	local g=Duel.SelectMatchingCard(tp,c100308022.filter,tp,LOCATION_DECK,0,1,1,nil)
	if g:GetCount()>0 and Duel.SendtoHand(g,nil,REASON_EFFECT)>0 then
		Duel.ConfirmCards(1-tp,g)
		local ct=Duel.GetMatchingGroupCount(c100308022.cfilter,tp,LOCATION_ONFIELD+LOCATION_GRAVE,0,nil)
		if ct>0 and Duel.GetMatchingGroupCount(Card.IsCanAddCounter,tp,LOCATION_ONFIELD,0,nil,0x1,1)>0
			and Duel.SelectYesNo(tp,aux.Stringid(100308022,0)) then
			while ct>0 do
				Duel.Hint(HINT_SELECTMSG,tp,aux.Stringid(100308022,1))
				local tc=Duel.SelectMatchingCard(tp,Card.IsCanAddCounter,tp,LOCATION_ONFIELD,0,1,1,nil,0x1,1):GetFirst()
				if not tc then break end
				tc:AddCounter(0x1,1)
				ct=ct-1
			end
		end
	end
end
