name: Plunder
card_text: If you control a "Plunder Patroll" monster: Draw cards equal to the number of Equip Cards you control +1, then shuffle cards from your hand into the Deck equal to the number of Equip Cards you control. You can only use this effect of "Plunder Patroll Parrrty" once per turn. If you Special Summon a "Plunder Patroll" monster(s) from the Extra Deck, while this card is in your GY: You can equip this card to that Special Summoned monster as an Equip Card with this effect.
  ● The equipped monster gains 500 ATK.
  You can only use this effect of "Plunder Patroll Parrrty" once per Duel.
external_ids: local SETCARD_ID_0 = 0x13f --Plunder
  
lua: local SETCARD_ID_0 = 0x13f --Plunder
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DRAW + CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--equip
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1 + EFFECT_COUNT_CODE_DUEL)
  	e2:SetCondition(s.eqcon)
  	e2:SetTarget(s.eqtg)
  	e2:SetOperation(s.eqop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.drfilter(c)
  	return (c:IsFaceup() or c:GetEquipTarget()) and c:IsType(TYPE_EQUIP)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local i = Duel.GetMatchingGroupCount(s.drfilter, tp, LOCATION_ONFIELD, 0, nil)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, i + 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(i + 1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, i + 1)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 0, tp, i)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local i = Duel.GetMatchingGroupCount(s.drfilter, p, LOCATION_ONFIELD, 0, nil)
  	if Duel.Draw(p, i + 1, REASON_EFFECT) == 0 then
  		return
  	end
  	if i > 0 then
  		Duel.ShuffleHand(tp)
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local g = Duel.SelectMatchingCard(tp, Card.IsAbleToDeck, tp, LOCATION_HAND, 0, i, i, nil)
  		if g:GetCount() > 0 then
  			Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  		end
  	end
  end
  function s.exfilter(c, tp)
  	return c:IsSummonLocation(LOCATION_EXTRA) and c:IsSummonPlayer(tp) and c:IsSetCard(SETCARD_ID_0) and c:IsFaceup()
  end
  function s.eqcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.exfilter, 1, nil, tp)
  end
  function s.eqfilter(c, g)
  	return g:IsContains(c)
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local g = eg:Filter(s.exfilter, nil, tp)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0
  			and not c:IsForbidden()
  			and c:CheckUniqueOnField(tp, LOCATION_SZONE)
  			and Duel.IsExistingMatchingCard(s.eqfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, g)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) < 1 then
  		return
  	end
  	if not c:IsRelateToEffect(e) or c:IsForbidden() or not c:CheckUniqueOnField(tp, LOCATION_SZONE) then
  		return
  	end
  	local g = eg:Filter(s.exfilter, nil, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local sg = Duel.SelectMatchingCard(tp, s.eqfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, g)
  	local tc = sg:GetFirst()
  	if tc then
  		Duel.HintSelection(sg)
  		if Duel.Equip(tp, c, tc) then
  			--Add Equip limit
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_EQUIP_LIMIT)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e1:SetLabelObject(tc)
  			e1:SetValue(s.eqlimit)
  			c:RegisterEffect(e1)
  			--Atk up
  			local e2 = Effect.CreateEffect(e:GetHandler())
  			e2:SetType(EFFECT_TYPE_EQUIP)
  			e2:SetCode(EFFECT_UPDATE_ATTACK)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e2:SetValue(500)
  			c:RegisterEffect(e2)
  		end
  	end
  end
  function s.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  
  
source_text: Plunder
  If you control a "Plunder Patroll" monster: Draw cards equal to the number of Equip Cards you control +1, then shuffle cards from your hand into the Deck equal to the number of Equip Cards you control. You can only use this effect of "Plunder Patroll Parrrty" once per turn. If you Special Summon a "Plunder Patroll" monster(s) from the Extra Deck, while this card is in your GY: You can equip this card to that Special Summoned monster as an Equip Card with this effect.
  ● The equipped monster gains 500 ATK.
  You can only use this effect of "Plunder Patroll Parrrty" once per Duel.
