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

Commit

Permalink
feat: add a thing to check the timeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Feb 27, 2024
1 parent 3016cef commit 57ad3f8
Show file tree
Hide file tree
Showing 15 changed files with 176 additions and 51 deletions.
4 changes: 2 additions & 2 deletions Resources/RotationSolverRecord.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"ClickingCount": 86236,
"SayingHelloCount": 75,
"ClickingCount": 87877,
"SayingHelloCount": 76,
"SaidUsers": []
}
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Actions/ActionTargetInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ private readonly bool CheckTimeToKill(GameObject gameObject)
DataCenter.TerritoryContentType == TerritoryContentType.Raids
&& DataCenter.AllianceMembers.Count(p => p is PlayerCharacter) == 8)
{
pts = pts.Union([Vector3.Zero, new(100, 0, 100)]).ToArray();
pts = [.. pts, Vector3.Zero, new(100, 0, 100)];
}
}

Expand Down
3 changes: 3 additions & 0 deletions RotationSolver.Basic/Actions/BaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,7 @@ public unsafe bool Use()
return ActionManager.Instance()->UseAction(ActionType.Action, adjustId, target.Target?.ObjectId ?? GameObject.InvalidGameObjectId);
}
}

/// <inheritdoc/>
public override string ToString() => Name;
}
24 changes: 24 additions & 0 deletions RotationSolver.Basic/Data/TimelineItem.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using System.Text.RegularExpressions;

namespace RotationSolver.Basic.Data;
internal readonly struct TimelineItem(float time, string name, params string[] ids)
{
public float Time => time;

public bool IsShown => !name.StartsWith("--") && !name.EndsWith("--");

public bool IsIdMatched(uint id)
{
return ids.Any(i => new Regex(i).IsMatch(id.ToString("X")));
}

public override string ToString()
{
return $"""
IsShown: {IsShown},
Time: {time},
Name: {name},
Ids: {string.Join(", ", ids)}
""";
}
}
4 changes: 4 additions & 0 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ internal static SpecialCommandType SpecialType
public static bool NotInCombatDelay => _notInCombatDelay.Delay(!InCombat);

internal static float CombatTimeRaw { get; set; }
internal static float RaidTimeOffset { get; set; } = 0;
internal static float RaidTimeRaw => CombatTimeRaw + RaidTimeOffset;

internal static TimelineItem[] TimelineItems { get; set; } = [];

public static BattleChara[] PartyMembers { get; internal set; } = [];
public static BattleChara[] AllianceMembers { get; internal set; } = [];
Expand Down
4 changes: 3 additions & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ public unsafe static byte LimitBreakLevel
get
{
var controller = UIState.Instance()->LimitBreakController;
return (byte)(controller.CurrentValue / *(ushort*)&controller.BarValue);
var barValue = *(ushort*)&controller.BarValue;
if (barValue == 0) return 0;
return (byte)(controller.CurrentValue / barValue);
}
}

Expand Down
4 changes: 1 addition & 3 deletions RotationSolver.Basic/Rotations/Duties/BozjaRotation.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
using ECommons.DalamudServices;

namespace RotationSolver.Basic.Rotations.Duties;
namespace RotationSolver.Basic.Rotations.Duties;

/// <summary>
/// The bozja action.
Expand Down
42 changes: 21 additions & 21 deletions RotationSolver.SourceGenerators/StaticCodeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,29 +25,29 @@ private static void Execute(SourceProductionContext context)
GenerateActionCate(context);
GenerateBaseRotation(context);
GenerateRotations(context);
GenerateOpCode(context);
//GenerateOpCode(context);
}

private static async void GenerateOpCode(SourceProductionContext context)
{
var code = $$"""
namespace RotationSolver.Basic.Data;
/// <summary>
/// The opcode
/// </summary>
public enum OpCode : ushort
{
/// <summary>
///
/// </summary>
None = 0,
{{Properties.Resources.OpCode.Table()}}
}
""";

context.AddSource("OpCode.g.cs", code);
}
//private static void GenerateOpCode(SourceProductionContext context)
//{
// var code = $$"""
// namespace RotationSolver.Basic.Data;

// /// <summary>
// /// The opcode
// /// </summary>
// public enum OpCode : ushort
// {
// /// <summary>
// ///
// /// </summary>
// None = 0,
// {{Properties.Resources.OpCode.Table()}}
// }
// """;

// context.AddSource("OpCode.g.cs", code);
//}

