141 lines
4.7 KiB
C#
141 lines
4.7 KiB
C#
using Core.Annotations;
|
|
using Core.Models.Eft.Common.Tables;
|
|
using Core.Models.Eft.Profile;
|
|
using Core.Servers;
|
|
using Core.Services;
|
|
using Core.Utils;
|
|
using ILogger = Core.Models.Utils.ILogger;
|
|
|
|
namespace Core.Helpers;
|
|
|
|
[Injectable]
|
|
public class DialogueHelper
|
|
{
|
|
private readonly ILogger _logger;
|
|
private readonly HashUtil _hashUtil;
|
|
private readonly SaveServer _saveServer;
|
|
private readonly DatabaseServer _databaseServer;
|
|
private readonly NotifierHelper _notifierHelper;
|
|
private readonly NotificationSendHelper _notificationSendHelper;
|
|
private readonly LocalisationService _localisationService;
|
|
private readonly ItemHelper _itemHelper;
|
|
|
|
public DialogueHelper
|
|
(
|
|
ILogger logger,
|
|
HashUtil hashUtil,
|
|
SaveServer saveServer,
|
|
DatabaseServer databaseServer,
|
|
NotifierHelper notifierHelper,
|
|
NotificationSendHelper notificationSendHelper,
|
|
LocalisationService localisationService,
|
|
ItemHelper itemHelper
|
|
)
|
|
{
|
|
_logger = logger;
|
|
_hashUtil = hashUtil;
|
|
_saveServer = saveServer;
|
|
_databaseServer = databaseServer;
|
|
_notifierHelper = notifierHelper;
|
|
_localisationService = localisationService;
|
|
_itemHelper = itemHelper;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the preview contents of the last message in a dialogue.
|
|
/// </summary>
|
|
/// <param name="dialogue"></param>
|
|
/// <returns>MessagePreview</returns>
|
|
public MessagePreview GetMessagePreview(Models.Eft.Profile.Dialogue dialogue)
|
|
{
|
|
// The last message of the dialogue should be shown on the preview.
|
|
var message = dialogue.Messages[dialogue.Messages.Count - 1];
|
|
MessagePreview result = new()
|
|
{
|
|
DateTime = message?.DateTime,
|
|
MessageType = message?.MessageType,
|
|
TemplateId = message?.TemplateId,
|
|
UserId = dialogue?.Id
|
|
};
|
|
|
|
if (message?.Text is not null)
|
|
result.Text = message.Text;
|
|
|
|
if (message?.SystemData is not null)
|
|
result.SystemData = message?.SystemData;
|
|
|
|
return result;
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the item contents for a particular message.
|
|
/// </summary>
|
|
/// <param name="messageID"></param>
|
|
/// <param name="sessionID"></param>
|
|
/// <param name="itemId">Item being moved to inventory</param>
|
|
/// <returns></returns>
|
|
public List<Item> GetMessageItemContents(string messageID, string sessionID, string itemId)
|
|
{
|
|
var dialogueData = _saveServer.GetProfile(sessionID).DialogueRecords;
|
|
foreach (var dialogue in dialogueData)
|
|
{
|
|
var message = dialogueData[dialogue.Key].Messages.FirstOrDefault(x => x.Id == messageID);
|
|
if (message is null)
|
|
continue;
|
|
|
|
if (message.Id == messageID)
|
|
{
|
|
var attachmentsNew = _saveServer.GetProfile(sessionID).DialogueRecords[dialogue.Key].AttachmentsNew;
|
|
if (attachmentsNew > 0)
|
|
_saveServer.GetProfile(sessionID).DialogueRecords[dialogue.Key].AttachmentsNew = attachmentsNew - 1;
|
|
|
|
// Check reward count when item being moved isn't in reward list
|
|
// If count is 0, it means after this move occurs the reward array will be empty and all rewards collected
|
|
if (message.Items.Data is null)
|
|
message.Items.Data = new();
|
|
|
|
var rewardItems = message.Items.Data?.Where(x => x.Id != itemId);
|
|
if (rewardItems.Count() == 0)
|
|
{
|
|
message.RewardCollected = true;
|
|
message.HasRewards = false;
|
|
}
|
|
|
|
return message.Items.Data;
|
|
}
|
|
}
|
|
|
|
return new List<Item>();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Get the dialogs dictionary for a profile, create if doesn't exist
|
|
/// </summary>
|
|
/// <param name="sessionId">Session/player id</param>
|
|
/// <returns>Dialog dictionary</returns>
|
|
public Dictionary<string, Models.Eft.Profile.Dialogue> GetDialogsForProfile(string sessionId)
|
|
{
|
|
var profile = _saveServer.GetProfile(sessionId);
|
|
if (profile.DialogueRecords is null)
|
|
profile.DialogueRecords = new();
|
|
|
|
return profile.DialogueRecords;
|
|
}
|
|
|
|
public Models.Eft.Profile.Dialogue? GetDialogueFromProfile(string profileId, string dialogueId)
|
|
{
|
|
Models.Eft.Profile.Dialogue? returnDialogue = null;
|
|
var dialogues = GetDialogsForProfile(profileId);
|
|
|
|
foreach (var dialogue in dialogues.Values)
|
|
{
|
|
if (dialogue.Id == dialogueId)
|
|
returnDialogue = dialogue;
|
|
|
|
break;
|
|
}
|
|
|
|
return returnDialogue;
|
|
}
|
|
}
|