name: D.D.
card_text: During the End Phase, if this card is currently banished, and was banished this turn: Special Summon it in face-up Attack Position. This effect can only activate once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--removed
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_REMOVE)
  	e1:SetOperation(s.rmop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_PHASE + PHASE_END)
  	e2:SetRange(LOCATION_REMOVED)
  	e2:SetCondition(s.condition)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsFacedown() then
  		return
  	end
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(3773197) == 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  	e:GetHandler():RegisterFlagEffect(3773197, RESET_EVENT + 0x4760000 + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  			Duel.SendtoGrave(e:GetHandler(), REASON_EFFECT)
  			return
  		end
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  	end
  end
  
  
source_text: D.D.
  During the End Phase, if this card is currently banished, and was banished this turn: Special Summon it in face-up Attack Position. This effect can only activate once per turn.
target_text: -- D.D.
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--removed
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_CONTINUOUS)
  	e1:SetCode(EVENT_REMOVE)
  	e1:SetOperation(s.rmop)
  	c:RegisterEffect(e1)
  	--special summon
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 0))
  	e2:SetCategory(CATEGORY_SPECIAL_SUMMON)
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_F)
  	e2:SetCode(EVENT_PHASE + PHASE_END)
  	e2:SetRange(LOCATION_REMOVED)
  	e2:SetCondition(s.condition)
  	e2:SetTarget(s.target)
  	e2:SetOperation(s.operation)
  	c:RegisterEffect(e2)
  end
  function s.rmop(e, tp, eg, ep, ev, re, r, rp)
  	if e:GetHandler():IsFacedown() then
  		return
  	end
  	e:GetHandler():RegisterFlagEffect(id, RESET_EVENT + RESETS_STANDARD + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():GetFlagEffect(id) ~= 0
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():GetFlagEffect(3773197) == 0
  	end
  	Duel.SetOperationInfo(0, CATEGORY_SPECIAL_SUMMON, e:GetHandler(), 1, 0, 0)
  	e:GetHandler():RegisterFlagEffect(3773197, RESET_EVENT + 0x4760000 + RESET_PHASE + PHASE_END, 0, 1)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if c:IsRelateToEffect(e) then
  		if Duel.GetLocationCount(tp, LOCATION_MZONE) <= 0 then
  			Duel.SendtoGrave(e:GetHandler(), REASON_EFFECT)
  			return
  		end
  		Duel.SpecialSummon(c, 0, tp, tp, false, false, POS_FACEUP_ATTACK)
  	end
  end
  
  