From 62dab77d841c264a406cb0f88dff05c1ff672631 Mon Sep 17 00:00:00 2001 From: Plenyx <1507236+Plenyx@users.noreply.github.com> Date: Wed, 21 Feb 2024 23:09:18 +0100 Subject: [PATCH] Added detecting for log uploader's account name Added base files for Healing stats plugin for arcpds --- DpsReport/DpsReportJsonExtraJson.cs | 2 + DpsReport/ExtraJSON/Player.cs | 6 ++ DpsReport/ExtraJSON/StatsBarrier.cs | 10 ++ .../ExtraJSON/StatsBarrierOutgoingBarrier.cs | 13 +++ DpsReport/ExtraJSON/StatsHealing.cs | 10 ++ .../ExtraJSON/StatsHealingOutgoingHealing.cs | 13 +++ Forms/FormDiscordWebhooks.cs | 4 +- Forms/FormLogSession.cs | 2 +- Forms/FormMain.cs | 2 +- Tools/SessionTextConstructor.cs | 95 ++++++++++--------- 10 files changed, 107 insertions(+), 50 deletions(-) create mode 100644 DpsReport/ExtraJSON/StatsBarrier.cs create mode 100644 DpsReport/ExtraJSON/StatsBarrierOutgoingBarrier.cs create mode 100644 DpsReport/ExtraJSON/StatsHealing.cs create mode 100644 DpsReport/ExtraJSON/StatsHealingOutgoingHealing.cs diff --git a/DpsReport/DpsReportJsonExtraJson.cs b/DpsReport/DpsReportJsonExtraJson.cs index e2ff20e..b6bbe58 100644 --- a/DpsReport/DpsReportJsonExtraJson.cs +++ b/DpsReport/DpsReportJsonExtraJson.cs @@ -58,5 +58,7 @@ internal Dictionary GetPlayerTargetDPS() } return dict; } + + internal string RecordedByAccountName => Players.FirstOrDefault(x => x.Name == RecordedBy)?.Account ?? RecordedBy; } } diff --git a/DpsReport/ExtraJSON/Player.cs b/DpsReport/ExtraJSON/Player.cs index b850370..a6cab30 100644 --- a/DpsReport/ExtraJSON/Player.cs +++ b/DpsReport/ExtraJSON/Player.cs @@ -44,5 +44,11 @@ internal sealed class Player [JsonProperty("defenses")] internal Defenses[] Defenses { get; set; } + + [JsonProperty("statsHealing")] + internal StatsHealing StatsHealing { get; set; } + + [JsonProperty("statsBarrier")] + internal StatsBarrier StatsBarrier { get; set; } } } diff --git a/DpsReport/ExtraJSON/StatsBarrier.cs b/DpsReport/ExtraJSON/StatsBarrier.cs new file mode 100644 index 0000000..e32d984 --- /dev/null +++ b/DpsReport/ExtraJSON/StatsBarrier.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace PlenBotLogUploader.DpsReport.ExtraJson +{ + internal class StatsBarrier + { + [JsonProperty("outgoingBarrier")] + internal StatsBarrierOutgoingBarrier OutgoingBarrier { get; set; } + } +} diff --git a/DpsReport/ExtraJSON/StatsBarrierOutgoingBarrier.cs b/DpsReport/ExtraJSON/StatsBarrierOutgoingBarrier.cs new file mode 100644 index 0000000..d5d15d6 --- /dev/null +++ b/DpsReport/ExtraJSON/StatsBarrierOutgoingBarrier.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace PlenBotLogUploader.DpsReport.ExtraJson +{ + internal class StatsBarrierOutgoingBarrier + { + [JsonProperty("barrier")] + internal long Barrier { get; set; } + + [JsonProperty("bps")] + internal long BarrierPerSecond { get; set; } + } +} diff --git a/DpsReport/ExtraJSON/StatsHealing.cs b/DpsReport/ExtraJSON/StatsHealing.cs new file mode 100644 index 0000000..3e711d0 --- /dev/null +++ b/DpsReport/ExtraJSON/StatsHealing.cs @@ -0,0 +1,10 @@ +using Newtonsoft.Json; + +namespace PlenBotLogUploader.DpsReport.ExtraJson +{ + internal class StatsHealing + { + [JsonProperty("outgoingHealing")] + internal StatsHealingOutgoingHealing[] OutgoingHealing; + } +} diff --git a/DpsReport/ExtraJSON/StatsHealingOutgoingHealing.cs b/DpsReport/ExtraJSON/StatsHealingOutgoingHealing.cs new file mode 100644 index 0000000..20a0461 --- /dev/null +++ b/DpsReport/ExtraJSON/StatsHealingOutgoingHealing.cs @@ -0,0 +1,13 @@ +using Newtonsoft.Json; + +namespace PlenBotLogUploader.DpsReport.ExtraJson +{ + internal class StatsHealingOutgoingHealing + { + [JsonProperty("healing")] + internal long Healing { get; set; } + + [JsonProperty("hps")] + internal long HealingPerSecond { get; set; } + } +} diff --git a/Forms/FormDiscordWebhooks.cs b/Forms/FormDiscordWebhooks.cs index 0491220..a62d41b 100644 --- a/Forms/FormDiscordWebhooks.cs +++ b/Forms/FormDiscordWebhooks.cs @@ -60,7 +60,7 @@ internal async Task ExecuteAllActiveWebhooksAsync(DpsReportJson reportJSON, List if (reportJSON.Encounter.BossId.Equals(1)) // WvW { var extraJSONFightName = (reportJSON.ExtraJson is null) ? reportJSON.Encounter.Boss : reportJSON.ExtraJson.FightName; - var extraJSON = (reportJSON.ExtraJson is null) ? "" : $"Recorded by: {reportJSON.ExtraJson.RecordedBy}\nDuration: {reportJSON.ExtraJson.Duration}\nElite Insights version: {reportJSON.ExtraJson.EliteInsightsVersion}"; + var extraJSON = (reportJSON.ExtraJson is null) ? "" : $"Recorded by: {reportJSON.ExtraJson.RecordedByAccountName}\nDuration: {reportJSON.ExtraJson.Duration}\nElite Insights version: {reportJSON.ExtraJson.EliteInsightsVersion}"; var icon = ""; var bossData = Bosses.GetBossDataFromId(1); if (bossData is not null) @@ -295,7 +295,7 @@ internal async Task ExecuteAllActiveWebhooksAsync(DpsReportJson reportJSON, List var bossName = $"{reportJSON.Encounter.Boss}{(reportJSON.ChallengeMode ? " CM" : "")}"; var successString = (reportJSON.Encounter.Success ?? false) ? ":white_check_mark:" : "❌"; var lastTarget = (reportJSON?.ExtraJson?.PossiblyLastTarget is not null) ? $"\n{reportJSON.ExtraJson.PossiblyLastTarget.Name} ({Math.Round(100 - reportJSON.ExtraJson.PossiblyLastTarget.HealthPercentBurned, 2)}%)" : ""; - var extraJSON = (reportJSON.ExtraJson is null) ? "" : $"Recorded by: {reportJSON.ExtraJson.RecordedBy}\nDuration: {reportJSON.ExtraJson.Duration}{lastTarget}\nElite Insights version: {reportJSON.ExtraJson.EliteInsightsVersion}\n"; + var extraJSON = (reportJSON.ExtraJson is null) ? "" : $"Recorded by: {reportJSON.ExtraJson.RecordedByAccountName}\nDuration: {reportJSON.ExtraJson.Duration}{lastTarget}\nElite Insights version: {reportJSON.ExtraJson.EliteInsightsVersion}\n"; var icon = ""; var bossData = Bosses.GetBossDataFromId(reportJSON.Encounter.BossId); if (bossData is not null) diff --git a/Forms/FormLogSession.cs b/Forms/FormLogSession.cs index ed73604..d9a0e34 100644 --- a/Forms/FormLogSession.cs +++ b/Forms/FormLogSession.cs @@ -83,7 +83,7 @@ private void ButtonSessionStarter_Click(object sender, EventArgs e) { var success = (reportJSON.Encounter.Success ?? false) ? "true" : "false"; File.AppendAllText($"{ApplicationSettings.LocalDir}{fileName}.csv", - $"{reportJSON.ExtraJson?.FightName ?? reportJSON.Encounter.Boss};{reportJSON.Encounter.BossId};{success};{reportJSON.ExtraJson?.Duration ?? ""};{reportJSON.ExtraJson?.RecordedBy ?? ""};{reportJSON.ExtraJson?.EliteInsightsVersion ?? ""};{reportJSON.Evtc.Type}{reportJSON.Evtc.Version};{reportJSON.ConfigAwarePermalink};{reportJSON.UserToken}\n"); + $"{reportJSON.ExtraJson?.FightName ?? reportJSON.Encounter.Boss};{reportJSON.Encounter.BossId};{success};{reportJSON.ExtraJson?.Duration ?? ""};{reportJSON.ExtraJson?.RecordedByAccountName ?? ""};{reportJSON.ExtraJson?.EliteInsightsVersion ?? ""};{reportJSON.Evtc.Type}{reportJSON.Evtc.Version};{reportJSON.ConfigAwarePermalink};{reportJSON.UserToken}\n"); } _ = SendSessionWebhooks(logSessionSettings); } diff --git a/Forms/FormMain.cs b/Forms/FormMain.cs index 27524cb..048115f 100644 --- a/Forms/FormMain.cs +++ b/Forms/FormMain.cs @@ -798,7 +798,7 @@ internal async Task HttpUploadLogAsync(string file, Dictionary p try { // log file - File.AppendAllText($"{ApplicationSettings.LocalDir}uploaded_logs.csv", $"{reportJson.ExtraJson?.FightName ?? reportJson.Encounter.Boss};{bossId};{success};{reportJson.ExtraJson?.Duration ?? ""};{reportJson.ExtraJson?.RecordedBy ?? ""};{reportJson.ExtraJson?.EliteInsightsVersion ?? ""};{reportJson.Evtc.Type}{reportJson.Evtc.Version};{reportJson.ConfigAwarePermalink};{reportJson.UserToken}\n"); + File.AppendAllText($"{ApplicationSettings.LocalDir}uploaded_logs.csv", $"{reportJson.ExtraJson?.FightName ?? reportJson.Encounter.Boss};{bossId};{success};{reportJson.ExtraJson?.Duration ?? ""};{reportJson.ExtraJson?.RecordedByAccountName ?? ""};{reportJson.ExtraJson?.EliteInsightsVersion ?? ""};{reportJson.Evtc.Type}{reportJson.Evtc.Version};{reportJson.ConfigAwarePermalink};{reportJson.UserToken}\n"); } catch (Exception e) { diff --git a/Tools/SessionTextConstructor.cs b/Tools/SessionTextConstructor.cs index 544b23f..1d1bbd2 100644 --- a/Tools/SessionTextConstructor.cs +++ b/Tools/SessionTextConstructor.cs @@ -66,7 +66,7 @@ internal static DiscordEmbeds ConstructSessionEmbeds(List reports .Where(x => Bosses.All .Any(y => y.BossId.Equals(x.Evtc.BossId) && y.Type.Equals(BossType.Golem))) .ToArray(); - var wvWLogs = reportsJSON + var wvwLogs = reportsJSON .Where(x => Bosses.All .Any(y => y.BossId.Equals(x.Evtc.BossId) && y.Type.Equals(BossType.WvW))) .ToArray(); @@ -79,9 +79,9 @@ internal static DiscordEmbeds ConstructSessionEmbeds(List reports .ToArray(); var durationText = $"Session duration: **{logSessionSettings.ElapsedTime}**"; - var builderSuccessFailure = ((wvWLogs.Length > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); - var builderSuccess = ((wvWLogs.Length > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); - var builderFailure = ((wvWLogs.Length > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); + var builderSuccessFailure = ((wvwLogs.Length > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); + var builderSuccess = ((wvwLogs.Length > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); + var builderFailure = ((wvwLogs.Length > 0) && logSessionSettings.MakeWvWSummaryEmbed) ? new StringBuilder() : new StringBuilder($"{durationText}\n\n"); int messageSuccessFailureCount = 0, messageSuccessCount = 0, messageFailureCount = 0; if (raidLogs.Length > 0) @@ -401,18 +401,18 @@ internal static DiscordEmbeds ConstructSessionEmbeds(List reports } } } - if (wvWLogs.Length > 0) + if (wvwLogs.Length > 0) { if (logSessionSettings.MakeWvWSummaryEmbed) { - var totalEnemyKills = wvWLogs.Select(x => + var totalEnemyKills = wvwLogs.Select(x => x.ExtraJson?.Players .Where(y => !y.FriendlyNpc && !y.NotInSquad) .Select(y => y.StatsTargets.Select(z => z[0].Killed).Sum()) .Sum() ?? 0) .Sum(); - var totalSquadDeaths = wvWLogs.Select(x => + var totalSquadDeaths = wvwLogs.Select(x => x.ExtraJson?.Players .Where(y => !y.FriendlyNpc && !y.NotInSquad) .Select(y => y.Defenses[0].DeadCount) @@ -422,54 +422,57 @@ internal static DiscordEmbeds ConstructSessionEmbeds(List reports discordEmbedSummary = MakeEmbedFromText($"{logSessionSettings.Name} - WvW Summary", $"{durationText}\n\n" + $"Total kills: **{totalEnemyKills}**\nTotal kills per minute: **{Math.Round(totalEnemyKills / logSessionSettings.ElapsedTimeSpan.TotalMinutes, 3).ToString(CultureInfo.InvariantCulture.NumberFormat)}**\n\n" + $"Total squad deaths: **{totalSquadDeaths}**\nTotal squad deaths per minute: **{Math.Round(totalSquadDeaths / logSessionSettings.ElapsedTimeSpan.TotalMinutes, 3).ToString(CultureInfo.InvariantCulture.NumberFormat)}**\n\n" + - $"Kill Death Ratio:: **{Math.Round((double)(totalEnemyKills / totalSquadDeaths), 2).ToString(CultureInfo.InvariantCulture.NumberFormat)}**"); + $"Kill Death Ratio: **{Math.Round((double)(totalEnemyKills / totalSquadDeaths), 2).ToString(CultureInfo.InvariantCulture.NumberFormat)}**"); discordEmbedSummary.Thumbnail = defaultWvWSummaryThumbnail; } - if (!builderSuccessFailure.ToString().EndsWith("***\n")) - { - builderSuccessFailure.Append("\n\n"); - } - if (!builderSuccess.ToString().EndsWith("***\n")) - { - builderSuccess.Append("\n\n"); - } - if (!builderFailure.ToString().EndsWith("***\n")) + if (logSessionSettings.EnableWvWLogList) { - builderFailure.Append("\n\n"); - } - builderSuccessFailure.Append("***WvW logs:***\n"); - builderSuccess.Append("***WvW logs:***\n"); - builderFailure.Append("***WvW logs:***\n"); - foreach (var log in wvWLogs.AsSpan()) - { - builderSuccessFailure.Append(log.ConfigAwarePermalink).Append('\n'); - if (builderSuccessFailure.Length >= maxAllowedMessageSize) + if (!builderSuccessFailure.ToString().EndsWith("***\n")) { - messageSuccessFailureCount++; - discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); - builderSuccessFailure.Clear(); - builderSuccessFailure.Append("***WvW logs:***\n"); + builderSuccessFailure.Append("\n\n"); } - if (log.Encounter.Success ?? false) + if (!builderSuccess.ToString().EndsWith("***\n")) { - builderSuccess.Append(log.ConfigAwarePermalink).Append('\n'); - if (builderSuccess.Length >= maxAllowedMessageSize) - { - messageSuccessCount++; - discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); - builderSuccess.Clear(); - builderSuccess.Append("***WvW logs:***\n"); - } + builderSuccess.Append("\n\n"); } - else + if (!builderFailure.ToString().EndsWith("***\n")) { - builderFailure.Append(log.ConfigAwarePermalink).Append('\n'); - if (builderFailure.Length >= maxAllowedMessageSize) + builderFailure.Append("\n\n"); + } + builderSuccessFailure.Append("***WvW logs:***\n"); + builderSuccess.Append("***WvW logs:***\n"); + builderFailure.Append("***WvW logs:***\n"); + foreach (var log in wvwLogs.AsSpan()) + { + builderSuccessFailure.Append(log.ConfigAwarePermalink).Append('\n'); + if (builderSuccessFailure.Length >= maxAllowedMessageSize) { - messageFailureCount++; - discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); - builderFailure.Clear(); - builderFailure.Append("***WvW logs:***\n"); + messageSuccessFailureCount++; + discordEmbedsSuccessFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessFailureCount > 1) ? $" part {messageSuccessFailureCount}" : ""), builderSuccessFailure.ToString())); + builderSuccessFailure.Clear(); + builderSuccessFailure.Append("***WvW logs:***\n"); + } + if (log.Encounter.Success ?? false) + { + builderSuccess.Append(log.ConfigAwarePermalink).Append('\n'); + if (builderSuccess.Length >= maxAllowedMessageSize) + { + messageSuccessCount++; + discordEmbedsSuccess.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageSuccessCount > 1) ? $" part {messageSuccessCount}" : ""), builderSuccess.ToString())); + builderSuccess.Clear(); + builderSuccess.Append("***WvW logs:***\n"); + } + } + else + { + builderFailure.Append(log.ConfigAwarePermalink).Append('\n'); + if (builderFailure.Length >= maxAllowedMessageSize) + { + messageFailureCount++; + discordEmbedsFailure.Add(MakeEmbedFromText(logSessionSettings.Name + ((messageFailureCount > 1) ? $" part {messageFailureCount}" : ""), builderFailure.ToString())); + builderFailure.Clear(); + builderFailure.Append("***WvW logs:***\n"); + } } } }