name: Freezing
card_text: When this card is activated: You can target 1 Level 4 or lower "Ice Barrier" monster in your GY; Special Summon it. While you control 3 or more "Ice Barrier" monsters, "Ice Barrier" monsters you control are unaffected by the activated effects of your opponent's monsters that were Special Summoned from the Extra Deck. You can only activate 1 "Freezing Chains of the Ice Barrier" per turn.
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)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  	--Unaffected
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_IMMUNE_EFFECT)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetCondition(s.condition)
  	e2:SetValue(s.efilter)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsLevelBelow(4) and c:IsSetCard(SETCARD_ID_0) 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_GRAVE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return true
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp) and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		e:SetOperation(s.activate)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	else
  		e:SetCategory(0)
  		e:SetProperty(0)
  		e:SetOperation(nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.imfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e)
  	return Duel.IsExistingMatchingCard(s.imfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 3, nil)
  end
  function s.efilter(e, te)
  	local tc = te:GetOwner()
  	return te:IsActiveType(TYPE_MONSTER) and te:IsActivated() and te:GetOwnerPlayer() == 1 - e:GetHandlerPlayer() and te:GetActivateLocation() == LOCATION_MZONE and tc:IsSummonLocation(LOCATION_EXTRA)
  end
  
  
source_text: Freezing
  When this card is activated: You can target 1 Level 4 or lower "Ice Barrier" monster in your GY; Special Summon it. While you control 3 or more "Ice Barrier" monsters, "Ice Barrier" monsters you control are unaffected by the activated effects of your opponent's monsters that were Special Summoned from the Extra Deck. You can only activate 1 "Freezing Chains of the Ice Barrier" per turn.
target_text: -- Freezing
  local SETCARD_ID_0 = 0x2f --Ice
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id + EFFECT_COUNT_CODE_OATH)
  	e1:SetTarget(s.target)
  	c:RegisterEffect(e1)
  	--Unaffected
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_IMMUNE_EFFECT)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e2:SetCondition(s.condition)
  	e2:SetValue(s.efilter)
  	c:RegisterEffect(e2)
  end
  function s.filter(c, e, tp)
  	return c:IsLevelBelow(4) and c:IsSetCard(SETCARD_ID_0) 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_GRAVE) and chkc:IsControler(tp) and s.filter(chkc)
  	end
  	if chk == 0 then
  		return true
  	end
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingTarget(s.filter, tp, LOCATION_GRAVE, 0, 1, nil, e, tp) and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		e:SetCategory(CATEGORY_SPECIAL_SUMMON)
  		e:SetProperty(EFFECT_FLAG_CARD_TARGET)
  		e:SetOperation(s.activate)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  		local g = Duel.SelectTarget(tp, s.filter, tp, LOCATION_GRAVE, 0, 1, 1, nil, e, tp)
  		Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, 1, 0, 0)
  	else
  		e:SetCategory(0)
  		e:SetProperty(0)
  		e:SetOperation(nil)
  	end
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SpecialSummon(tc, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  function s.imfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e)
  	return Duel.IsExistingMatchingCard(s.imfilter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 3, nil)
  end
  function s.efilter(e, te)
  	local tc = te:GetOwner()
  	return te:IsActiveType(TYPE_MONSTER) and te:IsActivated() and te:GetOwnerPlayer() == 1 - e:GetHandlerPlayer() and te:GetActivateLocation() == LOCATION_MZONE and tc:IsSummonLocation(LOCATION_EXTRA)
  end
  
  