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
This commit is contained in:
Dev 2023-11-12 10:10:34 +00:00
parent 6547a767ef
commit 0666aad779
4 changed files with 30 additions and 0 deletions

View File

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

View File

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

View File

@ -10,6 +10,7 @@ export enum ItemEventActions
TOGGLE = "Toggle",
TAG = "Tag",
BIND = "Bind",
UNBIND = "Unbind",
EXAMINE = "Examine",
READ_ENCYCLOPEDIA = "ReadEncyclopedia",
APPLY_INVENTORY_CHANGES = "ApplyInventoryChanges",

View File

@ -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: