From 0666aad779566b067cc248919693011cbe4a8e67 Mon Sep 17 00:00:00 2001 From: Dev Date: Sun, 12 Nov 2023 10:10:34 +0000 Subject: [PATCH] Implement `Unbind` event handler Occurs when player moves item from quick access panel to inventory Small optimistion for `Bind` event, once item is found, exit loop --- project/src/callbacks/InventoryCallbacks.ts | 5 +++++ .../src/controllers/InventoryController.ts | 21 +++++++++++++++++++ project/src/models/enums/ItemEventActions.ts | 1 + .../item_events/InventoryItemEventRouter.ts | 3 +++ 4 files changed, 30 insertions(+) diff --git a/project/src/callbacks/InventoryCallbacks.ts b/project/src/callbacks/InventoryCallbacks.ts index f40d800d..433a36b7 100644 --- a/project/src/callbacks/InventoryCallbacks.ts +++ b/project/src/callbacks/InventoryCallbacks.ts @@ -84,6 +84,11 @@ export class InventoryCallbacks return this.inventoryController.bindItem(pmcData, body, sessionID); } + public unbindItem(pmcData: IPmcData, body: IInventoryBindRequestData, sessionID: string): IItemEventRouterResponse + { + return this.inventoryController.unbindItem(pmcData, body, sessionID); + } + public examineItem(pmcData: IPmcData, body: IInventoryExamineRequestData, sessionID: string): IItemEventRouterResponse { return this.inventoryController.examineItem(pmcData, body, sessionID); diff --git a/project/src/controllers/InventoryController.ts b/project/src/controllers/InventoryController.ts index 73ab6778..4d88c02b 100644 --- a/project/src/controllers/InventoryController.ts +++ b/project/src/controllers/InventoryController.ts @@ -518,6 +518,7 @@ export class InventoryController /** * Bind an inventory item to the quick access menu at bottom of player screen + * Handle bind event * @param pmcData Player profile * @param bindRequest Reqeust object * @param sessionID Session id @@ -527,17 +528,37 @@ export class InventoryController { for (const index in pmcData.Inventory.fastPanel) { + // Find item with existing item in it and remove existing binding, you cant have same item bound to more than 1 slot if (pmcData.Inventory.fastPanel[index] === bindRequest.item) { pmcData.Inventory.fastPanel[index] = ""; + + break; } } + // Create link between fast panel slot and requested item pmcData.Inventory.fastPanel[bindRequest.index] = bindRequest.item; return this.eventOutputHolder.getOutput(sessionID); } + /** + * Unbind an inventory item from quick access menu at bottom of player screen + * Handle unbind event + * @param pmcData Player profile + * @param bindRequest Request object + * @param sessionID Session id + * @returns IItemEventRouterResponse + */ + public unbindItem(pmcData: IPmcData, request: IInventoryBindRequestData, sessionID: string): IItemEventRouterResponse + { + // Remove kvp from requested fast panel index + delete pmcData.Inventory.fastPanel[request.index]; + + return this.eventOutputHolder.getOutput(sessionID); + } + /** * Handles examining an item diff --git a/project/src/models/enums/ItemEventActions.ts b/project/src/models/enums/ItemEventActions.ts index 83e1f45b..6c96a540 100644 --- a/project/src/models/enums/ItemEventActions.ts +++ b/project/src/models/enums/ItemEventActions.ts @@ -10,6 +10,7 @@ export enum ItemEventActions TOGGLE = "Toggle", TAG = "Tag", BIND = "Bind", + UNBIND = "Unbind", EXAMINE = "Examine", READ_ENCYCLOPEDIA = "ReadEncyclopedia", APPLY_INVENTORY_CHANGES = "ApplyInventoryChanges", diff --git a/project/src/routers/item_events/InventoryItemEventRouter.ts b/project/src/routers/item_events/InventoryItemEventRouter.ts index 90267a03..54d19728 100644 --- a/project/src/routers/item_events/InventoryItemEventRouter.ts +++ b/project/src/routers/item_events/InventoryItemEventRouter.ts @@ -32,6 +32,7 @@ export class InventoryItemEventRouter extends ItemEventRouterDefinition new HandledRoute(ItemEventActions.TOGGLE, false), new HandledRoute(ItemEventActions.TAG, false), new HandledRoute(ItemEventActions.BIND, false), + new HandledRoute(ItemEventActions.UNBIND, false), new HandledRoute(ItemEventActions.EXAMINE, false), new HandledRoute(ItemEventActions.READ_ENCYCLOPEDIA, false), new HandledRoute(ItemEventActions.APPLY_INVENTORY_CHANGES, false), @@ -67,6 +68,8 @@ export class InventoryItemEventRouter extends ItemEventRouterDefinition return this.inventoryCallbacks.tagItem(pmcData, body, sessionID); case ItemEventActions.BIND: return this.inventoryCallbacks.bindItem(pmcData, body, sessionID); + case ItemEventActions.UNBIND: + return this.inventoryCallbacks.unbindItem(pmcData, body, sessionID); case ItemEventActions.EXAMINE: return this.inventoryCallbacks.examineItem(pmcData, body, sessionID); case ItemEventActions.READ_ENCYCLOPEDIA: