name: Firewall
card_text: 3+ Effect Monsters
  If this card is Link Summoned: You can place counters on this card equal to the number of different types of Cyberse monsters in your GY (Ritual, Fusion, Synchro, Xyz). This card gains 2500 ATK for each counter on it during the Battle Phase only. When your opponent activates a monster effect (Quick Effect): You can remove 1 counter from this card; negate the activation, also, if this effect was activated between this card's attack declaration and the end of the Damage Step, this card can make another attack in a row.
external_ids: local COUNTER_ID_0 = 0x52 --Counter(Firewall
  
lua: local COUNTER_ID_0 = 0x52 --Counter(Firewall
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x52)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 3)
  	c:EnableReviveLimit()
  	--counter
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_COUNTER)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.ctcon)
  	e1:SetTarget(s.cttg)
  	e1:SetOperation(s.ctop)
  	c:RegisterEffect(e1)
  	--atk up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.atkcon)
  	e2:SetValue(s.atkval)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_NEGATE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.discon)
  	e3:SetCost(s.discost)
  	e3:SetTarget(s.distg)
  	e3:SetOperation(s.disop)
  	c:RegisterEffect(e3)
  end
  function s.ctcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.cfilter(c, type)
  	return c:IsRace(RACE_CYBERSE) and c:IsType(type)
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = 0
  	for i, type in ipairs({ TYPE_FUSION, TYPE_RITUAL, TYPE_SYNCHRO, TYPE_XYZ }) do
  		if Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil, type) then
  			ct = ct + 1
  		end
  	end
  	if chk == 0 then
  		return ct > 0 and e:GetHandler():IsCanAddCounter(COUNTER_ID_0, ct)
  	end
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFacedown() or not c:IsRelateToEffect(e) then
  		return
  	end
  	local ct = 0
  	for i, type in ipairs({ TYPE_FUSION, TYPE_RITUAL, TYPE_SYNCHRO, TYPE_XYZ }) do
  		if Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil, type) then
  			ct = ct + 1
  		end
  	end
  	if ct > 0 then
  		c:AddCounter(COUNTER_ID_0, ct)
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE
  end
  function s.atkval(e, c)
  	return c:GetCounter(COUNTER_ID_0) * 2500
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev) and re:IsActiveType(TYPE_MONSTER)
  end
  function s.discost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, 1, REASON_COST)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if Duel.GetAttacker() == e:GetHandler() then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	Duel.NegateActivation(ev)
  	if e:GetLabel() == 1 and c:IsRelateToEffect(e) and c:IsChainAttackable(0) then
  		Duel.ChainAttack()
  	end
  end
  
  
source_text: Firewall
  3+ Effect Monsters
  If this card is Link Summoned: You can place counters on this card equal to the number of different types of Cyberse monsters in your GY (Ritual, Fusion, Synchro, Xyz). This card gains 2500 ATK for each counter on it during the Battle Phase only. When your opponent activates a monster effect (Quick Effect): You can remove 1 counter from this card; negate the activation, also, if this effect was activated between this card's attack declaration and the end of the Damage Step, this card can make another attack in a row.
target_text: -- Firewall
  local COUNTER_ID_0 = 0x52 --Counter(Firewall
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x52)
  	--link summon
  	aux.AddLinkProcedure(c, aux.FilterBoolFunction(Card.IsLinkType, TYPE_EFFECT), 3)
  	c:EnableReviveLimit()
  	--counter
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_COUNTER)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.ctcon)
  	e1:SetTarget(s.cttg)
  	e1:SetOperation(s.ctop)
  	c:RegisterEffect(e1)
  	--atk up
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE)
  	e2:SetCode(EFFECT_UPDATE_ATTACK)
  	e2:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.atkcon)
  	e2:SetValue(s.atkval)
  	c:RegisterEffect(e2)
  	--negate
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_NEGATE)
  	e3:SetType(EFFECT_TYPE_QUICK_O)
  	e3:SetCode(EVENT_CHAINING)
  	e3:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetCondition(s.discon)
  	e3:SetCost(s.discost)
  	e3:SetTarget(s.distg)
  	e3:SetOperation(s.disop)
  	c:RegisterEffect(e3)
  end
  function s.ctcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_LINK)
  end
  function s.cfilter(c, type)
  	return c:IsRace(RACE_CYBERSE) and c:IsType(type)
  end
  function s.cttg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local ct = 0
  	for i, type in ipairs({ TYPE_FUSION, TYPE_RITUAL, TYPE_SYNCHRO, TYPE_XYZ }) do
  		if Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil, type) then
  			ct = ct + 1
  		end
  	end
  	if chk == 0 then
  		return ct > 0 and e:GetHandler():IsCanAddCounter(COUNTER_ID_0, ct)
  	end
  end
  function s.ctop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsFacedown() or not c:IsRelateToEffect(e) then
  		return
  	end
  	local ct = 0
  	for i, type in ipairs({ TYPE_FUSION, TYPE_RITUAL, TYPE_SYNCHRO, TYPE_XYZ }) do
  		if Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_GRAVE, 0, 1, nil, type) then
  			ct = ct + 1
  		end
  	end
  	if ct > 0 then
  		c:AddCounter(COUNTER_ID_0, ct)
  	end
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	local ph = Duel.GetCurrentPhase()
  	return ph >= PHASE_BATTLE_START and ph <= PHASE_BATTLE
  end
  function s.atkval(e, c)
  	return c:GetCounter(COUNTER_ID_0) * 2500
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	return rp == 1 - tp and not e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) and Duel.IsChainNegatable(ev) and re:IsActiveType(TYPE_MONSTER)
  end
  function s.discost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsCanRemoveCounter(tp, COUNTER_ID_0, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveCounter(tp, COUNTER_ID_0, 1, REASON_COST)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if Duel.GetAttacker() == e:GetHandler() then
  		e:SetLabel(1)
  	else
  		e:SetLabel(0)
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	Duel.NegateActivation(ev)
  	if e:GetLabel() == 1 and c:IsRelateToEffect(e) and c:IsChainAttackable(0) then
  		Duel.ChainAttack()
  	end
  end
  
  