From 922adcfb5cdc09b4b53ea634472cc8a1cf2ee368 Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 1 Nov 2024 10:01:26 +0000 Subject: [PATCH] Implemented pin/lock/free on inventory items --- project/src/callbacks/InventoryCallbacks.ts | 8 +++--- .../src/controllers/InventoryController.ts | 27 +++++++++++++++++++ project/src/controllers/QuestController.ts | 17 ------------ project/src/models/eft/common/tables/IItem.ts | 7 +++++ .../models/eft/inventory/IPinItemRequest.ts | 7 ----- .../eft/inventory/IPinOrLockItemRequest.ts | 9 +++++++ project/src/models/enums/ItemEventActions.ts | 2 +- .../item_events/InventoryItemEventRouter.ts | 5 ++-- 8 files changed, 51 insertions(+), 31 deletions(-) delete mode 100644 project/src/models/eft/inventory/IPinItemRequest.ts create mode 100644 project/src/models/eft/inventory/IPinOrLockItemRequest.ts diff --git a/project/src/callbacks/InventoryCallbacks.ts b/project/src/callbacks/InventoryCallbacks.ts index b78b5d53..a9331989 100644 --- a/project/src/callbacks/InventoryCallbacks.ts +++ b/project/src/callbacks/InventoryCallbacks.ts @@ -18,7 +18,7 @@ import { IInventoryTagRequestData } from "@spt/models/eft/inventory/IInventoryTa import { IInventoryToggleRequestData } from "@spt/models/eft/inventory/IInventoryToggleRequestData"; import { IInventoryTransferRequestData } from "@spt/models/eft/inventory/IInventoryTransferRequestData"; import { IOpenRandomLootContainerRequestData } from "@spt/models/eft/inventory/IOpenRandomLootContainerRequestData"; -import { IPinItemRequest } from "@spt/models/eft/inventory/IPinItemRequest"; +import { IPinOrLockItemRequest } from "@spt/models/eft/inventory/IPinOrLockItemRequest"; import { IRedeemProfileRequestData } from "@spt/models/eft/inventory/IRedeemProfileRequestData"; import { ISetFavoriteItems } from "@spt/models/eft/inventory/ISetFavoriteItems"; import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; @@ -238,12 +238,12 @@ export class InventoryCallbacks { return this.questController.failQuest(pmcData, request, sessionID, output); } - public pin( + public pinOrLock( pmcData: IPmcData, - request: IPinItemRequest, + request: IPinOrLockItemRequest, sessionID: string, output: IItemEventRouterResponse, ): IItemEventRouterResponse { - return this.questController.pin(pmcData, request, sessionID, output); + return this.inventoryController.pinOrLock(pmcData, request, sessionID, output); } } diff --git a/project/src/controllers/InventoryController.ts b/project/src/controllers/InventoryController.ts index 4db0b0aa..8595656a 100644 --- a/project/src/controllers/InventoryController.ts +++ b/project/src/controllers/InventoryController.ts @@ -27,6 +27,7 @@ import { IInventoryTagRequestData } from "@spt/models/eft/inventory/IInventoryTa import { IInventoryToggleRequestData } from "@spt/models/eft/inventory/IInventoryToggleRequestData"; import { IInventoryTransferRequestData } from "@spt/models/eft/inventory/IInventoryTransferRequestData"; import { IOpenRandomLootContainerRequestData } from "@spt/models/eft/inventory/IOpenRandomLootContainerRequestData"; +import { IPinOrLockItemRequest } from "@spt/models/eft/inventory/IPinOrLockItemRequest"; import { IRedeemProfileRequestData } from "@spt/models/eft/inventory/IRedeemProfileRequestData"; import { ISetFavoriteItems } from "@spt/models/eft/inventory/ISetFavoriteItems"; import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; @@ -947,4 +948,30 @@ export class InventoryController { } } } + + /** + * Handle /client/game/profile/items/moving - PinLock + * Requires no response to client, only server change + * @param pmcData Players profile + * @param request Pin/Lock request data + * @param sessionID Session id + * @param output data to send back to client + */ + public pinOrLock( + pmcData: IPmcData, + request: IPinOrLockItemRequest, + sessionID: string, + output: IItemEventRouterResponse, + ): IItemEventRouterResponse { + const itemToAdjust = pmcData.Inventory.items.find((item) => item._id === request.Item); + if (!itemToAdjust) { + this.logger.error(`Unable find item: ${request.Item} to: ${request.State} on player ${sessionID} to: `); + return output; + } + + itemToAdjust.upd ||= {}; + itemToAdjust.upd.PinLockState = request.State; + + return output; + } } diff --git a/project/src/controllers/QuestController.ts b/project/src/controllers/QuestController.ts index 3548980e..328e804f 100644 --- a/project/src/controllers/QuestController.ts +++ b/project/src/controllers/QuestController.ts @@ -8,7 +8,6 @@ import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { IItem } from "@spt/models/eft/common/tables/IItem"; import { IQuest, IQuestCondition } from "@spt/models/eft/common/tables/IQuest"; import { IPmcDataRepeatableQuest, IRepeatableQuest } from "@spt/models/eft/common/tables/IRepeatableQuests"; -import { IPinItemRequest } from "@spt/models/eft/inventory/IPinItemRequest"; import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; import { IAcceptQuestRequestData } from "@spt/models/eft/quests/IAcceptQuestRequestData"; import { ICompleteQuestRequestData } from "@spt/models/eft/quests/ICompleteQuestRequestData"; @@ -523,20 +522,4 @@ export class QuestController { return output; } - - /** - * Handle /client/game/profile/items/moving - PinLock - * @param pmcData - * @param request - * @param sessionID - * @param output - */ - public pin( - pmcData: IPmcData, - request: IPinItemRequest, - sessionID: string, - output: IItemEventRouterResponse, - ): IItemEventRouterResponse { - throw new Error("Method not implemented."); - } } diff --git a/project/src/models/eft/common/tables/IItem.ts b/project/src/models/eft/common/tables/IItem.ts index 8aba488b..21820ab7 100644 --- a/project/src/models/eft/common/tables/IItem.ts +++ b/project/src/models/eft/common/tables/IItem.ts @@ -44,6 +44,13 @@ export interface IUpd { SideEffect?: IUpdSideEffect; RepairKit?: IUpdRepairKit; CultistAmulet?: IUpdCultistAmulet; + PinLockState?: PinLockState; +} + +export enum PinLockState { + FREE = "Free", + LOCKED = "Locked", + PINNED = "Pinned", } export interface IUpdBuff { diff --git a/project/src/models/eft/inventory/IPinItemRequest.ts b/project/src/models/eft/inventory/IPinItemRequest.ts deleted file mode 100644 index 156978f4..00000000 --- a/project/src/models/eft/inventory/IPinItemRequest.ts +++ /dev/null @@ -1,7 +0,0 @@ -export interface IPinItemRequest { - Action: "PinLock"; - /** Id of item being pinned */ - Item: string; - /** "Pinned"/"" */ - State: string; -} diff --git a/project/src/models/eft/inventory/IPinOrLockItemRequest.ts b/project/src/models/eft/inventory/IPinOrLockItemRequest.ts new file mode 100644 index 00000000..796c273e --- /dev/null +++ b/project/src/models/eft/inventory/IPinOrLockItemRequest.ts @@ -0,0 +1,9 @@ +import { PinLockState } from "../common/tables/IItem"; + +export interface IPinOrLockItemRequest { + Action: "PinLock"; + /** Id of item being pinned */ + Item: string; + /** "Pinned"/"Locked"/"Free" */ + State: PinLockState; +} diff --git a/project/src/models/enums/ItemEventActions.ts b/project/src/models/enums/ItemEventActions.ts index a64970a6..5d563c8b 100644 --- a/project/src/models/enums/ItemEventActions.ts +++ b/project/src/models/enums/ItemEventActions.ts @@ -26,5 +26,5 @@ export enum ItemEventActions { REDEEM_PROFILE_REWARD = "RedeemProfileReward", SET_FAVORITE_ITEMS = "SetFavoriteItems", QUEST_FAIL = "QuestFail", - PIN = "PinLock", + PIN_LOCK = "PinLock", } diff --git a/project/src/routers/item_events/InventoryItemEventRouter.ts b/project/src/routers/item_events/InventoryItemEventRouter.ts index a01a9158..2a0c6cfa 100644 --- a/project/src/routers/item_events/InventoryItemEventRouter.ts +++ b/project/src/routers/item_events/InventoryItemEventRouter.ts @@ -39,6 +39,7 @@ export class InventoryItemEventRouter extends ItemEventRouterDefinition { new HandledRoute(ItemEventActions.REDEEM_PROFILE_REWARD, false), new HandledRoute(ItemEventActions.SET_FAVORITE_ITEMS, false), new HandledRoute(ItemEventActions.QUEST_FAIL, false), + new HandledRoute(ItemEventActions.PIN_LOCK, false), ]; } @@ -94,8 +95,8 @@ export class InventoryItemEventRouter extends ItemEventRouterDefinition { return this.inventoryCallbacks.setFavoriteItem(pmcData, body, sessionID, output); case ItemEventActions.QUEST_FAIL: return this.inventoryCallbacks.failQuest(pmcData, body, sessionID, output); - case ItemEventActions.PIN: - return this.inventoryCallbacks.pin(pmcData, body, sessionID, output); + case ItemEventActions.PIN_LOCK: + return this.inventoryCallbacks.pinOrLock(pmcData, body, sessionID, output); default: throw new Error(`Unhandled event ${url} request: ${JSON.stringify(body)}`); }