From 6fdc39b4b6742c68849a98c935a3819322b7a584 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Wed, 10 Apr 2024 10:43:47 +0800 Subject: [PATCH] feat: add the duty rotation drawing stuff. Issus: #575 --- .../Rotations/CustomRotation_Invoke.cs | 1 + .../Rotations/Duties/DutyRotation.cs | 63 ++++++++++++++++++- .../SearchableConfigs/SearchableConfigRS.cs | 3 +- RotationSolver/Watcher.cs | 13 +++- 4 files changed, 74 insertions(+), 6 deletions(-) diff --git a/RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs b/RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs index 5f21e9e01..56fc2e835 100644 --- a/RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs +++ b/RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs @@ -14,6 +14,7 @@ public bool TryInvoke(out IAction? newAction, out IAction? gcdAction) try { UpdateInfo(); + DataCenter.RightNowDutyRotation?.UpdateInfo(); IBaseAction.ActionPreview = true; UpdateActions(Role); diff --git a/RotationSolver.Basic/Rotations/Duties/DutyRotation.cs b/RotationSolver.Basic/Rotations/Duties/DutyRotation.cs index 55df8224d..e3c05256a 100644 --- a/RotationSolver.Basic/Rotations/Duties/DutyRotation.cs +++ b/RotationSolver.Basic/Rotations/Duties/DutyRotation.cs @@ -4,6 +4,7 @@ using ECommons.DalamudServices; using FFXIVClientStructs.FFXIV.Client.Game.UI; using Dalamud.Plugin.Services; +using ECommons.Hooks.ActionEffectTypes; namespace RotationSolver.Basic.Rotations.Duties; #pragma warning disable CS1591 // Missing XML comment for publicly visible type or member @@ -365,10 +366,66 @@ public static bool IsLongerThan(float time) public static IEnumerable VfxNewData => DataCenter.VfxNewData.Reverse(); #endregion - //public virtual void GenerateDrawing() - //{ + #region Drawing + protected virtual Dictionary<(float time, uint actionId), Action> CastingAction { get; } = []; + private readonly Dictionary<(float time, uint actionId), DateTime> _usedTime = []; + internal void UpdateInfo() + { + UpdateCasting(); + } + + private void UpdateCasting() + { + if (CastingAction.Count == 0) return; + + foreach (var target in DataCenter.AllHostileTargets) + { + if (!target.IsCasting) continue; + if (target.TotalCastTime < 2.5) continue; + + var last = target.TotalCastTime - target.CurrentCastTime; + var id = target.CastActionId; + CanInvoke(last, id); + } + } + + private void CanInvoke(float last, uint id) + { + foreach ((var key, var value) in CastingAction) + { + if (key.actionId != id) continue; + if (key.time < last) continue; + if (key.time - 1 > last) continue; + if (_usedTime.TryGetValue(key, out var time)) + { + if ((DateTime.Now - time).TotalSeconds < 1.5) continue; + } + + _usedTime[key] = DateTime.Now; + value?.Invoke(); + } + } + + public virtual void OnActorVfxNew(in VfxNewData data) + { + + } + + public virtual void OnObjectEffect(in ObjectEffectData data) + { + + } - //} + public virtual void OnMapEffect(in MapEffectData data) + { + + } + + public virtual void OnActionFromEnemy(in ActionEffectSet data) + { + + } + #endregion public void Dispose() { diff --git a/RotationSolver/UI/SearchableConfigs/SearchableConfigRS.cs b/RotationSolver/UI/SearchableConfigs/SearchableConfigRS.cs index ed5ec17a9..abf509585 100644 --- a/RotationSolver/UI/SearchableConfigs/SearchableConfigRS.cs +++ b/RotationSolver/UI/SearchableConfigs/SearchableConfigRS.cs @@ -1,5 +1,4 @@ -using Dalamud.Interface.Internal; -using Dalamud.Interface.Utility; +using Dalamud.Interface.Utility; using ECommons.ExcelServices; using RotationSolver.Data; using XIVConfigUI; diff --git a/RotationSolver/Watcher.cs b/RotationSolver/Watcher.cs index 925a36993..749e581bd 100644 --- a/RotationSolver/Watcher.cs +++ b/RotationSolver/Watcher.cs @@ -62,6 +62,7 @@ public static void Enable() #if DEBUG Svc.Log.Debug(effect.ToString()); #endif + DataCenter.RightNowDutyRotation?.OnMapEffect(effect); }); } @@ -98,9 +99,9 @@ private static IntPtr ActorVfxNewHandler(string path, IntPtr a2, IntPtr a3, floa #if DEBUG Svc.Log.Debug(effect.ToString()); #endif + DataCenter.RightNowDutyRotation?.OnActorVfxNew(effect); } - } catch (Exception e) { @@ -136,6 +137,7 @@ private static unsafe long ProcessObjectEffectDetour(GameObject* a1, ushort a2, #if DEBUG Svc.Log.Debug(effect.ToString()); #endif + DataCenter.RightNowDutyRotation?.OnObjectEffect(effect); } catch (Exception e) { @@ -177,6 +179,15 @@ private static void ActionFromEnemy(ActionEffectSet set) if (battle.SubKind == 9) return; //Friend! if (Svc.Objects.SearchById(battle.ObjectId) is PlayerCharacter) return; + try + { + DataCenter.RightNowDutyRotation?.OnActionFromEnemy(set); + } + catch(Exception e) + { + Svc.Log.Warning(e, "Failed to act on the duty rotation about acion on enemy."); + } + var damageRatio = set.TargetEffects .Where(e => e.TargetID == Player.Object.ObjectId) .SelectMany(e => new EffectEntry[]