Skip to content
This repository has been archived by the owner on Aug 28, 2024. It is now read-only.

Commit

Permalink
feat: add the duty rotation drawing stuff.
Browse files Browse the repository at this point in the history
Issus: #575
  • Loading branch information
ArchiDog1998 committed Apr 10, 2024
1 parent d50856b commit 6fdc39b
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 6 deletions.
1 change: 1 addition & 0 deletions RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public bool TryInvoke(out IAction? newAction, out IAction? gcdAction)
try
{
UpdateInfo();
DataCenter.RightNowDutyRotation?.UpdateInfo();

IBaseAction.ActionPreview = true;
UpdateActions(Role);
Expand Down
63 changes: 60 additions & 3 deletions RotationSolver.Basic/Rotations/Duties/DutyRotation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -365,10 +366,66 @@ public static bool IsLongerThan(float time)
public static IEnumerable<VfxNewData> 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()
{
Expand Down
3 changes: 1 addition & 2 deletions RotationSolver/UI/SearchableConfigs/SearchableConfigRS.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility;
using ECommons.ExcelServices;
using RotationSolver.Data;
using XIVConfigUI;
Expand Down
13 changes: 12 additions & 1 deletion RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public static void Enable()
#if DEBUG
Svc.Log.Debug(effect.ToString());
#endif
DataCenter.RightNowDutyRotation?.OnMapEffect(effect);
});
}

Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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[]
Expand Down

0 comments on commit 6fdc39b

Please sign in to comment.