name: Timelord
card_text: 1 Tuner + 1+ non-Tuner monsters
  Cannot be destroyed by battle or card effects. You take no battle damage from attacks involving this card. At the end of the Damage Step, if this card that was Special Summoned from the Extra Deck battled: You can activate this effect; banish all monsters your opponent controls, also, for the rest of this turn, halve the battle damage your opponent takes. Once per turn, during the End Phase, if this effect was activated this turn: Special Summon as many monsters as possible that you banished with this card's effect, to your opponent's field.
external_ids: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  
lua: local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e2)
  	local e3 = e1:Clone()
  	e3:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	c:RegisterEffect(e3)
  	--banish
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_REMOVE)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetCondition(s.rmcond)
  	e4:SetTarget(s.rmtg)
  	e4:SetOperation(s.rmop)
  	c:RegisterEffect(e4)
  	--special summon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e5:SetCode(EVENT_PHASE + PHASE_END)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCountLimit(1)
  	e5:SetCondition(s.spcon)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.rmcond(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return aux.dsercon(e, tp, eg, ep, ev, re, r, rp) and c:IsSummonLocation(LOCATION_EXTRA) and c:GetBattledGroupCount() > 0
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, #g, 1 - tp, LOCATION_MZONE)
  end
  function s.rfilter(c)
  	return not c:IsReason(REASON_REDIRECT)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, nil)
  	if Duel.Remove(g, POS_FACEUP, REASON_EFFECT) > 0 then
  		local og = Duel.GetOperatedGroup()
  		local rg = og:Filter(s.rfilter, nil)
  		if #rg > 0 then
  			local lab = 0
  			if c:GetFlagEffect(67508933) == 0 then
  				lab = c:GetFieldID()
  				c:RegisterFlagEffect(67508933, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1, lab)
  			else
  				lab = c:GetFlagEffectLabel(67508933)
  			end
  			for oc in aux.Next(rg) do
  				oc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1, lab)
  			end
  		end
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(0, 1)
  	e1:SetValue(HALF_DAMAGE)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.spfilter(c, e, tp)
  	local lab = c:GetFlagEffectLabel(id)
  	return lab and lab == e:GetHandler():GetFlagEffectLabel(67508933) and c:GetReasonPlayer() == tp and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(67508933) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_REMOVED, LOCATION_REMOVED, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, #g, tp, LOCATION_REMOVED)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(1 - tp, LOCATION_MZONE)
  	local tg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_REMOVED, LOCATION_REMOVED, nil, e, tp)
  	if ft <= 0 or #tg == 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = tg:Select(tp, ft, ft, nil)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, 1 - tp, false, false, POS_FACEUP)
  	end
  end
  
  
source_text: Timelord
  1 Tuner + 1+ non-Tuner monsters
  Cannot be destroyed by battle or card effects. You take no battle damage from attacks involving this card. At the end of the Damage Step, if this card that was Special Summoned from the Extra Deck battled: You can activate this effect; banish all monsters your opponent controls, also, for the rest of this turn, halve the battle damage your opponent takes. Once per turn, during the End Phase, if this effect was activated this turn: Special Summon as many monsters as possible that you banished with this card's effect, to your opponent's field.
