From d5f9c1f2539966291402530417b0f9b3d6077f03 Mon Sep 17 00:00:00 2001 From: Chomp Date: Mon, 30 Dec 2024 16:55:32 +0000 Subject: [PATCH] Implemented updated endpoint for applying clothing to a players character Fixed dogtag customisation choice not being saved to the correct parameter Removed dead endpoint --- .../src/callbacks/CustomizationCallbacks.ts | 11 --- .../controllers/CustomizationController.ts | 76 +++++++++++-------- .../CustomizationItemEventRouter.ts | 2 - 3 files changed, 44 insertions(+), 45 deletions(-) diff --git a/project/src/callbacks/CustomizationCallbacks.ts b/project/src/callbacks/CustomizationCallbacks.ts index 9ef1c03d..c9df7ebc 100644 --- a/project/src/callbacks/CustomizationCallbacks.ts +++ b/project/src/callbacks/CustomizationCallbacks.ts @@ -42,17 +42,6 @@ export class CustomizationCallbacks { return this.httpResponse.getBody(this.customizationController.getTraderSuits(traderID, sessionID)); } - /** - * Handle CustomizationWear event - */ - public wearClothing( - pmcData: IPmcData, - body: IWearClothingRequestData, - sessionID: string, - ): IItemEventRouterResponse { - return this.customizationController.wearClothing(pmcData, body, sessionID); - } - /** * Handle CustomizationBuy event */ diff --git a/project/src/controllers/CustomizationController.ts b/project/src/controllers/CustomizationController.ts index e8991297..704e9d65 100644 --- a/project/src/controllers/CustomizationController.ts +++ b/project/src/controllers/CustomizationController.ts @@ -7,13 +7,14 @@ import type { IBuyClothingRequestData, IPaymentItemForClothing, } from "@spt/models/eft/customization/IBuyClothingRequestData"; -import type { ICustomizationSetRequest } from "@spt/models/eft/customization/ICustomizationSetRequest"; -import type { IWearClothingRequestData } from "@spt/models/eft/customization/IWearClothingRequestData"; +import type { + CustomizationSetOption, + ICustomizationSetRequest, +} from "@spt/models/eft/customization/ICustomizationSetRequest"; import type { IHideoutCustomisation } from "@spt/models/eft/hideout/IHideoutCustomisation"; import type { IItemEventRouterResponse } from "@spt/models/eft/itemEvent/IItemEventRouterResponse"; import { ISptProfile } from "@spt/models/eft/profile/ISptProfile"; import { GameEditions } from "@spt/models/enums/GameEditions"; -import { ItemTpl } from "@spt/models/enums/ItemTpl"; import type { ILogger } from "@spt/models/spt/utils/ILogger"; import { EventOutputHolder } from "@spt/routers/EventOutputHolder"; import { SaveServer } from "@spt/servers/SaveServer"; @@ -63,34 +64,6 @@ export class CustomizationController { return matchedSuits; } - /** - * Handle CustomizationWear event - * Equip one to many clothing items to player - */ - public wearClothing( - pmcData: IPmcData, - wearClothingRequest: IWearClothingRequestData, - sessionID: string, - ): IItemEventRouterResponse { - for (const suitId of wearClothingRequest.suites) { - // Find desired clothing item in db - const dbSuit = this.databaseService.getCustomization()[suitId]; - - // Legs - if (dbSuit._parent === this.clothingIds.lowerParentId) { - pmcData.Customization.Feet = dbSuit._props.Feet; - } - - // Torso - if (dbSuit._parent === this.clothingIds.upperParentId) { - pmcData.Customization.Body = dbSuit._props.Body; - pmcData.Customization.Hands = dbSuit._props.Hands; - } - } - - return this.eventOutputHolder.getOutput(sessionID); - } - /** * Handle CustomizationBuy event * Purchase/unlock a clothing item from a trader @@ -350,9 +323,48 @@ export class CustomizationController { pmcData: IPmcData, ): IItemEventRouterResponse { for (const customisation of request.customizations) { - pmcData.Customization[customisation.type] = customisation.id; + switch (customisation.type) { + case "dogTag": + pmcData.Customization.DogTag = customisation.id; + break; + case "suite": + this.applyClothingItemToProfile(customisation, pmcData); + break; + default: + this.logger.error(`Unhandled customisation type: ${customisation.type}`); + break; + } } return this.eventOutputHolder.getOutput(sessionId); } + + /** + * Applies a purchsed suit to the players doll + * @param customisation Suit to apply to profile + * @param pmcData Profile to update + */ + protected applyClothingItemToProfile(customisation: CustomizationSetOption, pmcData: IPmcData): void { + const dbSuit = this.databaseService.getCustomization()[customisation.id]; + if (!dbSuit) { + this.logger.error( + `Unable to find suit customisation id: ${customisation.id}, cannot apply clothing to player profile: ${pmcData._id}`, + ); + + return; + } + + // Body + if (dbSuit._parent === this.clothingIds.upperParentId) { + pmcData.Customization.Body = dbSuit._props.Body; + pmcData.Customization.Hands = dbSuit._props.Hands; + + return; + } + + // Feet + if (dbSuit._parent === this.clothingIds.lowerParentId) { + pmcData.Customization.Feet = dbSuit._props.Feet; + } + } } diff --git a/project/src/routers/item_events/CustomizationItemEventRouter.ts b/project/src/routers/item_events/CustomizationItemEventRouter.ts index 5e657e8f..77e42a2e 100644 --- a/project/src/routers/item_events/CustomizationItemEventRouter.ts +++ b/project/src/routers/item_events/CustomizationItemEventRouter.ts @@ -27,8 +27,6 @@ export class CustomizationItemEventRouter extends ItemEventRouterDefinition { sessionID: string, ): Promise { switch (url) { - case "CustomizationWear": - return this.customizationCallbacks.wearClothing(pmcData, body, sessionID); case "CustomizationBuy": return this.customizationCallbacks.buyClothing(pmcData, body, sessionID); case "CustomizationSet":