name: Codebreaker
card_text: All Link Monsters pointing to this card lose 1000 ATK, except "Codebreaker" Link Monsters. If a "Codebreaker" Link Monster(s) on the field is destroyed by battle or card effect, while this card is on the field: Destroy this card. If this card is destroyed by battle or card effect: You can add 1 "Codebreaker Zero Day" from your Deck to your hand.
external_ids: local SETCARD_ID_0 = 0x13c --Codebreaker
  
lua: local SETCARD_ID_0 = 0x13c --Codebreaker
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e1:SetTarget(s.atktg)
  	e1:SetValue(-1000)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetCondition(s.srcon)
  	e3:SetTarget(s.srtg)
  	e3:SetOperation(s.srop)
  	c:RegisterEffect(e3)
  end
  function s.atktg(e, c)
  	local lg1 = c:GetLinkedGroup()
  	local lg2 = e:GetHandler():GetLinkedGroup()
  	return c:IsFaceup() and c:IsType(TYPE_LINK) and not c:IsSetCard(SETCARD_ID_0) and (lg1 and lg1:IsContains(e:GetHandler()) or lg2 and lg2:IsContains(c))
  end
  function s.desfilter(c)
  	return c:IsPreviousPosition(POS_FACEUP)
  		and c:GetPreviousTypeOnField() & TYPE_LINK ~= 0
  		and c:IsPreviousSetCard(SETCARD_ID_0)
  		and c:IsReason(REASON_BATTLE + REASON_EFFECT)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.desfilter, 1, nil)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, c, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.Destroy(c, REASON_EFFECT)
  	end
  end
  function s.srcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsReason(REASON_BATTLE + REASON_EFFECT)
  end
  function s.srfilter(c)
  	return c:IsCode(id) and c:IsAbleToHand()
  end
  function s.srtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.srfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.srop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.srfilter, 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: Codebreaker
  All Link Monsters pointing to this card lose 1000 ATK, except "Codebreaker" Link Monsters. If a "Codebreaker" Link Monster(s) on the field is destroyed by battle or card effect, while this card is on the field: Destroy this card. If this card is destroyed by battle or card effect: You can add 1 "Codebreaker Zero Day" from your Deck to your hand.
target_text: -- Codebreaker
  local SETCARD_ID_0 = 0x13c --Codebreaker
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--atk
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_UPDATE_ATTACK)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_MZONE, LOCATION_MZONE)
  	e1:SetTarget(s.atktg)
  	e1:SetValue(-1000)
  	c:RegisterEffect(e1)
  	--destroy
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_DESTROYED)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCondition(s.descon)
  	e2:SetTarget(s.destg)
  	e2:SetOperation(s.desop)
  	c:RegisterEffect(e2)
  	--search
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e3:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCode(EVENT_DESTROYED)
  	e3:SetCondition(s.srcon)
  	e3:SetTarget(s.srtg)
  	e3:SetOperation(s.srop)
  	c:RegisterEffect(e3)
  end
  function s.atktg(e, c)
  	local lg1 = c:GetLinkedGroup()
  	local lg2 = e:GetHandler():GetLinkedGroup()
  	return c:IsFaceup() and c:IsType(TYPE_LINK) and not c:IsSetCard(SETCARD_ID_0) and (lg1 and lg1:IsContains(e:GetHandler()) or lg2 and lg2:IsContains(c))
  end
  function s.desfilter(c)
  	return c:IsPreviousPosition(POS_FACEUP)
  		and c:GetPreviousTypeOnField() & TYPE_LINK ~= 0
  		and c:IsPreviousSetCard(SETCARD_ID_0)
  		and c:IsReason(REASON_BATTLE + REASON_EFFECT)
  		and c:IsPreviousLocation(LOCATION_MZONE)
  end
  function s.descon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.desfilter, 1, nil)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_DESTROY, c, 1, 0, 0)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		Duel.Destroy(c, REASON_EFFECT)
  	end
  end
  function s.srcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsReason(REASON_BATTLE + REASON_EFFECT)
  end
  function s.srfilter(c)
  	return c:IsCode(id) and c:IsAbleToHand()
  end
  function s.srtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.srfilter, tp, LOCATION_DECK, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, tp, LOCATION_DECK)
  end
  function s.srop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectMatchingCard(tp, s.srfilter, 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
  
  