From 121c98b3dfaefb40499fd7a9a51102f09076f551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Wed, 19 Apr 2023 22:04:37 +0800 Subject: [PATCH] fix: add a animationLock Dictionary. --- Resources/AnimationLockTime.json | 12 +++++++ .../Configuration/PluginConfiguration.cs | 1 + RotationSolver.Basic/Helpers/IActionHelper.cs | 34 ++++++++++++++++++- RotationSolver/Commands/RSCommands_Actions.cs | 3 +- RotationSolver/RotationSolverPlugin.cs | 12 +++++++ RotationSolver/Updaters/ActionUpdater.cs | 2 ++ RotationSolver/Watcher.cs | 1 + 7 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 Resources/AnimationLockTime.json diff --git a/Resources/AnimationLockTime.json b/Resources/AnimationLockTime.json new file mode 100644 index 000000000..fe4b09f26 --- /dev/null +++ b/Resources/AnimationLockTime.json @@ -0,0 +1,12 @@ +{ + "31": 0.6, + "37": 0.6, + "45": 0.6, + "52": 0.6, + "3549": 0.6, + "7386": 0.6, + "7387": 0.6, + "7389": 0.6, + "16465": 0.6, + "25753": 1.15 +} \ No newline at end of file diff --git a/RotationSolver.Basic/Configuration/PluginConfiguration.cs b/RotationSolver.Basic/Configuration/PluginConfiguration.cs index 21e97a3fc..08eebc7ee 100644 --- a/RotationSolver.Basic/Configuration/PluginConfiguration.cs +++ b/RotationSolver.Basic/Configuration/PluginConfiguration.cs @@ -109,6 +109,7 @@ public class PluginConfiguration : IPluginConfiguration public float SpecialDuration = 3; public float AbilitiesInterval = 0.67f; public float ActionAhead = 0.08f; + public float ActionAheadForLast0GCD = 0.06f; public float WeaponDelayMin = 0; public float WeaponDelayMax = 0; diff --git a/RotationSolver.Basic/Helpers/IActionHelper.cs b/RotationSolver.Basic/Helpers/IActionHelper.cs index 2ad12d1bf..981b220ac 100644 --- a/RotationSolver.Basic/Helpers/IActionHelper.cs +++ b/RotationSolver.Basic/Helpers/IActionHelper.cs @@ -1,7 +1,39 @@ -namespace RotationSolver.Basic.Helpers; +using Dalamud.Logging; +using System.IO; + +namespace RotationSolver.Basic.Helpers; public static class IActionHelper { + public static SortedList AnimationLockTime = new SortedList(); + + public static async void GetAnimationLockTimeAsync(string directory) + { + var filename = $"{nameof(AnimationLockTime)}.json"; + var filePath = Path.Combine(directory, filename); + if (File.Exists(filePath)) + { + var str = File.ReadAllText(filePath); + AnimationLockTime = JsonConvert.DeserializeObject>(str); + } + else + { + try + { + var client = new HttpClient(); + var str = await client.GetStringAsync($"https://raw.githubusercontent.com/ArchiDog1998/RotationSolver/main/Resources/{nameof(AnimationLockTime)}.json"); + File.WriteAllText(filePath, str); + + AnimationLockTime = JsonConvert.DeserializeObject>(str); + } + catch (Exception ex) + { + PluginLog.Warning(ex, "Failed to download the animation lock time."); + } + } + + } + public static ActionID[] MovingActions = new ActionID[] { ActionID.EnAvant, diff --git a/RotationSolver/Commands/RSCommands_Actions.cs b/RotationSolver/Commands/RSCommands_Actions.cs index 2f12edf14..61f36759d 100644 --- a/RotationSolver/Commands/RSCommands_Actions.cs +++ b/RotationSolver/Commands/RSCommands_Actions.cs @@ -21,8 +21,7 @@ internal static unsafe void DoAnAction(bool isGCD) } _lastState = DataCenter.StateType; - var localPlayer = Service.Player; - if (localPlayer == null) return; + if (Service.Player == null) return; //Do not click the button in random time. if (DateTime.Now - _fastClickStopwatch < TimeSpan.FromMilliseconds(new Random().Next( diff --git a/RotationSolver/RotationSolverPlugin.cs b/RotationSolver/RotationSolverPlugin.cs index 91ef2aa4b..8735d8e35 100644 --- a/RotationSolver/RotationSolverPlugin.cs +++ b/RotationSolver/RotationSolverPlugin.cs @@ -59,6 +59,7 @@ public unsafe RotationSolverPlugin(DalamudPluginInterface pluginInterface) MajorUpdater.Enable(); TimeLineUpdater.Enable(pluginInterface.ConfigDirectory.FullName); + IActionHelper.GetAnimationLockTimeAsync(pluginInterface.ConfigDirectory.FullName); SocialUpdater.Enable(); _dis.Add(new Watcher()); _dis.Add(new MovingController()); @@ -107,6 +108,17 @@ public void Dispose() SocialUpdater.Disable(); IconSet.Dispose(); + +#if DEBUG + var directory = @"E:\OneDrive - stu.zafu.edu.cn\PartTime\FFXIV\RotationSolver\Resources"; +#else + var directory = Service.Interface.ConfigDirectory.FullName; +#endif + if (!Directory.Exists(directory)) return; + + //Default values. + var path = Path.Combine(directory, $"{nameof(IActionHelper.AnimationLockTime)}.json"); + File.WriteAllText(path, JsonConvert.SerializeObject(IActionHelper.AnimationLockTime, Formatting.Indented)); } private void OnOpenConfigUi() diff --git a/RotationSolver/Updaters/ActionUpdater.cs b/RotationSolver/Updaters/ActionUpdater.cs index 421886bef..4a2945b53 100644 --- a/RotationSolver/Updaters/ActionUpdater.cs +++ b/RotationSolver/Updaters/ActionUpdater.cs @@ -204,6 +204,8 @@ internal unsafe static void DoAction() if (_GCDDelay.Delay(canUseGCD)) RSCommands.DoAnAction(true); if (canUseGCD) return; + var ping = 0.06f; + //More then gcd. if (DataCenter.WeaponRemain < Service.Config.AbilitiesInterval || DataCenter.WeaponElapsed < Service.Config.AbilitiesInterval) diff --git a/RotationSolver/Watcher.cs b/RotationSolver/Watcher.cs index f2c0cbc6f..110c636b1 100644 --- a/RotationSolver/Watcher.cs +++ b/RotationSolver/Watcher.cs @@ -88,6 +88,7 @@ private static void ActionFromSelf(uint sourceId, ActionEffectSet set) //Record DataCenter.AddActionRec(set.Action); DataCenter.NextActionMinTime = DateTime.Now.AddSeconds(set.AnimationLock); + IActionHelper.AnimationLockTime[set.Action.RowId] = set.AnimationLock; ShowStrSelf = set.ToString(); //Macro