-
Notifications
You must be signed in to change notification settings - Fork 363
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
fix: bank deposit behavior #1720
Conversation
@Arufonsu Both of the videos look like the broken behavior, where is a video of the correct behavior with this fix? |
From Discord:
That should be addressed too in this PR. |
ccc385b
to
53d4df3
Compare
Updated PR, code and video previews, so far this manages to fix the issues and behaves as expected, discussed and suggested 👍🏽 |
53d4df3
to
b8782af
Compare
b8782af
to
21d88be
Compare
21d88be
to
267ef4a
Compare
74b76c2
to
f18b668
Compare
Updated PR (lot of force pushes, won't happen after the first review - unless is required by the maintainer). 2023-04-15.01-30-35.mp4Hopefully this yields the expected behavior, PR feels ready for review as well 👍🏽 |
948ff6b
to
e5e8c88
Compare
self-reminder: restored the ability to deposit multiple non-stackable items 2023-08-27.00-58-01.mp4PR is ready for review and it's about to be built and published by @intersectbot for the ease of testing ~ |
Introduces the 'FindAvailableBankSpaceForItem' method to calculate the total available space within the bank for specific items. This enhancement streamlines the bank deposit process by automatically determining the appropriate values for the 'quantity' and 'maxQuantity' parameters in the deposit slider, improving user experience and accuracy when depositing items in the bank. 2023-08-27.14-41-01.mp4 |
client enhancement: NoSpace bank system message
2023-08-27.15-09-12.mp4 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't an exhaustive review but there is a missing thing and a few over-complicated things that I think can be simplified
int spaceLeft = 0; | ||
for (int i = 0; i < mMaxSlots; i++) | ||
{ | ||
if (mBank[i]?.ItemId == itemId) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Before the if statement add this as a short-circuit to skip costly searches
if (spaceLeft >= amount)
{
return amount;
}
// Not a stacking item, so can we contain the amount we want to give them? | ||
else | ||
{ | ||
if (FindOpenSlots().Count >= item.Quantity) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This case appears to not be covered in the new code?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be covering it when it comes to non stackable items:
Intersect-Engine/Intersect.Server/Entities/BankInterface.cs
Lines 205 to 209 in 0765628
// If this item isn't stackable we just need to find an open slot. | |
if (!item.Descriptor.Stackable) | |
{ | |
return FindOpenSlot() != -1; | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah but the code specifically said >= item.Quantity
not 1
-- it makes me think there's a case where something can be not stackable with a quantity > 1...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
that would be weird (?) but just to make sure, i can add this check back, although i would have to see how it behaves with this... which tbh feels weird, right now we are just looking away for an available slot whenever it comes to non-stackables, since they aren't supposed to ... stack together in a single a slot (?)
var depositMultipleItems = mPlayer.FindInventoryItemQuantity(inventoryItemItemId) > 1; | ||
var maxAmount = depositMultipleItems ? Math.Min(mPlayer.FindInventoryItemQuantity(inventoryItemItemId), | ||
FindAvailableSpaceForItem(inventoryItemItemId, amount)) : 1; | ||
amount = Math.Min(amount, maxAmount); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
depositMultipleItems
should be based on this line instead?
var maxAmount = depositMultipleItems ? Math.Min(mPlayer.FindInventoryItemQuantity(inventoryItemItemId), | ||
FindAvailableSpaceForItem(inventoryItemItemId, amount)) : 1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mPlayer.FindInventoryItemQuantity(inventoryItemItemId)
is repeated in both the condition and the branch, the branch is totally unnecessary here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be changed to
var inventoryQuantity = mPlayer.FindInventoryItemQuantity(inventoryItemItemId);
amount = Math.Min(amount, inventoryQuantity); // This is to optimize the next line
var availableStorageSpace = FindAvailableSpaceForItem(inventoryItemItemId, amount));
var maxAmount = Math.Min(inventoryQuantity, availableStorageSpace);
if (depositMultipleItems) | ||
{ | ||
if (destSlot < 0 || mBank?[destSlot]?.ItemId != Guid.Empty) | ||
{ | ||
// Try to find an open slot with the same item type and not at maximum stack size | ||
for (int i = 0; i < mMaxSlots; i++) | ||
{ | ||
var bankItem = mBank[i]; | ||
if (bankItem.ItemId == Guid.Empty || | ||
(bankItem.ItemId != Guid.Empty && bankItem.ItemId == inventoryItemItemId && | ||
amount + bankItem.Quantity < bankItem.Descriptor.MaxBankStack)) | ||
{ | ||
if (itemBase.IsStackable) | ||
{ | ||
PutItem(new Item(itemBase.Id, amount), destSlot, sendUpdate); | ||
mPlayer.TryTakeItem(itemBase.Id, amount, ItemHandling.Normal, sendUpdate); | ||
|
||
if (mGuild != null) | ||
{ | ||
DbInterface.Pool.QueueWorkItem(mGuild.Save); | ||
} | ||
|
||
return true; | ||
} | ||
else | ||
{ | ||
PutItem(mPlayer.Items[slot], destSlot, sendUpdate); | ||
|
||
mPlayer.Items[slot].Set(Item.None); | ||
mPlayer.EquipmentProcessItemLoss(slot); | ||
|
||
if (sendUpdate) | ||
{ | ||
PacketSender.SendInventoryItemUpdate(mPlayer, slot); | ||
} | ||
|
||
if (mGuild != null) | ||
{ | ||
DbInterface.Pool.QueueWorkItem(mGuild.Save); | ||
} | ||
|
||
return true; | ||
} | ||
destSlot = i; | ||
break; | ||
} | ||
else | ||
{ | ||
PacketSender.SendChatMsg(mPlayer, Strings.Banks.banknospace, ChatMessageType.Bank, CustomColors.Alerts.Error); | ||
} | ||
} | ||
} | ||
else | ||
} | ||
else | ||
{ | ||
if (destSlot < 0 || mBank?[destSlot]?.ItemId != Guid.Empty) | ||
{ | ||
PacketSender.SendChatMsg(mPlayer, Strings.Banks.depositinvalid, ChatMessageType.Bank, CustomColors.Alerts.Error); | ||
destSlot = FindOpenSlot(); | ||
} | ||
|
||
if (destSlot < 0) | ||
{ | ||
PacketSender.SendChatMsg(mPlayer, Strings.Banks.banknospace, ChatMessageType.Bank, | ||
CustomColors.Alerts.Error); | ||
return false; | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm wondering if generic and simpler logic is better than introducing an "if 1" condition
FindAvailableSpaceForItem(inventoryItemItemId, amount)) : 1; | ||
amount = Math.Min(amount, maxAmount); | ||
|
||
if (amount <= 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
amount < 1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maxAmount < 1 after the suggested changes (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, it would still be amount < 1
because you would not be getting rid of the last amount = Math.Min(amount, maxAmount);
e6db3c8
to
0f879b4
Compare
* Fixes: - Adjusts quantity and maxQuantity for stackable item's slider. - Checks if item is stackable when required so we don't unnecessarily show up the deposit slider on single equipment items. - Context menu bank deposit d/c fix: when destination slot is < 0 (context menu deposit) -> FindsOpenSlot and deposit. - Non-stackable items fix: we weren't checking stackable items properly, which translated into non-stackable items being placed over each other, leading to glitched bank slots. - Single stackable items (ie, an arrow) won't overwrite existing item(s) in slot anymore and they stack along with the rest of the same stackable items. * More fixes along with improvements: - We can now easily fill the bank when depositing stackable items, just drag the slider to the right! the server will make sure to adjust the amount and fill the required slots. - If the bank slot that an item is dropped on (slot is used as "hint") does not stack or is full of stackable items but there is still available slots in the bank, the server makes sure to find a new slot for non stackable items and fills the non-fully-stacked items. - If the bank slot used as "hint" is empty, the server fills the non-fully-stacked items and deposits the rest within the "hint" slot. - If there's no initial "hint" (ie, context menu deposit), then finds an open slot to deposit the rest of the stackable items. - Updates and simplifies the "CanStore" method to properly work along with this commit changes. - Creates the "FindAvailableSpaceForStackableItem" method which finds the amount of available space in the bank for a stackable item. - Added in-game system messages to be sent to players when successfully depositing and withdrawing items from the bank.
changes to CanStoreItem: - restored as public method. - properly checks for partial stack filling. - the for loop for stackable items has been removed from this boolean method as it was unnecessary. Checking for the destination slots is already performed outside of this method, making it redundant to have the loop here.
- Introduces the 'FindAvailableBankSpaceForItem' method to calculate the total available space within the bank for specific items. This enhancement streamlines the bank deposit process by automatically determining the appropriate values for the 'quantity' and 'maxQuantity' parameters in the deposit slider, improving user experience and accuracy when depositing items in the bank.
- Instead of blindly opening the item deposit slider when there's no space left in the bank, we now inform the player "There is no space left in your bank for that item!" before the slider is up with a max quantity of 0 (which is pointless to do).
( we don't really need to *Get* this value on each loop when calculating bank space ! )
- Properly checks default values - We don't need to get the maxBankStack on each calculation loop !
0f879b4
to
748bd38
Compare
Should resolve #1681
Fixes:
More fixes along with improvements:
Previews
~
(April 15th, 2023)
2023-04-15.01-30-35.mp4
~
2023-04-12.21-09-07.mp4
~
2023-04-12.21-10-50.mp4
~
2023-04-12.20-47-54.mp4