name: Spiritual
card_text: If this card in its owner's possession is destroyed by an opponent's card: You can Special Summon 1 "Ritual Beast" monster from your Deck or Extra Deck, ignoring its Summoning conditions. You can only Special Summon "Spiritual Beast Tamer Winda(s)" once per turn.
external_ids: local SETCARD_ID_0 = 0xb5 --Ritual
  
lua: local SETCARD_ID_0 = 0xb5 --Ritual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetSPSummonOnce(id)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_DESTROYED)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and e:GetHandler():IsPreviousControler(tp)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_MONSTER)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  		and (c:IsLocation(LOCATION_DECK) and Duel.GetMZoneCount(tp) > 0 or c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, true, false, POS_FACEUP)
  	end
  end
  
  
source_text: Spiritual
  If this card in its owner's possession is destroyed by an opponent's card: You can Special Summon 1 "Ritual Beast" monster from your Deck or Extra Deck, ignoring its Summoning conditions. You can only Special Summon "Spiritual Beast Tamer Winda(s)" once per turn.
target_text: -- Spiritual
  local SETCARD_ID_0 = 0xb5 --Ritual
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetSPSummonOnce(id)
  	--special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_DESTROYED)
  	e1:SetCondition(s.spcon)
  	e1:SetTarget(s.sptg)
  	e1:SetOperation(s.spop)
  	c:RegisterEffect(e1)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and e:GetHandler():IsPreviousControler(tp)
  end
  function s.spfilter(c, e, tp)
  	return c:IsSetCard(SETCARD_ID_0)
  		and c:IsType(TYPE_MONSTER)
  		and c:IsCanBeSpecialSummoned(e, 0, tp, true, false)
  		and (c:IsLocation(LOCATION_DECK) and Duel.GetMZoneCount(tp) > 0 or c:IsLocation(LOCATION_EXTRA) and Duel.GetLocationCountFromEx(tp, tp, nil, c) > 0)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_DECK + LOCATION_EXTRA)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_DECK + LOCATION_EXTRA, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, true, false, POS_FACEUP)
  	end
  end
  
  