name: Sacred
card_text: Cannot be Special Summoned. Once per turn, during the End Phase, if this card was Normal Summoned or flipped face-up this turn: Return this card to the hand. If you control another "Ice Barrier" monster, this card's End Phase effect instead becomes "Target 1 monster your opponent controls; return it to the hand".
external_ids: local SETCARD_ID_0 = 0x2f --Ice
  
lua: local SETCARD_ID_0 = 0x2f --Ice
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e1)
  	--summon,flip
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetOperation(s.retreg)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_FLIP)
  	c:RegisterEffect(e3)
  end
  function s.retreg(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e1:SetDescription(1104)
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetCode(EVENT_PHASE + PHASE_END)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, EFFECT_COUNT_CODE_SINGLE)
  	e1:SetReset(RESET_EVENT + 0x1ee0000 + RESET_PHASE + PHASE_END)
  	e1:SetCondition(s.retcon)
  	e1:SetTarget(aux.SpiritReturnTargetForced)
  	e1:SetOperation(aux.SpiritReturnOperation)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetTarget(aux.SpiritReturnTargetOptional)
  	c:RegisterEffect(e2)
  	--to hand, target version
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetDescription(1104)
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCountLimit(1, EFFECT_COUNT_CODE_SINGLE)
  	e3:SetReset(RESET_EVENT + 0x1ee0000 + RESET_PHASE + PHASE_END)
  	e3:SetCondition(s.retcon2)
  	e3:SetTarget(s.rettg2)
  	e3:SetOperation(s.retop2)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, e:GetHandler()) then
  		return false
  	end
  	if e:IsHasType(EFFECT_TYPE_TRIGGER_F) then
  		return aux.SpiritReturnConditionForced(e, tp, eg, ep, ev, re, r, rp)
  	else
  		return aux.SpiritReturnConditionOptional(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  function s.retcon2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, e:GetHandler())
  end
  function s.rettg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and chkc:IsAbleToHand()
  	end
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToHand, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, g:GetCount(), 0, 0)
  end
  function s.retop2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsControler(1 - tp) and tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  
source_text: Sacred
  Cannot be Special Summoned. Once per turn, during the End Phase, if this card was Normal Summoned or flipped face-up this turn: Return this card to the hand. If you control another "Ice Barrier" monster, this card's End Phase effect instead becomes "Target 1 monster your opponent controls; return it to the hand".
target_text: -- Sacred
  local SETCARD_ID_0 = 0x2f --Ice
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--cannot special summon
  	local e1 = Effect.CreateEffect(c)
  	e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE + EFFECT_FLAG_UNCOPYABLE)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetCode(EFFECT_SPSUMMON_CONDITION)
  	c:RegisterEffect(e1)
  	--summon,flip
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_SUMMON_SUCCESS)
  	e2:SetOperation(s.retreg)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EVENT_FLIP)
  	c:RegisterEffect(e3)
  end
  function s.retreg(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e1:SetDescription(1104)
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetCode(EVENT_PHASE + PHASE_END)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, EFFECT_COUNT_CODE_SINGLE)
  	e1:SetReset(RESET_EVENT + 0x1ee0000 + RESET_PHASE + PHASE_END)
  	e1:SetCondition(s.retcon)
  	e1:SetTarget(aux.SpiritReturnTargetForced)
  	e1:SetOperation(aux.SpiritReturnOperation)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetTarget(aux.SpiritReturnTargetOptional)
  	c:RegisterEffect(e2)
  	--to hand, target version
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e3:SetDescription(1104)
  	e3:SetCategory(CATEGORY_TOHAND)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetCountLimit(1, EFFECT_COUNT_CODE_SINGLE)
  	e3:SetReset(RESET_EVENT + 0x1ee0000 + RESET_PHASE + PHASE_END)
  	e3:SetCondition(s.retcon2)
  	e3:SetTarget(s.rettg2)
  	e3:SetOperation(s.retop2)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.retcon(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, e:GetHandler()) then
  		return false
  	end
  	if e:IsHasType(EFFECT_TYPE_TRIGGER_F) then
  		return aux.SpiritReturnConditionForced(e, tp, eg, ep, ev, re, r, rp)
  	else
  		return aux.SpiritReturnConditionOptional(e, tp, eg, ep, ev, re, r, rp)
  	end
  end
  function s.retcon2(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, e:GetHandler())
  end
  function s.rettg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and chkc:IsAbleToHand()
  	end
  	if chk == 0 then
  		return true
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  	local g = Duel.SelectTarget(tp, Card.IsAbleToHand, tp, 0, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, g:GetCount(), 0, 0)
  end
  function s.retop2(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc and tc:IsControler(1 - tp) and tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  
  