target_text: -- Timelord
  local CARD_ID_0 = 59822133 --Blue-Eyes Spirit Dragon
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--indes
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE)
  	e1:SetProperty(EFFECT_FLAG_SINGLE_RANGE)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCode(EFFECT_INDESTRUCTABLE_BATTLE)
  	e1:SetValue(1)
  	c:RegisterEffect(e1)
  	local e2 = e1:Clone()
  	e2:SetCode(EFFECT_INDESTRUCTABLE_EFFECT)
  	c:RegisterEffect(e2)
  	local e3 = e1:Clone()
  	e3:SetCode(EFFECT_AVOID_BATTLE_DAMAGE)
  	c:RegisterEffect(e3)
  	--banish
  	local e4 = Effect.CreateEffect(c)
  	e4:SetDescription(aux.Stringid(id, 0))
  	e4:SetCategory(CATEGORY_REMOVE)
  	e4:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e4:SetCode(EVENT_DAMAGE_STEP_END)
  	e4:SetCondition(s.rmcond)
  	e4:SetTarget(s.rmtg)
  	e4:SetOperation(s.rmop)
  	c:RegisterEffect(e4)
  	--special summon
  	local e5 = Effect.CreateEffect(c)
  	e5:SetDescription(aux.Stringid(id, 1))
  	e5:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e5:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e5:SetCode(EVENT_PHASE + PHASE_END)
  	e5:SetRange(LOCATION_MZONE)
  	e5:SetCountLimit(1)
  	e5:SetCondition(s.spcon)
  	e5:SetTarget(s.sptg)
  	e5:SetOperation(s.spop)
  	c:RegisterEffect(e5)
  end
  function s.rmcond(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	return aux.dsercon(e, tp, eg, ep, ev, re, r, rp) and c:IsSummonLocation(LOCATION_EXTRA) and c:GetBattledGroupCount() > 0
  end
  function s.rmtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, 1, nil)
  	end
  	local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, nil)
  	Duel.SetOperationInfo(0, CATEGORY_REMOVE, g, #g, 1 - tp, LOCATION_MZONE)
  end
  function s.rfilter(c)
  	return not c:IsReason(REASON_REDIRECT)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local g = Duel.GetMatchingGroup(Card.IsAbleToRemove, tp, 0, LOCATION_MZONE, nil)
  	if Duel.Remove(g, POS_FACEUP, REASON_EFFECT) > 0 then
  		local og = Duel.GetOperatedGroup()
  		local rg = og:Filter(s.rfilter, nil)
  		if #rg > 0 then
  			local lab = 0
  			if c:GetFlagEffect(67508933) == 0 then
  				lab = c:GetFieldID()
  				c:RegisterFlagEffect(67508933, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1, lab)
  			else
  				lab = c:GetFlagEffectLabel(67508933)
  			end
  			for oc in aux.Next(rg) do
  				oc:RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1, lab)
  			end
  		end
  	end
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_FIELD)
  	e1:SetCode(EFFECT_CHANGE_BATTLE_DAMAGE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetTargetRange(0, 1)
  	e1:SetValue(HALF_DAMAGE)
  	e1:SetReset(RESET_PHASE + PHASE_END)
  	Duel.RegisterEffect(e1, tp)
  end
  function s.spfilter(c, e, tp)
  	local lab = c:GetFlagEffectLabel(id)
  	return lab and lab == e:GetHandler():GetFlagEffectLabel(67508933) and c:GetReasonPlayer() == tp and c:IsCanBeSpecialSummoned(e, 0, tp, false, false, POS_FACEUP, 1 - tp)
  end
  function s.spcon(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(67508933) > 0
  end
  function s.sptg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	local g = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_REMOVED, LOCATION_REMOVED, nil, e, tp)
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, g, #g, tp, LOCATION_REMOVED)
  end
  function s.spop(e, tp, eg, ep, ev, re, r, rp)
  	local ft = Duel.GetLocationCount(1 - tp, LOCATION_MZONE)
  	local tg = Duel.GetMatchingGroup(s.spfilter, tp, LOCATION_REMOVED, LOCATION_REMOVED, nil, e, tp)
  	if ft <= 0 or #tg == 0 then
  		return
  	end
  	if Duel.IsPlayerAffectedByEffect(tp, CARD_ID_0) then
  		ft = 1
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_SPSUMMON)
  	local g = tg:Select(tp, ft, ft, nil)
  	if #g > 0 then
  		Duel.SpecialSummon(g, 0, tp, 1 - tp, false, false, POS_FACEUP)
  	end
  end
  
  