From f075ff55dcd1f27f33c8ebc8ff91a628f58dfe5b Mon Sep 17 00:00:00 2001 From: kalilistic <35899782+kalilistic@users.noreply.github.com> Date: Tue, 21 Sep 2021 23:01:06 -0400 Subject: [PATCH] feat: add roll reminder --- src/Kapture.Test/Kapture.Test.csproj | 1 + src/Kapture.Test/Mocks/KapturePluginMock.cs | 1 - src/Kapture/Kapture.csproj | 2 +- src/Kapture/Kapture/Model/ItemList.cs | 18 +++++ src/Kapture/Kapture/Model/LootRoller.cs | 10 +++ .../Plugin/Configuration/KaptureConfig.cs | 10 +++ .../Resource/source/Kapture_Localizable.json | 66 ++++++++++++------- src/Kapture/Kapture/Service/RollMonitor.cs | 19 ++++++ .../Kapture/UserInterface/SettingsWindow.cs | 34 +++++++++- 9 files changed, 133 insertions(+), 28 deletions(-) create mode 100644 src/Kapture/Kapture/Model/ItemList.cs diff --git a/src/Kapture.Test/Kapture.Test.csproj b/src/Kapture.Test/Kapture.Test.csproj index e8563eca..61823b06 100644 --- a/src/Kapture.Test/Kapture.Test.csproj +++ b/src/Kapture.Test/Kapture.Test.csproj @@ -15,6 +15,7 @@ + diff --git a/src/Kapture.Test/Mocks/KapturePluginMock.cs b/src/Kapture.Test/Mocks/KapturePluginMock.cs index 8ea40561..89067949 100644 --- a/src/Kapture.Test/Mocks/KapturePluginMock.cs +++ b/src/Kapture.Test/Mocks/KapturePluginMock.cs @@ -1,5 +1,4 @@ using System.Collections.Generic; -using Dalamud.DrunkenToad; using Dalamud.Game.ClientState.Party; using Dalamud.Game.Text; diff --git a/src/Kapture/Kapture.csproj b/src/Kapture/Kapture.csproj index 21329cbe..d8e65dd4 100644 --- a/src/Kapture/Kapture.csproj +++ b/src/Kapture/Kapture.csproj @@ -99,7 +99,7 @@ - + all runtime; build; native; contentfiles; analyzers; buildtransitive diff --git a/src/Kapture/Kapture/Model/ItemList.cs b/src/Kapture/Kapture/Model/ItemList.cs new file mode 100644 index 00000000..33fae085 --- /dev/null +++ b/src/Kapture/Kapture/Model/ItemList.cs @@ -0,0 +1,18 @@ +namespace Kapture +{ + /// + /// Item list. + /// + public class ItemList + { + /// + /// Gets item ids. + /// + public uint[] ItemIds { get; init; } = null!; + + /// + /// Gets item names. + /// + public string[] ItemNames { get; init; } = null!; + } +} diff --git a/src/Kapture/Kapture/Model/LootRoller.cs b/src/Kapture/Kapture/Model/LootRoller.cs index dc7720b5..5fef8b61 100644 --- a/src/Kapture/Kapture/Model/LootRoller.cs +++ b/src/Kapture/Kapture/Model/LootRoller.cs @@ -36,5 +36,15 @@ public class LootRoller /// Gets or sets a value indicating whether is winner. /// public bool IsWinner { get; set; } + + /// + /// Gets or sets a value indicating whether alert roll has been made. + /// + public bool IsReminderSent { get; set; } + + /// + /// Gets a value indicating whether is local player. + /// + public bool IsLocalPlayer { get; init; } } } diff --git a/src/Kapture/Kapture/Plugin/Configuration/KaptureConfig.cs b/src/Kapture/Kapture/Plugin/Configuration/KaptureConfig.cs index a40e99aa..d7ca5e90 100644 --- a/src/Kapture/Kapture/Plugin/Configuration/KaptureConfig.cs +++ b/src/Kapture/Kapture/Plugin/Configuration/KaptureConfig.cs @@ -206,5 +206,15 @@ public class KaptureConfig : IPluginConfiguration /// public int Version { get; set; } + + /// + /// Gets or sets a value indicating whether gets or sets a value indicating to send alert. + /// + public bool SendRollReminder { get; set; } = true; + + /// + /// Gets or sets the time in ms for alert warning. + /// + public int RollReminderTime { get; set; } = 15000; } } diff --git a/src/Kapture/Kapture/Resource/source/Kapture_Localizable.json b/src/Kapture/Kapture/Resource/source/Kapture_Localizable.json index 32486c2f..8f1ab44d 100644 --- a/src/Kapture/Kapture/Resource/source/Kapture_Localizable.json +++ b/src/Kapture/Kapture/Resource/source/Kapture_Localizable.json @@ -7,45 +7,57 @@ "message": "Use /loot and /roll for the overlays and /lootconfig for settings.", "description": "KapturePlugin.HandleFreshInstall" }, + "WatchListAddedAlert": { + "message": "{0} dropped and is on your watch list.", + "description": "RollMonitor.ProcessRoll" + }, + "WatchListObtainedAlert": { + "message": "{0} obtained so removing from your watch list.", + "description": "RollMonitor.ProcessRoll" + }, + "RollMonitorLost": { + "message": "Dropped to floor", + "description": "RollMonitor.ProcessRoll" + }, + "RollReminder": { + "message": "Roll soon on {0}!", + "description": "RollMonitor.SendRollReminder" + }, "LootOverlayWindow": { "message": "Loot", - "description": "LootOverlayWindow.DrawView" + "description": "LootWindow..ctor" }, "LootItemName": { "message": "Item", - "description": "LootOverlayWindow.DrawView" + "description": "LootWindow.Draw" }, "LootEventType": { "message": "Event", - "description": "LootOverlayWindow.DrawView" + "description": "LootWindow.Draw" }, "LootPlayer": { "message": "Player", - "description": "LootOverlayWindow.DrawView" + "description": "LootWindow.Draw" }, "WaitingForItems": { "message": "Waiting for items.", - "description": "LootOverlayWindow.DrawView" + "description": "LootWindow.Draw" }, "RollMonitorOverlayWindow": { "message": "Roll Monitor", - "description": "RollMonitorOverlay.DrawView" + "description": "RollWindow..ctor" }, "MonitorItemName": { "message": "Item", - "description": "RollMonitorOverlay.DrawView" + "description": "RollWindow.Draw" }, "MonitorRollers": { "message": "Rollers", - "description": "RollMonitorOverlay.DrawView" + "description": "RollWindow.Draw" }, "MonitorWinner": { "message": "Winner", - "description": "RollMonitorOverlay.DrawView" - }, - "SettingsWindow": { - "message": "Kapture Settings", - "description": "SettingsWindow.DrawView" + "description": "RollWindow.Draw" }, "General": { "message": "General", @@ -131,6 +143,14 @@ "message": "show roll monitor overlay window", "description": "SettingsWindow.DrawRolls" }, + "ShowRollReminder": { + "message": "Show Roll Reminder in Chat", + "description": "SettingsWindow.DrawRolls" + }, + "ShowRollReminder_HelpMarker": { + "message": "send roll reminder before item drops", + "description": "SettingsWindow.DrawRolls" + }, "RollDisplayMode": { "message": "Display Mode", "description": "SettingsWindow.DrawRolls" @@ -163,6 +183,14 @@ "message": "amount of time before removing obtained/lost items from roll monitor", "description": "SettingsWindow.DrawRolls" }, + "RollReminderTime": { + "message": "Roll Reminder Warning (seconds)", + "description": "SettingsWindow.DrawRolls" + }, + "RollReminderTime_HelpMarker": { + "message": "amount of time in advanced of missing roll to send reminder", + "description": "SettingsWindow.DrawRolls" + }, "AddEnabled": { "message": "Add", "description": "SettingsWindow.DrawEventTypes" @@ -326,17 +354,5 @@ "ClearData": { "message": "Clear Data", "description": "SettingsWindow.DrawLinks" - }, - "WatchListAddedAlert": { - "message": "{0} dropped and is on your watch list.", - "description": "RollMonitor.ProcessRoll" - }, - "WatchListObtainedAlert": { - "message": "{0} obtained so removing from your watch list.", - "description": "RollMonitor.ProcessRoll" - }, - "RollMonitorLost": { - "message": "Dropped to floor", - "description": "RollMonitor.ProcessRoll" } } diff --git a/src/Kapture/Kapture/Service/RollMonitor.cs b/src/Kapture/Kapture/Service/RollMonitor.cs index 1f23e61d..e22de873 100644 --- a/src/Kapture/Kapture/Service/RollMonitor.cs +++ b/src/Kapture/Kapture/Service/RollMonitor.cs @@ -64,6 +64,7 @@ public void UpdateRolls() this.plugin.Configuration.RollMonitorObtainedTimeout); this.plugin.IsRolling = this.plugin.LootRolls.Count > 0; this.CreateDisplayList(); + this.SendRollReminder(); } catch (Exception ex) { @@ -103,6 +104,7 @@ public void ProcessRoll(LootEvent lootEvent) this.plugin.Configuration.RollNameFormat, player.Name.ToString()), RollColor = ImGuiColorUtil.GetColorByNumber(0), + IsLocalPlayer = player.ObjectId == KapturePlugin.ClientState.LocalPlayer?.ObjectId, }); } @@ -260,5 +262,22 @@ private void CreateDisplayList() this.plugin.LootRollsDisplay = JsonConvert.DeserializeObject>(JsonConvert.SerializeObject(this.plugin.LootRolls)); } + + private void SendRollReminder() + { + if (!this.plugin.Configuration.SendRollReminder) return; + foreach (var lootRoll in this.plugin.LootRolls.Where(roll => !roll.IsWon)) + { + var rollerMatch = lootRoll.Rollers.FirstOrDefault(roller => + roller.IsLocalPlayer && + !roller.HasRolled && !roller.IsReminderSent && + DateUtil.CurrentTime() > lootRoll.Timestamp + 300000 - this.plugin.Configuration.RollReminderTime); + if (rollerMatch != null) + { + rollerMatch.IsReminderSent = true; + KapturePlugin.Chat.PluginPrintNotice(string.Format(Loc.Localize("RollReminder", "Roll soon on {0}!"), lootRoll.ItemName)); + } + } + } } } diff --git a/src/Kapture/Kapture/UserInterface/SettingsWindow.cs b/src/Kapture/Kapture/UserInterface/SettingsWindow.cs index 32093c5a..f3a67fa4 100644 --- a/src/Kapture/Kapture/UserInterface/SettingsWindow.cs +++ b/src/Kapture/Kapture/UserInterface/SettingsWindow.cs @@ -54,7 +54,7 @@ private enum Tab /// public override void Draw() { - ImGui.SetNextWindowSize(new Vector2(500 * ImGuiHelpers.GlobalScale, 320 * ImGuiHelpers.GlobalScale), ImGuiCond.Appearing); + ImGui.SetNextWindowSize(new Vector2(500 * ImGuiHelpers.GlobalScale, 360 * ImGuiHelpers.GlobalScale), ImGuiCond.Appearing); this.DrawTabs(); switch (this.currentTab) { @@ -271,6 +271,22 @@ private void DrawRolls() "show roll monitor overlay window")); ImGui.Spacing(); + // show roll reminder + var showRollReminder = this.plugin.Configuration.SendRollReminder; + if (ImGui.Checkbox( + Loc.Localize("ShowRollReminder", "Show Roll Reminder in Chat") + "###Kapture_ShowRollReminder_Checkbox", + ref showRollReminder)) + { + this.plugin.Configuration.ShowRollMonitorOverlay = showRollReminder; + this.Plugin.WindowManager.RollWindow!.IsOpen = showRollReminder; + this.plugin.SaveConfig(); + } + + ImGuiComponents.HelpMarker(Loc.Localize( + "ShowRollReminder_HelpMarker", + "send roll reminder before item drops")); + ImGui.Spacing(); + // display mode ImGui.Text(Loc.Localize("RollDisplayMode", "Display Mode")); ImGuiComponents.HelpMarker(Loc.Localize( @@ -340,6 +356,22 @@ private void DrawRolls() } ImGui.Spacing(); + + // roll reminder warning + ImGui.Text(Loc.Localize("RollReminderTime", "Roll Reminder Warning (seconds)")); + ImGuiComponents.HelpMarker(Loc.Localize( + "RollReminderTime_HelpMarker", + "amount of time in advanced of missing roll to send reminder")); + var rollReminderTime = + this.plugin.Configuration.RollReminderTime.FromMillisecondsToSeconds(); + if (ImGui.SliderInt("###PlayerTrack_RollReminderTime_Slider", ref rollReminderTime, 5, 60)) + { + this.plugin.Configuration.RollReminderTime = + rollReminderTime.FromSecondsToMilliseconds(); + this.plugin.SaveConfig(); + } + + ImGui.Spacing(); } private void DrawEventTypes()