name: Cybersal
card_text: Target 1 Link Monster your opponent controls; banish 1 monster from your GY that has the same Link Rating as that monster, and if you do, destroy that monster, then, if the original Type of the monster you banished was Cyberse, you can destroy 1 face-up card in your opponent's Spell & Trap Zone.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_LINK) and Duel.IsExistingMatchingCard(s.rmfilter, tp, LOCATION_GRAVE, 0, 1, nil, c:GetLink())
  end
  function s.rmfilter(c, link)
  	return c:IsType(TYPE_MONSTER) and c:IsLink(link) and c:IsAbleToRemove()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, 0, LOCATION_MZONE, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.desfilter(c)
  	return c:IsFaceup() and c:GetSequence() < 5
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.rmfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, tc:GetLink())
  	local rc = g:GetFirst()
  	if rc and Duel.Remove(rc, 0, REASON_EFFECT) ~= 0 and rc:IsLocation(LOCATION_REMOVED) and Duel.Destroy(tc, REASON_EFFECT) ~= 0 and bit.band(rc:GetOriginalRace(), RACE_CYBERSE) > 0 then
  		local sg = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_SZONE, nil)
  		if sg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local dg = sg:Select(tp, 1, 1, nil)
  			Duel.HintSelection(dg)
  			Duel.Destroy(dg, REASON_EFFECT)
  		end
  	end
  end
  
  
source_text: Cybersal
  Target 1 Link Monster your opponent controls; banish 1 monster from your GY that has the same Link Rating as that monster, and if you do, destroy that monster, then, if the original Type of the monster you banished was Cyberse, you can destroy 1 face-up card in your opponent's Spell & Trap Zone.
target_text: -- Cybersal
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_DESTROY + CATEGORY_REMOVE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  end
  function s.filter(c, tp)
  	return c:IsFaceup() and c:IsType(TYPE_LINK) and Duel.IsExistingMatchingCard(s.rmfilter, tp, LOCATION_GRAVE, 0, 1, nil, c:GetLink())
  end
  function s.rmfilter(c, link)
  	return c:IsType(TYPE_MONSTER) and c:IsLink(link) and c:IsAbleToRemove()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(1 - tp) and chkc:IsLocation(LOCATION_MZONE) and s.filter(chkc, tp)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.filter, tp, 0, LOCATION_MZONE, 1, nil, tp)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  	local g = Duel.SelectTarget(tp, s.filter, tp, 0, LOCATION_MZONE, 1, 1, nil, tp)
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, nil, 1, tp, LOCATION_GRAVE)
  end
  function s.desfilter(c)
  	return c:IsFaceup() and c:GetSequence() < 5
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if not tc:IsRelateToEffect(e) then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.rmfilter), tp, LOCATION_GRAVE, 0, 1, 1, nil, tc:GetLink())
  	local rc = g:GetFirst()
  	if rc and Duel.Remove(rc, 0, REASON_EFFECT) ~= 0 and rc:IsLocation(LOCATION_REMOVED) and Duel.Destroy(tc, REASON_EFFECT) ~= 0 and bit.band(rc:GetOriginalRace(), RACE_CYBERSE) > 0 then
  		local sg = Duel.GetMatchingGroup(s.desfilter, tp, 0, LOCATION_SZONE, nil)
  		if sg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DESTROY)
  			local dg = sg:Select(tp, 1, 1, nil)
  			Duel.HintSelection(dg)
  			Duel.Destroy(dg, REASON_EFFECT)
  		end
  	end
  end
  
  