name: Skilled
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 1 Spell Counter from this card, then activate 1 of these effects;
  ● This card gains 1500 ATK, and its Level is increased by 1.
  ● Add 1 "Kuriboh" monster or 1 "Multiply" from your Deck or GY to your hand.
  You can only use this effect of "Skilled Brown Magician" once per turn.
external_ids: local CARD_ID_0 = 40703222 --Multiply
  local SETCARD_ID_0 = 0xa4 --Kuriboh
  local COUNTER_ID_0 = 0x1 --Spell
  
lua: local CARD_ID_0 = 40703222 --Multiply
  local SETCARD_ID_0 = 0xa4 --Kuriboh
  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)
  	--atk/lv up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.cost)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  	--Search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_GRAVE_ACTION)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetCost(s.cost)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  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.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, 1, REASON_COST)
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(1500)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_UPDATE_LEVEL)
  		e2:SetValue(1)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e2)
  	end
  end
  function s.thfilter(c)
  	return (c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) or c:IsCode(CARD_ID_0)) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Skilled
  Each time a Spell Card is activated, place 1 Spell Counter on this card when that Spell resolves (max. 3). You can remove 1 Spell Counter from this card, then activate 1 of these effects;
  ● This card gains 1500 ATK, and its Level is increased by 1.
  ● Add 1 "Kuriboh" monster or 1 "Multiply" from your Deck or GY to your hand.
  You can only use this effect of "Skilled Brown Magician" once per turn.
target_text: -- Skilled
  local CARD_ID_0 = 40703222 --Multiply
  local SETCARD_ID_0 = 0xa4 --Kuriboh
  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)
  	--atk/lv up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_ATKCHANGE)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCost(s.cost)
  	e2:SetOperation(s.atkop)
  	c:RegisterEffect(e2)
  	--Search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH + CATEGORY_GRAVE_ACTION)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCountLimit(1, id)
  	e3:SetCost(s.cost)
  	e3:SetTarget(s.thtg)
  	e3:SetOperation(s.thop)
  	c:RegisterEffect(e3)
  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.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, 1, REASON_COST)
  	Duel.Hint(HINT_OPSELECTED, 1 - tp, e:GetDescription())
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFaceup() and c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetValue(1500)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e1)
  		local e2 = Effect.CreateEffect(c)
  		e2:SetType(EFFECT_TYPE_SINGLE)
  		e2:SetCode(EFFECT_UPDATE_LEVEL)
  		e2:SetValue(1)
  		e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_DISABLE)
  		c:RegisterEffect(e2)
  	end
  end
  function s.thfilter(c)
  	return (c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) or c:IsCode(CARD_ID_0)) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK + LOCATION_GRAVE)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.thfilter), tp, LOCATION_DECK + LOCATION_GRAVE, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  