name: Judge
card_text: While you control another "Ice Barrier" monster, each time your opponent activates a card or effect by paying LP, they lose 500 LP. You can only use each of the following effects of "Judge of the Ice Barrier" once per turn. You can target 1 or 2 "Ice Barrier" monsters in your GY and 1 or 2 cards in your opponent's GY; shuffle them into the Deck. If you control an "Ice Barrier" monster: You can banish this card from your GY, then target 1 Attack Position monster on the field; change it to Defense Position.
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)
  	--It Loses 500 LP for each time they pay/activate a card effect
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e0:SetCode(EVENT_PAY_LPCOST)
  	e0:SetRange(LOCATION_MZONE)
  	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e0:SetOperation(s.regop)
  	c:RegisterEffect(e0)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_CHAIN_SOLVED)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetOperation(s.llpop)
  	c:RegisterEffect(e1)
  	--Target up to 2 "Ice Barrier" and opponent's card to the Deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  	--Change it to the Defense Position by banishing this card
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_POSITION)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCost(aux.bfgcost)
  	e3:SetCondition(s.poscon)
  	e3:SetTarget(s.postg)
  	e3:SetOperation(s.posop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if ep == 1 - tp and re:IsActivated() and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, c) then
  		c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET + RESET_CHAIN, 0, 1)
  	end
  end
  function s.llpop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if ep == 1 - tp and c:GetFlagEffect(id) > 0 and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, c) then
  		Duel.Hint(HINT_CARD, 0, id)
  		Duel.SetLP(1 - tp, Duel.GetLP(1 - tp) - 500)
  	end
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingTarget(Card.IsAbleToDeck, tp, 0, LOCATION_GRAVE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g1 = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 2, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g2 = Duel.SelectTarget(tp, Card.IsAbleToDeck, tp, 0, LOCATION_GRAVE, 1, 2, nil)
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g1, g1:GetCount(), 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #g > 0 then
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.posfilter(c)
  	return c:IsAttackPos() and c:IsCanChangePosition()
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.posfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.posfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_POSCHANGE)
  	local g = Duel.SelectTarget(tp, s.posfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, g, 1, 0, 0)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsAttackPos() and tc:IsRelateToEffect(e) then
  		Duel.ChangePosition(tc, POS_FACEUP_DEFENSE)
  	end
  end
  
  
source_text: Judge
  While you control another "Ice Barrier" monster, each time your opponent activates a card or effect by paying LP, they lose 500 LP. You can only use each of the following effects of "Judge of the Ice Barrier" once per turn. You can target 1 or 2 "Ice Barrier" monsters in your GY and 1 or 2 cards in your opponent's GY; shuffle them into the Deck. If you control an "Ice Barrier" monster: You can banish this card from your GY, then target 1 Attack Position monster on the field; change it to Defense Position.
target_text: -- Judge
  local SETCARD_ID_0 = 0x2f --Ice
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--It Loses 500 LP for each time they pay/activate a card effect
  	local e0 = Effect.CreateEffect(c)
  	e0:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e0:SetCode(EVENT_PAY_LPCOST)
  	e0:SetRange(LOCATION_MZONE)
  	e0:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e0:SetOperation(s.regop)
  	c:RegisterEffect(e0)
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_CHAIN_SOLVED)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetOperation(s.llpop)
  	c:RegisterEffect(e1)
  	--Target up to 2 "Ice Barrier" and opponent's card to the Deck
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetTarget(s.tdtg)
  	e2:SetOperation(s.tdop)
  	c:RegisterEffect(e2)
  	--Change it to the Defense Position by banishing this card
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_POSITION)
  	e3:SetType(EFFECT_TYPE_IGNITION)
  	e3:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id + 1)
  	e3:SetCost(aux.bfgcost)
  	e3:SetCondition(s.poscon)
  	e3:SetTarget(s.postg)
  	e3:SetOperation(s.posop)
  	c:RegisterEffect(e3)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if ep == 1 - tp and re:IsActivated() and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, c) then
  		c:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD - RESET_TURN_SET + RESET_CHAIN, 0, 1)
  	end
  end
  function s.llpop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if ep == 1 - tp and c:GetFlagEffect(id) > 0 and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, c) then
  		Duel.Hint(HINT_CARD, 0, id)
  		Duel.SetLP(1 - tp, Duel.GetLP(1 - tp) - 500)
  	end
  end
  function s.tdfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToDeck()
  end
  function s.tdtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return false
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tdfilter, tp, LOCATION_GRAVE, 0, 1, nil) and Duel.IsExistingTarget(Card.IsAbleToDeck, tp, 0, LOCATION_GRAVE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g1 = Duel.SelectTarget(tp, s.tdfilter, tp, LOCATION_GRAVE, 0, 1, 2, nil)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g2 = Duel.SelectTarget(tp, Card.IsAbleToDeck, tp, 0, LOCATION_GRAVE, 1, 2, nil)
  	g1:Merge(g2)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g1, g1:GetCount(), 0, 0)
  end
  function s.tdop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetChainInfo(0, CHAININFO_TARGET_CARDS):Filter(Card.IsRelateToEffect, nil, e)
  	if #g > 0 then
  		Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	end
  end
  function s.poscon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.posfilter(c)
  	return c:IsAttackPos() and c:IsCanChangePosition()
  end
  function s.postg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and s.posfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.posfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_POSCHANGE)
  	local g = Duel.SelectTarget(tp, s.posfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_POSITION, g, 1, 0, 0)
  end
  function s.posop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsAttackPos() and tc:IsRelateToEffect(e) then
  		Duel.ChangePosition(tc, POS_FACEUP_DEFENSE)
  	end
  end
  
  