name: Mythical
card_text: Each time an opponent's monster effect is activated, place 1 Spell Counter on this card when that effect resolves. You can send this card with 6 or more Spell Counters to the GY; add 1 Spell from your Deck to your hand. You can only use this effect of "Mythical Bestiamorph" once per turn.
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)
  	--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_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetOperation(aux.chainreg)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_CHAIN_SOLVED)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetOperation(s.acop)
  	c:RegisterEffect(e3)
  	--search
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.thcon)
  	e4:SetCost(s.thcost)
  	e4:SetTarget(s.thtg)
  	e4:SetOperation(s.thop)
  	c:RegisterEffect(e4)
  end
  function s.acop(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_PLAYER)
  	local c = e:GetHandler()
  	if re:IsActiveType(TYPE_MONSTER) and p ~= tp and c:GetFlagEffect(FLAG_ID_CHAINING) > 0 then
  		c:AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) >= 6
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_SPELL) 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, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, 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
  
  
source_text: Mythical
  Each time an opponent's monster effect is activated, place 1 Spell Counter on this card when that effect resolves. You can send this card with 6 or more Spell Counters to the GY; add 1 Spell from your Deck to your hand. You can only use this effect of "Mythical Bestiamorph" once per turn.
target_text: -- Mythical
  local COUNTER_ID_0 = 0x1 --Spell
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x1)
  	--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_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetOperation(aux.chainreg)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_CHAIN_SOLVED)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetOperation(s.acop)
  	c:RegisterEffect(e3)
  	--search
  	local e4 = Effect.CreateEffect(c)
  	e4:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_FREE_CHAIN)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetCountLimit(1, id)
  	e4:SetCondition(s.thcon)
  	e4:SetCost(s.thcost)
  	e4:SetTarget(s.thtg)
  	e4:SetOperation(s.thop)
  	c:RegisterEffect(e4)
  end
  function s.acop(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_PLAYER)
  	local c = e:GetHandler()
  	if re:IsActiveType(TYPE_MONSTER) and p ~= tp and c:GetFlagEffect(FLAG_ID_CHAINING) > 0 then
  		c:AddCounter(COUNTER_ID_0, 1)
  	end
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetCounter(COUNTER_ID_0) >= 6
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToGraveAsCost()
  	end
  	Duel.SendtoGrave(e:GetHandler(), REASON_COST)
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_SPELL) 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, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, 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
  
  