2023-12-24 19:54:27 +00:00
|
|
|
import { inject, injectAll, injectable } from "tsyringe";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2023-12-24 19:54:27 +00:00
|
|
|
import { IDialogueChatBot } from "@spt-aki/helpers/Dialogue/IDialogueChatBot";
|
2023-10-19 17:21:17 +00:00
|
|
|
import { DialogueHelper } from "@spt-aki/helpers/DialogueHelper";
|
|
|
|
import { IGetAllAttachmentsResponse } from "@spt-aki/models/eft/dialog/IGetAllAttachmentsResponse";
|
|
|
|
import { IGetFriendListDataResponse } from "@spt-aki/models/eft/dialog/IGetFriendListDataResponse";
|
|
|
|
import { IGetMailDialogViewRequestData } from "@spt-aki/models/eft/dialog/IGetMailDialogViewRequestData";
|
|
|
|
import { IGetMailDialogViewResponseData } from "@spt-aki/models/eft/dialog/IGetMailDialogViewResponseData";
|
|
|
|
import { ISendMessageRequest } from "@spt-aki/models/eft/dialog/ISendMessageRequest";
|
|
|
|
import { Dialogue, DialogueInfo, IAkiProfile, IUserDialogInfo, Message } from "@spt-aki/models/eft/profile/IAkiProfile";
|
|
|
|
import { MessageType } from "@spt-aki/models/enums/MessageType";
|
|
|
|
import { ILogger } from "@spt-aki/models/spt/utils/ILogger";
|
|
|
|
import { SaveServer } from "@spt-aki/servers/SaveServer";
|
|
|
|
import { MailSendService } from "@spt-aki/services/MailSendService";
|
|
|
|
import { TimeUtil } from "@spt-aki/utils/TimeUtil";
|
2023-03-03 15:23:46 +00:00
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export class DialogueController
|
|
|
|
{
|
2023-12-24 19:54:27 +00:00
|
|
|
protected registeredDialogueChatBots: Map<string, IDialogueChatBot> = new Map<string, IDialogueChatBot>();
|
2023-08-09 16:01:51 +01:00
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
constructor(
|
2023-07-21 17:08:32 +00:00
|
|
|
@inject("WinstonLogger") protected logger: ILogger,
|
2023-03-03 15:23:46 +00:00
|
|
|
@inject("SaveServer") protected saveServer: SaveServer,
|
|
|
|
@inject("TimeUtil") protected timeUtil: TimeUtil,
|
2023-07-20 19:27:28 +00:00
|
|
|
@inject("DialogueHelper") protected dialogueHelper: DialogueHelper,
|
2023-07-21 17:08:32 +00:00
|
|
|
@inject("MailSendService") protected mailSendService: MailSendService,
|
2023-12-24 19:54:27 +00:00
|
|
|
@injectAll("DialogueChatBot") protected dialogueChatBots: IDialogueChatBot[],
|
2023-03-03 15:23:46 +00:00
|
|
|
)
|
2023-08-09 16:01:51 +01:00
|
|
|
{
|
2023-12-24 19:54:27 +00:00
|
|
|
for (const dialogueChatBot of dialogueChatBots)
|
|
|
|
{
|
|
|
|
if (this.registeredDialogueChatBots.has(dialogueChatBot.getChatBot()._id))
|
|
|
|
{
|
|
|
|
this.logger.error(
|
|
|
|
`Could not register ${dialogueChatBot.getChatBot()._id} as it is already in use. Skipping.`,
|
|
|
|
);
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
this.registeredDialogueChatBots.set(dialogueChatBot.getChatBot()._id, dialogueChatBot);
|
|
|
|
}
|
2023-08-09 16:01:51 +01:00
|
|
|
}
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2023-07-15 10:56:00 +01:00
|
|
|
/** Handle onUpdate spt event */
|
2023-03-03 15:23:46 +00:00
|
|
|
public update(): void
|
|
|
|
{
|
|
|
|
const profiles = this.saveServer.getProfiles();
|
|
|
|
for (const sessionID in profiles)
|
|
|
|
{
|
2023-04-22 22:41:04 +00:00
|
|
|
this.removeExpiredItemsFromMessages(sessionID);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-07-15 10:56:00 +01:00
|
|
|
/**
|
|
|
|
* Handle client/friend/list
|
|
|
|
* @returns IGetFriendListDataResponse
|
|
|
|
*/
|
2023-03-03 15:23:46 +00:00
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
public getFriendList(sessionID: string): IGetFriendListDataResponse
|
|
|
|
{
|
2023-07-23 12:30:15 +01:00
|
|
|
// Force a fake friend called SPT into friend list
|
2023-12-24 19:54:27 +00:00
|
|
|
return {
|
|
|
|
Friends: Array.from(this.registeredDialogueChatBots.values()).map((v) => v.getChatBot()),
|
|
|
|
Ignore: [],
|
|
|
|
InIgnoreList: [],
|
|
|
|
};
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 10:56:00 +01:00
|
|
|
* Handle client/mail/dialog/list
|
2023-03-03 15:23:46 +00:00
|
|
|
* Create array holding trader dialogs and mail interactions with player
|
|
|
|
* Set the content of the dialogue on the list tab.
|
|
|
|
* @param sessionID Session Id
|
|
|
|
* @returns array of dialogs
|
|
|
|
*/
|
|
|
|
public generateDialogueList(sessionID: string): DialogueInfo[]
|
|
|
|
{
|
|
|
|
const data: DialogueInfo[] = [];
|
2023-08-04 18:58:00 +01:00
|
|
|
for (const dialogueId in this.dialogueHelper.getDialogsForProfile(sessionID))
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
|
|
|
data.push(this.getDialogueInfo(dialogueId, sessionID));
|
|
|
|
}
|
|
|
|
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the content of a dialogue
|
|
|
|
* @param dialogueID Dialog id
|
|
|
|
* @param sessionID Session Id
|
|
|
|
* @returns DialogueInfo
|
|
|
|
*/
|
|
|
|
public getDialogueInfo(dialogueID: string, sessionID: string): DialogueInfo
|
|
|
|
{
|
2023-08-04 18:58:00 +01:00
|
|
|
const dialogs = this.dialogueHelper.getDialogsForProfile(sessionID);
|
|
|
|
const dialogue = dialogs[dialogueID];
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2023-03-07 22:25:23 +00:00
|
|
|
const result: DialogueInfo = {
|
2023-07-21 17:08:32 +00:00
|
|
|
_id: dialogueID,
|
|
|
|
type: dialogue.type ? dialogue.type : MessageType.NPC_TRADER,
|
|
|
|
message: this.dialogueHelper.getMessagePreview(dialogue),
|
|
|
|
new: dialogue.new,
|
|
|
|
attachmentsNew: dialogue.attachmentsNew,
|
|
|
|
pinned: dialogue.pinned,
|
2023-11-16 21:42:06 +00:00
|
|
|
Users: this.getDialogueUsers(dialogue, dialogue.type, sessionID),
|
2023-03-03 15:23:46 +00:00
|
|
|
};
|
2023-03-07 22:25:23 +00:00
|
|
|
|
|
|
|
return result;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
2023-07-21 17:08:32 +00:00
|
|
|
/**
|
2023-07-25 15:59:39 +01:00
|
|
|
* Get the users involved in a dialog (player + other party)
|
|
|
|
* @param dialog The dialog to check for users
|
|
|
|
* @param messageType What type of message is being sent
|
|
|
|
* @param sessionID Player id
|
|
|
|
* @returns IUserDialogInfo array
|
2023-07-21 17:08:32 +00:00
|
|
|
*/
|
|
|
|
public getDialogueUsers(dialog: Dialogue, messageType: MessageType, sessionID: string): IUserDialogInfo[]
|
2023-07-20 19:27:28 +00:00
|
|
|
{
|
|
|
|
const profile = this.saveServer.getProfile(sessionID);
|
|
|
|
|
2023-07-25 15:59:39 +01:00
|
|
|
// User to user messages are special in that they need the player to exist in them, add if they don't
|
2023-11-16 21:42:06 +00:00
|
|
|
if (
|
2023-12-24 19:54:27 +00:00
|
|
|
messageType === MessageType.USER_MESSAGE
|
|
|
|
&& !dialog.Users?.find((x) => x._id === profile.characters.pmc.sessionId)
|
2023-11-16 21:42:06 +00:00
|
|
|
)
|
2023-07-20 19:27:28 +00:00
|
|
|
{
|
2023-07-21 17:08:32 +00:00
|
|
|
if (!dialog.Users)
|
|
|
|
{
|
|
|
|
dialog.Users = [];
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.Users.push({
|
2023-12-24 19:54:27 +00:00
|
|
|
_id: profile.characters.pmc.sessionId,
|
2023-07-20 19:27:28 +00:00
|
|
|
info: {
|
|
|
|
Level: profile.characters.pmc.Info.Level,
|
|
|
|
Nickname: profile.characters.pmc.Info.Nickname,
|
|
|
|
Side: profile.characters.pmc.Info.Side,
|
2023-11-16 21:42:06 +00:00
|
|
|
MemberCategory: profile.characters.pmc.Info.MemberCategory,
|
|
|
|
},
|
2023-07-20 19:27:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-21 17:08:32 +00:00
|
|
|
return dialog.Users ? dialog.Users : undefined;
|
2023-07-20 19:27:28 +00:00
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
/**
|
2023-07-15 10:56:00 +01:00
|
|
|
* Handle client/mail/dialog/view
|
2023-03-03 15:23:46 +00:00
|
|
|
* Handle player clicking 'messenger' and seeing all the messages they've recieved
|
|
|
|
* Set the content of the dialogue on the details panel, showing all the messages
|
|
|
|
* for the specified dialogue.
|
2023-07-15 15:01:23 +01:00
|
|
|
* @param request Get dialog request
|
|
|
|
* @param sessionId Session id
|
2023-03-03 15:23:46 +00:00
|
|
|
* @returns IGetMailDialogViewResponseData object
|
|
|
|
*/
|
2023-11-16 21:42:06 +00:00
|
|
|
public generateDialogueView(
|
|
|
|
request: IGetMailDialogViewRequestData,
|
|
|
|
sessionId: string,
|
|
|
|
): IGetMailDialogViewResponseData
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-07-15 15:01:23 +01:00
|
|
|
const dialogueId = request.dialogId;
|
2023-07-25 15:59:39 +01:00
|
|
|
const fullProfile = this.saveServer.getProfile(sessionId);
|
|
|
|
const dialogue = this.getDialogByIdFromProfile(fullProfile, request);
|
2023-07-15 15:01:23 +01:00
|
|
|
|
2023-07-25 15:59:39 +01:00
|
|
|
// Dialog was opened, remove the little [1] on screen
|
2023-03-03 15:23:46 +00:00
|
|
|
dialogue.new = 0;
|
|
|
|
|
|
|
|
// Set number of new attachments, but ignore those that have expired.
|
2023-07-15 15:01:23 +01:00
|
|
|
dialogue.attachmentsNew = this.getUnreadMessagesWithAttachmentsCount(sessionId, dialogueId);
|
2023-03-03 15:23:46 +00:00
|
|
|
|
2023-11-16 21:42:06 +00:00
|
|
|
return {
|
2023-03-03 15:23:46 +00:00
|
|
|
messages: dialogue.messages,
|
2023-07-25 15:59:39 +01:00
|
|
|
profiles: this.getProfilesForMail(fullProfile, dialogue.Users),
|
2023-11-16 21:42:06 +00:00
|
|
|
hasMessagesWithRewards: this.messagesHaveUncollectedRewards(dialogue.messages),
|
2023-03-03 15:23:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-15 15:01:23 +01:00
|
|
|
/**
|
|
|
|
* Get dialog from player profile, create if doesn't exist
|
|
|
|
* @param profile Player profile
|
|
|
|
* @param request get dialog request (params used when dialog doesnt exist in profile)
|
|
|
|
* @returns Dialogue
|
|
|
|
*/
|
|
|
|
protected getDialogByIdFromProfile(profile: IAkiProfile, request: IGetMailDialogViewRequestData): Dialogue
|
|
|
|
{
|
|
|
|
if (!profile.dialogues[request.dialogId])
|
|
|
|
{
|
|
|
|
profile.dialogues[request.dialogId] = {
|
|
|
|
_id: request.dialogId,
|
|
|
|
attachmentsNew: 0,
|
|
|
|
pinned: false,
|
|
|
|
messages: [],
|
|
|
|
new: 0,
|
2023-11-16 21:42:06 +00:00
|
|
|
type: request.type,
|
2023-07-15 15:01:23 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
if (request.type === MessageType.USER_MESSAGE)
|
|
|
|
{
|
|
|
|
profile.dialogues[request.dialogId].Users = [];
|
2023-12-24 19:54:27 +00:00
|
|
|
if (this.registeredDialogueChatBots.has(request.dialogId))
|
|
|
|
{
|
|
|
|
profile.dialogues[request.dialogId].Users.push(
|
|
|
|
this.registeredDialogueChatBots.get(request.dialogId).getChatBot(),
|
|
|
|
);
|
|
|
|
}
|
2023-07-15 15:01:23 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return profile.dialogues[request.dialogId];
|
|
|
|
}
|
2023-07-21 17:08:32 +00:00
|
|
|
/**
|
2023-07-26 16:41:54 +01:00
|
|
|
* Get the users involved in a mail between two entities
|
2023-07-25 15:59:39 +01:00
|
|
|
* @param fullProfile Player profile
|
|
|
|
* @param dialogUsers The participants of the mail
|
|
|
|
* @returns IUserDialogInfo array
|
2023-07-21 17:08:32 +00:00
|
|
|
*/
|
2023-07-25 15:59:39 +01:00
|
|
|
protected getProfilesForMail(fullProfile: IAkiProfile, dialogUsers: IUserDialogInfo[]): IUserDialogInfo[]
|
2023-03-07 22:25:23 +00:00
|
|
|
{
|
|
|
|
const result: IUserDialogInfo[] = [];
|
|
|
|
if (dialogUsers)
|
|
|
|
{
|
|
|
|
result.push(...dialogUsers);
|
2023-07-25 15:59:39 +01:00
|
|
|
|
2023-07-26 16:41:54 +01:00
|
|
|
// Player doesnt exist, add them in before returning
|
2023-11-16 21:42:06 +00:00
|
|
|
if (!result.find((x) => x._id === fullProfile.info.id))
|
2023-07-25 15:59:39 +01:00
|
|
|
{
|
|
|
|
const pmcProfile = fullProfile.characters.pmc;
|
|
|
|
result.push({
|
|
|
|
_id: fullProfile.info.id,
|
|
|
|
info: {
|
|
|
|
Nickname: pmcProfile.Info.Nickname,
|
|
|
|
Side: pmcProfile.Info.Side,
|
|
|
|
Level: pmcProfile.Info.Level,
|
2023-11-16 21:42:06 +00:00
|
|
|
MemberCategory: pmcProfile.Info.MemberCategory,
|
|
|
|
},
|
2023-07-25 15:59:39 +01:00
|
|
|
});
|
|
|
|
}
|
2023-03-07 22:25:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
/**
|
|
|
|
* Get a count of messages with attachments from a particular dialog
|
|
|
|
* @param sessionID Session id
|
|
|
|
* @param dialogueID Dialog id
|
|
|
|
* @returns Count of messages with attachments
|
|
|
|
*/
|
|
|
|
protected getUnreadMessagesWithAttachmentsCount(sessionID: string, dialogueID: string): number
|
|
|
|
{
|
|
|
|
let newAttachmentCount = 0;
|
|
|
|
const activeMessages = this.getActiveMessagesFromDialog(sessionID, dialogueID);
|
|
|
|
for (const message of activeMessages)
|
|
|
|
{
|
|
|
|
if (message.hasRewards && !message.rewardCollected)
|
|
|
|
{
|
|
|
|
newAttachmentCount++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return newAttachmentCount;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does array have messages with uncollected rewards (includes expired rewards)
|
|
|
|
* @param messages Messages to check
|
|
|
|
* @returns true if uncollected rewards found
|
|
|
|
*/
|
|
|
|
protected messagesHaveUncollectedRewards(messages: Message[]): boolean
|
|
|
|
{
|
2023-11-16 21:42:06 +00:00
|
|
|
return messages.some((x) => x.items?.data?.length > 0);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:47:42 +01:00
|
|
|
/**
|
|
|
|
* Handle client/mail/dialog/remove
|
|
|
|
* Remove an entire dialog with an entity (trader/user)
|
|
|
|
* @param dialogueId id of the dialog to remove
|
|
|
|
* @param sessionId Player id
|
|
|
|
*/
|
|
|
|
public removeDialogue(dialogueId: string, sessionId: string): void
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-07-26 12:47:42 +01:00
|
|
|
const profile = this.saveServer.getProfile(sessionId);
|
|
|
|
const dialog = profile.dialogues[dialogueId];
|
|
|
|
if (!dialog)
|
|
|
|
{
|
|
|
|
this.logger.error(`No dialog in profile: ${sessionId} found with id: ${dialogueId}`);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
delete profile.dialogues[dialogueId];
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:47:42 +01:00
|
|
|
/** Handle client/mail/dialog/pin && Handle client/mail/dialog/unpin */
|
|
|
|
public setDialoguePin(dialogueId: string, shouldPin: boolean, sessionId: string): void
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-08-03 12:25:09 +01:00
|
|
|
const dialog = this.dialogueHelper.getDialogsForProfile(sessionId)[dialogueId];
|
2023-07-26 12:47:42 +01:00
|
|
|
if (!dialog)
|
|
|
|
{
|
|
|
|
this.logger.error(`No dialog in profile: ${sessionId} found with id: ${dialogueId}`);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
dialog.pinned = shouldPin;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
2023-07-26 12:47:42 +01:00
|
|
|
/**
|
|
|
|
* Handle client/mail/dialog/read
|
|
|
|
* Set a dialog to be read (no number alert/attachment alert)
|
|
|
|
* @param dialogueIds Dialog ids to set as read
|
|
|
|
* @param sessionId Player profile id
|
|
|
|
*/
|
|
|
|
public setRead(dialogueIds: string[], sessionId: string): void
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-08-03 12:25:09 +01:00
|
|
|
const dialogs = this.dialogueHelper.getDialogsForProfile(sessionId);
|
2023-07-26 12:47:42 +01:00
|
|
|
if (!dialogs)
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-07-26 12:47:42 +01:00
|
|
|
this.logger.error(`No dialog object in profile: ${sessionId}`);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const dialogId of dialogueIds)
|
|
|
|
{
|
|
|
|
dialogs[dialogId].new = 0;
|
|
|
|
dialogs[dialogId].attachmentsNew = 0;
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-07-15 10:56:00 +01:00
|
|
|
* Handle client/mail/dialog/getAllAttachments
|
2023-03-03 15:23:46 +00:00
|
|
|
* Get all uncollected items attached to mail in a particular dialog
|
2023-07-26 12:47:42 +01:00
|
|
|
* @param dialogueId Dialog to get mail attachments from
|
|
|
|
* @param sessionId Session id
|
2023-11-16 21:42:06 +00:00
|
|
|
* @returns
|
2023-03-03 15:23:46 +00:00
|
|
|
*/
|
2023-07-26 12:47:42 +01:00
|
|
|
public getAllAttachments(dialogueId: string, sessionId: string): IGetAllAttachmentsResponse
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-08-03 12:25:09 +01:00
|
|
|
const dialogs = this.dialogueHelper.getDialogsForProfile(sessionId);
|
|
|
|
const dialog = dialogs[dialogueId];
|
2023-07-26 12:47:42 +01:00
|
|
|
if (!dialog)
|
|
|
|
{
|
|
|
|
this.logger.error(`No dialog in profile: ${sessionId} found with id: ${dialogueId}`);
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
// Removes corner 'new messages' tag
|
2023-07-26 12:47:42 +01:00
|
|
|
dialog.attachmentsNew = 0;
|
2023-11-16 21:42:06 +00:00
|
|
|
|
2023-07-26 12:47:42 +01:00
|
|
|
const activeMessages = this.getActiveMessagesFromDialog(sessionId, dialogueId);
|
2023-03-03 15:23:46 +00:00
|
|
|
const messagesWithAttachments = this.getMessagesWithAttachments(activeMessages);
|
|
|
|
|
2023-11-16 21:42:06 +00:00
|
|
|
return {
|
2023-03-03 15:23:46 +00:00
|
|
|
messages: messagesWithAttachments,
|
|
|
|
profiles: [],
|
2023-11-16 21:42:06 +00:00
|
|
|
hasMessagesWithRewards: this.messagesHaveUncollectedRewards(messagesWithAttachments),
|
2023-03-03 15:23:46 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2023-07-15 15:01:23 +01:00
|
|
|
/** client/mail/msg/send */
|
|
|
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
|
|
public sendMessage(sessionId: string, request: ISendMessageRequest): string
|
|
|
|
{
|
2023-07-21 17:08:32 +00:00
|
|
|
this.mailSendService.sendPlayerMessageToNpc(sessionId, request.dialogId, request.text);
|
|
|
|
|
2023-12-24 19:54:27 +00:00
|
|
|
if (this.registeredDialogueChatBots.has(request.dialogId))
|
2023-07-15 15:01:23 +01:00
|
|
|
{
|
2023-12-24 19:54:27 +00:00
|
|
|
return this.registeredDialogueChatBots.get(request.dialogId).handleMessage(sessionId, request);
|
2023-07-15 15:01:23 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return request.dialogId;
|
|
|
|
}
|
|
|
|
|
2023-03-03 15:23:46 +00:00
|
|
|
/**
|
|
|
|
* Get messages from a specific dialog that have items not expired
|
|
|
|
* @param sessionId Session id
|
|
|
|
* @param dialogueId Dialog to get mail attachments from
|
|
|
|
* @returns Message array
|
|
|
|
*/
|
|
|
|
protected getActiveMessagesFromDialog(sessionId: string, dialogueId: string): Message[]
|
|
|
|
{
|
|
|
|
const timeNow = this.timeUtil.getTimestamp();
|
2023-08-03 12:25:09 +01:00
|
|
|
const dialogs = this.dialogueHelper.getDialogsForProfile(sessionId);
|
2023-11-16 21:42:06 +00:00
|
|
|
return dialogs[dialogueId].messages.filter((x) => timeNow < (x.dt + x.maxStorageTime));
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Return array of messages with uncollected items (includes expired)
|
|
|
|
* @param messages Messages to parse
|
|
|
|
* @returns messages with items to collect
|
|
|
|
*/
|
|
|
|
protected getMessagesWithAttachments(messages: Message[]): Message[]
|
|
|
|
{
|
2023-11-16 21:42:06 +00:00
|
|
|
return messages.filter((x) => x.items?.data?.length > 0);
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2023-04-22 22:41:04 +00:00
|
|
|
* Delete expired items from all messages in player profile. triggers when updating traders.
|
|
|
|
* @param sessionId Session id
|
2023-03-03 15:23:46 +00:00
|
|
|
*/
|
2023-04-22 22:41:04 +00:00
|
|
|
protected removeExpiredItemsFromMessages(sessionId: string): void
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-08-03 12:25:09 +01:00
|
|
|
for (const dialogueId in this.dialogueHelper.getDialogsForProfile(sessionId))
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-04-22 22:41:04 +00:00
|
|
|
this.removeExpiredItemsFromMessage(sessionId, dialogueId);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Removes expired items from a message in player profile
|
|
|
|
* @param sessionId Session id
|
|
|
|
* @param dialogueId Dialog id
|
|
|
|
*/
|
|
|
|
protected removeExpiredItemsFromMessage(sessionId: string, dialogueId: string): void
|
|
|
|
{
|
2023-08-03 12:25:09 +01:00
|
|
|
const dialogs = this.dialogueHelper.getDialogsForProfile(sessionId);
|
|
|
|
const dialog = dialogs[dialogueId];
|
|
|
|
if (!dialog.messages)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (const message of dialog.messages)
|
2023-04-22 22:41:04 +00:00
|
|
|
{
|
|
|
|
if (this.messageHasExpired(message))
|
2023-03-03 15:23:46 +00:00
|
|
|
{
|
2023-04-22 22:41:04 +00:00
|
|
|
message.items = {};
|
2023-03-03 15:23:46 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-04-22 22:41:04 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Has a dialog message expired
|
|
|
|
* @param message Message to check expiry of
|
|
|
|
* @returns true or false
|
|
|
|
*/
|
|
|
|
protected messageHasExpired(message: Message): boolean
|
|
|
|
{
|
|
|
|
return (this.timeUtil.getTimestamp()) > (message.dt + message.maxStorageTime);
|
|
|
|
}
|
2023-11-16 21:42:06 +00:00
|
|
|
}
|