Replace use of dialogueHelper.addDialogueMessage inside sendInsuredItems() with MailSendService.sendMessage()
This commit is contained in:
parent
e0b5d43fd5
commit
8d59ab7c77
@ -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
|
||||
{
|
||||
|
@ -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,
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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],
|
||||
});
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user