name: Adamancipator
card_text: 1 Tuner + 1+ non-Tuner monsters
  During your Main Phase: You can excavate the top 5 cards of your Deck, and if you do, you can return cards your opponent controls to the hand, up to the number of excavated Rock monsters, also place the excavated cards on the bottom of your Deck in any order. When your opponent activates a Spell/Trap Card or effect, while a WATER monster is in your GY (Quick Effect): You can negate the activation, and if you do, destroy it. You can only use each effect of "Adamancipator Risen - Dragite" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--negate
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.discon)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 4
  	end
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) <= 4 then
  		return
  	end
  	Duel.ConfirmDecktop(tp, 5)
  	local g = Duel.GetDecktopGroup(tp, 5)
  	if
  		g:GetCount() > 0
  		and g:FilterCount(Card.IsRace, nil, RACE_ROCK) > 0
  		and Duel.IsExistingMatchingCard(Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, nil)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  	then
  		local ct = g:FilterCount(Card.IsRace, nil, RACE_ROCK)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  		local sg = Duel.SelectMatchingCard(tp, Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, ct, nil)
  		Duel.HintSelection(sg)
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  	end
  	if g:GetCount() > 0 then
  		Duel.SortDecktop(tp, tp, g:GetCount())
  		for i = 1, g:GetCount() do
  			local mg = Duel.GetDecktopGroup(tp, 1)
  			Duel.MoveSequence(mg:GetFirst(), SEQ_DECKBOTTOM)
  		end
  	end
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	if ep == tp or e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) then
  		return false
  	end
  	return re:IsActiveType(TYPE_SPELL + TYPE_TRAP) and Duel.IsChainNegatable(ev) and Duel.IsExistingMatchingCard(Card.IsAttribute, tp, LOCATION_GRAVE, 0, 1, nil, ATTRIBUTE_WATER)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  
  
source_text: Adamancipator
  1 Tuner + 1+ non-Tuner monsters
  During your Main Phase: You can excavate the top 5 cards of your Deck, and if you do, you can return cards your opponent controls to the hand, up to the number of excavated Rock monsters, also place the excavated cards on the bottom of your Deck in any order. When your opponent activates a Spell/Trap Card or effect, while a WATER monster is in your GY (Quick Effect): You can negate the activation, and if you do, destroy it. You can only use each effect of "Adamancipator Risen - Dragite" once per turn.
target_text: -- Adamancipator
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--synchro summon
  	aux.AddSynchroProcedure(c, nil, aux.NonTuner(nil), 1)
  	c:EnableReviveLimit()
  	--to hand
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_TOHAND)
  	e1:SetType(EFFECT_TYPE_IGNITION)
  	e1:SetRange(LOCATION_MZONE)
  	e1:SetCountLimit(1, id)
  	e1:SetTarget(s.thtg)
  	e1:SetOperation(s.thop)
  	c:RegisterEffect(e1)
  	--negate
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetCategory(CATEGORY_NEGATE + CATEGORY_DESTROY)
  	e2:SetType(EFFECT_TYPE_QUICK_O)
  	e2:SetCode(EVENT_CHAINING)
  	e2:SetProperty(EFFECT_FLAG_DAMAGE_STEP + EFFECT_FLAG_DAMAGE_CAL)
  	e2:SetRange(LOCATION_MZONE)
  	e2:SetCountLimit(1, id + 1)
  	e2:SetCondition(s.discon)
  	e2:SetTarget(s.distg)
  	e2:SetOperation(s.disop)
  	c:RegisterEffect(e2)
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) > 4
  	end
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.GetFieldGroupCount(tp, LOCATION_DECK, 0) <= 4 then
  		return
  	end
  	Duel.ConfirmDecktop(tp, 5)
  	local g = Duel.GetDecktopGroup(tp, 5)
  	if
  		g:GetCount() > 0
  		and g:FilterCount(Card.IsRace, nil, RACE_ROCK) > 0
  		and Duel.IsExistingMatchingCard(Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, nil)
  		and Duel.SelectYesNo(tp, aux.Stringid(id, 2))
  	then
  		local ct = g:FilterCount(Card.IsRace, nil, RACE_ROCK)
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_RTOHAND)
  		local sg = Duel.SelectMatchingCard(tp, Card.IsAbleToHand, tp, 0, LOCATION_ONFIELD, 1, ct, nil)
  		Duel.HintSelection(sg)
  		Duel.SendtoHand(sg, nil, REASON_EFFECT)
  	end
  	if g:GetCount() > 0 then
  		Duel.SortDecktop(tp, tp, g:GetCount())
  		for i = 1, g:GetCount() do
  			local mg = Duel.GetDecktopGroup(tp, 1)
  			Duel.MoveSequence(mg:GetFirst(), SEQ_DECKBOTTOM)
  		end
  	end
  end
  function s.discon(e, tp, eg, ep, ev, re, r, rp)
  	if ep == tp or e:GetHandler():IsStatus(STATUS_BATTLE_DESTROYED) then
  		return false
  	end
  	return re:IsActiveType(TYPE_SPELL + TYPE_TRAP) and Duel.IsChainNegatable(ev) and Duel.IsExistingMatchingCard(Card.IsAttribute, tp, LOCATION_GRAVE, 0, 1, nil, ATTRIBUTE_WATER)
  end
  function s.distg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		return true
  	end
  	Duel.SetOperationInfo(0, CATEGORY_NEGATE, eg, 1, 0, 0)
  	if re:GetHandler():IsDestructable() and re:GetHandler():IsRelateToEffect(re) then
  		Duel.SetOperationInfo(0, CATEGORY_DESTROY, eg, 1, 0, 0)
  	end
  end
  function s.disop(e, tp, eg, ep, ev, re, r, rp)
  	if Duel.NegateActivation(ev) and re:GetHandler():IsRelateToEffect(re) then
  		Duel.Destroy(eg, REASON_EFFECT)
  	end
  end
  
  