name: Despian
card_text: 1 Level 4 Tuner + 1+ non-Tuner monsters
  Once per turn, if a card(s) leaves the Extra Deck (except during the Damage Step): You can make all monsters you currently control gain 500 ATK (permanently), then you can negate the effects of 1 face-up card on the field, until the end of this turn. During the End Phase, if this card is in the GY because it was sent there this turn: You can Special Summon 1 LIGHT Spellcaster monster from your hand or Deck whose ATK equals its own DEF. You can only use this effect of "Despian Luluwalilith" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsLevel, 4), aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--atkup
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DISABLE)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_LEAVE_DECK)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.atkcon)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsPreviousLocation, 1, nil, LOCATION_EXTRA)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsFaceup, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  end
  function s.atkfilter(c, e)
  	return c:IsFaceup() and not c:IsImmuneToEffect(e)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, 0, nil, e)
  	if g:GetCount() > 0 then
  		for tc in aux.Next(g) do
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(500)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  		end
  		local sg = Duel.GetMatchingGroup(aux.NegateAnyFilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  		if sg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISABLE)
  			local tg = sg:Select(tp, 1, 1, nil)
  			Duel.HintSelection(tg)
  			local sc = tg:GetFirst()
  			Duel.NegateRelatedChain(sc, RESET_TURN_SET)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e2:SetCode(EFFECT_DISABLE)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			sc:RegisterEffect(e2)
  			local e3 = e2:Clone()
  			e3:SetCode(EFFECT_DISABLE_EFFECT)
  			e3:SetValue(RESET_TURN_SET)
  			sc:RegisterEffect(e3)
  			if sc:IsType(TYPE_TRAPMONSTER) then
  				local e4 = e2:Clone()
  				e4:SetCode(EFFECT_DISABLE_TRAPMONSTER)
  				sc:RegisterEffect(e4)
  			end
  		end
  	end
  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.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) > 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsRace(RACE_SPELLCASTER) and aux.AtkEqualsDef(c) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Despian
  1 Level 4 Tuner + 1+ non-Tuner monsters
  Once per turn, if a card(s) leaves the Extra Deck (except during the Damage Step): You can make all monsters you currently control gain 500 ATK (permanently), then you can negate the effects of 1 face-up card on the field, until the end of this turn. During the End Phase, if this card is in the GY because it was sent there this turn: You can Special Summon 1 LIGHT Spellcaster monster from your hand or Deck whose ATK equals its own DEF. You can only use this effect of "Despian Luluwalilith" once per turn.
target_text: -- Despian
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, aux.FilterBoolFunction(Card.IsLevel, 4), aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--atkup
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_ATKCHANGE + CATEGORY_DISABLE)
  	e1:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCode(EVENT_LEAVE_DECK)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1)
  	e1:SetCondition(s.atkcon)
  	e1:SetTarget(s.atktg)
  	e1:SetOperation(s.atkop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  	e2:SetCode(EVENT_TO_GRAVE)
  	e2:SetOperation(s.regop)
  	c:RegisterEffect(e2)
  	local e3 = Effect.CreateEffect(c)
  	e3:SetDescription(aux.Stringid(id, 1))
  	e3:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e3:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e3:SetCode(EVENT_PHASE + PHASE_END)
  	e3:SetRange(LOCATION_GRAVE)
  	e3:SetCountLimit(1, id)
  	e3:SetCondition(s.spcon)
  	e3:SetTarget(s.sptg)
  	e3:SetOperation(s.spop)
  	c:RegisterEffect(e3)
  end
  function s.atkcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(Card.IsPreviousLocation, 1, nil, LOCATION_EXTRA)
  end
  function s.atktg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsFaceup, tp, LOCATION_MZONE, 0, 1, nil)
  	end
  end
  function s.atkfilter(c, e)
  	return c:IsFaceup() and not c:IsImmuneToEffect(e)
  end
  function s.atkop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(s.atkfilter, tp, LOCATION_MZONE, 0, nil, e)
  	if g:GetCount() > 0 then
  		for tc in aux.Next(g) do
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetCode(EFFECT_UPDATE_ATTACK)
  			e1:SetValue(500)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			tc:RegisterEffect(e1)
  		end
  		local sg = Duel.GetMatchingGroup(aux.NegateAnyFilter, tp, LOCATION_ONFIELD, LOCATION_ONFIELD, nil)
  		if sg:GetCount() > 0 and Duel.SelectYesNo(tp, aux.Stringid(id, 2)) then
  			Duel.BreakEffect()
  			Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISABLE)
  			local tg = sg:Select(tp, 1, 1, nil)
  			Duel.HintSelection(tg)
  			local sc = tg:GetFirst()
  			Duel.NegateRelatedChain(sc, RESET_TURN_SET)
  			local e2 = Effect.CreateEffect(c)
  			e2:SetType(EFFECT_TYPE_SINGLE)
  			e2:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e2:SetCode(EFFECT_DISABLE)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END)
  			sc:RegisterEffect(e2)
  			local e3 = e2:Clone()
  			e3:SetCode(EFFECT_DISABLE_EFFECT)
  			e3:SetValue(RESET_TURN_SET)
  			sc:RegisterEffect(e3)
  			if sc:IsType(TYPE_TRAPMONSTER) then
  				local e4 = e2:Clone()
  				e4:SetCode(EFFECT_DISABLE_TRAPMONSTER)
  				sc:RegisterEffect(e4)
  			end
  		end
  	end
  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.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) > 0
  end
  function s.spfilter(c, e, tp)
  	return c:IsAttribute(ATTRIBUTE_LIGHT) and c:IsRace(RACE_SPELLCASTER) and aux.AtkEqualsDef(c) and c:IsCanBeSpecialSummoned(e, 0, tp, false, false)
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_MZONE) > 0 and Duel.IsExistingMatchingCard(s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, nil, e, tp)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, nil, 1, tp, LOCATION_HAND + LOCATION_DECK)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = Duel.SelectMatchingCard(tp, s.spfilter, tp, LOCATION_HAND + LOCATION_DECK, 0, 1, 1, nil, e, tp)
  	if g:GetCount() > 0 then
  		Duel.SpecialSummon(g, 0, tp, tp, false, false, POS_FACEUP)
  	end
  end
  
  