diff --git a/Resources/HostileCastingArea.json b/Resources/HostileCastingArea.json index 60046b5d7..1b0bd21e5 100644 --- a/Resources/HostileCastingArea.json +++ b/Resources/HostileCastingArea.json @@ -375,5 +375,13 @@ 32114, 31727, 33018, - 7946 + 7946, + 33080, + 33087, + 33250, + 33274, + 33275, + 33497, + 33490, + 33494 ] \ No newline at end of file diff --git a/Resources/RotationSolverRecord.json b/Resources/RotationSolverRecord.json new file mode 100644 index 000000000..62501ebec --- /dev/null +++ b/Resources/RotationSolverRecord.json @@ -0,0 +1,3 @@ +{ + "ClickingCount": 1 +} \ No newline at end of file diff --git a/RotationSolver.Basic/Configuration/OtherConfiguration.cs b/RotationSolver.Basic/Configuration/OtherConfiguration.cs index 77d1792ac..cc9133d77 100644 --- a/RotationSolver.Basic/Configuration/OtherConfiguration.cs +++ b/RotationSolver.Basic/Configuration/OtherConfiguration.cs @@ -19,6 +19,8 @@ public class OtherConfiguration public static HashSet InvincibleStatus = new(); + public static RotationSolverRecord RotationSolverRecord = new (); + public static void Init() { if (!Directory.Exists(Svc.PluginInterface.ConfigDirectory.FullName)) @@ -39,6 +41,8 @@ public static void Init() Task.Run(() => InitOne(ref HostileCastingTank, nameof(HostileCastingTank))); Task.Run(() => InitOne(ref BeneficialPositions, nameof(BeneficialPositions))); + + Task.Run(() => InitOne(ref RotationSolverRecord, nameof(RotationSolverRecord), false)); } public static void Save() @@ -50,6 +54,12 @@ public static void Save() SaveHostileCastingArea(); SaveHostileCastingTank(); SaveBeneficialPositions(); + SaveRotationSolverRecord(); + } + + public static void SaveRotationSolverRecord() + { + Task.Run(() => Save(RotationSolverRecord, nameof(RotationSolverRecord))); } public static void SaveBeneficialPositions() @@ -104,10 +114,13 @@ private static void Save(T value, string name) private static void SavePath(T value, string path) { File.WriteAllTextAsync(path, - JsonConvert.SerializeObject(value, Formatting.Indented)); + JsonConvert.SerializeObject(value, Formatting.Indented, new JsonSerializerSettings() + { + TypeNameHandling = TypeNameHandling.None, + })); } - private static void InitOne(ref T value, string name) + private static void InitOne(ref T value, string name, bool download = true) { var path = GetFilePath(name); if (File.Exists(path)) @@ -121,7 +134,7 @@ private static void InitOne(ref T value, string name) PluginLog.Warning(ex, $"Failed to load {name}."); } } - else + else if(download) { try { @@ -129,13 +142,24 @@ private static void InitOne(ref T value, string name) var str = client.GetStringAsync($"https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Resources/{name}.json").Result; File.WriteAllText(path, str); - value = JsonConvert.DeserializeObject(str); + value = JsonConvert.DeserializeObject(str, new JsonSerializerSettings() + { + MissingMemberHandling = MissingMemberHandling.Error, + Error = delegate (object sender, Newtonsoft.Json.Serialization.ErrorEventArgs args) + { + args.ErrorContext.Handled = true; + } + }); } catch { SavePath(value, path); } } + else + { + SavePath(value, path); + } } } #pragma warning restore CS1591 // Missing XML comment for publicly visible type or member diff --git a/RotationSolver.Basic/Configuration/RotationSolverRecord.cs b/RotationSolver.Basic/Configuration/RotationSolverRecord.cs new file mode 100644 index 000000000..c13ac08f1 --- /dev/null +++ b/RotationSolver.Basic/Configuration/RotationSolverRecord.cs @@ -0,0 +1,12 @@ +namespace RotationSolver.Basic.Configuration; + +/// +/// Record something about your using of Rotation Solver. +/// +public class RotationSolverRecord +{ + /// + /// How many times have rs clicked for you + /// + public ulong ClickingCount { get; set; } = 0; +} diff --git a/RotationSolver/Commands/RSCommands_Actions.cs b/RotationSolver/Commands/RSCommands_Actions.cs index 88c715d28..dc765f3e8 100644 --- a/RotationSolver/Commands/RSCommands_Actions.cs +++ b/RotationSolver/Commands/RSCommands_Actions.cs @@ -2,6 +2,7 @@ using Dalamud.Logging; using ECommons.DalamudServices; using ECommons.GameHelpers; +using RotationSolver.Basic.Configuration; using RotationSolver.Localization; using RotationSolver.UI; using RotationSolver.Updaters; @@ -26,7 +27,7 @@ internal static unsafe bool CanDoAnAction(bool isGCD) //Do not click the button in random time. if (DateTime.Now - _lastClickTime < TimeSpan.FromMilliseconds(new Random().Next( - (int)(Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMin) * 1000), (int)(Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMax) * 1000)))) return false; + (int)(Service.Config.GetValue(PluginConfigFloat.ClickingDelayMin) * 1000), (int)(Service.Config.GetValue(PluginConfigFloat.ClickingDelayMax) * 1000)))) return false; _lastClickTime = DateTime.Now; if (!isGCD && ActionUpdater.NextAction is IBaseAction act1 && act1.IsRealGCD) return false; @@ -37,7 +38,7 @@ internal static unsafe bool CanDoAnAction(bool isGCD) internal static uint _lastActionID; public static void DoAction() { - var wrong = new Random().NextDouble() < Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.MistakeRatio) && ActionUpdater.WrongAction != null; + var wrong = new Random().NextDouble() < Service.Config.GetValue(PluginConfigFloat.MistakeRatio) && ActionUpdater.WrongAction != null; var nextAction = wrong ? ActionUpdater.WrongAction : ActionUpdater.NextAction; if (nextAction == null) return; @@ -53,19 +54,21 @@ public static void DoAction() // Svc.Chat.Print($"Will Do {acti}"); #endif - if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.KeyBoardNoise)) + if (Service.Config.GetValue(PluginConfigBool.KeyBoardNoise)) { PreviewUpdater.PulseActionBar(nextAction.AdjustedID); } if (nextAction.Use()) { + OtherConfiguration.RotationSolverRecord.ClickingCount++; + _lastActionID = nextAction.AdjustedID; _lastUsedTime = DateTime.Now; if (nextAction is BaseAction act) { - if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.KeyBoardNoise)) + if (Service.Config.GetValue(PluginConfigBool.KeyBoardNoise)) Task.Run(() => PulseSimulation(nextAction.AdjustedID)); if (act.ShouldEndSpecial) ResetSpecial(); @@ -73,7 +76,7 @@ public static void DoAction() //Svc.Chat.Print($"{act}, {act.Target.Name}, {ActionUpdater.AbilityRemainCount}, {ActionUpdater.WeaponElapsed}"); #endif //Change Target - if (act.Target != null && (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.SwitchTargetFriendly) && !DataCenter.IsManual || ((Svc.Targets.Target?.IsNPCEnemy() ?? true) + if (act.Target != null && (Service.Config.GetValue(PluginConfigBool.SwitchTargetFriendly) && !DataCenter.IsManual || ((Svc.Targets.Target?.IsNPCEnemy() ?? true) || Svc.Targets.Target?.GetObjectKind() == Dalamud.Game.ClientState.Objects.Enums.ObjectKind.Treasure) && act.Target.IsNPCEnemy())) { @@ -90,12 +93,12 @@ static async void PulseSimulation(uint id) started = true; try { - for (int i = 0; i < new Random().Next(Service.Config.GetValue(Basic.Configuration.PluginConfigInt.KeyBoardNoiseMin), - Service.Config.GetValue(Basic.Configuration.PluginConfigInt.KeyBoardNoiseMax)); i++) + for (int i = 0; i < new Random().Next(Service.Config.GetValue(PluginConfigInt.KeyBoardNoiseMin), + Service.Config.GetValue(PluginConfigInt.KeyBoardNoiseMax)); i++) { PreviewUpdater.PulseActionBar(id); - var time = Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMin) + - new Random().NextDouble() * (Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMax) - Service.Config.GetValue(Basic.Configuration.PluginConfigFloat.ClickingDelayMin)); + var time = Service.Config.GetValue(PluginConfigFloat.ClickingDelayMin) + + new Random().NextDouble() * (Service.Config.GetValue(PluginConfigFloat.ClickingDelayMax) - Service.Config.GetValue(PluginConfigFloat.ClickingDelayMin)); await Task.Delay((int)(time * 1000)); } } @@ -131,18 +134,18 @@ internal static void UpdateRotationState() { CancelState(); } - else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.AutoOffWhenDead) + else if (Service.Config.GetValue(PluginConfigBool.AutoOffWhenDead) && Player.Available && Player.Object.CurrentHp == 0) { CancelState(); } - else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.AutoOffCutScene) + else if (Service.Config.GetValue(PluginConfigBool.AutoOffCutScene) && Svc.Condition[ConditionFlag.OccupiedInCutSceneEvent]) { CancelState(); } - else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.AutoOffBetweenArea) + else if (Service.Config.GetValue(PluginConfigBool.AutoOffBetweenArea) && ( Svc.Condition[ConditionFlag.BetweenAreas] || Svc.Condition[ConditionFlag.BetweenAreas51])) @@ -156,7 +159,7 @@ internal static void UpdateRotationState() CancelState(); } //Auto manual on being attacked by someone. - else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.StartOnAttackedBySomeone) + else if (Service.Config.GetValue(PluginConfigBool.StartOnAttackedBySomeone) && target != null && !target.IsDummy()) { @@ -166,7 +169,7 @@ internal static void UpdateRotationState() } } //Auto start at count Down. - else if (Service.Config.GetValue(Basic.Configuration.PluginConfigBool.StartOnCountdown) + else if (Service.Config.GetValue(PluginConfigBool.StartOnCountdown) && Service.CountDownTime > 0) { _lastCountdownTime = Service.CountDownTime; diff --git a/RotationSolver/Localization/Localization.json b/RotationSolver/Localization/Localization.json index e452c9d17..fd2e4f88d 100644 --- a/RotationSolver/Localization/Localization.json +++ b/RotationSolver/Localization/Localization.json @@ -496,5 +496,7 @@ "ConfigWindow_Basic_IdealClickingTime": "The ideal click time.", "ConfigWindow_Basic_RealClickingTime": "The real click time.", "ConfigWindow_Basic_ClickingDuration": "The clicking duration, RS will try to click at this duration.", - "ConfigWindow_Basic_WeaponDelay": "This is the clipping time.\nGCD is over. However, RS forgets to click the next action." + "ConfigWindow_Basic_WeaponDelay": "This is the clipping time.\nGCD is over. However, RS forgets to click the next action.", + "ConfigWindow_About_ClickingCount": "Rotation Solver helped you by clicking actions {0:N0} times.", + "ConfigWindow_About_ClickingTooMuch": "Well, you must be a lazy player!" } \ No newline at end of file diff --git a/RotationSolver/Localization/Strings.cs b/RotationSolver/Localization/Strings.cs index cfb3b066e..2574263ea 100644 --- a/RotationSolver/Localization/Strings.cs +++ b/RotationSolver/Localization/Strings.cs @@ -715,4 +715,6 @@ internal partial class Strings public string ConfigWindow_Basic_RealClickingTime { get; set; } = "The real click time."; public string ConfigWindow_Basic_ClickingDuration { get; set; } = "The clicking duration, RS will try to click at this duration."; public string ConfigWindow_Basic_WeaponDelay { get; set; } = "This is the clipping time.\nGCD is over. However, RS forgets to click the next action."; + public string ConfigWindow_About_ClickingCount { get; set; } = "Rotation Solver helped you by clicking actions {0:N0} times."; + public string ConfigWindow_About_ClickingTooMuch { get; set; } = "Well, you must be a lazy player!"; } \ No newline at end of file diff --git a/RotationSolver/UI/RotationConfigWindow.cs b/RotationSolver/UI/RotationConfigWindow.cs index ad28e83e8..3876e5964 100644 --- a/RotationSolver/UI/RotationConfigWindow.cs +++ b/RotationSolver/UI/RotationConfigWindow.cs @@ -495,6 +495,29 @@ private static void DrawAbout() Util.OpenLink("https://discord.gg/4fECHunam9"); } + var clickingCount = OtherConfiguration.RotationSolverRecord.ClickingCount; + if (clickingCount > 0) + { + ImGui.PushStyleColor(ImGuiCol.Text, new Vector4(0.2f, 0.6f, 0.95f, 1)); + var countStr = string.Format(LocalizationManager.RightLang.ConfigWindow_About_ClickingCount, + clickingCount); + ImGuiHelper.DrawItemMiddle(() => + { + ImGui.TextWrapped(countStr); + }, width, ImGui.CalcTextSize(countStr).X); + + if (clickingCount >= 100_000) + { + countStr = LocalizationManager.RightLang.ConfigWindow_About_ClickingTooMuch; + ImGuiHelper.DrawItemMiddle(() => + { + ImGui.TextWrapped(countStr); + }, width, ImGui.CalcTextSize(countStr).X); + } + ImGui.PopStyleColor(); + } + + _aboutHeaders.Draw(); }