From 8d59ab7c77429eb032985ccde7907ddc6a67ecb6 Mon Sep 17 00:00:00 2001 From: Dev Date: Fri, 2 Feb 2024 11:57:10 +0000 Subject: [PATCH] Replace use of dialogueHelper.addDialogueMessage inside sendInsuredItems() with MailSendService.sendMessage() --- project/src/controllers/DialogueController.ts | 2 +- .../src/controllers/InsuranceController.ts | 19 ++- project/src/helpers/DialogueHelper.ts | 142 ------------------ project/src/models/eft/profile/IAkiProfile.ts | 16 +- project/src/services/InsuranceService.ts | 43 +++--- 5 files changed, 33 insertions(+), 189 deletions(-) diff --git a/project/src/controllers/DialogueController.ts b/project/src/controllers/DialogueController.ts index 0a7b8c0d..9013825c 100644 --- a/project/src/controllers/DialogueController.ts +++ b/project/src/controllers/DialogueController.ts @@ -343,7 +343,7 @@ export class DialogueController * Get all uncollected items attached to mail in a particular dialog * @param dialogueId Dialog to get mail attachments from * @param sessionId Session id - * @returns + * @returns IGetAllAttachmentsResponse */ public getAllAttachments(dialogueId: string, sessionId: string): IGetAllAttachmentsResponse { diff --git a/project/src/controllers/InsuranceController.ts b/project/src/controllers/InsuranceController.ts index 801635b7..8b85e3da 100644 --- a/project/src/controllers/InsuranceController.ts +++ b/project/src/controllers/InsuranceController.ts @@ -13,7 +13,6 @@ import { IItemEventRouterResponse } from "@spt-aki/models/eft/itemEvent/IItemEve import { ISystemData, Insurance } from "@spt-aki/models/eft/profile/IAkiProfile"; import { IProcessBuyTradeRequestData } from "@spt-aki/models/eft/trade/IProcessBuyTradeRequestData"; import { ConfigTypes } from "@spt-aki/models/enums/ConfigTypes"; -import { MessageType } from "@spt-aki/models/enums/MessageType"; import { SkillTypes } from "@spt-aki/models/enums/SkillTypes"; import { IInsuranceConfig } from "@spt-aki/models/spt/config/IInsuranceConfig"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; @@ -140,7 +139,7 @@ export class InsuranceController this.sendMail(sessionID, insured); // Remove the fully processed insurance package from the profile. - this.removeInsurancePackageFromProfile(sessionID, insured.messageContent.systemData); + this.removeInsurancePackageFromProfile(sessionID, insured.systemData); } } @@ -165,9 +164,9 @@ export class InsuranceController { const profile = this.saveServer.getProfile(sessionID); profile.insurance = profile.insurance.filter((insurance) => - insurance.messageContent.systemData.date !== packageInfo.date - || insurance.messageContent.systemData.time !== packageInfo.time - || insurance.messageContent.systemData.location !== packageInfo.location + insurance.systemData.date !== packageInfo.date + || insurance.systemData.time !== packageInfo.time + || insurance.systemData.location !== packageInfo.location ); this.logger.debug( @@ -528,18 +527,18 @@ export class InsuranceController { const insuranceFailedTemplates = this.databaseServer.getTables().traders[insurance.traderId].dialogue.insuranceFailed; - insurance.messageContent.templateId = this.randomUtil.getArrayValue(insuranceFailedTemplates); + insurance.messageTemplateId = this.randomUtil.getArrayValue(insuranceFailedTemplates); } // Send the insurance message this.mailSendService.sendLocalisedNpcMessageToPlayer( sessionID, this.traderHelper.getTraderById(insurance.traderId), - MessageType.INSURANCE_RETURN, - insurance.messageContent.templateId, + insurance.messageType, + insurance.messageTemplateId, insurance.items, - insurance.messageContent.maxStorageTime, - insurance.messageContent.systemData, + insurance.maxStorageTime, + insurance.systemData, ); } diff --git a/project/src/helpers/DialogueHelper.ts b/project/src/helpers/DialogueHelper.ts index 5cd1b285..fb417ca9 100644 --- a/project/src/helpers/DialogueHelper.ts +++ b/project/src/helpers/DialogueHelper.ts @@ -6,19 +6,13 @@ import { NotifierHelper } from "@spt-aki/helpers/NotifierHelper"; import { Item } from "@spt-aki/models/eft/common/tables/IItem"; import { Dialogue, - Message, - MessageContent, - MessageItems, MessagePreview, } from "@spt-aki/models/eft/profile/IAkiProfile"; -import { BaseClasses } from "@spt-aki/models/enums/BaseClasses"; -import { MessageType } from "@spt-aki/models/enums/MessageType"; import { ILogger } from "@spt-aki/models/spt/utils/ILogger"; import { DatabaseServer } from "@spt-aki/servers/DatabaseServer"; import { SaveServer } from "@spt-aki/servers/SaveServer"; import { LocalisationService } from "@spt-aki/services/LocalisationService"; import { HashUtil } from "@spt-aki/utils/HashUtil"; -import { TimeUtil } from "@spt-aki/utils/TimeUtil"; @injectable() export class DialogueHelper @@ -35,142 +29,6 @@ export class DialogueHelper ) {} - /** - * @deprecated Use MailSendService.sendMessage() or helpers - */ - public createMessageContext(templateId: string, messageType: MessageType, maxStoreTime = null): MessageContent - { - const result: MessageContent = { templateId: templateId, type: messageType }; - - if (maxStoreTime) - { - result.maxStorageTime = maxStoreTime * TimeUtil.ONE_HOUR_AS_SECONDS; - } - - return result; - } - - /** - * @deprecated Use MailSendService.sendMessage() or helpers - */ - public addDialogueMessage( - dialogueID: string, - messageContent: MessageContent, - sessionID: string, - rewards: Item[] = [], - messageType = MessageType.NPC_TRADER, - ): void - { - const dialogueData = this.saveServer.getProfile(sessionID).dialogues; - const isNewDialogue = !(dialogueID in dialogueData); - let dialogue: Dialogue = dialogueData[dialogueID]; - - if (isNewDialogue) - { - dialogue = { _id: dialogueID, type: messageType, messages: [], pinned: false, new: 0, attachmentsNew: 0 }; - - dialogueData[dialogueID] = dialogue; - } - - dialogue.new += 1; - - // Generate item stash if we have rewards. - let items: MessageItems = {}; - - if (rewards.length > 0) - { - const stashId = this.hashUtil.generate(); - items = { stash: stashId, data: [] }; - - rewards = this.itemHelper.replaceIDs(null, rewards); - for (const reward of rewards) - { - if (!("slotId" in reward) || reward.slotId === "hideout") - { - reward.parentId = stashId; - reward.slotId = "main"; - } - - const itemTemplate = this.databaseServer.getTables().templates.items[reward._tpl]; - if (!itemTemplate) - { - // Can happen when modded items are insured + mod is removed - this.logger.error( - this.localisationService.getText("dialog-missing_item_template", { - tpl: reward._tpl, - type: MessageType[messageContent.type], - }), - ); - - continue; - } - - if ("StackSlots" in itemTemplate._props) - { - // Boxes can contain sub-items - if (this.itemHelper.isOfBaseclass(itemTemplate._id, BaseClasses.AMMO_BOX)) - { - const boxAndCartridges: Item[] = [reward]; - this.itemHelper.addCartridgesToAmmoBox(boxAndCartridges, itemTemplate); - - // Push box + cartridge children into array - items.data.push(...boxAndCartridges); - } - else - { - // Item is sanitised and ready to be pushed into holding array - items.data.push(reward); - } - } - } - - if (items.data.length === 0) - { - delete items.data; - } - - dialogue.attachmentsNew += 1; - } - - const message: Message = { - _id: this.hashUtil.generate(), - uid: dialogueID, - type: messageContent.type, - dt: Math.round(Date.now() / 1000), - text: messageContent.text ?? "", - templateId: messageContent.templateId, - hasRewards: items.data?.length > 0, - rewardCollected: false, - items: items, - maxStorageTime: messageContent.maxStorageTime, - systemData: messageContent.systemData ? messageContent.systemData : undefined, - profileChangeEvents: (messageContent.profileChangeEvents?.length === 0) - ? messageContent.profileChangeEvents - : undefined, - }; - - if (!message.templateId) - { - delete message.templateId; - } - - dialogue.messages.push(message); - - // Offer Sold notifications are now separate from the main notification - if (messageContent.type === MessageType.FLEAMARKET_MESSAGE && messageContent.ragfair) - { - const offerSoldMessage = this.notifierHelper.createRagfairOfferSoldNotification( - message, - messageContent.ragfair, - ); - this.notificationSendHelper.sendMessage(sessionID, offerSoldMessage); - message.type = MessageType.MESSAGE_WITH_ITEMS; // Should prevent getting the same notification popup twice - } - - const notificationMessage = this.notifierHelper.createNewMessageNotification(message); - this.notificationSendHelper.sendMessage(sessionID, notificationMessage); - } - /** * Get the preview contents of the last message in a dialogue. * @param dialogue diff --git a/project/src/models/eft/profile/IAkiProfile.ts b/project/src/models/eft/profile/IAkiProfile.ts index bf7db028..58dd1e1b 100644 --- a/project/src/models/eft/profile/IAkiProfile.ts +++ b/project/src/models/eft/profile/IAkiProfile.ts @@ -289,21 +289,13 @@ export interface Insurance { scheduledTime: number; traderId: string; - messageContent: MessageContent; + maxStorageTime: number; + systemData: ISystemData; + messageType: MessageType + messageTemplateId: string items: Item[]; } -export interface MessageContent -{ - ragfair?: MessageContentRagfair; - text?: string; - templateId: string; - type: MessageType; - maxStorageTime?: number; - profileChangeEvents?: any[]; - systemData?: ISystemData; -} - export interface MessageContentRagfair { offerId: string; diff --git a/project/src/services/InsuranceService.ts b/project/src/services/InsuranceService.ts index e316e15d..5928415d 100644 --- a/project/src/services/InsuranceService.ts +++ b/project/src/services/InsuranceService.ts @@ -7,7 +7,6 @@ import { SecureContainerHelper } from "@spt-aki/helpers/SecureContainerHelper"; import { TraderHelper } from "@spt-aki/helpers/TraderHelper"; import { IPmcData } from "@spt-aki/models/eft/common/IPmcData"; import { Item } from "@spt-aki/models/eft/common/tables/IItem"; -import { ITemplateItem } from "@spt-aki/models/eft/common/tables/ITemplateItem"; import { ITraderBase } from "@spt-aki/models/eft/common/tables/ITrader"; import { IInsuredItemsData } from "@spt-aki/models/eft/inRaid/IInsuredItemsData"; import { ISaveProgressRequestData } from "@spt-aki/models/eft/inRaid/ISaveProgressRequestData"; @@ -99,42 +98,38 @@ export class InsuranceService */ public sendInsuredItems(pmcData: IPmcData, sessionID: string, mapId: string): void { + // Get insurance items for each trader for (const traderId in this.getInsurance(sessionID)) { const traderBase = this.traderHelper.getTrader(traderId, sessionID); const insuranceReturnTimestamp = this.getInsuranceReturnTimestamp(pmcData, traderBase); const dialogueTemplates = this.databaseServer.getTables().traders[traderId].dialogue; - // Construct "i will go look for your stuff" message - const messageContent = this.dialogueHelper.createMessageContext( - this.randomUtil.getArrayValue(dialogueTemplates.insuranceStart), - MessageType.NPC_TRADER, - traderBase.insurance.max_storage_time, - ); - messageContent.text = ""; // Live insurance returns have an empty string for the text property - messageContent.profileChangeEvents = []; - messageContent.systemData = { + const systemData = { date: this.timeUtil.getDateMailFormat(), time: this.timeUtil.getTimeMailFormat(), - location: mapId, + location: mapId }; + // Send "i will go look for your stuff" message from trader to player + this.mailSendService.sendLocalisedNpcMessageToPlayer( + sessionID, + this.traderHelper.getTraderById(traderId), + MessageType.NPC_TRADER, + this.randomUtil.getArrayValue(dialogueTemplates.insuranceStart), + null, + null, + systemData + ); - // MUST occur after systemData is hydrated - // Store "i will go look for your stuff" message in player profile - this.dialogueHelper.addDialogueMessage(traderId, messageContent, sessionID); - - // Remove 'hideout' slotid property on all insurance items - this.removeLocationProperty(sessionID, traderId); - - // Reuse existing context for message sent to player with insurance return - messageContent.templateId = this.randomUtil.getArrayValue(dialogueTemplates.insuranceFound); - messageContent.type = MessageType.INSURANCE_RETURN; - - // Store insurance return details in profile + "hey i found your stuff, here you go!" message details to send player at a later date + // Store insurance to send to player later in profile + // Store insurance return details in profile + "hey i found your stuff, here you go!" message details to send to player at a later date this.saveServer.getProfile(sessionID).insurance.push({ scheduledTime: insuranceReturnTimestamp, traderId: traderId, - messageContent: messageContent, + maxStorageTime: this.timeUtil.getHoursAsSeconds(traderBase.insurance.max_storage_time), + systemData: systemData, + messageType: MessageType.INSURANCE_RETURN, + messageTemplateId: this.randomUtil.getArrayValue(dialogueTemplates.insuranceFound), items: this.getInsurance(sessionID)[traderId], }); }