name: DDDの人事権
card_text: 1:自分の手札・フィールド・墓地の「DD」モンスター及び自分のPゾーンの「DD」カードの中から合計3枚選んで持ち主のデッキに戻す。
  その後、デッキから「DD」モンスター2体を手札に加える事ができる。
external_ids: local SETCARD_ID_0 = 0xaf --DD
  
lua: local SETCARD_ID_0 = 0xaf --DD
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck() and (not c:IsLocation(LOCATION_MZONE) or c:IsFaceup()) and (c:IsType(TYPE_MONSTER) or c:IsLocation(LOCATION_PZONE))
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_MZONE + LOCATION_PZONE + LOCATION_GRAVE + LOCATION_HAND, 0, 3, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 3, tp, LOCATION_MZONE + LOCATION_PZONE + LOCATION_GRAVE + LOCATION_HAND)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.filter), tp, LOCATION_MZONE + LOCATION_PZONE + LOCATION_GRAVE + LOCATION_HAND, 0, nil)
  	if g:GetCount() < 3 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local sg = g:Select(tp, 3, 3, nil)
  	local cg = sg:Filter(Card.IsLocation, nil, LOCATION_HAND)
  	Duel.ConfirmCards(1 - tp, cg)
  	Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local og = Duel.GetOperatedGroup()
  	if not og:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK + LOCATION_EXTRA) then
  		return
  	end
  	local dg = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if dg:GetCount() > 1 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local tg = dg:Select(tp, 2, 2, nil)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tg)
  	else
  		if og:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK) then
  			Duel.ShuffleDeck(tp)
  		end
  	end
  end
  
  
source_text: DDDの人事権
  1:自分の手札・フィールド・墓地の「DD」モンスター及び自分のPゾーンの「DD」カードの中から合計3枚選んで持ち主のデッキに戻す。
  その後、デッキから「DD」モンスター2体を手札に加える事ができる。
target_text: -- DDDの人事権
  local SETCARD_ID_0 = 0xaf --DD
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetCategory(CATEGORY_TODECK + CATEGORY_TOHAND + CATEGORY_SEARCH)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.operation)
  	c:RegisterEffect(e1)
  end
  function s.filter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck() and (not c:IsLocation(LOCATION_MZONE) or c:IsFaceup()) and (c:IsType(TYPE_MONSTER) or c:IsLocation(LOCATION_PZONE))
  end
  function s.thfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsType(TYPE_MONSTER) and c:IsAbleToHand()
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.filter, tp, LOCATION_MZONE + LOCATION_PZONE + LOCATION_GRAVE + LOCATION_HAND, 0, 3, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 3, tp, LOCATION_MZONE + LOCATION_PZONE + LOCATION_GRAVE + LOCATION_HAND)
  end
  function s.operation(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(aux.NecroValleyFilter(s.filter), tp, LOCATION_MZONE + LOCATION_PZONE + LOCATION_GRAVE + LOCATION_HAND, 0, nil)
  	if g:GetCount() < 3 then
  		return
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local sg = g:Select(tp, 3, 3, nil)
  	local cg = sg:Filter(Card.IsLocation, nil, LOCATION_HAND)
  	Duel.ConfirmCards(1 - tp, cg)
  	Duel.SendtoDeck(sg, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  	local og = Duel.GetOperatedGroup()
  	if not og:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK + LOCATION_EXTRA) then
  		return
  	end
  	local dg = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if dg:GetCount() > 1 and Duel.SelectYesNo(tp, aux.Stringid(id, 0)) then
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_ATOHAND)
  		local tg = dg:Select(tp, 2, 2, nil)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  		Duel.ConfirmCards(1 - tp, tg)
  	else
  		if og:IsExists(Card.IsLocation, 1, nil, LOCATION_DECK) then
  			Duel.ShuffleDeck(tp)
  		end
  	end
  end
  
  