name: Stellarknight
card_text: 3+ Level 5 LIGHT monsters
  During your Main Phase 2, you can also Xyz Summon this card by using a "tellarknight" Xyz Monster you control as material, except "Stellarknight Constellar Diamond". (Transfer its materials to this card.) While this card has material, neither player can send cards from the Deck to the GY, and any card that returns from the GY to the hand is banished instead. When an opponent's DARK monster's effect is activated (Quick Effect): You can detach 1 material from this card; negate that activation, and if you do, destroy it.
external_ids: local SETCARD_ID_0 = 0x9c --tellarknight
  
lua: local SETCARD_ID_0 = 0x9c --tellarknight
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, aux.FilterBoolFunction(Card.IsAttribute, ATTRIBUTE_LIGHT), 5, 3, s.ovfilter, aux.Stringid(id, 0), 99)
  	c:EnableReviveLimit()
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_TO_GRAVE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_DECK, LOCATION_DECK)
  	e1:SetCondition(s.effcon)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_DISCARD_DECK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 1)
  	e2:SetCondition(s.effcon)
  	c:RegisterEffect(e2)
  	--
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_TO_HAND_REDIRECT)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(LOCATION_GRAVE, LOCATION_GRAVE)
  	e3:SetValue(LOCATION_REMOVED)
  	e3:SetCondition(s.effcon)
  	c:RegisterEffect(e3)
  	--Negate
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_CHAINING)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e4:SetCondition(s.condition)
  	e4:SetCost(s.cost)
  	e4:SetTarget(s.target)
  	e4:SetOperation(s.operation)
  	c:RegisterEffect(e4)
  end
  function s.ovfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ) and not c:IsCode(id) and Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.effcon(e)
  	return e:GetHandler():GetOverlayCount() > 0
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local attr = Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_ATTRIBUTE)
  	return ep ~= tp and re:IsActiveType(TYPE_MONSTER) and attr & ATTRIBUTE_DARK > 0 and Duel.IsChainNegatable(ev)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  
  
source_text: Stellarknight
  3+ Level 5 LIGHT monsters
  During your Main Phase 2, you can also Xyz Summon this card by using a "tellarknight" Xyz Monster you control as material, except "Stellarknight Constellar Diamond". (Transfer its materials to this card.) While this card has material, neither player can send cards from the Deck to the GY, and any card that returns from the GY to the hand is banished instead. When an opponent's DARK monster's effect is activated (Quick Effect): You can detach 1 material from this card; negate that activation, and if you do, destroy it.
target_text: -- Stellarknight
  local SETCARD_ID_0 = 0x9c --tellarknight
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--xyz summon
  	aux.AddXyzProcedure(c, aux.FilterBoolFunction(Card.IsAttribute, ATTRIBUTE_LIGHT), 5, 3, s.ovfilter, aux.Stringid(id, 0), 99)
  	c:EnableReviveLimit()
  	--
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CANNOT_TO_GRAVE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetTargetRange(LOCATION_DECK, LOCATION_DECK)
  	e1:SetCondition(s.effcon)
  	c:RegisterEffect(e1)
  	--
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_FIELD)
  	e2:SetCode(EFFECT_CANNOT_DISCARD_DECK)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e2:SetTargetRange(1, 1)
  	e2:SetCondition(s.effcon)
  	c:RegisterEffect(e2)
  	--
  	local e3 = Effect.CreateEffect(c)
  	e3:SetType(EFFECT_TYPE_FIELD)
  	e3:SetCode(EFFECT_TO_HAND_REDIRECT)
  	e3:SetRange(LOCATION_MZONE)
  	e3:SetTargetRange(LOCATION_GRAVE, LOCATION_GRAVE)
  	e3:SetValue(LOCATION_REMOVED)
  	e3:SetCondition(s.effcon)
  	c:RegisterEffect(e3)
  	--Negate
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 1))
  	e4:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e4:SetType(EFFECT_TYPE_QUICK_O)
  	e4:SetCode(EVENT_CHAINING)
  	e4:SetRange(LOCATION_MZONE)
  	e4:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e4:SetCondition(s.condition)
  	e4:SetCost(s.cost)
  	e4:SetTarget(s.target)
  	e4:SetOperation(s.operation)
  	c:RegisterEffect(e4)
  end
  function s.ovfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_XYZ) and not c:IsCode(id) and Duel.GetCurrentPhase() == PHASE_MAIN2
  end
  function s.effcon(e)
  	return e:GetHandler():GetOverlayCount() > 0
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	local attr = Duel.GetChainInfo(ev, CHAININFO_TRIGGERING_ATTRIBUTE)
  	return ep ~= tp and re:IsActiveType(TYPE_MONSTER) and attr & ATTRIBUTE_DARK > 0 and Duel.IsChainNegatable(ev)
  end
  function s.cost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():CheckRemoveOverlayCard(tp, 1, REASON_COST)
  	end
  	e:GetHandler():RemoveOverlayCard(tp, 1, 1, REASON_COST)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  
  