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

Commit

Permalink
fix: add more thing to sync the raid time.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Feb 28, 2024
1 parent de75e3c commit d13d846
Show file tree
Hide file tree
Showing 16 changed files with 304 additions and 115 deletions.
13 changes: 12 additions & 1 deletion RotationSolver.Basic/Actions/ActionCooldownInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ namespace RotationSolver.Basic.Actions;
/// <summary>
///
/// </summary>
public float RecastTimeRemainOneCharge => RecastTimeRemainOneChargeRaw + DataCenter.WeaponRemain;
public float RecastTimeRemainOneCharge => RecastTimeRemainOneChargeRaw - DataCenter.WeaponRemain;

float RecastTimeRemainOneChargeRaw => RecastTimeRemain % RecastTimeOneChargeRaw;

Expand Down Expand Up @@ -130,6 +130,17 @@ public bool WillHaveOneChargeGCD(uint gcdCount = 0, float offset = 0)
public bool WillHaveOneCharge(float remain)
=> HasOneCharge || RecastTimeRemainOneCharge <= remain;

/// <summary>
/// Is this action used after several time.
/// </summary>
/// <param name="time"></param>
/// <returns></returns>
public bool JustUsedAfter(float time)
{
var elapsed = RecastTimeElapsedRaw % RecastTimeOneChargeRaw;
return elapsed + DataCenter.WeaponRemain < time;
}

internal bool CooldownCheck(bool isEmpty, bool onLastAbility, bool ignoreClippingCheck, byte gcdCountForAbility)
{
if (!_action.Info.IsGeneralGCD)
Expand Down
75 changes: 70 additions & 5 deletions RotationSolver.Basic/Data/TimelineItem.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,75 @@
using System.Text.RegularExpressions;
using ECommons.DalamudServices;
using Newtonsoft.Json.Linq;
using System.Text.RegularExpressions;

namespace RotationSolver.Basic.Data;
internal readonly struct TimelineItem(float time, string name, params string[] ids)
internal enum TimelineType : byte
{
Unknown,
InCombat,
GameLog,
Ability,
StartsUsing,
SystemLogMessage,
ActorControl,
}

internal readonly struct TimelineItem(float time, string name, TimelineType type, string[] ids, JObject? obj)
{
public TimelineType Type => type;

public float Time => time;

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

public string Name => name;

public bool IsShown => name is not "--Reset--" and not "--sync--";

public string this[string propertyName] => Object?[propertyName]?.ToString() ?? string.Empty;

public TimelineItem(float time, string name, string type, string[] ids, JObject? obj)
: this(time, name, GetTypeFromName(type), ids, obj)
{

}

private static TimelineType GetTypeFromName(string type)
{
switch(type)
{
case "":
return TimelineType.Unknown;

case "ActorControl":
return TimelineType.ActorControl; //TODO: how to check that command.

case "InCombat":
return TimelineType.InCombat;

case "GameLog":
return TimelineType.GameLog;

case "Ability":
return TimelineType.Ability;

case "StartsUsing":
return TimelineType.StartsUsing;

case "SystemLogMessage":
return TimelineType.SystemLogMessage; //TODO: a6s for testing

default:
Svc.Log.Warning($"New timelinetype: {type}");
return TimelineType.Unknown;
}
}

public void UpdateRaidTimeOffset()
{
DataCenter.RaidTimeRaw = Time;
Svc.Log.Debug($"Reset the {nameof(DataCenter.RaidTimeRaw)} to {DataCenter.RaidTimeRaw}.");
}

public bool IsIdMatched(uint id)
{
Expand All @@ -16,8 +80,9 @@ public override string ToString()
{
return $"""
IsShown: {IsShown},
Time: {time},
Name: {name},
Time: {Time},
Name: {Name},
Type: {Type},
Ids: {string.Join(", ", ids)}
""";
}
Expand Down
18 changes: 16 additions & 2 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,19 @@ 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;
private static DateTime _startRaidTime = DateTime.MinValue;
internal static float RaidTimeRaw
{
get
{
if (_startRaidTime == DateTime.MinValue) return 0;
return (float)(DateTime.Now - _startRaidTime).TotalSeconds;
}
set
{
_startRaidTime = DateTime.Now - TimeSpan.FromSeconds(value);
}
}

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

Expand Down Expand Up @@ -423,4 +434,7 @@ internal static void AddDamageRec(float damageRatio)
internal static DateTime KnockbackFinished { get; set; } = DateTime.MinValue;
internal static DateTime KnockbackStart { get; set; } = DateTime.MinValue;
#endregion

internal static SortedList<string, string> AuthorHashes { get; set; } = [];
internal static string[] ContributorsHash { get; set; } = [];
}
40 changes: 31 additions & 9 deletions RotationSolver.Basic/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using FFXIVClientStructs.FFXIV.Common.Component.BGCollision;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic.Configuration;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;

namespace RotationSolver.Basic.Helpers;
Expand Down Expand Up @@ -87,17 +89,16 @@ internal static bool IsAttackable(this BattleChara battleChara)
if (names.Any(n => !string.IsNullOrEmpty(n) && new Regex(n).Match(battleChara.Name.TextValue).Success)) return false;


//if (gameObject is PlayerCharacter p)
//{
// var hash = SocialUpdater.EncryptString(p);

// //Don't attack authors!!
// if (RotationUpdater.AuthorHashes.ContainsKey(hash)) return false;
if (battleChara is PlayerCharacter p)
{
var hash = EncryptString(p);

// //Don't attack contributors!!
// if (DownloadHelper.ContributorsHash.Contains(hash)) return false;
//}
//Don't attack authors!!
if (DataCenter.AuthorHashes.ContainsKey(hash)) return false;

//Don't attack contributors!!
if (DataCenter.ContributorsHash.Contains(hash)) return false;
}

//Fate
if (DataCenter.TerritoryContentType != TerritoryContentType.Eureka)
Expand Down Expand Up @@ -132,6 +133,27 @@ internal static bool IsAttackable(this BattleChara battleChara)
};
}


