From 8180fab8b8e3dc4dd5445c8f015422bbdbc3c5e2 Mon Sep 17 00:00:00 2001 From: Chomp Date: Sat, 18 Jan 2025 17:03:21 +0000 Subject: [PATCH] Implemented various dialog functions --- Core/Controllers/DialogueController.cs | 112 ++++++++++++++++-- .../Helpers/Dialogue/CommandoDialogChatBot.cs | 2 +- 2 files changed, 104 insertions(+), 10 deletions(-) diff --git a/Core/Controllers/DialogueController.cs b/Core/Controllers/DialogueController.cs index fb43c002..6bef46c5 100644 --- a/Core/Controllers/DialogueController.cs +++ b/Core/Controllers/DialogueController.cs @@ -22,6 +22,7 @@ public class DialogueController protected ConfigServer _configServer; protected SaveServer _saveServer; protected LocalisationService _localisationService; + protected MailSendService _mailSendService; protected List _dialogueChatBots; protected CoreConfig _coreConfig; @@ -33,6 +34,7 @@ public class DialogueController ConfigServer configServer, SaveServer saveServer, LocalisationService localisationService, + MailSendService mailSendService, IEnumerable dialogueChatBots) { _logger = logger; @@ -42,6 +44,7 @@ public class DialogueController _configServer = configServer; _saveServer = saveServer; _localisationService = localisationService; + _mailSendService = mailSendService; _dialogueChatBots = dialogueChatBots.ToList(); _coreConfig = _configServer.GetConfig(); @@ -221,7 +224,21 @@ public class DialogueController GetMailDialogViewRequestData request, string sessionId) { - throw new NotImplementedException(); + var dialogueId = request.DialogId; + var fullProfile = _saveServer.GetProfile(sessionId); + var dialogue = GetDialogByIdFromProfile(fullProfile, request); + + // Dialog was opened, remove the little [1] on screen + dialogue.New = 0; + + // Set number of new attachments, but ignore those that have expired. + dialogue.AttachmentsNew = GetUnreadMessagesWithAttachmentsCount(sessionId, dialogueId); + + return new GetMailDialogViewResponseData{ + Messages = dialogue.Messages, + Profiles = GetProfilesForMail(fullProfile, dialogue.Users), + HasMessagesWithRewards = MessagesHaveUncollectedRewards(dialogue.Messages), + }; } /// @@ -234,7 +251,31 @@ public class DialogueController SptProfile profile, GetMailDialogViewRequestData request) { - throw new NotImplementedException(); + if (!profile.DialogueRecords.ContainsKey(request.DialogId)) + { + profile.DialogueRecords[request.DialogId] = new Dialogue{ + Id = request.DialogId, + AttachmentsNew = 0, + Pinned = false, + Messages = [], + New = 0, + Type = request.Type, + }; + + if (request.Type == MessageType.USER_MESSAGE) + { + var dialogue = profile.DialogueRecords[request.DialogId]; + dialogue.Users = []; + var chatBot = _dialogueChatBots.FirstOrDefault((cb) => cb.GetChatBot().Id == request.DialogId); + if (chatBot is not null) + { + dialogue.Users ??= []; + dialogue.Users.Add(chatBot.GetChatBot()); + } + } + } + + return profile.DialogueRecords[request.DialogId]; } /// @@ -243,11 +284,36 @@ public class DialogueController /// Player profile /// The participants of the mail /// UserDialogInfo list - private List GetProfilesForMail( - SptProfile fullProfile, - List? userDialogs) + private List GetProfilesForMail(SptProfile fullProfile, List? userDialogs) { - throw new NotImplementedException(); + List result = []; + if (userDialogs is null) + { + // Nothing to add + return result; + } + + result.AddRange(userDialogs); + + if (result.All(userDialog => userDialog.Id != fullProfile.ProfileInfo.ProfileId)) + { + // Player doesn't exist, add them in before returning + var pmcProfile = fullProfile.CharacterData.PmcData; + result.Add( new UserDialogInfo{ + Id = fullProfile.ProfileInfo.ProfileId, + Aid = fullProfile.ProfileInfo.Aid, + Info = new UserDialogDetails + { + Nickname = pmcProfile.Info.Nickname, + Side = pmcProfile.Info.Side, + Level = pmcProfile.Info.Level, + MemberCategory = pmcProfile.Info.MemberCategory, + SelectedMemberCategory = pmcProfile.Info.SelectedMemberCategory, + } + }); + } + + return result; } /// @@ -260,7 +326,29 @@ public class DialogueController string sessionId, string dialogueId) { - throw new NotImplementedException(); + var newAttachmentCount = 0; + var activeMessages = GetActiveMessagesFromDialog(sessionId, dialogueId); + foreach (var message in activeMessages) { + if (message.HasRewards.GetValueOrDefault(false) && !message.RewardCollected.GetValueOrDefault(false)) + { + newAttachmentCount++; + } + } + + return newAttachmentCount; + } + + /** + * 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 List GetActiveMessagesFromDialog(string sessionId, string dialogueId) { + var timeNow = _timeUtil.GetTimeStamp(); + var dialogs = _dialogueHelper.GetDialogsForProfile(sessionId); + + return dialogs[dialogueId].Messages.Where((message) => timeNow @@ -270,7 +358,7 @@ public class DialogueController /// true if uncollected rewards found private bool MessagesHaveUncollectedRewards(List messages) { - throw new NotImplementedException(); + return messages.Any((message) => (message.Items?.Data?.Count ?? 0) > 0); } /// @@ -337,7 +425,13 @@ public class DialogueController string sessionId, SendMessageRequest request) { - throw new NotImplementedException(); + _mailSendService.SendPlayerMessageToNpc(sessionId, request.DialogId, request.Text); + + return ( + _dialogueChatBots + .FirstOrDefault((cb) => cb.GetChatBot().Id == request.DialogId) + ?.HandleMessage(sessionId, request) ?? request.DialogId + ); } /// diff --git a/Core/Helpers/Dialogue/CommandoDialogChatBot.cs b/Core/Helpers/Dialogue/CommandoDialogChatBot.cs index e1ccd1bc..626e2970 100644 --- a/Core/Helpers/Dialogue/CommandoDialogChatBot.cs +++ b/Core/Helpers/Dialogue/CommandoDialogChatBot.cs @@ -36,7 +36,7 @@ public class CommandoDialogChatBot : AbstractDialogChatBot Level = 1, MemberCategory = MemberCategory.DEVELOPER, SelectedMemberCategory = MemberCategory.DEVELOPER, - Nickname = _coreConfig.SptFriendNickname, + Nickname = "Commando", Side = "Usec" } };