name: Royal
card_text: Each time a Spell Card is activated, place 1 Spell Counter on this card when that Spell resolves (max. 3). You can remove 3 Spell Counters from this card; draw 1 card.
external_ids: local COUNTER_ID_0 = 0x1 --Spell
  
lua: local COUNTER_ID_0 = 0x1 --Spell
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x1)
  	c:SetCounterLimit(0x1, 3)
  	--add counter
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e0:SetCode(EVENT_CHAINING)
  	e0:SetRange(LOCATION_MZONE)
  	e0:SetOperation(aux.chainreg)
  	c:RegisterEffect(e0)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e1:SetCode(EVENT_CHAIN_SOLVED)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetOperation(s.acop)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCost(s.drcost)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  end
  function s.acop(e, tp, eg, ep, ev, re, r, rp)
  	if re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:IsActiveType(TYPE_SPELL) and e:GetHandler():GetFlagEffect(FLAG_ID_CHAINING) > 0 then
  		e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.drcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 3, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, 3, REASON_COST)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  
  
source_text: Royal
  Each time a Spell Card is activated, place 1 Spell Counter on this card when that Spell resolves (max. 3). You can remove 3 Spell Counters from this card; draw 1 card.
target_text: -- Royal
  local COUNTER_ID_0 = 0x1 --Spell
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x1)
  	c:SetCounterLimit(0x1, 3)
  	--add counter
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e0:SetCode(EVENT_CHAINING)
  	e0:SetRange(LOCATION_MZONE)
  	e0:SetOperation(aux.chainreg)
  	c:RegisterEffect(e0)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e1:SetCode(EVENT_CHAIN_SOLVED)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetOperation(s.acop)
  	c:RegisterEffect(e1)
  	--draw
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DRAW)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetCost(s.drcost)
  	e2:SetTarget(s.drtg)
  	e2:SetOperation(s.drop)
  	c:RegisterEffect(e2)
  end
  function s.acop(e, tp, eg, ep, ev, re, r, rp)
  	if re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:IsActiveType(TYPE_SPELL) and e:GetHandler():GetFlagEffect(FLAG_ID_CHAINING) > 0 then
  		e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.drcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 3, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, 3, REASON_COST)
  end
  function s.drtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, 1)
  end
  function s.drop(e, tp, eg, ep, ev, re, r, rp)
  	local p, d = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER, CHAININFO_TARGET_PARAM)
  	Duel.Draw(p, d, REASON_EFFECT)
  end
  
  