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 { WishlistController } from "@spt/controllers/WishlistController";
import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; 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() @injectable()
export class WishlistCallbacks export class WishlistCallbacks
@ -11,18 +13,32 @@ export class WishlistCallbacks
{} {}
/** Handle AddToWishList event */ /** 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 */ /** Handle RemoveFromWishList event */
public removeFromWishlist( public removeFromWishlist(
pmcData: IPmcData, pmcData: IPmcData,
body: IWishlistActionData, request: IRemoveFromWishlistRequest,
sessionID: string, sessionID: string,
): IItemEventRouterResponse ): 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; 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; const pmcProfile = fullProfile.characters.pmc;
this.logger.debug(`Started game with sessionId: ${sessionID} ${pmcProfile.Info?.Nickname}`); this.logger.debug(`Started game with sessionId: ${sessionID} ${pmcProfile.Info?.Nickname}`);

View File

@ -1,7 +1,9 @@
import { inject, injectable } from "tsyringe"; import { inject, injectable } from "tsyringe";
import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { IPmcData } from "@spt/models/eft/common/IPmcData";
import { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; 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"; import { EventOutputHolder } from "@spt/routers/EventOutputHolder";
@injectable() @injectable()
@ -11,37 +13,40 @@ export class WishlistController
{} {}
/** Handle AddToWishList */ /** 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 pmcData.WishList[itemId] = request.items[itemId];
if (pmcData.WishList[item] === body.templateId)
{
return this.eventOutputHolder.getOutput(sessionID);
}
} }
// add the item to the wishlist
pmcData.WishList.push(body.templateId);
return this.eventOutputHolder.getOutput(sessionID); return this.eventOutputHolder.getOutput(sessionID);
} }
/** Handle RemoveFromWishList event */ /** Handle RemoveFromWishList event */
public removeFromWishList( public removeFromWishList(
pmcData: IPmcData, pmcData: IPmcData,
body: IWishlistActionData, request: IRemoveFromWishlistRequest,
sessionID: string, sessionID: string,
): IItemEventRouterResponse ): IItemEventRouterResponse
{ {
for (let i = 0; i < pmcData.WishList.length; i++) for (const itemId of request.items)
{ {
if (pmcData.WishList[i] === body.templateId) delete pmcData.WishList[itemId];
{
pmcData.WishList.splice(i, 1);
}
} }
return this.eventOutputHolder.getOutput(sessionID); 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.Quests = existingScavDataClone.Quests ?? [];
scavData.TaskConditionCounters = existingScavDataClone.TaskConditionCounters ?? {}; scavData.TaskConditionCounters = existingScavDataClone.TaskConditionCounters ?? {};
scavData.Notes = existingScavDataClone.Notes ?? { Notes: [] }; scavData.Notes = existingScavDataClone.Notes ?? { Notes: [] };
scavData.WishList = existingScavDataClone.WishList ?? []; scavData.WishList = existingScavDataClone.WishList ?? {};
scavData.Encyclopedia = pmcDataClone.Encyclopedia ?? {}; scavData.Encyclopedia = pmcDataClone.Encyclopedia ?? {};
// Add additional items to player scav as loot // Add additional items to player scav as loot

View File

@ -36,7 +36,7 @@ export interface IBotBase
CarExtractCounts: Record<string, number> CarExtractCounts: Record<string, number>
CoopExtractCounts: Record<string, number> CoopExtractCounts: Record<string, number>
SurvivorClass: SurvivorClass SurvivorClass: SurvivorClass
WishList: string[] WishList: Record<string, number>
moneyTransferLimitData: IMoneyTransferLimits moneyTransferLimitData: IMoneyTransferLimits
/** SPT specific property used during bot generation in raid */ /** SPT specific property used during bot generation in raid */
sptIsPmc?: boolean 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[] 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( public override async handleItemEvent(
url: string, url: string,
pmcData: IPmcData, pmcData: IPmcData,
body: any, request: any,
sessionID: string, sessionID: string,
): Promise<IItemEventRouterResponse> ): Promise<IItemEventRouterResponse>
{ {
switch (url) switch (url)
{ {
case "AddToWishList": case "AddToWishList":
return this.wishlistCallbacks.addToWishlist(pmcData, body, sessionID); return this.wishlistCallbacks.addToWishlist(pmcData, request, sessionID);
case "RemoveFromWishList": 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);
} }
} }
} }