diff --git a/project/src/callbacks/WishlistCallbacks.ts b/project/src/callbacks/WishlistCallbacks.ts index e7cea1aa..7f103231 100644 --- a/project/src/callbacks/WishlistCallbacks.ts +++ b/project/src/callbacks/WishlistCallbacks.ts @@ -2,7 +2,9 @@ import { inject, injectable } from "tsyringe"; import { WishlistController } from "@spt/controllers/WishlistController"; import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; -import { IWishlistActionData } from "@spt/models/eft/wishlist/IWishlistActionData"; +import { IAddToWishlistRequest } from "@spt/models/eft/wishlist/IAddToWishlistRequest"; +import { IChangeWishlistItemCategoryRequest } from "@spt/models/eft/wishlist/IChangeWishlistItemCategoryRequest"; +import { IRemoveFromWishlistRequest } from "@spt/models/eft/wishlist/IRemoveFromWishlistRequest"; @injectable() export class WishlistCallbacks @@ -11,18 +13,32 @@ export class WishlistCallbacks {} /** Handle AddToWishList event */ - public addToWishlist(pmcData: IPmcData, body: IWishlistActionData, sessionID: string): IItemEventRouterResponse + public addToWishlist( + pmcData: IPmcData, + request: IAddToWishlistRequest, + sessionID: string, + ): IItemEventRouterResponse { - return this.wishlistController.addToWishList(pmcData, body, sessionID); + return this.wishlistController.addToWishList(pmcData, request, sessionID); } /** Handle RemoveFromWishList event */ public removeFromWishlist( pmcData: IPmcData, - body: IWishlistActionData, + request: IRemoveFromWishlistRequest, sessionID: string, ): IItemEventRouterResponse { - return this.wishlistController.removeFromWishList(pmcData, body, sessionID); + return this.wishlistController.removeFromWishList(pmcData, request, sessionID); + } + + /** Handle ChangeWishlistItemCategory */ + changeWishlistItemCategory( + pmcData: IPmcData, + request: IChangeWishlistItemCategoryRequest, + sessionID: string, + ): IItemEventRouterResponse + { + return this.wishlistController.changeWishlistItemCategory(pmcData, request, sessionID); } } diff --git a/project/src/controllers/GameController.ts b/project/src/controllers/GameController.ts index a73eaa89..30cab90c 100644 --- a/project/src/controllers/GameController.ts +++ b/project/src/controllers/GameController.ts @@ -152,6 +152,16 @@ export class GameController return; } + if (Array.isArray(fullProfile.characters.pmc.WishList)) + { + fullProfile.characters.pmc.WishList = {}; + } + + if (Array.isArray(fullProfile.characters.scav.WishList)) + { + fullProfile.characters.scav.WishList = {}; + } + const pmcProfile = fullProfile.characters.pmc; this.logger.debug(`Started game with sessionId: ${sessionID} ${pmcProfile.Info?.Nickname}`); diff --git a/project/src/controllers/WishlistController.ts b/project/src/controllers/WishlistController.ts index 0f270d48..373719e2 100644 --- a/project/src/controllers/WishlistController.ts +++ b/project/src/controllers/WishlistController.ts @@ -1,7 +1,9 @@ import { inject, injectable } from "tsyringe"; import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; -import { IWishlistActionData } from "@spt/models/eft/wishlist/IWishlistActionData"; +import { IAddToWishlistRequest } from "@spt/models/eft/wishlist/IAddToWishlistRequest"; +import { IChangeWishlistItemCategoryRequest } from "@spt/models/eft/wishlist/IChangeWishlistItemCategoryRequest"; +import { IRemoveFromWishlistRequest } from "@spt/models/eft/wishlist/IRemoveFromWishlistRequest"; import { EventOutputHolder } from "@spt/routers/EventOutputHolder"; @injectable() @@ -11,37 +13,40 @@ export class WishlistController {} /** Handle AddToWishList */ - public addToWishList(pmcData: IPmcData, body: IWishlistActionData, sessionID: string): IItemEventRouterResponse + public addToWishList(pmcData: IPmcData, request: IAddToWishlistRequest, sessionID: string): IItemEventRouterResponse { - for (const item in pmcData.WishList) + for (const itemId of Object.keys(request.items)) { - // Don't add the item - if (pmcData.WishList[item] === body.templateId) - { - return this.eventOutputHolder.getOutput(sessionID); - } + pmcData.WishList[itemId] = request.items[itemId]; } - // add the item to the wishlist - pmcData.WishList.push(body.templateId); return this.eventOutputHolder.getOutput(sessionID); } /** Handle RemoveFromWishList event */ public removeFromWishList( pmcData: IPmcData, - body: IWishlistActionData, + request: IRemoveFromWishlistRequest, sessionID: string, ): IItemEventRouterResponse { - for (let i = 0; i < pmcData.WishList.length; i++) + for (const itemId of request.items) { - if (pmcData.WishList[i] === body.templateId) - { - pmcData.WishList.splice(i, 1); - } + delete pmcData.WishList[itemId]; } return this.eventOutputHolder.getOutput(sessionID); } + + /** Handle changeWishlistItemCategory event */ + public changeWishlistItemCategory( + pmcData: IPmcData, + request: IChangeWishlistItemCategoryRequest, + sessionID: string, + ): IItemEventRouterResponse + { + pmcData.WishList[request.item] = request.category; + + return this.eventOutputHolder.getOutput(sessionID); + } } diff --git a/project/src/generators/PlayerScavGenerator.ts b/project/src/generators/PlayerScavGenerator.ts index 1cc80859..c9208c5c 100644 --- a/project/src/generators/PlayerScavGenerator.ts +++ b/project/src/generators/PlayerScavGenerator.ts @@ -112,7 +112,7 @@ export class PlayerScavGenerator scavData.Quests = existingScavDataClone.Quests ?? []; scavData.TaskConditionCounters = existingScavDataClone.TaskConditionCounters ?? {}; scavData.Notes = existingScavDataClone.Notes ?? { Notes: [] }; - scavData.WishList = existingScavDataClone.WishList ?? []; + scavData.WishList = existingScavDataClone.WishList ?? {}; scavData.Encyclopedia = pmcDataClone.Encyclopedia ?? {}; // Add additional items to player scav as loot diff --git a/project/src/models/eft/common/tables/IBotBase.ts b/project/src/models/eft/common/tables/IBotBase.ts index 27550cc0..d2d3ef53 100644 --- a/project/src/models/eft/common/tables/IBotBase.ts +++ b/project/src/models/eft/common/tables/IBotBase.ts @@ -36,7 +36,7 @@ export interface IBotBase CarExtractCounts: Record CoopExtractCounts: Record SurvivorClass: SurvivorClass - WishList: string[] + WishList: Record moneyTransferLimitData: IMoneyTransferLimits /** SPT specific property used during bot generation in raid */ sptIsPmc?: boolean diff --git a/project/src/models/eft/wishlist/IAddToWishlistRequest.ts b/project/src/models/eft/wishlist/IAddToWishlistRequest.ts new file mode 100644 index 00000000..107fe1ba --- /dev/null +++ b/project/src/models/eft/wishlist/IAddToWishlistRequest.ts @@ -0,0 +1,5 @@ +export interface IAddToWishlistRequest +{ + Action: string + items: Record +} diff --git a/project/src/models/eft/wishlist/IChangeWishlistItemCategoryRequest.ts b/project/src/models/eft/wishlist/IChangeWishlistItemCategoryRequest.ts new file mode 100644 index 00000000..76c84254 --- /dev/null +++ b/project/src/models/eft/wishlist/IChangeWishlistItemCategoryRequest.ts @@ -0,0 +1,6 @@ +export interface IChangeWishlistItemCategoryRequest +{ + Action: string + item: string + category: number +} diff --git a/project/src/models/eft/wishlist/IRemoveFromWishlistRequest.ts b/project/src/models/eft/wishlist/IRemoveFromWishlistRequest.ts new file mode 100644 index 00000000..8aca5cab --- /dev/null +++ b/project/src/models/eft/wishlist/IRemoveFromWishlistRequest.ts @@ -0,0 +1,5 @@ +export interface IRemoveFromWishlistRequest +{ + Action: string + items: string[] +} diff --git a/project/src/models/eft/wishlist/IWishlistActionData.ts b/project/src/models/eft/wishlist/IWishlistActionData.ts deleted file mode 100644 index d44d002f..00000000 --- a/project/src/models/eft/wishlist/IWishlistActionData.ts +++ /dev/null @@ -1,5 +0,0 @@ -export interface IWishlistActionData -{ - Action: string - templateId: string -} diff --git a/project/src/routers/item_events/WishlistItemEventRouter.ts b/project/src/routers/item_events/WishlistItemEventRouter.ts index 69166a56..dfa1cd8f 100644 --- a/project/src/routers/item_events/WishlistItemEventRouter.ts +++ b/project/src/routers/item_events/WishlistItemEventRouter.ts @@ -14,22 +14,28 @@ export class WishlistItemEventRouter extends ItemEventRouterDefinition public override getHandledRoutes(): HandledRoute[] { - return [new HandledRoute("AddToWishList", false), new HandledRoute("RemoveFromWishList", false)]; + return [ + new HandledRoute("AddToWishList", false), + new HandledRoute("RemoveFromWishList", false), + new HandledRoute("ChangeWishlistItemCategory", false), + ]; } public override async handleItemEvent( url: string, pmcData: IPmcData, - body: any, + request: any, sessionID: string, ): Promise { switch (url) { case "AddToWishList": - return this.wishlistCallbacks.addToWishlist(pmcData, body, sessionID); + return this.wishlistCallbacks.addToWishlist(pmcData, request, sessionID); case "RemoveFromWishList": - return this.wishlistCallbacks.removeFromWishlist(pmcData, body, sessionID); + return this.wishlistCallbacks.removeFromWishlist(pmcData, request, sessionID); + case "ChangeWishlistItemCategory": + return this.wishlistCallbacks.changeWishlistItemCategory(pmcData, request, sessionID); } } }