name: Tool
card_text: If you control a monster: You can reveal 2 Equip Spells from your Deck with different names, your opponent randomly picks 1 for you to add to your hand, also place the remaining card on the bottom of your Deck. You can only use this effect of "Tool Box" once per turn.
lua: local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) > 0
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_EQUIP) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  		return g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, 0, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetClassCount(Card.GetCode) >= 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local sg = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  		Duel.ConfirmCards(1 - tp, sg)
  		local tg = sg:RandomSelect(1 - tp, 1)
  		tg:GetFirst():SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  		Duel.ShuffleDeck(tp)
  		local tc2 = (sg - tg):GetFirst()
  		Duel.MoveSequence(tc2, SEQ_DECKBOTTOM)
  	end
  end
  
  
source_text: Tool
  If you control a monster: You can reveal 2 Equip Spells from your Deck with different names, your opponent randomly picks 1 for you to add to your hand, also place the remaining card on the bottom of your Deck. You can only use this effect of "Tool Box" once per turn.
target_text: -- Tool
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	c:RegisterEffect(e1)
  	--to hand
  	local e2 = Effect.CreateEffect(c)
  	e2:SetCategory(CATEGORY_SEARCH + CATEGORY_TOHAND)
  	e2:SetType(EFFECT_TYPE_IGNITION)
  	e2:SetRange(LOCATION_SZONE)
  	e2:SetCountLimit(1, id)
  	e2:SetCondition(s.thcon)
  	e2:SetTarget(s.thtg)
  	e2:SetOperation(s.thop)
  	c:RegisterEffect(e2)
  end
  function s.thcon(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.GetFieldGroupCount(tp, LOCATION_MZONE, 0) > 0
  end
  function s.thfilter(c)
  	return c:IsType(TYPE_EQUIP) and c:IsAbleToHand()
  end
  function s.thtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	if chk == 0 then
  		local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  		return g:GetClassCount(Card.GetCode) >= 2
  	end
  	Duel.SetOperationInfo(0, CATEGORY_TOHAND, nil, 1, 0, LOCATION_DECK)
  end
  function s.thop(e, tp, eg, ep, ev, re, r, rp)
  	local g = Duel.GetMatchingGroup(s.thfilter, tp, LOCATION_DECK, 0, nil)
  	if g:GetClassCount(Card.GetCode) >= 2 then
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_CONFIRM)
  		local sg = g:SelectSubGroup(tp, aux.dncheck, false, 2, 2)
  		Duel.ConfirmCards(1 - tp, sg)
  		local tg = sg:RandomSelect(1 - tp, 1)
  		tg:GetFirst():SetStatus(STATUS_TO_HAND_WITHOUT_CONFIRM, true)
  		Duel.SendtoHand(tg, nil, REASON_EFFECT)
  		Duel.ShuffleDeck(tp)
  		local tc2 = (sg - tg):GetFirst()
  		Duel.MoveSequence(tc2, SEQ_DECKBOTTOM)
  	end
  end
  
  