name: Nagel's
card_text: "Tindangle" monsters in your Main Monster Zones cannot be destroyed by battle or your opponent's card effects. Once per turn, if your "Tindangle" monster inflicts battle damage to your opponent, the damage is doubled. You can banish this card from your GY and discard 1 "Tindangle" card; add 1 "Nagel's Protection" from your Deck to your hand. You can only use this effect of "Nagel's Protection" once per turn.
external_ids: local SETCARD_ID_0 = 0x10b --Tindangle
  
lua: local SETCARD_ID_0 = 0x10b --Tindangle
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.indtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e3:SetValue(aux.indoval)
  	c:RegisterEffect(e3)
  	--double damage
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, 0)
  	e4:SetCondition(s.damcon)
  	e4:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e4:SetValue(aux.ChangeBattleDamage(1, DOUBLE_DAMAGE))
  	c:RegisterEffect(e4)
  	--search
  	local e5 = Effect.CreateEffect(c)
  	e5:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_GRAVE)
  	e5:SetCountLimit(1, id)
  	e5:SetCost(s.thcost)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  	--reg
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e6:SetCode(EVENT_PRE_BATTLE_DAMAGE)
  	e6:SetRange(LOCATION_SZONE)
  	e6:SetCondition(s.regcon)
  	e6:SetOperation(s.regop)
  	c:RegisterEffect(e6)
  end
  function s.indtg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:GetSequence() < 5
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == 1 - tp and eg:GetFirst():IsSetCard(SETCARD_ID_0)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.damcon(e)
  	return e:GetHandler():GetFlagEffect(id) == 0
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsDiscardable()
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_COST)
  	Duel.DiscardHand(tp, s.cfilter, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.filter(c)
  	return c:IsCode(id) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, 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)
  	local tc = Duel.GetFirstMatchingCard(s.filter, tp, LOCATION_DECK, 0, nil)
  	if tc then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tc)
  	end
  end
  
  
source_text: Nagel's
  "Tindangle" monsters in your Main Monster Zones cannot be destroyed by battle or your opponent's card effects. Once per turn, if your "Tindangle" monster inflicts battle damage to your opponent, the damage is doubled. You can banish this card from your GY and discard 1 "Tindangle" card; add 1 "Nagel's Protection" from your Deck to your hand. You can only use this effect of "Nagel's Protection" once per turn.
target_text: -- Nagel's
  local SETCARD_ID_0 = 0x10b --Tindangle
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetTargetRange(LOCATION_MZONE, 0)
  	e2:SetTarget(s.indtg)
  	e2:SetValue(1)
  	c:RegisterEffect(e2)
  	local e3 = e2:Clone()
  	e3:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	e3:SetValue(aux.indoval)
  	c:RegisterEffect(e3)
  	--double damage
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTargetRange(LOCATION_MZONE, 0)
  	e4:SetCondition(s.damcon)
  	e4:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e4:SetValue(aux.ChangeBattleDamage(1, DOUBLE_DAMAGE))
  	c:RegisterEffect(e4)
  	--search
  	local e5 = Effect.CreateEffect(c)
  	e5:SetCategory(CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e5:SetType(EFFECT_TYPE_IGNITION)
  	e5:SetRange(LOCATION_GRAVE)
  	e5:SetCountLimit(1, id)
  	e5:SetCost(s.thcost)
  	e5:SetTarget(s.thtg)
  	e5:SetOperation(s.thop)
  	c:RegisterEffect(e5)
  	--reg
  	local e6 = Effect.CreateEffect(c)
  	e6:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_CONTINUOUS)
  	e6:SetCode(EVENT_PRE_BATTLE_DAMAGE)
  	e6:SetRange(LOCATION_SZONE)
  	e6:SetCondition(s.regcon)
  	e6:SetOperation(s.regop)
  	c:RegisterEffect(e6)
  end
  function s.indtg(e, c)
  	return c:IsSetCard(SETCARD_ID_0) and c:GetSequence() < 5
  end
  function s.regcon(e, tp, eg, ep, ev, re, r, rp)
  	return ep == 1 - tp and eg:GetFirst():IsSetCard(SETCARD_ID_0)
  end
  function s.regop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.damcon(e)
  	return e:GetHandler():GetFlagEffect(id) == 0
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsDiscardable()
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsAbleToRemoveAsCost() and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, nil)
  	end
  	Duel.Remove(e:GetHandler(), POS_FACEUP, REASON_COST)
  	Duel.DiscardHand(tp, s.cfilter, 1, 1, REASON_COST + REASON_DISCARD)
  end
  function s.filter(c)
  	return c:IsCode(id) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, 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)
  	local tc = Duel.GetFirstMatchingCard(s.filter, tp, LOCATION_DECK, 0, nil)
  	if tc then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tc)
  	end
  end
  
  