name: Blockout
card_text: If a card(s) you control would be destroyed by battle or an opponent's card effect, you can destroy this card instead of 1 of those cards. If a card(s) your opponent controls would be destroyed by battle or card effect, you can banish this card from your GY instead of 1 of those cards. You can only use each effect of "Blockout Curtain" once per turn.
lua: 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)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTarget(s.reptg1)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop1)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetTarget(s.reptg2)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop2)
  	c:RegisterEffect(e3)
  end
  function s.repfilter1(c, tp)
  	return c:IsOnField() and c:IsControler(tp) and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp)) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return eg:IsExists(s.repfilter1, 1, c, tp) and c:IsDestructable(e) and not c:IsStatus(STATUS_DESTROY_CONFIRMED)
  	end
  	if Duel.SelectEffectYesNo(tp, c, 96) then
  		local sg = eg:Filter(s.repfilter1, c, tp)
  		if sg:GetCount() > 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 0))
  			sg = sg:Select(tp, 1, 1, nil)
  		end
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.repval(e, c)
  	local g = e:GetLabelObject()
  	return g:IsContains(c)
  end
  function s.repop1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT + REASON_REPLACE)
  	local g = e:GetLabelObject()
  	g:DeleteGroup()
  end
  function s.repfilter2(c, tp)
  	return c:IsOnField() and c:IsControler(1 - tp) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return eg:IsExists(s.repfilter2, 1, nil, tp) and c:IsAbleToRemove()
  	end
  	if Duel.SelectEffectYesNo(tp, c, 96) then
  		local sg = eg:Filter(s.repfilter2, nil, tp)
  		if sg:GetCount() > 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 0))
  			sg = sg:Select(tp, 1, 1, nil)
  		end
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.repop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  	local g = e:GetLabelObject()
  	g:DeleteGroup()
  end
  
  
source_text: Blockout
  If a card(s) you control would be destroyed by battle or an opponent's card effect, you can destroy this card instead of 1 of those cards. If a card(s) your opponent controls would be destroyed by battle or card effect, you can banish this card from your GY instead of 1 of those cards. You can only use each effect of "Blockout Curtain" once per turn.
target_text: -- Blockout
  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)
  	c:RegisterEffect(e1)
  	--destroy replace
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e2:SetCode(EFFECT_DESTROY_REPLACE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTarget(s.reptg1)
  	e2:SetValue(s.repval)
  	e2:SetOperation(s.repop1)
  	c:RegisterEffect(e2)
  	--destroy replace
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e3:SetCode(EFFECT_DESTROY_REPLACE)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetTarget(s.reptg2)
  	e3:SetValue(s.repval)
  	e3:SetOperation(s.repop2)
  	c:RegisterEffect(e3)
  end
  function s.repfilter1(c, tp)
  	return c:IsOnField() and c:IsControler(tp) and (c:IsReason(REASON_BATTLE) or (c:IsReason(REASON_EFFECT) and c:GetReasonPlayer() == 1 - tp)) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return eg:IsExists(s.repfilter1, 1, c, tp) and c:IsDestructable(e) and not c:IsStatus(STATUS_DESTROY_CONFIRMED)
  	end
  	if Duel.SelectEffectYesNo(tp, c, 96) then
  		local sg = eg:Filter(s.repfilter1, c, tp)
  		if sg:GetCount() > 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 0))
  			sg = sg:Select(tp, 1, 1, nil)
  		end
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.repval(e, c)
  	local g = e:GetLabelObject()
  	return g:IsContains(c)
  end
  function s.repop1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Destroy(e:GetHandler(), REASON_EFFECT + REASON_REPLACE)
  	local g = e:GetLabelObject()
  	g:DeleteGroup()
  end
  function s.repfilter2(c, tp)
  	return c:IsOnField() and c:IsControler(1 - tp) and c:IsReason(REASON_BATTLE + REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.reptg2(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return eg:IsExists(s.repfilter2, 1, nil, tp) and c:IsAbleToRemove()
  	end
  	if Duel.SelectEffectYesNo(tp, c, 96) then
  		local sg = eg:Filter(s.repfilter2, nil, tp)
  		if sg:GetCount() > 1 then
  			Duel.Hint(HINT_SELECTMSG, tp, aux.Stringid(id, 0))
  			sg = sg:Select(tp, 1, 1, nil)
  		end
  		sg:KeepAlive()
  		e:SetLabelObject(sg)
  		return true
  	else
  		return false
  	end
  end
  function s.repop2(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_EFFECT)
  	local g = e:GetLabelObject()
  	g:DeleteGroup()
  end
  
  