name: Lightsworn
card_text: Once per turn: You can send 1 "Lightsworn" monster from your hand to the Graveyard, then target 1 other "Lightsworn" monster in your Graveyard; add it to your hand. Each time a card(s) is sent from your Deck to the Graveyard, place 1 Shine Counter on this card. If a "Lightsworn" card(s) you control would be destroyed by a card effect, you can remove 2 Shine Counters from your side of the field for each of those "Lightsworn" card(s) instead.
external_ids: local SETCARD_ID_0 = 0x38 --Lightsworn
  local COUNTER_ID_0 = 0x5 --Shine
  
lua: local SETCARD_ID_0 = 0x38 --Lightsworn
  local COUNTER_ID_0 = 0x5 --Shine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	--add counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCondition(s.accon)
  	e3:SetOperation(s.acop)
  	c:RegisterEffect(e3)
  	--destroy replace
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_DESTROY_REPLACE)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTarget(s.destg)
  	e4:SetValue(s.value)
  	e4:SetOperation(s.desop)
  	c:RegisterEffect(e4)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGraveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_HAND, 0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:FilterSelect(tp, s.costfilter, 1, 1, nil)
  	e:SetLabelObject(sg:GetFirst())
  	Duel.SendtoGrave(sg, REASON_COST)
  end
  function s.tgfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local cc = e:GetLabelObject()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.tgfilter(chkc) and chkc ~= cc
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tgfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = Duel.SelectTarget(tp, s.tgfilter, tp, LOCATION_GRAVE, 0, 1, 1, cc)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, sg, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousLocation(LOCATION_DECK) and c:IsPreviousControler(tp)
  end
  function s.accon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.acop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  end
  function s.dfilter(c, tp)
  	return c:IsFaceup() and c:IsOnField() and c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp) and c:IsReason(REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local count = eg:FilterCount(s.dfilter, nil, tp)
  		e:SetLabel(count)
  		return count > 0 and Duel.IsCanRemoveCounter(tp, 1, 0, COUNTER_ID_0, count * 2, REASON_EFFECT)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.value(e, c)
  	return c:IsFaceup() and c:IsOnField() and c:IsSetCard(SETCARD_ID_0) and c:IsControler(e:GetHandlerPlayer()) and c:IsReason(REASON_EFFECT)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local count = e:GetLabel()
  	Duel.RemoveCounter(tp, 1, 0, COUNTER_ID_0, count * 2, REASON_EFFECT)
  end
  
  
source_text: Lightsworn
  Once per turn: You can send 1 "Lightsworn" monster from your hand to the Graveyard, then target 1 other "Lightsworn" monster in your Graveyard; add it to your hand. Each time a card(s) is sent from your Deck to the Graveyard, place 1 Shine Counter on this card. If a "Lightsworn" card(s) you control would be destroyed by a card effect, you can remove 2 Shine Counters from your side of the field for each of those "Lightsworn" card(s) instead.
target_text: -- Lightsworn
  local SETCARD_ID_0 = 0x38 --Lightsworn
  local COUNTER_ID_0 = 0x5 --Shine
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:EnableCounterPermit(0x5)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCost(s.cost)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  	--add counter
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e3:SetCode(EVENT_TO_GRAVE)
  	e3:SetRange(LOCATION_SZONE)
  	e3:SetProperty(EFFECT_FLAG_DELAY)
  	e3:SetCondition(s.accon)
  	e3:SetOperation(s.acop)
  	c:RegisterEffect(e3)
  	--destroy replace
  	local e4 = Effect.CreateEffect(c)
  	e4:SetType(EFFECT_TYPE_CONTINUOUS + EFFECT_TYPE_FIELD)
  	e4:SetCode(EFFECT_DESTROY_REPLACE)
  	e4:SetRange(LOCATION_SZONE)
  	e4:SetTarget(s.destg)
  	e4:SetValue(s.value)
  	e4:SetOperation(s.desop)
  	c:RegisterEffect(e4)
  end
  function s.costfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToGraveAsCost()
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.costfilter, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	local g = Duel.GetFieldGroup(tp, LOCATION_HAND, 0)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TOGRAVE)
  	local sg = g:FilterSelect(tp, s.costfilter, 1, 1, nil)
  	e:SetLabelObject(sg:GetFirst())
  	Duel.SendtoGrave(sg, REASON_COST)
  end
  function s.tgfilter(c)
  	return c:IsType(TYPE_MONSTER) and c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local cc = e:GetLabelObject()
  	if chkc then
  		return chkc:IsLocation(LOCATION_GRAVE) and chkc:IsControler(tp) and s.tgfilter(chkc) and chkc ~= cc
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.tgfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local sg = Duel.SelectTarget(tp, s.tgfilter, tp, LOCATION_GRAVE, 0, 1, 1, cc)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, sg, 1, 0, 0)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.cfilter(c, tp)
  	return c:IsPreviousLocation(LOCATION_DECK) and c:IsPreviousControler(tp)
  end
  function s.accon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.cfilter, 1, nil, tp)
  end
  function s.acop(e, tp, eg, ep, ev, re, r, rp)
  	e:GetHandler():AddCounter(COUNTER_ID_0, 1)
  end
  function s.dfilter(c, tp)
  	return c:IsFaceup() and c:IsOnField() and c:IsSetCard(SETCARD_ID_0) and c:IsControler(tp) and c:IsReason(REASON_EFFECT) and not c:IsReason(REASON_REPLACE)
  end
  function s.destg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local count = eg:FilterCount(s.dfilter, nil, tp)
  		e:SetLabel(count)
  		return count > 0 and Duel.IsCanRemoveCounter(tp, 1, 0, COUNTER_ID_0, count * 2, REASON_EFFECT)
  	end
  	return Duel.SelectEffectYesNo(tp, e:GetHandler(), 96)
  end
  function s.value(e, c)
  	return c:IsFaceup() and c:IsOnField() and c:IsSetCard(SETCARD_ID_0) and c:IsControler(e:GetHandlerPlayer()) and c:IsReason(REASON_EFFECT)
  end
  function s.desop(e, tp, eg, ep, ev, re, r, rp)
  	local count = e:GetLabel()
  	Duel.RemoveCounter(tp, 1, 0, COUNTER_ID_0, count * 2, REASON_EFFECT)
  end
  
  