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

fix: bank deposit behavior #1720

Closed
wants to merge 10 commits into from
Closed

fix: bank deposit behavior #1720

wants to merge 10 commits into from

Conversation

Arufonsu
Copy link
Contributor

@Arufonsu Arufonsu commented Feb 3, 2023

Should resolve #1681

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.

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

@Arufonsu Arufonsu requested review from a team February 3, 2023 08:24
@Arufonsu Arufonsu marked this pull request as draft February 3, 2023 16:57
@Arufonsu Arufonsu marked this pull request as ready for review February 3, 2023 17:22
@lodicolo
Copy link
Member

lodicolo commented Feb 5, 2023

@Arufonsu Both of the videos look like the broken behavior, where is a video of the correct behavior with this fix?

@lodicolo
Copy link
Member

lodicolo commented Feb 6, 2023

From Discord:

If the bank slot does not stack but there is space in the bank still, the move should not fail
the slot that an item is dropped on should be a "hint" not an absolute "this is where it goes"

That should be addressed too in this PR.

@Arufonsu Arufonsu marked this pull request as draft February 8, 2023 00:41
@Arufonsu Arufonsu added the help wanted Extra attention is needed label Mar 29, 2023
@Arufonsu Arufonsu force-pushed the aru/fix-TryDepositItem branch from ccc385b to 53d4df3 Compare April 12, 2023 02:51
@Arufonsu Arufonsu marked this pull request as ready for review April 12, 2023 02:52
@Arufonsu
Copy link
Contributor Author

Updated PR, code and video previews, so far this manages to fix the issues and behaves as expected, discussed and suggested 👍🏽

@Arufonsu Arufonsu force-pushed the aru/fix-TryDepositItem branch from 53d4df3 to b8782af Compare April 12, 2023 03:12
@Arufonsu Arufonsu marked this pull request as draft April 12, 2023 19:12
@Arufonsu Arufonsu force-pushed the aru/fix-TryDepositItem branch from b8782af to 21d88be Compare April 13, 2023 00:46
@Arufonsu Arufonsu marked this pull request as ready for review April 13, 2023 00:48
@Arufonsu Arufonsu marked this pull request as draft April 13, 2023 00:57
@Arufonsu Arufonsu force-pushed the aru/fix-TryDepositItem branch from 21d88be to 267ef4a Compare April 13, 2023 01:08
@Arufonsu Arufonsu marked this pull request as ready for review April 13, 2023 01:08
@Arufonsu Arufonsu marked this pull request as draft April 14, 2023 02:39
@Arufonsu Arufonsu force-pushed the aru/fix-TryDepositItem branch 4 times, most recently from 74b76c2 to f18b668 Compare April 15, 2023 05:27
@Arufonsu Arufonsu changed the title fix: TryDepositItem behavior fix: bank deposit behavior Apr 15, 2023
@Arufonsu Arufonsu added the enhancement Minor feature addition or quality of life change label Apr 15, 2023
@Arufonsu
Copy link
Contributor Author

Arufonsu commented Apr 15, 2023

Updated PR (lot of force pushes, won't happen after the first review - unless is required by the maintainer).
Fixed some logic issues i've encountered, also added some nice additions, preview:

2023-04-15.01-30-35.mp4

Hopefully this yields the expected behavior, PR feels ready for review as well 👍🏽

@Arufonsu Arufonsu marked this pull request as ready for review April 15, 2023 05:42
@Arufonsu Arufonsu marked this pull request as draft April 16, 2023 03:28
@Arufonsu Arufonsu force-pushed the aru/fix-TryDepositItem branch from 948ff6b to e5e8c88 Compare April 16, 2023 05:09
@Arufonsu Arufonsu requested review from AlexVild, jcsnider, WeylonSantana and a team August 27, 2023 05:12
@Arufonsu Arufonsu marked this pull request as ready for review August 27, 2023 05:12
@Arufonsu
Copy link
Contributor Author

Arufonsu commented Aug 27, 2023

self-reminder: restored the ability to deposit multiple non-stackable items

2023-08-27.00-58-01.mp4

PR is ready for review and it's about to be built and published by @intersectbot for the ease of testing ~

@AscensionGameDev AscensionGameDev deleted a comment from intersectbot Aug 27, 2023
@Arufonsu Arufonsu added the bug Something isn't working label Aug 27, 2023
@AscensionGameDev AscensionGameDev deleted a comment from intersectbot Aug 27, 2023
@Arufonsu
Copy link
Contributor Author

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

@Arufonsu
Copy link
Contributor Author

client enhancement: NoSpace bank system message

  • 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).
2023-08-27.15-09-12.mp4

Copy link
Member

@lodicolo lodicolo left a 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)
Copy link
Member

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)
Copy link
Member

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?

Copy link
Contributor Author

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:

// If this item isn't stackable we just need to find an open slot.
if (!item.Descriptor.Stackable)
{
return FindOpenSlot() != -1;
}

Copy link
Member

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...

Copy link
Contributor Author

@Arufonsu Arufonsu Aug 27, 2023

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);
Copy link
Member

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?

Comment on lines 343 to 344
var maxAmount = depositMultipleItems ? Math.Min(mPlayer.FindInventoryItemQuantity(inventoryItemItemId),
FindAvailableSpaceForItem(inventoryItemItemId, amount)) : 1;
Copy link
Member

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.

Copy link
Member

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);

Comment on lines 354 to 394
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;
}
}
Copy link
Member

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

amount < 1

Copy link
Contributor Author

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 (?)

Copy link
Member

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);

@Arufonsu Arufonsu requested a review from lodicolo August 27, 2023 23:59
@Arufonsu Arufonsu force-pushed the aru/fix-TryDepositItem branch from e6db3c8 to 0f879b4 Compare October 2, 2023 23:38
* 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 !
@Arufonsu Arufonsu force-pushed the aru/fix-TryDepositItem branch from 0f879b4 to 748bd38 Compare October 13, 2023 00:17
@Arufonsu Arufonsu self-assigned this Oct 13, 2023
@Arufonsu Arufonsu closed this Oct 21, 2023
@Arufonsu Arufonsu mentioned this pull request Oct 21, 2023
@Arufonsu Arufonsu deleted the aru/fix-TryDepositItem branch March 10, 2024 05:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement Minor feature addition or quality of life change help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

bug: single stackable item from inventory to the bank
2 participants