name: Spiritual
card_text: Tribute 1 LIGHT monster to target 1 banished monster; your opponent can reveal 1 Trap Card from their hand to negate this card's effect, otherwise you Special Summon that monster.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.rfilter(c, ft, tp)
  	return c:IsAttribute(ATTRIBUTE_LIGHT) and (ft > 0 or (c:IsControler(tp) and c:GetSequence() < 5)) and (c:IsControler(tp) or c:IsFaceup())
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if chk == 0 then
  		return ft > -1 and Duel.CheckReleaseGroup(tp, s.rfilter, 1, nil, ft, tp)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.rfilter, 1, 1, nil, ft, tp)
  	Duel.Release(g, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsFaceup() and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		if e:GetLabel() == 1 then
  			e:SetLabel(0)
  			return Duel.IsExistingTarget(s.filter, tp, LOCATION_REMOVED, LOCATION_REMOVED, 1, nil, e, tp)
  		else
  			return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_REMOVED, LOCATION_REMOVED, 1, nil, e, tp)
  		end
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_REMOVED, LOCATION_REMOVED, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.cfilter(c)
  	return not c:IsPublic() and c:IsType(TYPE_TRAP)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsChainDisablable(0) then
  		local sel = 1
  		local g = Duel.GetMatchingGroup(s.cfilter, tp, 0, LOCATION_HAND, nil)
  		Duel.Hint(HINT_SELECTMSG, 1 - tp, aux.Stringid(id, 0))
  		if g:GetCount() > 0 then
  			sel = Duel.SelectOption(1 - tp, 1213, 1214)
  		else
  			sel = Duel.SelectOption(1 - tp, 1214) + 1
  		end
  		if sel == 0 then
  			Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_CONFIRM)
  			local sg = g:Select(1 - tp, 1, 1, nil)
  			Duel.ConfirmCards(tp, sg)
  			Duel.ShuffleHand(1 - tp)
  			Duel.NegateEffect(0)
  			return
  		end
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Spiritual
  Tribute 1 LIGHT monster to target 1 banished monster; your opponent can reveal 1 Trap Card from their hand to negate this card's effect, otherwise you Special Summon that monster.
target_text: -- Spiritual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCost(s.cost)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.rfilter(c, ft, tp)
  	return c:IsAttribute(ATTRIBUTE_LIGHT) and (ft > 0 or (c:IsControler(tp) and c:GetSequence() < 5)) and (c:IsControler(tp) or c:IsFaceup())
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	e:SetLabel(1)
  	local ft = Duel.GetLocationCount(tp, LOCATION_MZONE)
  	if chk == 0 then
  		return ft > -1 and Duel.CheckReleaseGroup(tp, s.rfilter, 1, nil, ft, tp)
  	end
  	local g = Duel.SelectReleaseGroup(tp, s.rfilter, 1, 1, nil, ft, tp)
  	Duel.Release(g, REASON_COST)
  end
  function s.filter(c, e, tp)
  	return c:IsFaceup() and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_REMOVED) and s.filter(chkc, e, tp)
  	end
  	if chk == 0 then
  		if e:GetLabel() == 1 then
  			e:SetLabel(0)
  			return Duel.IsExistingTarget(s.filter, tp, LOCATION_REMOVED, LOCATION_REMOVED, 1, nil, e, tp)
  		else
  			return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_REMOVED, LOCATION_REMOVED, 1, nil, e, tp)
  		end
  	end
  	e:SetLabel(0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_REMOVED, LOCATION_REMOVED, 1, 1, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  end
  function s.cfilter(c)
  	return not c:IsPublic() and c:IsType(TYPE_TRAP)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsChainDisablable(0) then
  		local sel = 1
  		local g = Duel.GetMatchingGroup(s.cfilter, tp, 0, LOCATION_HAND, nil)
  		Duel.Hint(HINT_SELECTMSG, 1 - tp, aux.Stringid(id, 0))
  		if g:GetCount() > 0 then
  			sel = Duel.SelectOption(1 - tp, 1213, 1214)
  		else
  			sel = Duel.SelectOption(1 - tp, 1214) + 1
  		end
  		if sel == 0 then
  			Duel.Hint(HINT_SELECTMSG, 1 - tp, HINTMSG_CONFIRM)
  			local sg = g:Select(1 - tp, 1, 1, nil)
  			Duel.ConfirmCards(tp, sg)
  			Duel.ShuffleHand(1 - tp)
  			Duel.NegateEffect(0)
  			return
  		end
  	end
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  