internal static string EncryptString(this PlayerCharacter player)
{
if (player == null) return string.Empty;

try
{
byte[] inputByteArray = Encoding.UTF8.GetBytes(player.HomeWorld.GameData!.InternalName.ToString()
+ " - " + player.Name.ToString() + "U6Wy.zCG");

var tmpHash = MD5.HashData(inputByteArray);
var retB = Convert.ToBase64String(tmpHash);
return retB;
}
catch (Exception ex)
{
Svc.Log.Warning(ex, "Failed to read the player's name and world.");
return string.Empty;
}
}

internal static unsafe bool IsInEnemiesList(this BattleChara battleChara)
{
var addons = Service.GetAddons<AddonEnemyList>();
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 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
6 changes: 3 additions & 3 deletions RotationSolver/Commands/RSCommands_Actions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ public static void DoAction()
&& act1.TargetInfo.IsSingleTarget
&& act1.Target?.Target is PlayerCharacter p && p != Player.Object)
{
var hash = SocialUpdater.EncryptString(p);
var hash = p.EncryptString();

//Don't attack authors and contributors!!
if ((RotationUpdater.AuthorHashes.ContainsKey(hash)
|| DownloadHelper.ContributorsHash.Contains(hash)))
if ((DataCenter.AuthorHashes.ContainsKey(hash)
|| DataCenter.ContributorsHash.Contains(hash)))
{
Svc.Chat.PrintError($"Please don't attack RS developers with RS by {act1}!");
return;
Expand Down
3 changes: 1 addition & 2 deletions RotationSolver/Helpers/DownloadHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ public static class DownloadHelper
/// <para>Maximum HP and MP are increased.</para>
/// </summary>
public static string[] LinkLibraries { get; private set; } = [];
public static string[] ContributorsHash { get; private set; } = [];
public static string[] UsersHash { get; private set; } = [];
public static string[] Supporters { get; private set; } = [];
public static IncompatiblePlugin[] IncompatiblePlugins { get; private set; } = [];
Expand All @@ -20,7 +19,7 @@ public static async Task DownloadAsync()
LinkLibraries = await DownloadOneAsync<string[]>($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Resources/downloadList.json") ?? [];
IncompatiblePlugins = await DownloadOneAsync<IncompatiblePlugin[]>($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Resources/IncompatiblePlugins.json") ?? [];

ContributorsHash = await DownloadOneAsync<string[]>($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Resources/ContributorsHash.json") ?? [];
DataCenter.ContributorsHash = await DownloadOneAsync<string[]>($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Resources/ContributorsHash.json") ?? [];

UsersHash = await DownloadOneAsync<string[]>($"https://raw.githubusercontent.com/{Service.USERNAME}/{Service.REPO}/main/Resources/UsersHash.json") ?? [];

Expand Down
6 changes: 3 additions & 3 deletions RotationSolver/UI/RotationConfigWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2432,8 +2432,8 @@ private static unsafe void DrawStatus()
}
private static unsafe void DrawParty()
{
ImGui.Text("Party: " + DataCenter.PartyMembers.Count().ToString());
ImGui.Text("Alliance: " + DataCenter.AllianceMembers.Count().ToString());
ImGui.Text("Party: " + DataCenter.PartyMembers.Length.ToString());
ImGui.Text("Alliance: " + DataCenter.AllianceMembers.Length.ToString());

ImGui.Text("PartyMembersAverHP: " + DataCenter.PartyMembersAverHP.ToString());

Expand Down Expand Up @@ -2495,7 +2495,7 @@ private static unsafe void DrawTargetData()
}

ImGui.Text("All: " + DataCenter.AllTargets.Count().ToString());
ImGui.Text("Hostile: " + DataCenter.AllHostileTargets.Count().ToString());
ImGui.Text("Hostile: " + DataCenter.AllHostileTargets.Length.ToString());
foreach (var item in DataCenter.AllHostileTargets)
{
ImGui.Text(item.Name.ToString());
Expand Down
8 changes: 4 additions & 4 deletions RotationSolver/UI/RotationConfigWindow_Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private static void DrawBasicNamedConditions()
{
if (!DataCenter.RightSet.NamedConditions.Any(c => string.IsNullOrEmpty(c.Name)))
{
DataCenter.RightSet.NamedConditions = DataCenter.RightSet.NamedConditions.Append((string.Empty, new ConditionSet())).ToArray();
DataCenter.RightSet.NamedConditions = [.. DataCenter.RightSet.NamedConditions, (string.Empty, new ConditionSet())];
}

ImGui.Spacing();
Expand Down Expand Up @@ -271,13 +271,13 @@ private static void DrawBasicOthers()

if (Service.Config.SayHelloToAll)
{
var str = SocialUpdater.EncryptString(Player.Object);
var str = Player.Object.EncryptString();
ImGui.SetNextItemWidth(ImGui.CalcTextSize(str).X + 10);
ImGui.InputText("That is your HASH:", ref str, 100);

if (!DownloadHelper.ContributorsHash.Contains(str)
if (!DataCenter.ContributorsHash.Contains(str)
&& !DownloadHelper.UsersHash.Contains(str)
&& !RotationUpdater.AuthorHashes.ContainsKey(str))
&& !DataCenter.AuthorHashes.ContainsKey(str))
{
if (ImGui.Button("DM your Hash to ArchiTed for being greeted."))
{
Expand Down
13 changes: 12 additions & 1 deletion RotationSolver/Updaters/ActionUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using FFXIVClientStructs.FFXIV.Client.Game;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using RotationSolver.Commands;
using System.Text.RegularExpressions;
using System.Windows.Forms;

namespace RotationSolver.Updaters;

Expand Down Expand Up @@ -143,10 +145,19 @@ private static void UpdateCombatTime()
if (_startCombatTime == DateTime.MinValue)
{
DataCenter.CombatTimeRaw = 0;
DataCenter.RaidTimeOffset = 0;
}
else
{
if (DataCenter.CombatTimeRaw == 0)
{
foreach (var item in DataCenter.TimelineItems)
{
if (item.Type is not TimelineType.InCombat) continue;

item.UpdateRaidTimeOffset();
break;
}
}
DataCenter.CombatTimeRaw = (float)(DateTime.Now - _startCombatTime).TotalSeconds;
}
}
Expand Down
Loading

0 comments on commit d13d846

Please sign in to comment.