From 3703698a1a7a77d8525aaee9c300c2b99f501ae1 Mon Sep 17 00:00:00 2001 From: DrakiaXYZ Date: Fri, 27 Sep 2024 07:19:20 +0000 Subject: [PATCH] Implement TransitItemsDelivery service via expansion of the BTR item delivery handler (!413) - Fixes exception thrown when attempting to transfer items during transit - Implements transit item transfer by expanding on the existing BTR item transfer code (They are both BTR services) Co-authored-by: DrakiaXYZ <565558+TheDgtl@users.noreply.github.com> Reviewed-on: https://dev.sp-tarkov.com/SPT/Server/pulls/413 Co-authored-by: DrakiaXYZ Co-committed-by: DrakiaXYZ --- .../database/templates/locationServices.json | 10 +++++ .../656f0f98d80a697f855d34b1/services.json | 7 ++- project/src/models/enums/TraderServiceType.ts | 1 + .../src/services/LocationLifecycleService.ts | 45 ++++++++----------- 4 files changed, 34 insertions(+), 29 deletions(-) diff --git a/project/assets/database/templates/locationServices.json b/project/assets/database/templates/locationServices.json index 20be3e8f..a05c971d 100644 --- a/project/assets/database/templates/locationServices.json +++ b/project/assets/database/templates/locationServices.json @@ -102,6 +102,16 @@ }, "ServiceItemCost": [], "UniqueItems": [] + }, + "TransitItemsDelivery": { + "TraderId": "656f0f98d80a697f855d34b1", + "TraderServiceType": "TransitItemsDelivery", + "Requirements": { + "CompletedQuests": [], + "Standings": [] + }, + "ServiceItemCost": [], + "UniqueItems": [] } } }, diff --git a/project/assets/database/traders/656f0f98d80a697f855d34b1/services.json b/project/assets/database/traders/656f0f98d80a697f855d34b1/services.json index df7483c7..4b6ffe5b 100644 --- a/project/assets/database/traders/656f0f98d80a697f855d34b1/services.json +++ b/project/assets/database/traders/656f0f98d80a697f855d34b1/services.json @@ -7,5 +7,8 @@ }, { "serviceType": "BtrBotCover" - } -] \ No newline at end of file + }, + { + "serviceType": "TransitItemsDelivery" + } +] diff --git a/project/src/models/enums/TraderServiceType.ts b/project/src/models/enums/TraderServiceType.ts index f1a29061..9f018b89 100644 --- a/project/src/models/enums/TraderServiceType.ts +++ b/project/src/models/enums/TraderServiceType.ts @@ -5,4 +5,5 @@ export enum TraderServiceType { BTR_ITEMS_DELIVERY = "BtrItemsDelivery", PLAYER_TAXI = "PlayerTaxi", BTR_BOT_COVER = "BtrBotCover", + TRANSIT_ITEMS_DELIVERY = "TransitItemsDelivery", } diff --git a/project/src/services/LocationLifecycleService.ts b/project/src/services/LocationLifecycleService.ts index 78d3649f..cab5153a 100644 --- a/project/src/services/LocationLifecycleService.ts +++ b/project/src/services/LocationLifecycleService.ts @@ -311,10 +311,8 @@ export class LocationLifecycleService { const isDead = this.isPlayerDead(request.results); const isSurvived = this.isPlayerSurvived(request.results); - // Handle items transferred via BTR to player - this.handleBTRItemTransferEvent(sessionId, request); - - this.handleTransitItemTransferEvent(sessionId, request); + // Handle items transferred via BTR or transit to player + this.handleItemTransferEvent(sessionId, request); if (!isPmc) { this.handlePostRaidPlayerScav(sessionId, pmcProfile, scavProfile, isDead, request); @@ -688,23 +686,28 @@ export class LocationLifecycleService { } /** - * Check if player used BTR item sending service and send items to player via mail if found + * Check if player used BTR or transit item sending service and send items to player via mail if found * @param sessionId Session id * @param request End raid request */ - protected handleBTRItemTransferEvent(sessionId: string, request: IEndLocalRaidRequestData): void { - const btrId = `${Traders.BTR}_btr`; - let itemsToSend = request.transferItems[btrId] ?? []; - if (itemsToSend.length === 0) { - return; - } + protected handleItemTransferEvent(sessionId: string, request: IEndLocalRaidRequestData): void { + const transferTypes = ["btr", "transit"]; - // Filter out the btr container item from transferred items before delivering - itemsToSend = itemsToSend.filter((item) => item._id !== btrId); - this.btrItemDelivery(sessionId, Traders.BTR, itemsToSend); + for (const trasferType of transferTypes) { + const rootId = `${Traders.BTR}_${trasferType}`; + let itemsToSend = request.transferItems[rootId] ?? []; + + // Filter out the btr container item from transferred items before delivering + itemsToSend = itemsToSend.filter((item) => item._id !== Traders.BTR); + if (itemsToSend.length === 0) { + continue; + } + + this.transferItemDelivery(sessionId, Traders.BTR, itemsToSend); + } } - protected btrItemDelivery(sessionId: string, traderId: string, items: IItem[]): void { + protected transferItemDelivery(sessionId: string, traderId: string, items: IItem[]): void { const serverProfile = this.saveServer.getProfile(sessionId); const pmcData = serverProfile.characters.pmc; @@ -737,18 +740,6 @@ export class LocationLifecycleService { ); } - protected handleTransitItemTransferEvent(sessionId: string, request: IEndLocalRaidRequestData) { - const id = "TODO_DUMP"; - const transitRootId = `${id}_transit`; - const itemsToSend = request.transferItems[transitRootId] ?? []; - if (itemsToSend.length === 0) { - this.logger.error("NOT IMPLEMENTED"); - return; - } - - this.logger.error("NOT IMPLEMENTED"); - } - protected handleInsuredItemLostEvent( sessionId: string, preRaidPmcProfile: IPmcData,