Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: ability to drop multiple stacks of stackable items #2351

Merged
merged 2 commits into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 38 additions & 5 deletions Intersect.Client/Entities/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using Intersect.Config.Guilds;
using Intersect.Configuration;
using Intersect.Enums;
using Intersect.Extensions;
using Intersect.GameObjects;
using Intersect.GameObjects.Maps;
using Intersect.Logging;
Expand Down Expand Up @@ -400,17 +401,49 @@ public void TryDropItem(int inventorySlotIndex)
prompt: prompt.ToString(itemDescriptor.Name),
inputType: inputType,
quantity: quantity,
maxQuantity: quantity,
maxQuantity: GetQuantityOfItemInInventory(itemDescriptor.Id),
userData: inventorySlotIndex,
onSuccess: (s, e) =>
{
if (s is InputBox inputBox && inputBox.UserData is int invSlot)
if (s is not InputBox inputBox || inputBox.UserData is not int invSlot)
{
var value = (int)Math.Round(inputBox.Value);
if (value > 0)
return;
}

var value = (int)Math.Round(inputBox.Value);

if (value <= 0)
{
return;
}

// Check if the item can be dropped in multiple quantities or if value is less than or equal to the quantity in the initial slot
if (!canDropMultiple || value <= quantity)
{
PacketSender.SendDropItem(invSlot, !canDropMultiple ? 1 : value);
return;
}

// Find all slots containing the item.
var itemSlots = Inventory.Where(s => s.ItemId == itemDescriptor.Id).ToList();

// Send the drop item packet for the initial slot.
PacketSender.SendDropItem(invSlot, quantity);
value -= quantity;
_ = itemSlots.Remove(inventorySlot); // Remove the initial slot from the list of item slots

// Iterate through the remaining slots containing the item
foreach (var slot in itemSlots)
{
var dropAmount = Math.Min(value, slot.Quantity);

if (dropAmount <= 0)
{
PacketSender.SendDropItem(invSlot, value);
break;
}

PacketSender.SendDropItem(Inventory.IndexOf(slot), dropAmount);
value -= dropAmount;
}
}
);
Expand Down
5 changes: 5 additions & 0 deletions Intersect.Client/Interface/Game/Inventory/InventoryItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Intersect.Client.General;
using Intersect.Client.Interface.Game.DescriptionWindows;
using Intersect.Client.Localization;
using Intersect.Client.Networking;
using Intersect.Configuration;
using Intersect.GameObjects;
using Intersect.Utilities;
Expand Down Expand Up @@ -531,6 +532,10 @@ public void Update()
}
}
}
else if (!Globals.Me.IsBusy)
{
PacketSender.SendDropItem(mMySlot, Globals.Me.Inventory[mMySlot].Quantity);
}

mDragIcon.Dispose();
}
Expand Down
3 changes: 2 additions & 1 deletion Intersect.Client/Interface/Shared/InputBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,10 @@ public InputBox(
{
NotchCount = maxQuantity,
SnapToNotches = true,
Min = 1,
Max = maxQuantity,
Value = quantity
};
_numericSlider.SetRange(1, maxQuantity);
_numericSlider.ValueChanged += _numericSlider_ValueChanged;
_txtNumericSlider = new TextBoxNumeric(_numericSliderBg, "SliderboxText")
{
Expand Down
Loading