target_text: -- Plunder
  local SETCARD_ID_0 = 0x13f --Plunder
  local s, id, o = GetID()
  function s.initial_effect(c)
  	--Activate
  	local e1 = Effect.CreateEffect(c)
  	e1:SetDescription(aux.Stringid(id, 0))
  	e1:SetCategory(CATEGORY_DRAW + CATEGORY_TODECK)
  	e1:SetType(EFFECT_TYPE_ACTIVATE)
  	e1:SetProperty(EFFECT_FLAG_PLAYER_TARGET)
  	e1:SetCode(EVENT_FREE_CHAIN)
  	e1:SetCountLimit(1, id)
  	e1:SetCondition(s.condition)
  	e1:SetTarget(s.target)
  	e1:SetOperation(s.activate)
  	c:RegisterEffect(e1)
  	--equip
  	local e2 = Effect.CreateEffect(c)
  	e2:SetDescription(aux.Stringid(id, 1))
  	e2:SetType(EFFECT_TYPE_FIELD + EFFECT_TYPE_TRIGGER_O)
  	e2:SetCategory(CATEGORY_LEAVE_GRAVE)
  	e2:SetProperty(EFFECT_FLAG_DELAY)
  	e2:SetCode(EVENT_SPSUMMON_SUCCESS)
  	e2:SetRange(LOCATION_GRAVE)
  	e2:SetCountLimit(1, id + 1 + EFFECT_COUNT_CODE_DUEL)
  	e2:SetCondition(s.eqcon)
  	e2:SetTarget(s.eqtg)
  	e2:SetOperation(s.eqop)
  	c:RegisterEffect(e2)
  end
  function s.cfilter(c)
  	return c:IsFaceup() and c:IsSetCard(SETCARD_ID_0)
  end
  function s.condition(e, tp, eg, ep, ev, re, r, rp)
  	return Duel.IsExistingMatchingCard(s.cfilter, tp, LOCATION_MZONE, 0, 1, nil)
  end
  function s.drfilter(c)
  	return (c:IsFaceup() or c:GetEquipTarget()) and c:IsType(TYPE_EQUIP)
  end
  function s.target(e, tp, eg, ep, ev, re, r, rp, chk)
  	local i = Duel.GetMatchingGroupCount(s.drfilter, tp, LOCATION_ONFIELD, 0, nil)
  	if chk == 0 then
  		return Duel.IsPlayerCanDraw(tp, i + 1)
  	end
  	Duel.SetTargetPlayer(tp)
  	Duel.SetTargetParam(i + 1)
  	Duel.SetOperationInfo(0, CATEGORY_DRAW, nil, 0, tp, i + 1)
  	Duel.SetOperationInfo(0, CATEGORY_TODECK, nil, 0, tp, i)
  end
  function s.activate(e, tp, eg, ep, ev, re, r, rp)
  	local p = Duel.GetChainInfo(0, CHAININFO_TARGET_PLAYER)
  	local i = Duel.GetMatchingGroupCount(s.drfilter, p, LOCATION_ONFIELD, 0, nil)
  	if Duel.Draw(p, i + 1, REASON_EFFECT) == 0 then
  		return
  	end
  	if i > 0 then
  		Duel.ShuffleHand(tp)
  		Duel.BreakEffect()
  		Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_TODECK)
  		local g = Duel.SelectMatchingCard(tp, Card.IsAbleToDeck, tp, LOCATION_HAND, 0, i, i, nil)
  		if g:GetCount() > 0 then
  			Duel.SendtoDeck(g, nil, SEQ_DECKSHUFFLE, REASON_EFFECT)
  		end
  	end
  end
  function s.exfilter(c, tp)
  	return c:IsSummonLocation(LOCATION_EXTRA) and c:IsSummonPlayer(tp) and c:IsSetCard(SETCARD_ID_0) and c:IsFaceup()
  end
  function s.eqcon(e, tp, eg, ep, ev, re, r, rp)
  	return eg:IsExists(s.exfilter, 1, nil, tp)
  end
  function s.eqfilter(c, g)
  	return g:IsContains(c)
  end
  function s.eqtg(e, tp, eg, ep, ev, re, r, rp, chk)
  	local c = e:GetHandler()
  	local g = eg:Filter(s.exfilter, nil, tp)
  	if chk == 0 then
  		return Duel.GetLocationCount(tp, LOCATION_SZONE) > 0
  			and not c:IsForbidden()
  			and c:CheckUniqueOnField(tp, LOCATION_SZONE)
  			and Duel.IsExistingMatchingCard(s.eqfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, nil, g)
  	end
  	Duel.SetOperationInfo(0, CATEGORY_LEAVE_GRAVE, e:GetHandler(), 1, 0, 0)
  end
  function s.eqop(e, tp, eg, ep, ev, re, r, rp)
  	local c = e:GetHandler()
  	if Duel.GetLocationCount(tp, LOCATION_SZONE) < 1 then
  		return
  	end
  	if not c:IsRelateToEffect(e) or c:IsForbidden() or not c:CheckUniqueOnField(tp, LOCATION_SZONE) then
  		return
  	end
  	local g = eg:Filter(s.exfilter, nil, tp)
  	Duel.Hint(HINT_SELECTMSG, tp, HINTMSG_FACEUP)
  	local sg = Duel.SelectMatchingCard(tp, s.eqfilter, tp, LOCATION_MZONE, LOCATION_MZONE, 1, 1, nil, g)
  	local tc = sg:GetFirst()
  	if tc then
  		Duel.HintSelection(sg)
  		if Duel.Equip(tp, c, tc) then
  			--Add Equip limit
  			local e1 = Effect.CreateEffect(c)
  			e1:SetType(EFFECT_TYPE_SINGLE)
  			e1:SetCode(EFFECT_EQUIP_LIMIT)
  			e1:SetProperty(EFFECT_FLAG_CANNOT_DISABLE)
  			e1:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e1:SetLabelObject(tc)
  			e1:SetValue(s.eqlimit)
  			c:RegisterEffect(e1)
  			--Atk up
  			local e2 = Effect.CreateEffect(e:GetHandler())
  			e2:SetType(EFFECT_TYPE_EQUIP)
  			e2:SetCode(EFFECT_UPDATE_ATTACK)
  			e2:SetReset(RESET_EVENT + RESETS_STANDARD)
  			e2:SetValue(500)
  			c:RegisterEffect(e2)
  		end
  	end
  end
  function s.eqlimit(e, c)
  	return c == e:GetLabelObject()
  end
  
  