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

Commit

Permalink
fix: make status check more precise
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Apr 27, 2023
1 parent ec2044f commit a771748
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 13 deletions.
7 changes: 4 additions & 3 deletions Resources/AnimationLockTime.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,12 @@
"3590": 0.6,
"3593": 0.6,
"3595": 0.6,
"3596": 0.1,
"3596": 0.6,
"3598": 0.1,
"3599": 0.6,
"3600": 0.1,
"3601": 0.6,
"3603": 0.1,
"3601": 0.1,
"3603": 0.6,
"3606": 0.6,
"3608": 0.6,
"3610": 0.1,
Expand Down
30 changes: 29 additions & 1 deletion RotationSolver.Basic/Data/ActionEffectSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,19 @@ public ActionEffectSet(uint sourceId, ActionEffectHeader* effectHeader, ActionEf
}
}

public Dictionary<uint, ushort> GetSpecificTypeEffect(ActionEffectType type)
{
var result = new Dictionary<uint, ushort>();
foreach (var effect in TargetEffects)
{
if(effect.GetSpecificTypeEffect(type, out var e))
{
result[effect.Target.ObjectId] = e.Value;
}
}
return result;
}

public override string ToString()
{
var str = $"S:{Source?.Name}, T:{Target?.Name}, Lock:{AnimationLock}";
Expand Down Expand Up @@ -74,10 +87,25 @@ public override string ToString()
var str = Target?.Name?.ToString();
for (int i = 0; i < 8; i++)
{
var e = _effects[i];
var e = this[i];
str += "\n " + e.ToString();
}
return str;
}

public bool GetSpecificTypeEffect(ActionEffectType type, out ActionEffect effect)
{
for (int i = 0; i < 8; i++)
{
var e = this[i];
if(e.Type == type)
{
effect = e;
return true;
}
}
effect = default;
return false;
}
}

15 changes: 15 additions & 0 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,28 @@
using FFXIVClientStructs.FFXIV.Client.Game.Fate;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Basic.Data;
using Action = Lumina.Excel.GeneratedSheets.Action;
using CharacterManager = FFXIVClientStructs.FFXIV.Client.Game.Character.CharacterManager;

namespace RotationSolver.Basic;

