name: Darklord
card_text: You can discard this card and 1 "Darklord" card, then target 1 "Darklord" card in your Graveyard; add it to your hand. During either player's turn: You can pay 1000 LP, then target 1 "Darklord" Spell/Trap Card in your Graveyard; apply that target's effect, then shuffle that target into the Deck. You can only use each effect of "Darklord Amdusc" once per turn. You can only Special Summon "Darklord Amdusc(s)" once per turn.
external_ids: local SETCARD_ID_0 = 0xef --Darklord
  
lua: local SETCARD_ID_0 = 0xef --Darklord
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetSPSummonOnce(id)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.thcost)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--copy effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.cpcost)
  	e2:SetTarget(s.cptg)
  	e2:SetOperation(s.cpop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsDiscardable()
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable() and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISCARD)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_HAND, 0, 1, 1, e:GetHandler())
  	g:AddCard(e:GetHandler())
  	Duel.SendtoGrave(g, REASON_DISCARD + REASON_COST)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.cpcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckLPCost(tp, 1000)
  	end
  	Duel.PayLPCost(tp, 1000)
  end
  function s.cpfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToDeck() and c:CheckActivateEffect(false, true, false) ~= nil
  end
  function s.cptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		local te = e:GetLabelObject()
  		local tg = te:GetTarget()
  		return tg and tg(e, tp, eg, ep, ev, re, r, rp, 0, chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.cpfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.cpfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(false, true, true)
  	Duel.ClearTargetCard()
  	g:GetFirst():CreateEffectRelation(e)
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  end
  function s.cpop(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	if not te:GetHandler():IsRelateToEffect(e) then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  	Duel.BreakEffect()
  	Duel.SendtoDeck(te:GetHandler(), nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  end
  
  
source_text: Darklord
  You can discard this card and 1 "Darklord" card, then target 1 "Darklord" card in your Graveyard; add it to your hand. During either player's turn: You can pay 1000 LP, then target 1 "Darklord" Spell/Trap Card in your Graveyard; apply that target's effect, then shuffle that target into the Deck. You can only use each effect of "Darklord Amdusc" once per turn. You can only Special Summon "Darklord Amdusc(s)" once per turn.
target_text: -- Darklord
  local SETCARD_ID_0 = 0xef --Darklord
  local s, id, o = GetID()
  function s.initial_effect(c)
  	c:SetSPSummonOnce(id)
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e1:SetRange(LOCATION_HAND)
  	e1:SetCountLimit(1, id)
  	e1:SetCost(s.thcost)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--copy effect
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCode(EVENT_FREE_CHAIN)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCost(s.cpcost)
  	e2:SetTarget(s.cptg)
  	e2:SetOperation(s.cpop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsDiscardable()
  end
  function s.thcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return e:GetHandler():IsDiscardable() and Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_HAND, 0, 1, e:GetHandler())
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_DISCARD)
  	local g = Duel.SelectMatchingCard(tp, s.cfilter, tp, LOCATION_HAND, 0, 1, 1, e:GetHandler())
  	g:AddCard(e:GetHandler())
  	Duel.SendtoGrave(g, REASON_DISCARD + REASON_COST)
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		return chkc:IsControler(tp) and chkc:IsLocation(LOCATION_GRAVE) and s.thfilter(chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.thfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  	local g = Duel.SelectTarget(tp, s.thfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, g, 1, 0, 0)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) then
  		Duel.SendtoHand(tc, nil, REASON_EFFECT)
  	end
  end
  function s.cpcost(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.CheckLPCost(tp, 1000)
  	end
  	Duel.PayLPCost(tp, 1000)
  end
  function s.cpfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_SPELL + TYPE_TRAP) and c:IsAbleToDeck() and c:CheckActivateEffect(false, true, false) ~= nil
  end
  function s.cptg(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	if chkc then
  		local te = e:GetLabelObject()
  		local tg = te:GetTarget()
  		return tg and tg(e, tp, eg, ep, ev, re, r, rp, 0, chkc)
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.cpfilter, tp, LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.cpfilter, tp, LOCATION_GRAVE, 0, 1, 1, nil)
  	local te, ceg, cep, cev, cre, cr, crp = g:GetFirst():CheckActivateEffect(false, true, true)
  	Duel.ClearTargetCard()
  	g:GetFirst():CreateEffectRelation(e)
  	local tg = te:GetTarget()
  	if tg then
  		tg(e, tp, ceg, cep, cev, cre, cr, crp, 1)
  	end
  	te:SetLabelObject(e:GetLabelObject())
  	e:SetLabelObject(te)
  	Duel.ClearOperationInfo(0)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, g, 1, 0, 0)
  end
  function s.cpop(e, tp, eg, ep, ev, re, r, rp)
  	local te = e:GetLabelObject()
  	if not te then
  		return
  	end
  	if not te:GetHandler():IsRelateToEffect(e) then
  		return
  	end
  	e:SetLabelObject(te:GetLabelObject())
  	local op = te:GetOperation()
  	if op then
  		op(e, tp, eg, ep, ev, re, r, rp)
  	end
  	Duel.BreakEffect()
  	Duel.SendtoDeck(te:GetHandler(), nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  end
  
  