From 305843b4f0d4b9569bbfe7a724795e48f56ddb1d Mon Sep 17 00:00:00 2001 From: Danial Date: Wed, 6 Oct 2021 19:03:10 +1300 Subject: [PATCH 1/3] Banking fixes Fix withdrawing non stackable items as stacks Fix not being able to withdraw more noted items than you have space left in inventory. --- src/engine/world/items/item-container.ts | 3 ++- src/plugins/objects/bank/bank.plugin.ts | 10 ++++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/engine/world/items/item-container.ts b/src/engine/world/items/item-container.ts index 730a46bd4..af6b450b2 100644 --- a/src/engine/world/items/item-container.ts +++ b/src/engine/world/items/item-container.ts @@ -4,6 +4,7 @@ import { filestore } from '@server/game/game-server'; import { hasValueNotNull } from '@engine/util/data'; import { findItem } from '@engine/config/config-handler'; import { logger } from '@runejs/core'; +import { fromNote } from '.'; export interface ContainerUpdateEvent { @@ -308,7 +309,7 @@ export class ItemContainer { if(!itemDefinition) { throw new Error(`Item ID ${ item.itemId } not found!`); } - if(itemDefinition.stackable || everythingStacks) { + if(itemDefinition.stackable || everythingStacks || fromNote(item) > -1) { if(this.has(item.itemId)) { const invItem = this.items[this.findIndex(item.itemId)]; return invItem.amount + item.amount <= 2147483647; diff --git a/src/plugins/objects/bank/bank.plugin.ts b/src/plugins/objects/bank/bank.plugin.ts index c25c1976c..a958e71bd 100644 --- a/src/plugins/objects/bank/bank.plugin.ts +++ b/src/plugins/objects/bank/bank.plugin.ts @@ -114,10 +114,12 @@ export const withdrawItem: itemInteractionActionHandler = (details) => { } let itemIdToAdd: number = details.itemId; + let stackable = details.itemDetails.stackable; if (details.player.settings.bankWithdrawNoteMode) { const toNoteId: number = toNote(details.itemId); if (toNoteId > -1) { itemIdToAdd = toNoteId; + stackable = true; } else { details.player.sendMessage('This item can not be withdrawn as a note.'); } @@ -154,7 +156,7 @@ export const withdrawItem: itemInteractionActionHandler = (details) => { countToRemove = itemAmount; } - if (!details.itemDetails.stackable) { + if (!stackable) { const slots = playerInventory.getOpenSlotCount(); if (slots < countToRemove) { countToRemove = slots; @@ -170,7 +172,11 @@ export const withdrawItem: itemInteractionActionHandler = (details) => { amount: removeFromContainer(playerBank, details.itemId, countToRemove) }; - playerInventory.add({ itemId: itemToAdd.itemId, amount: itemToAdd.amount }); + if (stackable) + playerInventory.add({ itemId: itemToAdd.itemId, amount: itemToAdd.amount }); + else + for(let count = 0; count < itemToAdd.amount; count++) + playerInventory.add({ itemId: itemToAdd.itemId, amount: 1 }); updateBankingInterface(details.player); }; From 73cf9ada4fac867afd89a736527683c651d9bf1b Mon Sep 17 00:00:00 2001 From: Danial Date: Wed, 6 Oct 2021 20:27:32 +1300 Subject: [PATCH 2/3] fixup? --- src/engine/world/items/item-container.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/engine/world/items/item-container.ts b/src/engine/world/items/item-container.ts index af6b450b2..e77354865 100644 --- a/src/engine/world/items/item-container.ts +++ b/src/engine/world/items/item-container.ts @@ -4,7 +4,7 @@ import { filestore } from '@server/game/game-server'; import { hasValueNotNull } from '@engine/util/data'; import { findItem } from '@engine/config/config-handler'; import { logger } from '@runejs/core'; -import { fromNote } from '.'; +import { fromNote } from '@engine/world/items/item'; export interface ContainerUpdateEvent { From 10e1e47ca8ebb36ed29069f2b19861d937520460 Mon Sep 17 00:00:00 2001 From: Danial Date: Thu, 7 Oct 2021 00:33:40 +1300 Subject: [PATCH 3/3] Apply suggestions from code review --- src/plugins/objects/bank/bank.plugin.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/plugins/objects/bank/bank.plugin.ts b/src/plugins/objects/bank/bank.plugin.ts index a958e71bd..77c423d28 100644 --- a/src/plugins/objects/bank/bank.plugin.ts +++ b/src/plugins/objects/bank/bank.plugin.ts @@ -114,7 +114,7 @@ export const withdrawItem: itemInteractionActionHandler = (details) => { } let itemIdToAdd: number = details.itemId; - let stackable = details.itemDetails.stackable; + let stackable: boolean = details.itemDetails.stackable; if (details.player.settings.bankWithdrawNoteMode) { const toNoteId: number = toNote(details.itemId); if (toNoteId > -1) { @@ -172,11 +172,13 @@ export const withdrawItem: itemInteractionActionHandler = (details) => { amount: removeFromContainer(playerBank, details.itemId, countToRemove) }; - if (stackable) + if (stackable) { playerInventory.add({ itemId: itemToAdd.itemId, amount: itemToAdd.amount }); - else - for(let count = 0; count < itemToAdd.amount; count++) + } else { + for(let count = 0; count < itemToAdd.amount; count++) { playerInventory.add({ itemId: itemToAdd.itemId, amount: 1 }); + } + } updateBankingInterface(details.player); };