name: Cyber
card_text: You can Ritual Summon this card with "Machine Angel Ritual". If this card is Ritual Summoned: You can destroy as many face-up monsters your opponent controls as possible that were Special Summoned from the Extra Deck, and if you do, inflict 1000 damage to your opponent for each, and if you do that, this card can make a second attack during each Battle Phase this turn. Once per turn, during either player's turn, when a card or effect is activated that would destroy a card on the field: You can shuffle 1 Ritual Monster from your Graveyard into the Deck; negate the activation, and if you do, destroy that card.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.descon)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  	--negate
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.negcon)
  	e2:SetCost(s.negcost)
  	e2:SetTarget(s.negtg)
  	e2:SetOperation(s.negop)
  	c:RegisterEffect(e2)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_RITUAL)
  end
  function s.desfilter(c)
  	return c:IsSummonLocation(LOCATION_EXTRA)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.desfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, g:GetCount() * 1000)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil)
  	local ct = Duel.Destroy(g, REASON_EFFECT)
  	if ct > 0 then
  		Duel.Damage(1 - tp, ct * 1000, REASON_EFFECT)
  	end
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_EXTRA_ATTACK)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		c:RegisterEffect(e1)
  	end
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) or not Duel.IsChainNegatable(ev) then
  		return false
  	end
  	if re:IsHasCategory(CATEGORY_NEGATE) and Duel.GetChainInfo(ev - 1, CHAININFO_TRIGGERING_EFFECT):IsHasType(EFFECT_TYPE_ACTIVATE) then
  		return false
  	end
  	local ex, tg, tc = Duel.GetOperationInfo(ev, CATEGORY_DESTROY)
  	return ex and tg ~= nil and tc + tg:FilterCount(Card.IsOnField, nil) - tg:GetCount() > 0
  end
  function s.costfilter(c)
  	return bit.band(c:GetType(), 0x81) == 0x81 and c:IsAbleToDeckAsCost()
  end
  function s.negcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.HintSelection(g)
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_COST)
  end
  function s.negtg(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 re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  
  
source_text: Cyber
  You can Ritual Summon this card with "Machine Angel Ritual". If this card is Ritual Summoned: You can destroy as many face-up monsters your opponent controls as possible that were Special Summoned from the Extra Deck, and if you do, inflict 1000 damage to your opponent for each, and if you do that, this card can make a second attack during each Battle Phase this turn. Once per turn, during either player's turn, when a card or effect is activated that would destroy a card on the field: You can shuffle 1 Ritual Monster from your Graveyard into the Deck; negate the activation, and if you do, destroy that card.
target_text: -- Cyber
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--destroy
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_DAMAGE)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetCondition(s.descon)
  	e1:SetTarget(s.destg)
  	e1:SetOperation(s.desop)
  	c:RegisterEffect(e1)
  	--negate
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1)
  	e2:SetCondition(s.negcon)
  	e2:SetCost(s.negcost)
  	e2:SetTarget(s.negtg)
  	e2:SetOperation(s.negop)
  	c:RegisterEffect(e2)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSummonType(SUMMON_TYPE_RITUAL)
  end
  function s.desfilter(c)
  	return c:IsSummonLocation(LOCATION_EXTRA)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.desfilter, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, g:GetCount(), 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_DAMAGE, nil, 0, 1 - tp, g:GetCount() * 1000)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_MZONE, nil)
  	local ct = Duel.Destroy(g, REASON_EFFECT)
  	if ct > 0 then
  		Duel.Damage(1 - tp, ct * 1000, REASON_EFFECT)
  	end
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		local e1 = Effect.CreateEffect(c)
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_EXTRA_ATTACK)
  		e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  		e1:SetValue(1)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		c:RegisterEffect(e1)
  	end
  end
  function s.negcon(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) or not Duel.IsChainNegatable(ev) then
  		return false
  	end
  	if re:IsHasCategory(CATEGORY_NEGATE) and Duel.GetChainInfo(ev - 1, CHAININFO_TRIGGERING_EFFECT):IsHasType(EFFECT_TYPE_ACTIVATE) then
  		return false
  	end
  	local ex, tg, tc = Duel.GetOperationInfo(ev, CATEGORY_DESTROY)
  	return ex and tg ~= nil and tc + tg:FilterCount(Card.IsOnField, nil) - tg:GetCount() > 0
  end
  function s.costfilter(c)
  	return bit.band(c:GetType(), 0x81) == 0x81 and c:IsAbleToDeckAsCost()
  end
  function s.negcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, s.costfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.HintSelection(g)
  	Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_COST)
  end
  function s.negtg(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 re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.negop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  
  