name: Sacred
card_text: If you activate a Counter Trap Card, OR if you negate the activation of a Spell/Trap Card, or monster effect (except during the Damage Step): You can banish 2 other Fairy monsters from your hand, field and/or GY; Special Summon this card from the GY (if it was there when you activated/negated) or hand (even if not). If this card attacks a Defense Position monster, inflict piercing battle damage. When this card inflicts battle damage to your opponent: You can add 1 "Parshath" card or 1 Counter Trap from your Deck to your hand.
external_ids: local SETCARD_ID_0 = 0x10a --Parshath
  
lua: local SETCARD_ID_0 = 0x10a --Parshath
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetRange(LOCATION_HAND + LOCATION_GRAVE)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCondition(s.spcon1)
  	e3:SetCost(s.spcost)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_CHAIN_NEGATED)
  	e4:SetCondition(s.spcon2)
  	c:RegisterEffect(e4)
  	--pierce
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE)
  	e5:SetCode(EFFECT_PIERCE)
  	c:RegisterEffect(e5)
  	--search
  	local e6 = Effect.CreateEffect(c)
  	e6:SetDescription(aux.Stringid(id, 1))
  	e6:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e6:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e6:SetCode(EVENT_BATTLE_DAMAGE)
  	e6:SetCondition(s.thcon)
  	e6:SetTarget(s.thtg)
  	e6:SetOperation(s.thop)
  	c:RegisterEffect(e6)
  end
  function s.spcon1(e, tp, eg, ep, ev, re, r, rp)
  	return rp == tp and re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:IsActiveType(TYPE_COUNTER)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	local dp = Duel.GetChainInfo(ev, CHAININFO_DISABLE_PLAYER)
  	return dp == tp and (re:IsActiveType(TYPE_MONSTER) or re:IsHasType(EFFECT_TYPE_ACTIVATE))
  end
  function s.cfilter(c)
  	return c:IsRace(RACE_FAIRY) and (c:IsFaceup() or not c:IsLocation(LOCATION_MZONE)) and c:IsAbleToRemoveAsCost()
  end
  function s.mzfilter(c)
  	return c:IsLocation(LOCATION_MZONE) and c:GetSequence() < 5
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local rg = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_HAND + LOCATION_MZONE + LOCATION_GRAVE, 0, c)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local ct = -ft + 1
  	if chk == 0 then
  		return ft > -2 and rg:GetCount() > 1 and (ft > 0 or rg:IsExists(s.mzfilter, ct, nil))
  	end
  	local g = nil
  	if ft > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		g = rg:Select(tp, 2, 2, nil)
  	elseif ft == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		g = rg:FilterSelect(tp, s.mzfilter, 1, 1, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local g2 = rg:Select(tp, 1, 1, g:GetFirst())
  		g:Merge(g2)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		g = rg:FilterSelect(tp, s.mzfilter, 2, 2, nil)
  	end
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep ~= tp
  end
  function s.thfilter(c)
  	return (c:IsSetCard(SETCARD_ID_0) or c:IsType(TYPE_COUNTER)) 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: Sacred
  If you activate a Counter Trap Card, OR if you negate the activation of a Spell/Trap Card, or monster effect (except during the Damage Step): You can banish 2 other Fairy monsters from your hand, field and/or GY; Special Summon this card from the GY (if it was there when you activated/negated) or hand (even if not). If this card attacks a Defense Position monster, inflict piercing battle damage. When this card inflicts battle damage to your opponent: You can add 1 "Parshath" card or 1 Counter Trap from your Deck to your hand.
target_text: -- Sacred
  local SETCARD_ID_0 = 0x10a --Parshath
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--special summon
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 0))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetRange(LOCATION_HAND + LOCATION_GRAVE)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCondition(s.spcon1)
  	e3:SetCost(s.spcost)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  	local e4 = e3:Clone()
  	e4:SetCode(EVENT_CHAIN_NEGATED)
  	e4:SetCondition(s.spcon2)
  	c:RegisterEffect(e4)
  	--pierce
  	local e5 = Effect.CreateEffect(c)
  	e5:SetType(EFFECT_TYPE_SINGLE)
  	e5:SetCode(EFFECT_PIERCE)
  	c:RegisterEffect(e5)
  	--search
  	local e6 = Effect.CreateEffect(c)
  	e6:SetDescription(aux.Stringid(id, 1))
  	e6:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e6:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e6:SetCode(EVENT_BATTLE_DAMAGE)
  	e6:SetCondition(s.thcon)
  	e6:SetTarget(s.thtg)
  	e6:SetOperation(s.thop)
  	c:RegisterEffect(e6)
  end
  function s.spcon1(e, tp, eg, ep, ev, re, r, rp)
  	return rp == tp and re:IsHasType(EFFECT_TYPE_ACTIVATE) and re:IsActiveType(TYPE_COUNTER)
  end
  function s.spcon2(e, tp, eg, ep, ev, re, r, rp)
  	local dp = Duel.GetChainInfo(ev, CHAININFO_DISABLE_PLAYER)
  	return dp == tp and (re:IsActiveType(TYPE_MONSTER) or re:IsHasType(EFFECT_TYPE_ACTIVATE))
  end
  function s.cfilter(c)
  	return c:IsRace(RACE_FAIRY) and (c:IsFaceup() or not c:IsLocation(LOCATION_MZONE)) and c:IsAbleToRemoveAsCost()
  end
  function s.mzfilter(c)
  	return c:IsLocation(LOCATION_MZONE) and c:GetSequence() < 5
  end
  function s.spcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local rg = Duel.GetMatchingGroup(s.cfilter, tp, LOCATION_HAND + LOCATION_MZONE + LOCATION_GRAVE, 0, c)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	local ct = -ft + 1
  	if chk == 0 then
  		return ft > -2 and rg:GetCount() > 1 and (ft > 0 or rg:IsExists(s.mzfilter, ct, nil))
  	end
  	local g = nil
  	if ft > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		g = rg:Select(tp, 2, 2, nil)
  	elseif ft == 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		g = rg:FilterSelect(tp, s.mzfilter, 1, 1, nil)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local g2 = rg:Select(tp, 1, 1, g:GetFirst())
  		g:Merge(g2)
  	else
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		g = rg:FilterSelect(tp, s.mzfilter, 2, 2, nil)
  	end
  	Duel.Remove(g, POS_FACEUP, REASON_COST)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanBeSpecialSummoned(e, 0, tp, false, false)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep ~= tp
  end
  function s.thfilter(c)
  	return (c:IsSetCard(SETCARD_ID_0) or c:IsType(TYPE_COUNTER)) 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
  
  