public static class DataCenter
{
public static DateTime EffectTime { get; set; } = DateTime.Now;
public static Dictionary<uint, ushort> HealHP { get; set; } = new Dictionary<uint, ushort>();
public static Dictionary<uint, ushort> ApplyStatus { private get; set; } = new Dictionary<uint, ushort>();
public static bool HasApplyStatus(uint id, StatusID[] ids)
{
if ((DateTime.Now - EffectTime).TotalSeconds < 1)
{
if (ApplyStatus.TryGetValue(id, out var statusId))
{
if (ids.Any(s => (ushort)s == statusId)) return true;
}
}
return false;
}
public static bool InHighEndDuty { get; set; } = false;
public static TerritoryContentType TerritoryContentType { get; set; } = TerritoryContentType.None;

Expand Down
5 changes: 4 additions & 1 deletion RotationSolver.Basic/Helpers/StatusHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ internal record Burst2MinsInfo( StatusID status, bool isOnHostile, byte level, p
/// <returns></returns>
public static bool WillStatusEndGCD(this BattleChara obj, uint gcdCount = 0, float offset = 0, bool isFromSelf = true, params StatusID[] statusIDs)
{
if (DataCenter.HasApplyStatus(obj?.ObjectId ?? 0, statusIDs)) return false;
var remain = obj.StatusTime(isFromSelf, statusIDs);
//as infinite
if (remain < 0 && obj.HasStatus(isFromSelf, statusIDs)) return false;
Expand All @@ -151,6 +152,7 @@ public static bool WillStatusEndGCD(this BattleChara obj, uint gcdCount = 0, flo
/// <returns></returns>
public static bool WillStatusEnd(this BattleChara obj, float time, bool isFromSelf = true, params StatusID[] statusIDs)
{
if (DataCenter.HasApplyStatus(obj?.ObjectId ?? 0, statusIDs)) return false;
var remain = obj.StatusTime(isFromSelf, statusIDs);
return CooldownHelper.RecastAfter(remain, time);
}
Expand All @@ -165,6 +167,7 @@ public static bool WillStatusEnd(this BattleChara obj, float time, bool isFromSe
[EditorBrowsable(EditorBrowsableState.Never)]
public static float StatusTime(this BattleChara obj, bool isFromSelf, params StatusID[] statusIDs)
{
if (DataCenter.HasApplyStatus(obj?.ObjectId ?? 0, statusIDs)) return float.MaxValue;
var times = obj.StatusTimes(isFromSelf, statusIDs);
if (times == null || !times.Any()) return 0;
return times.Min();
Expand Down Expand Up @@ -196,6 +199,7 @@ private static IEnumerable<byte> StatusStacks(this BattleChara obj, bool isFromS
/// <returns></returns>
public static bool HasStatus(this BattleChara obj, bool isFromSelf, params StatusID[] statusIDs)
{
if(DataCenter.HasApplyStatus(obj?.ObjectId ?? 0, statusIDs)) return true;
return obj.GetStatus(isFromSelf, statusIDs).Any();
}

Expand Down Expand Up @@ -227,7 +231,6 @@ private static IEnumerable<Status> GetAllStatus(this BattleChara obj, bool isFro
public static bool IsInvincible(this Status status)
{
if (status.GameData.Icon == 15024) return true;

return InvincibleStatus.Any(id => (uint)id == status.StatusId);
}

Expand Down
6 changes: 3 additions & 3 deletions RotationSolver/Updaters/TargetUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,8 +252,8 @@ private static float GetPartyMemberHPRatio(BattleChara member)
{
if (member == null) return 0;

if ((DateTime.Now - Watcher.HealTime).TotalSeconds > 1
|| !Watcher.HealHP.TryGetValue(member.ObjectId, out var hp))
if ((DateTime.Now - DataCenter.EffectTime).TotalSeconds > 1
|| !DataCenter.HealHP.TryGetValue(member.ObjectId, out var hp))
{
return (float)member.CurrentHp / member.MaxHp;
}
Expand All @@ -265,7 +265,7 @@ private static float GetPartyMemberHPRatio(BattleChara member)

if (rightHp - lastHp == hp)
{
Watcher.HealHP.Remove(member.ObjectId);
DataCenter.HealHP.Remove(member.ObjectId);
return (float)member.CurrentHp / member.MaxHp;
}
return Math.Min(1, (hp + rightHp) / (float)member.MaxHp);
Expand Down
8 changes: 3 additions & 5 deletions RotationSolver/Watcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ public class Watcher : IDisposable
private static Hook<ReceiveAbilityDelegate> _receiveAbilityHook;
public static ICallGateSubscriber<object, object> IpcSubscriber;

public static DateTime HealTime { get; private set; } = DateTime.Now;
public static Dictionary<uint, ushort> HealHP { get; private set; } = new Dictionary<uint, ushort>();
public Watcher()
{
SignatureHelper.Initialise(this);
Expand Down Expand Up @@ -103,9 +101,9 @@ private static void ActionFromSelf(uint sourceId, ActionEffectSet set, uint id)
DataCenter.AddActionRec(set.Action);
ShowStrSelf = set.ToString();

HealHP = set.TargetEffects.Where(e => e[0].Type == ActionEffectType.Heal).ToDictionary(e =>
e.Target.ObjectId, e => e[0].Value);
HealTime = DateTime.Now;
DataCenter.HealHP = set.GetSpecificTypeEffect(ActionEffectType.Heal);
DataCenter.ApplyStatus = set.GetSpecificTypeEffect(ActionEffectType.ApplyStatusEffectTarget);
DataCenter.EffectTime = DateTime.Now;

//Macro
foreach (var item in Service.Config.Events)
Expand Down

0 comments on commit a771748

Please sign in to comment.