Implemented new wishlist system

This commit is contained in:
Dev 2024-07-05 15:06:43 +01:00
parent b4a5556d14
commit ce0123efd3
10 changed files with 80 additions and 32 deletions

View File

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

View File

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

View File

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

View File

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

View File

@ -36,7 +36,7 @@ export interface IBotBase
CarExtractCounts: Record<string, number>
CoopExtractCounts: Record<string, number>
SurvivorClass: SurvivorClass
WishList: string[]
WishList: Record<string, number>
moneyTransferLimitData: IMoneyTransferLimits
/** SPT specific property used during bot generation in raid */
sptIsPmc?: boolean

View File

@ -0,0 +1,5 @@
export interface IAddToWishlistRequest
{
Action: string
items: Record<string, number>
}

View File

@ -0,0 +1,6 @@
export interface IChangeWishlistItemCategoryRequest
{
Action: string
item: string
category: number
}

View File

@ -0,0 +1,5 @@
export interface IRemoveFromWishlistRequest
{
Action: string
items: string[]
}

View File

@ -1,5 +0,0 @@
export interface IWishlistActionData
{
Action: string
templateId: string
}

View File

@ -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<IItemEventRouterResponse>
{
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);
}
}
}