name: Spell
card_text: Add 1 "Endymion" card from your Deck to your hand, then you can count the number of "Spell Power Mastery" and "Spell Power Grasp" you control and/or have in your GY, and place that many Spell Counters among card(s) you control that you can place a Spell Counter on. You can only activate 1 "Spell Power Mastery" per turn.
external_ids: local CARD_ID_0 = 75014062 --Spell Power Grasp
  local SETCARD_ID_0 = 0x12a --Endymion
  local COUNTER_ID_0 = 0x1 --Spell
  
lua: local CARD_ID_0 = 75014062 --Spell Power Grasp
  local SETCARD_ID_0 = 0x12a --Endymion
  local COUNTER_ID_0 = 0x1 --Spell
  local s, id, o = GetID()
  function s.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, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.cfilter(c)
  	return c:IsCode(id, CARD_ID_0) and (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE))
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.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(s.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(id, 0)) then
  			while ct > 0 do
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_COUNTER)
  				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(COUNTER_ID_0, 1)
  				ct = ct - 1
  			end
  		end
  	end
  end
  
  
source_text: Spell
  Add 1 "Endymion" card from your Deck to your hand, then you can count the number of "Spell Power Mastery" and "Spell Power Grasp" you control and/or have in your GY, and place that many Spell Counters among card(s) you control that you can place a Spell Counter on. You can only activate 1 "Spell Power Mastery" per turn.
target_text: -- Spell
  local CARD_ID_0 = 75014062 --Spell Power Grasp
  local SETCARD_ID_0 = 0x12a --Endymion
  local COUNTER_ID_0 = 0x1 --Spell
  local s, id, o = GetID()
  function s.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, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.cfilter(c)
  	return c:IsCode(id, CARD_ID_0) and (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE))
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.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(s.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(id, 0)) then
  			while ct > 0 do
  				Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_COUNTER)
  				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(COUNTER_ID_0, 1)
  				ct = ct - 1
  			end
  		end
  	end
  end
  
  