private static void GenerateStatus(SourceProductionContext context)
{
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver/RotationSolverPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public RotationSolverPlugin(DalamudPluginInterface pluginInterface)
IconSet.InIt();

//Init!
Clipper.InflatePaths(new PathsD(new PathD[] { Clipper.MakePath(new double[] { 0, 0, 1, 1 }) }), 0, JoinType.Round, EndType.Joined);
Clipper.InflatePaths(new PathsD([Clipper.MakePath(new double[] { 0, 0, 1, 1 })]), 0, JoinType.Round, EndType.Joined);

_dis.Add(new Service());
try
Expand Down
24 changes: 5 additions & 19 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Dalamud.Interface.Internal;
using Dalamud.Interface.Utility;
using Dalamud.Interface.Utility.Raii;
using Dalamud.Interface.Utility.Table;
using Dalamud.Interface.Windowing;
using Dalamud.Utility;
using ECommons.DalamudServices;
Expand Down Expand Up @@ -2386,7 +2385,7 @@ private static void DrawDebug()
{() =>"Target Data", DrawTargetData },
{() =>"Next Action", DrawNextAction },
{() =>"Last Action", DrawLastAction },
{() =>"Icon", DrawIcon },
{() =>"Others", DrawOthers },
{() =>"Effect", () =>
{
ImGui.Text(Watcher.ShowStrSelf);
Expand Down Expand Up @@ -2512,7 +2511,6 @@ private static void DrawNextAction()
ImGui.Text("Ability Remain: " + DataCenter.AbilityRemain.ToString());
ImGui.Text("Action Remain: " + DataCenter.ActionRemain.ToString());
ImGui.Text("Weapon Remain: " + DataCenter.WeaponRemain.ToString());
ImGui.Text("Time: " + (DataCenter.CombatTimeRaw + DataCenter.WeaponRemain).ToString());
}

private static void DrawLastAction()
Expand All @@ -2523,23 +2521,11 @@ private static void DrawLastAction()
DrawAction(DataCenter.LastComboAction, nameof(DataCenter.LastComboAction));
}

private static unsafe void DrawIcon()
private static unsafe void DrawOthers()
{
//ImGui.Text("Hate");
//foreach (var hate in UIState.Instance()->Hate.HateArraySpan)
//{
// var name = Svc.Objects.SearchById(hate.ObjectId)?.Name ?? "Unknown";
// ImGui.Text($"{name} : {hate.Enmity}");
//}
//ImGui.Spacing();
//ImGui.Text("Hater");
//foreach (var hater in UIState.Instance()->Hater.HaterArraySpan)
//{
// var name = Svc.Objects.SearchById(hater.ObjectId)?.Name ?? "Unknown";
// ImGui.Text($"{name} : {hater.Enmity}");
//}

ImGui.Text(CustomRotation.LimitBreakLevel.ToString());
ImGui.Text("Combat Time: " + (DataCenter.CombatTimeRaw).ToString());
ImGui.Text("Raid Time: " + (DataCenter.RaidTimeRaw).ToString());
ImGui.Text("Limit Break: " + CustomRotation.LimitBreakLevel.ToString());
}

private static void DrawAction(ActionID id, string type)
Expand Down
1 change: 1 addition & 0 deletions RotationSolver/Updaters/ActionUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ private static void UpdateCombatTime()
if (_startCombatTime == DateTime.MinValue)
{
DataCenter.CombatTimeRaw = 0;
DataCenter.RaidTimeOffset = 0;
}
else
{
Expand Down
4 changes: 3 additions & 1 deletion RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ private static void ShowWarning()
{
if (id == 2)
{
Util.OpenLink("http://qm.qq.com/cgi-bin/qm/qr?_wv=1027&k=EyT0BfZWCVq8v2yiMjSqcb4lEqYuaF_P&authKey=UJFoVZ3OljlBhSilXpeLKIIzofI4ZUjJfjuqCgr%2BiaT3Y6HmQFVbXZ5xBOlSv5yZ&noverify=0&group_code=552689154");
Util.OpenLink("https://discord.gg/w2DPwRRZuT");
}
}),
new UIForegroundPayload(31),
Expand Down Expand Up @@ -149,6 +149,7 @@ public static void Enable()
{
ActionSequencerUpdater.Enable(Svc.PluginInterface.ConfigDirectory.FullName + "\\Conditions");
SocialUpdater.Enable();
RaidTimeUpdater.Enable();

Svc.Framework.Update += FrameworkUpdate;
}
Expand Down Expand Up @@ -283,5 +284,6 @@ public static void Dispose()
ActionSequencerUpdater.SaveFiles();
SocialUpdater.Disable();
ActionUpdater.ClearNextAction();
RaidTimeUpdater.Disable();
}
}
83 changes: 83 additions & 0 deletions RotationSolver/Updaters/RaidTimeUpdater.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
using ECommons.DalamudServices;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;

