From 31ba17a3275e996d46ed0dcc313f49b6a51d0476 Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 5 Jul 2024 19:02:02 +0100 Subject: [PATCH] Added handling of BTR item delivery --- .../database/templates/locationServices.json | 8 ++-- project/src/callbacks/InraidCallbacks.ts | 12 +---- project/src/callbacks/MatchCallbacks.ts | 6 ++- project/src/controllers/InraidController.ts | 38 +-------------- project/src/controllers/MatchController.ts | 46 +++++++++++++++++++ .../eft/match/IEndLocalRaidRequestData.ts | 3 ++ .../src/routers/static/InraidStaticRouter.ts | 7 --- 7 files changed, 60 insertions(+), 60 deletions(-) diff --git a/project/assets/database/templates/locationServices.json b/project/assets/database/templates/locationServices.json index 2be3edad..20be3e8f 100644 --- a/project/assets/database/templates/locationServices.json +++ b/project/assets/database/templates/locationServices.json @@ -158,8 +158,8 @@ "MapID": "TarkovStreets", "ChanceSpawn": 100, "SpawnPeriod": { - "x": 300, - "y": 600, + "x": 0, + "y": 10, "z": 0 }, "MoveSpeed": 8, @@ -183,8 +183,8 @@ "MapID": "Woods", "ChanceSpawn": 100, "SpawnPeriod": { - "x": 180, - "y": 360, + "x": 0, + "y": 10, "z": 0 }, "MoveSpeed": 8, diff --git a/project/src/callbacks/InraidCallbacks.ts b/project/src/callbacks/InraidCallbacks.ts index 7661e218..70c4d2d3 100644 --- a/project/src/callbacks/InraidCallbacks.ts +++ b/project/src/callbacks/InraidCallbacks.ts @@ -2,7 +2,6 @@ import { inject, injectable } from "tsyringe"; import { InraidController } from "@spt/controllers/InraidController"; import { IEmptyRequestData } from "@spt/models/eft/common/IEmptyRequestData"; import { INullResponseData } from "@spt/models/eft/httpResponse/INullResponseData"; -import { IItemDeliveryRequestData } from "@spt/models/eft/inRaid/IItemDeliveryRequestData"; import { IRegisterPlayerRequestData } from "@spt/models/eft/inRaid/IRegisterPlayerRequestData"; import { ISaveProgressRequestData } from "@spt/models/eft/inRaid/ISaveProgressRequestData"; import { HttpResponseUtil } from "@spt/utils/HttpResponseUtil"; @@ -93,15 +92,6 @@ export class InraidCallbacks return this.httpResponse.noBody(this.inraidController.getTraderServices(sessionId, traderId)); } - /** - * Handle singleplayer/traderServices/itemDelivery - */ - public itemDelivery(url: string, request: IItemDeliveryRequestData, sessionId: string): INullResponseData - { - this.inraidController.itemDelivery(sessionId, request.traderId, request.items); - return this.httpResponse.nullResponse(); - } - public getTraitorScavHostileChance(url: string, info: IEmptyRequestData, sessionId: string): string { return this.httpResponse.noBody(this.inraidController.getTraitorScavHostileChance(url, sessionId)); @@ -114,6 +104,6 @@ export class InraidCallbacks public getBossConvertSettings(url: string, info: IEmptyRequestData, sessionId: string): string { - return this.httpResponse.noBody(this.inraidController.getBossConvertSettings(url, sessionId)) + return this.httpResponse.noBody(this.inraidController.getBossConvertSettings(url, sessionId)); } } diff --git a/project/src/callbacks/MatchCallbacks.ts b/project/src/callbacks/MatchCallbacks.ts index c39a6c78..e66fa4c6 100644 --- a/project/src/callbacks/MatchCallbacks.ts +++ b/project/src/callbacks/MatchCallbacks.ts @@ -234,7 +234,11 @@ export class MatchCallbacks } /** Handle client/match/offline/end */ - public endOfflineRaid(url: string, info: IEndOfflineRaidRequestData, sessionID: string): INullResponseData + public endOfflineRaid( + url: string, + info: IEndOfflineRaidRequestData, + sessionID: string, + ): INullResponseData { this.matchController.endOfflineRaid(info, sessionID); return this.httpResponse.nullResponse(); diff --git a/project/src/controllers/InraidController.ts b/project/src/controllers/InraidController.ts index dc4b8884..8c66e5ec 100644 --- a/project/src/controllers/InraidController.ts +++ b/project/src/controllers/InraidController.ts @@ -11,17 +11,16 @@ import { TraderHelper } from "@spt/helpers/TraderHelper"; import { ILocationBase } from "@spt/models/eft/common/ILocationBase"; import { IPmcData } from "@spt/models/eft/common/IPmcData"; import { BodyPartHealth } from "@spt/models/eft/common/tables/IBotBase"; -import { Item } from "@spt/models/eft/common/tables/IItem"; import { IRegisterPlayerRequestData } from "@spt/models/eft/inRaid/IRegisterPlayerRequestData"; import { ISaveProgressRequestData } from "@spt/models/eft/inRaid/ISaveProgressRequestData"; import { ConfigTypes } from "@spt/models/enums/ConfigTypes"; import { ItemTpl } from "@spt/models/enums/ItemTpl"; -import { MessageType } from "@spt/models/enums/MessageType"; import { PlayerRaidEndState } from "@spt/models/enums/PlayerRaidEndState"; import { QuestStatus } from "@spt/models/enums/QuestStatus"; import { SkillTypes } from "@spt/models/enums/SkillTypes"; import { Traders } from "@spt/models/enums/Traders"; import { IAirdropConfig } from "@spt/models/spt/config/IAirdropConfig"; +import { IBotConfig } from "@spt/models/spt/config/IBotConfig"; import { IBTRConfig } from "@spt/models/spt/config/IBTRConfig"; import { IHideoutConfig } from "@spt/models/spt/config/IHideoutConfig"; import { IInRaidConfig } from "@spt/models/spt/config/IInRaidConfig"; @@ -41,7 +40,6 @@ import { PmcChatResponseService } from "@spt/services/PmcChatResponseService"; import { TraderServicesService } from "@spt/services/TraderServicesService"; import { RandomUtil } from "@spt/utils/RandomUtil"; import { TimeUtil } from "@spt/utils/TimeUtil"; -import { IBotConfig } from "@spt/models/spt/config/IBotConfig"; /** * Logic for handling In Raid callbacks @@ -662,40 +660,6 @@ export class InraidController return this.traderServicesService.getTraderServices(sessionId, traderId); } - /** - * Handle singleplayer/traderServices/itemDelivery - */ - public itemDelivery(sessionId: string, traderId: string, items: Item[]): void - { - const serverProfile = this.saveServer.getProfile(sessionId); - const pmcData = serverProfile.characters.pmc; - - const dialogueTemplates = this.databaseService.getTrader(traderId).dialogue; - if (!dialogueTemplates) - { - this.logger.error(this.localisationService.getText("inraid-unable_to_deliver_item_no_trader_found", traderId)); - - return; - } - const messageId = this.randomUtil.getArrayValue(dialogueTemplates.itemsDelivered); - const messageStoreTime = this.timeUtil.getHoursAsSeconds(this.traderConfig.fence.btrDeliveryExpireHours); - - // Remove any items that were returned by the item delivery, but also insured, from the player's insurance list - // This is to stop items being duplicated by being returned from both the item delivery, and insurance - const deliveredItemIds = items.map((x) => x._id); - pmcData.InsuredItems = pmcData.InsuredItems.filter((x) => !deliveredItemIds.includes(x.itemId)); - - // Send the items to the player - this.mailSendService.sendLocalisedNpcMessageToPlayer( - sessionId, - this.traderHelper.getTraderById(traderId), - MessageType.BTR_ITEMS_DELIVERY, - messageId, - items, - messageStoreTime, - ); - } - public getTraitorScavHostileChance(url: string, sessionID: string): number { return this.inRaidConfig.playerScavHostileChancePercent; diff --git a/project/src/controllers/MatchController.ts b/project/src/controllers/MatchController.ts index 3def6f30..9a535129 100644 --- a/project/src/controllers/MatchController.ts +++ b/project/src/controllers/MatchController.ts @@ -35,6 +35,7 @@ import { SaveServer } from "@spt/servers/SaveServer"; import { BotGenerationCacheService } from "@spt/services/BotGenerationCacheService"; import { BotLootCacheService } from "@spt/services/BotLootCacheService"; import { DatabaseService } from "@spt/services/DatabaseService"; +import { LocalisationService } from "@spt/services/LocalisationService"; import { MailSendService } from "@spt/services/MailSendService"; import { MatchBotDetailsCacheService } from "@spt/services/MatchBotDetailsCacheService"; import { MatchLocationService } from "@spt/services/MatchLocationService"; @@ -71,6 +72,7 @@ export class MatchController @inject("PmcChatResponseService") protected pmcChatResponseService: PmcChatResponseService, @inject("TraderHelper") protected traderHelper: TraderHelper, @inject("BotLootCacheService") protected botLootCacheService: BotLootCacheService, + @inject("LocalisationService") protected localisationService: LocalisationService, @inject("ConfigServer") protected configServer: ConfigServer, @inject("ProfileSnapshotService") protected profileSnapshotService: ProfileSnapshotService, @inject("BotGenerationCacheService") protected botGenerationCacheService: BotGenerationCacheService, @@ -472,6 +474,50 @@ export class MatchController // Player killed PMCs, send some responses to them this.pmcChatResponseService.sendVictimResponse(sessionId, victims, pmcProfile); } + + // Handle items transferred via BTR to player + const btrKey = "BTRTransferStash"; + const btrContainerAndItems = request.transferItems[btrKey] ?? []; + if (btrContainerAndItems.length > 0) + { + const itemsToSend = btrContainerAndItems.filter((item) => item._id !== btrKey); + this.btrItemDelivery(sessionId, Traders.BTR, itemsToSend); + } + } + + /** + * Handle singleplayer/traderServices/itemDelivery + */ + protected btrItemDelivery(sessionId: string, traderId: string, items: Item[]): void + { + const serverProfile = this.saveServer.getProfile(sessionId); + const pmcData = serverProfile.characters.pmc; + + const dialogueTemplates = this.databaseService.getTrader(traderId).dialogue; + if (!dialogueTemplates) + { + this.logger.error(this.localisationService.getText("inraid-unable_to_deliver_item_no_trader_found", traderId)); + + return; + } + const messageId = this.randomUtil.getArrayValue(dialogueTemplates.itemsDelivered); + const messageStoreTime = this.timeUtil.getHoursAsSeconds(this.traderConfig.fence.btrDeliveryExpireHours); + + // Remove any items that were returned by the item delivery, but also insured, from the player's insurance list + // This is to stop items being duplicated by being returned from both item delivery and insurance + const deliveredItemIds = items.map((item) => item._id); + pmcData.InsuredItems = pmcData.InsuredItems + .filter((insuredItem) => !deliveredItemIds.includes(insuredItem.itemId)); + + // Send the items to the player + this.mailSendService.sendLocalisedNpcMessageToPlayer( + sessionId, + this.traderHelper.getTraderById(traderId), + MessageType.BTR_ITEMS_DELIVERY, + messageId, + items, + messageStoreTime, + ); } /** diff --git a/project/src/models/eft/match/IEndLocalRaidRequestData.ts b/project/src/models/eft/match/IEndLocalRaidRequestData.ts index 6e3cce20..f3995953 100644 --- a/project/src/models/eft/match/IEndLocalRaidRequestData.ts +++ b/project/src/models/eft/match/IEndLocalRaidRequestData.ts @@ -4,9 +4,12 @@ import { Item } from "../common/tables/IItem"; export interface IEndLocalRaidRequestData { + /** ID of server player just left */ serverId: string results: IEndRaidResult + /** Insured items left in raid by player */ lostInsuredItems: Item[] + /** Items sent via traders to player, keyed to service e.g. BTRTransferStash */ transferItems: Record } diff --git a/project/src/routers/static/InraidStaticRouter.ts b/project/src/routers/static/InraidStaticRouter.ts index 36cc371f..84bd46cf 100644 --- a/project/src/routers/static/InraidStaticRouter.ts +++ b/project/src/routers/static/InraidStaticRouter.ts @@ -44,13 +44,6 @@ export class InraidStaticRouter extends StaticRouter return this.inraidCallbacks.getBTRConfig(); }, ), - new RouteAction( - "/singleplayer/traderServices/itemDelivery", - async (url: string, info: any, sessionID: string, output: string): Promise => - { - return this.inraidCallbacks.itemDelivery(url, info, sessionID); - }, - ), new RouteAction( "/singleplayer/scav/traitorscavhostile", async (url: string, info: any, sessionID: string, output: string): Promise =>