name: Adamancipator
card_text: If this card is Special Summoned by the effect of an "Adamancipator" card: You can place 1 "Adamancipator" card from your hand or GY on top of the Deck. If this card is in your GY: You can target 1 FIRE Synchro Monster you control or in your GY; return it to the Extra Deck, and if you do, place this card on top of the Deck. You can only use each effect of "Adamancipator Crystal - Leonite" once per turn.
external_ids: local SETCARD_ID_0 = 0x140 --Adamancipator
  
lua: local SETCARD_ID_0 = 0x140 --Adamancipator
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to decktop1
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.dtcon1)
  	e1:SetTarget(s.dttg1)
  	e1:SetOperation(s.dtop1)
  	c:RegisterEffect(e1)
  	--to decktop2
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOEXTRA + CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.dttg2)
  	e2:SetOperation(s.dtop2)
  	c:RegisterEffect(e2)
  end
  function s.dtcon1(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSpecialSummonSetCard(SETCARD_ID_0)
  end
  function s.dtfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck()
  end
  function s.dttg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.dtfilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.dtop1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.dtfilter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		if tc:IsLocation(LOCATION_HAND) then
  			Duel.ConfirmCards(1 - tp, tc)
  		else
  			Duel.HintSelection(g)
  		end
  		Duel.SendtoDeck(g, nil, SEQ_DECKTOP, REASON_EFFECT)
  	end
  end
  function s.texfilter(c)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsAttribute(ATTRIBUTE_FIRE) and c:IsType(TYPE_SYNCHRO) and c:IsAbleToExtra()
  end
  function s.dttg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE + LOCATION_GRAVE) and chkc:IsControler(tp) and s.texfilter(chkc) and chkc ~= c
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.texfilter, tp, LOCATION_MZONE + LOCATION_GRAVE, 0, 1, c) and c:IsAbleToDeck()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.texfilter, tp, LOCATION_MZONE + LOCATION_GRAVE, 0, 1, 1, c)
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, c, 1, 0, 0)
  end
  function s.dtop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoDeck(tc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_EXTRA) and c:IsRelateToEffect(e) then
  		Duel.SendtoDeck(c, nil, SEQ_DECKTOP, REASON_EFFECT)
  	end
  end
  
  
source_text: Adamancipator
  If this card is Special Summoned by the effect of an "Adamancipator" card: You can place 1 "Adamancipator" card from your hand or GY on top of the Deck. If this card is in your GY: You can target 1 FIRE Synchro Monster you control or in your GY; return it to the Extra Deck, and if you do, place this card on top of the Deck. You can only use each effect of "Adamancipator Crystal - Leonite" once per turn.
target_text: -- Adamancipator
  local SETCARD_ID_0 = 0x140 --Adamancipator
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--to decktop1
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_SINGLE + EFFECT_TYPE_TRIGGER_O)
  	e1:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e1:SetProperty(EFFECT_FLAG_DELAY)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.dtcon1)
  	e1:SetTarget(s.dttg1)
  	e1:SetOperation(s.dtop1)
  	c:RegisterEffect(e1)
  	--to decktop2
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_TOEXTRA + CATEGORY_TODECK)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetProperty(EFFECT_FLAG_CARD_TARGET)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetTarget(s.dttg2)
  	e2:SetOperation(s.dtop2)
  	c:RegisterEffect(e2)
  end
  function s.dtcon1(e, tp, eg, ep, ev, re, r, rp)
  	return e:GetHandler():IsSpecialSummonSetCard(SETCARD_ID_0)
  end
  function s.dtfilter(c)
  	return c:IsSetCard(SETCARD_ID_0) and c:IsAbleToDeck()
  end
  function s.dttg1(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.IsExistingMatchingCard(s.dtfilter, tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, nil)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 1, tp, LOCATION_HAND + LOCATION_GRAVE)
  end
  function s.dtop1(e, tp, eg, ep, ev, re, r, rp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  	local g = Duel.SelectMatchingCard(tp, aux.NecroValleyFilter(s.dtfilter), tp, LOCATION_HAND + LOCATION_GRAVE, 0, 1, 1, nil)
  	local tc = g:GetFirst()
  	if tc then
  		if tc:IsLocation(LOCATION_HAND) then
  			Duel.ConfirmCards(1 - tp, tc)
  		else
  			Duel.HintSelection(g)
  		end
  		Duel.SendtoDeck(g, nil, SEQ_DECKTOP, REASON_EFFECT)
  	end
  end
  function s.texfilter(c)
  	return (c:IsFaceup() or c:IsLocation(LOCATION_GRAVE)) and c:IsAttribute(ATTRIBUTE_FIRE) and c:IsType(TYPE_SYNCHRO) and c:IsAbleToExtra()
  end
  function s.dttg2(e, tp, eg, ep, ev, re, r, rp, chk, chkc)
  	local c = e:GetHandler()
  	if chkc then
  		return chkc:IsLocation(LOCATION_MZONE + LOCATION_GRAVE) and chkc:IsControler(tp) and s.texfilter(chkc) and chkc ~= c
  	end
  	if chk == 0 then
  		return Duel.IsExistingTarget(s.texfilter, tp, LOCATION_MZONE + LOCATION_GRAVE, 0, 1, c) and c:IsAbleToDeck()
  	end
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TARGET)
  	local g = Duel.SelectTarget(tp, s.texfilter, tp, LOCATION_MZONE + LOCATION_GRAVE, 0, 1, 1, c)
  	Duel.SetOperationInfo(0, CATEGORY_TOEXTRA, g, 1, 0, 0)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, c, 1, 0, 0)
  end
  function s.dtop2(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	local tc = Duel.GetFirstTarget()
  	if tc:IsRelateToEffect(e) and Duel.SendtoDeck(tc, nil, SEQ_DECKSHUFFLE, REASON_EFFECT) ~= 0 and tc:IsLocation(LOCATION_EXTRA) and c:IsRelateToEffect(e) then
  		Duel.SendtoDeck(c, nil, SEQ_DECKTOP, REASON_EFFECT)
  	end
  end
  
  