namespace RotationSolver.Updaters;
internal static partial class RaidTimeUpdater
{
internal static void Enable()
{
Svc.ClientState.TerritoryChanged += ClientState_TerritoryChanged;
ClientState_TerritoryChanged(Svc.ClientState.TerritoryType);
}

internal static void Disable()
{
Svc.ClientState.TerritoryChanged -= ClientState_TerritoryChanged;
}

private static void ClientState_TerritoryChanged(ushort obj)
{
try
{
UpdateRaidTime("06-ew/raid/p9s.txt");
}
catch (Exception e)
{
Svc.Log.Warning(e, "Failed to update the raid timeline!");
}
}
static async void UpdateRaidTime(string path)
{
using var client = new HttpClient();
var message = await client.GetAsync("https://raw.githubusercontent.com/OverlayPlugin/cactbot/main/ui/raidboss/data/" + path);

if (!message.IsSuccessStatusCode) return;

var str = await message.Content.ReadAsStringAsync();

var result = new List<TimelineItem>();
foreach (var timelineItem in TimeLineItem().Matches(str).Cast<Match>())
{
try
{
var header = TimeHeader().Match(timelineItem.Value);
var action = JObject.Parse(ActionGetter().Match(timelineItem.Value).Value)["id"];
var time = float.Parse(Time().Match(header.Value).Value);
var name = Name().Match(header.Value).Value[1..^1];

string[] ids = [];
if (action is JArray array)
{
ids = [..array.Select(i => i.ToString())];
}
else
{
ids = [action?.ToString() ?? string.Empty];
}

result.Add(new (time, name, ids));
}
catch (Exception ex)
{
Svc.Log.Warning(ex, "sth wrong with matching!");
}
}
DataCenter.TimelineItems = [..result];
}

[GeneratedRegex("\\d+\\.\\d.*Ability.*")]
private static partial Regex TimeLineItem();

[GeneratedRegex("^\\d+\\.\\d")]
private static partial Regex Time();

[GeneratedRegex("\".*?\"")]
private static partial Regex Name();

[GeneratedRegex("^\\d+\\.\\d \".*?\"")]
private static partial Regex TimeHeader();

[GeneratedRegex("{.*}")]
private static partial Regex ActionGetter();
}
1 change: 0 additions & 1 deletion RotationSolver/Updaters/SocialUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ internal class SocialUpdater
{
#if DEBUG
#else

private static readonly List<string> _macroToAuthor =
[
"blush",
Expand Down
25 changes: 24 additions & 1 deletion RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,22 @@ public static void Enable()
Svc.Log.Debug(effect.ToString());
#endif
});

//Svc.GameNetwork.NetworkMessage += GameNetwork_NetworkMessage;
}

// private static void GameNetwork_NetworkMessage(nint dataPtr, ushort opCode, uint sourceActorId, uint targetActorId, Dalamud.Game.Network.NetworkMessageDirection direction)
// {
// if (direction != Dalamud.Game.Network.NetworkMessageDirection.ZoneDown) return;
// OpCode op = (OpCode)opCode;

//#if DEBUG
// var source = Svc.Objects.SearchById(sourceActorId)?.Name.TextValue;
// var target = Svc.Objects.SearchById(targetActorId)?.Name.TextValue;
// Svc.Log.Debug($"From {source} to {target} by {op}.");
//#endif
// }

public static void Disable()
{
#if DEBUG
Expand All @@ -74,6 +88,7 @@ public static void Disable()
MapEffect.Dispose();
ActionEffect.ActionEffectEvent -= ActionFromEnemy;
ActionEffect.ActionEffectEvent -= ActionFromSelf;
//Svc.GameNetwork.NetworkMessage -= GameNetwork_NetworkMessage;
}

private static IntPtr ActorVfxNewHandler(string path, IntPtr a2, IntPtr a3, float a4, char a5, ushort a6, char a7)
Expand Down Expand Up @@ -153,6 +168,15 @@ private static void UpdateRTTDetour(dynamic obj)

private static void ActionFromEnemy(ActionEffectSet set)
{
foreach (var item in DataCenter.TimelineItems)
{
if (!item.IsIdMatched(set.Action?.RowId ?? 0)) continue;

DataCenter.RaidTimeOffset = item.Time - DataCenter.CombatTimeRaw;
Svc.Log.Debug($"Reset the {nameof(DataCenter.RaidTimeOffset)} to {DataCenter.RaidTimeOffset} by the action {set.Action}");
break;
}

//Check Source.
var source = set.Source;
if (source == null) return;
Expand All @@ -174,7 +198,6 @@ private static void ActionFromEnemy(ActionEffectSet set)

ShowStrEnemy = $"Damage Ratio: {damageRatio}\n{set}";


foreach (var effect in set.TargetEffects)
{
if (effect.TargetID != Player.Object.ObjectId) continue;
Expand Down

0 comments on commit 57ad3f8

Please sign in to comment.