name: Twilight
card_text: Target 1 face-up monster you control; banish any number of "Lightsworn" monsters from your GY, and if you do, that monster gains 200 ATK and DEF for each monster banished by this effect, until the end of this turn. If this card is sent from the Deck to the GY by a "Lightsworn" monster's effect: You can activate this effect; this turn, "Lightsworn" monsters you control cannot be destroyed by battle or card effects.
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:SetCategory(CATEGORY_REMOVE + CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetCondition(aux.dscon)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.indcon)
  	e2:SetOperation(s.indop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil)
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and g:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local sg = g:Select(tp, 1, g:GetCount(), nil)
  		local rc = Duel.Remove(sg, POS_FACEUP, REASON_EFFECT)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e1:SetValue(200 * rc)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_UPDATE_DEFENSE)
  		tc:RegisterEffect(e2)
  	end
  end
  function s.indcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_DECK) and re:IsActiveType(TYPE_MONSTER) and re:GetHandler():IsSetCard(SETCARD_ID_0) and bit.band(r, REASON_EFFECT) ~= 0
  end
  function s.indop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e1:SetValue(1)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	Duel.RegisterEffect(e2, tp)
  end
  
  
source_text: Twilight
  Target 1 face-up monster you control; banish any number of "Lightsworn" monsters from your GY, and if you do, that monster gains 200 ATK and DEF for each monster banished by this effect, until the end of this turn. If this card is sent from the Deck to the GY by a "Lightsworn" monster's effect: You can activate this effect; this turn, "Lightsworn" monsters you control cannot be destroyed by battle or card effects.
target_text: -- Twilight
  local SETCARD_ID_0 = 0x38 --Lightsworn
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_REMOVE + CATEGORY_ATKCHANGE + CATEGORY_DEFCHANGE)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET + EFFECT_FLAG_DAMAGE_STEP)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetHintTiming(TIMING_DAMAGE_STEP)
  	e1:SetCondition(aux.dscon)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--indes
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCondition(s.indcon)
  	e2:SetOperation(s.indop)
  	c:RegisterEffect(e2)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToRemove()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE) and chkc:IsControler(tp) and chkc:IsFaceup()
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(Card.IsFaceup, tp, LOCATION_MZONE, 0, 1, nil) and Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	Duel.SelectTarget(tp, Card.IsFaceup, tp, LOCATION_MZONE, 0, 1, 1, nil)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	local g = Duel.GetMatchingGroup(s.filter, tp, LOCATION_GRAVE, 0, nil)
  	if tc:IsRelateToEffect(e) and tc:IsFaceup() and g:GetCount() > 0 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_REMOVE)
  		local sg = g:Select(tp, 1, g:GetCount(), nil)
  		local rc = Duel.Remove(sg, POS_FACEUP, REASON_EFFECT)
  		local e1 = Effect.CreateEffect(e:GetHandler())
  		e1:SetType(EFFECT_TYPE_SINGLE)
  		e1:SetCode(EFFECT_UPDATE_ATTACK)
  		e1:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  		e1:SetValue(200 * rc)
  		tc:RegisterEffect(e1)
  		local e2 = e1:Clone()
  		e2:SetCode(EFFECT_UPDATE_DEFENSE)
  		tc:RegisterEffect(e2)
  	end
  end
  function s.indcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsPreviousLocation(LOCATION_DECK) and re:IsActiveType(TYPE_MONSTER) and re:GetHandler():IsSetCard(SETCARD_ID_0) and bit.band(r, REASON_EFFECT) ~= 0
  end
  function s.indop(e, tp, eg, ep, ev, re, r, rp)
  	local e1 = Effect.CreateEffect(e:GetHandler())
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetTargetRange(LOCATION_MZONE, 0)
  	e1:SetTarget(aux.TargetBoolFunction(Card.IsSetCard, SETCARD_ID_0))
  	e1:SetValue(1)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	Duel.RegisterEffect(e2, tp)
  end
  
  