name: Cyberse
card_text: You can Ritual Summon this card with "Cynet Ritual". Any damage you take is halved. (You cannot halve the same damage twice this way.) While you control a Link Monster, monsters your opponent controls cannot target monsters you control for attacks, except this one, also your opponent cannot target monsters you control with card effects, except this one. If this card battles a Link Monster, it gains 1000 ATK during that damage calculation only. If this card in your possession is destroyed by an opponent's card effect: You can add 1 Cyberse monster from your Deck to your hand.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--halve damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(1, 0)
  	e1:SetValue(s.val)
  	c:RegisterEffect(e1)
  	--target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(0, LOCATION_MZONE)
  	e2:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e2:SetCondition(s.atcon)
  	e2:SetValue(s.atlimit)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE + EFFECT_FLAG_SET_AVAILABLE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetCondition(s.atcon)
  	e3:SetTarget(s.tglimit)
  	e3:SetValue(aux.tgoval)
  	c:RegisterEffect(e3)
  	--atk up
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_UPDATE_ATTACK)
  	e4:SetCondition(s.atkcon)
  	e4:SetValue(1000)
  	c:RegisterEffect(e4)
  	--to hand
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetCategory(CATEGORY_TOHAND)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_DESTROYED)
  	e5:SetCondition(s.thcon)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  end
  function s.val(e, re, dam, r, rp, rc)
  	return math.floor(dam / 2)
  end
  function s.filter(c)
  	return c:IsType(TYPE_LINK)
  end
  function s.atcon(e)
  	return Duel.IsExistingMatchingCard(s.filter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil)
  end
  function s.atlimit(e, c)
  	return c ~= e:GetHandler()
  end
  function s.tglimit(e, c)
  	return c ~= e:GetHandler()
  end
  function s.atkcon(e)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	return Duel.GetCurrentPhase() == PHASE_DAMAGE_CAL and bc and bc:IsType(TYPE_LINK)
  end
  function s.thfilter(c)
  	return c:IsRace(RACE_CYBERSE) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_EFFECT) and rp == 1 - tp and c:IsPreviousControler(tp)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  
source_text: Cyberse
  You can Ritual Summon this card with "Cynet Ritual". Any damage you take is halved. (You cannot halve the same damage twice this way.) While you control a Link Monster, monsters your opponent controls cannot target monsters you control for attacks, except this one, also your opponent cannot target monsters you control with card effects, except this one. If this card battles a Link Monster, it gains 1000 ATK during that damage calculation only. If this card in your possession is destroyed by an opponent's card effect: You can add 1 Cyberse monster from your Deck to your hand.
target_text: -- Cyberse
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableReviveLimit()
  	--halve damage
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(1, 0)
  	e1:SetValue(s.val)
  	c:RegisterEffect(e1)
  	--target
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetTargetRange(0, LOCATION_MZONE)
  	e2:SetCode(EFFECT_CANNOT_SELECT_BATTLE_TARGET)
  	e2:SetCondition(s.atcon)
  	e2:SetValue(s.atlimit)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_CANNOT_BE_EFFECT_TARGET)
  	e3:SetProperty(EFFECT_FLAG_IGNORE_IMMUNE + EFFECT_FLAG_SET_AVAILABLE)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(LOCATION_MZONE, 0)
  	e3:SetCondition(s.atcon)
  	e3:SetTarget(s.tglimit)
  	e3:SetValue(aux.tgoval)
  	c:RegisterEffect(e3)
  	--atk up
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_SINGLE)
  	e4:SetCode(EFFECT_UPDATE_ATTACK)
  	e4:SetCondition(s.atkcon)
  	e4:SetValue(1000)
  	c:RegisterEffect(e4)
  	--to hand
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 0))
  	e5:SetCategory(CATEGORY_TOHAND)
  	e5:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e5:SetProperty(EFFECT_FLAG_DELAY)
  	e5:SetCode(EVENT_DESTROYED)
  	e5:SetCondition(s.thcon)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  end
  function s.val(e, re, dam, r, rp, rc)
  	return math.floor(dam / 2)
  end
  function s.filter(c)
  	return c:IsType(TYPE_LINK)
  end
  function s.atcon(e)
  	return Duel.IsExistingMatchingCard(s.filter, e:GetHandlerPlayer(), LOCATION_MZONE, 0, 1, nil)
  end
  function s.atlimit(e, c)
  	return c ~= e:GetHandler()
  end
  function s.tglimit(e, c)
  	return c ~= e:GetHandler()
  end
  function s.atkcon(e)
  	local c = e:GetHandler()
  	local bc = c:GetBattleTarget()
  	return Duel.GetCurrentPhase() == PHASE_DAMAGE_CAL and bc and bc:IsType(TYPE_LINK)
  end
  function s.thfilter(c)
  	return c:IsRace(RACE_CYBERSE) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return c:IsReason(REASON_EFFECT) and rp == 1 - tp and c:IsPreviousControler(tp)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.thfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.thfilter, tp, LOCATION_DECK, 0, 1, 1, nil)
  	if g:GetCount() > 0 then
  		Duel.SendtoHand(g, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, g)
  	end
  end
  
  