name: Lightsworn
card_text: When a "Lightsworn" monster you control is targeted for an attack: You can send the top 2 cards of your Deck to the Graveyard, then target the attacking monster; negate the attack.
external_ids: local SETCARD_ID_0 = 0x38 --Lightsworn
  
lua: local SETCARD_ID_0 = 0x38 --Lightsworn
  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)
  	--quick
  	local e2 = Effect.CreateEffect(c)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_BE_BATTLE_TARGET)
  	e2:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e2:SetCondition(s.qcon)
  	e2:SetCost(s.qcost)
  	e2:SetTarget(s.qtg)
  	e2:SetOperation(s.qop)
  	c:RegisterEffect(e2)
  end
  function s.qcon(e, tp, eg, ep, ev, re, r, rp)
  	local d = Duel.GetAttackTarget()
  	return d:IsFaceup() and d:IsSetCard(SETCARD_ID_0) and d:IsControler(tp)
  end
  function s.qcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeckAsCost(tp, 2)
  	end
  	Duel.DiscardDeck(tp, 2, REASON_COST)
  end
  function s.qtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local tg = Duel.GetAttacker()
  	if chkc then
  		return chkc == tg
  	end
  	if chk == 0 then
  		return tg:IsOnField() and tg:IsCanBeEffectTarget(e)
  	end
  	Duel.SetTargetCard(tg)
  end
  function s.qop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateAttack()
  end
  
  
source_text: Lightsworn
  When a "Lightsworn" monster you control is targeted for an attack: You can send the top 2 cards of your Deck to the Graveyard, then target the attacking monster; negate the attack.
target_text: -- Lightsworn
  local SETCARD_ID_0 = 0x38 --Lightsworn
  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)
  	--quick
  	local e2 = Effect.CreateEffect(c)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCode(EVENT_BE_BATTLE_TARGET)
  	e2:SetCountLimit(1, EFFECT_COUNT_CODE_CHAIN)
  	e2:SetCondition(s.qcon)
  	e2:SetCost(s.qcost)
  	e2:SetTarget(s.qtg)
  	e2:SetOperation(s.qop)
  	c:RegisterEffect(e2)
  end
  function s.qcon(e, tp, eg, ep, ev, re, r, rp)
  	local d = Duel.GetAttackTarget()
  	return d:IsFaceup() and d:IsSetCard(SETCARD_ID_0) and d:IsControler(tp)
  end
  function s.qcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsPlayerCanDiscardDeckAsCost(tp, 2)
  	end
  	Duel.DiscardDeck(tp, 2, REASON_COST)
  end
  function s.qtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local tg = Duel.GetAttacker()
  	if chkc then
  		return chkc == tg
  	end
  	if chk == 0 then
  		return tg:IsOnField() and tg:IsCanBeEffectTarget(e)
  	end
  	Duel.SetTargetCard(tg)
  end
  function s.qop(e, tp, eg, ep, ev, re, r, rp)
  	Duel.NegateAttack()
  end
  
  