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

Commit

Permalink
fix!: removed the CooldownHelper! Changed the logic of cd.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jun 22, 2023
1 parent 96dba39 commit e16e9e7
Show file tree
Hide file tree
Showing 25 changed files with 132 additions and 250 deletions.
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Actions/BaseAction_ActionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private bool WillCooldown
&& ChoiceTarget != TargetFilter.FindTargetForMoving
&& DataCenter.LastAction == (ActionID)AdjustedID) return false;

if (!WillHaveOneCharge(DataCenter.ActionRemain, false)) return false;
if (RecastTimeRemainOneChargeRaw > DataCenter.ActionRemain) return false;
}
}

Expand Down
95 changes: 27 additions & 68 deletions RotationSolver.Basic/Actions/BaseAction_Cooldown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,90 +6,49 @@ namespace RotationSolver.Basic.Actions;
public partial class BaseAction
{
public bool ElapsedOneChargeAfterGCD(uint gcdCount = 0, float offset = 0)
{
if (!IsCoolingDown) return false;
var elapsed = RecastTimeElapsedOneCharge;
return CooldownHelper.ElapsedAfterGCD(elapsed, gcdCount, offset);
}
=> ElapsedOneChargeAfter(DataCenter.GCDTime(gcdCount, offset));

public bool ElapsedOneChargeAfter(float time)
{
if (!IsCoolingDown) return false;
var elapsed = RecastTimeElapsedOneCharge;
return CooldownHelper.ElapsedAfter(elapsed, time);
}
=> IsCoolingDown && time <= RecastTimeElapsedOneCharge;

public bool ElapsedAfterGCD(uint gcdCount = 0, float offset = 0)
{
if (!IsCoolingDown) return false;
var elapsed = RecastTimeElapsed;
return CooldownHelper.ElapsedAfterGCD(elapsed, gcdCount, offset);
}
=> ElapsedAfter(DataCenter.GCDTime(gcdCount, offset));

public bool ElapsedAfter(float time)
{
if (!IsCoolingDown) return false;
var elapsed = RecastTimeElapsed;
return CooldownHelper.ElapsedAfter(elapsed, time);
}

=> IsCoolingDown && time <= RecastTimeElapsed;

public bool WillHaveOneChargeGCD(uint gcdCount = 0, float offset = 0)
{
if (HasOneCharge) return true;
var recast = RecastTimeRemainOneCharge;
return CooldownHelper.RecastAfterGCD(recast, gcdCount, offset);
}

public bool WillHaveOneCharge(float remain) => WillHaveOneCharge(remain, true);
=> WillHaveOneCharge(DataCenter.GCDTime(gcdCount, offset));

private bool WillHaveOneCharge(float remain, bool addWeaponRemain)
{
if (HasOneCharge) return true;
var recast = RecastTimeRemainOneCharge;
return CooldownHelper.RecastAfter(recast, remain, addWeaponRemain);
}
public bool WillHaveOneCharge(float remain)
=> HasOneCharge || RecastTimeRemainOneCharge <= remain;

private unsafe RecastDetail* CoolDownDetail => ActionManager.Instance()->GetRecastGroupDetail(CoolDownGroup - 1);
/// <summary>
/// 复唱时间
/// </summary>

private unsafe float RecastTime => CoolDownDetail->Total;

/// <summary>
/// 复唱经过时间
/// </summary>
public unsafe float RecastTimeElapsed => CoolDownDetail->Elapsed;
public float RecastTimeElapsed => RecastTimeElapsedRaw - DataCenter.WeaponElapsed;

[EditorBrowsable(EditorBrowsableState.Never)]
public unsafe float RecastTimeElapsedRaw => CoolDownDetail->Elapsed;

/// <summary>
/// 是否正在冷却中
/// </summary>
public unsafe bool IsCoolingDown => CoolDownDetail->IsActive != 0;

/// <summary>
/// 复唱剩余时间
/// </summary>
private float RecastTimeRemain => RecastTime - RecastTimeElapsed;
private float RecastTimeRemain => RecastTime - RecastTimeElapsedRaw;

/// <summary>
/// 技能的最大层数
/// </summary>
public unsafe ushort MaxCharges => Math.Max(ActionManager.GetMaxCharges(AdjustedID, (uint)Player.Level), (ushort)1);
/// <summary>
/// 是否起码有一层技能
/// </summary>
public bool HasOneCharge => !IsCoolingDown || RecastTimeElapsed >= RecastTimeOneCharge;
/// <summary>
/// 当前技能层数
/// </summary>
public ushort CurrentCharges => IsCoolingDown ? (ushort)(RecastTimeElapsed / RecastTimeOneCharge) : MaxCharges;

public float RecastTimeOneCharge => ActionManager.GetAdjustedRecastTime(ActionType.Spell, AdjustedID) / 1000f;

/// <summary>
/// 下一层转好的时间
/// </summary>
private float RecastTimeRemainOneCharge => RecastTimeRemain % RecastTimeOneCharge;

private float RecastTimeElapsedOneCharge => RecastTimeElapsed % RecastTimeOneCharge;

public bool HasOneCharge => !IsCoolingDown || RecastTimeElapsedRaw >= RecastTimeOneChargeRaw;

public ushort CurrentCharges => IsCoolingDown ? (ushort)(RecastTimeElapsedRaw / RecastTimeOneChargeRaw) : MaxCharges;

public float RecastTimeOneChargeRaw => ActionManager.GetAdjustedRecastTime(ActionType.Spell, AdjustedID) / 1000f;

public float RecastTimeRemainOneCharge => RecastTimeRemainOneChargeRaw - DataCenter.WeaponRemain;

private float RecastTimeRemainOneChargeRaw => RecastTimeRemain % RecastTimeOneChargeRaw;

public float RecastTimeElapsedOneCharge => RecastTimeElapsedOneChargeRaw - DataCenter.WeaponElapsed;

private float RecastTimeElapsedOneChargeRaw => RecastTimeElapsedRaw % RecastTimeOneChargeRaw;
}
8 changes: 4 additions & 4 deletions RotationSolver.Basic/Actions/BaseItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public bool IsInCooldown

public string Description => string.Empty;

public unsafe float RecastTimeOneCharge => ActionManager.Instance()->GetRecastTime(ActionType.Item, ID);
public unsafe float RecastTimeOneChargeRaw => ActionManager.Instance()->GetRecastTime(ActionType.Item, ID);

public unsafe float RecastTimeElapsed => ActionManager.Instance()->GetRecastTimeElapsed(ActionType.Item, ID);
public unsafe float RecastTimeElapsedRaw => ActionManager.Instance()->GetRecastTimeElapsed(ActionType.Item, ID);

public bool EnoughLevel => true;

Expand Down Expand Up @@ -96,13 +96,13 @@ public virtual unsafe bool CanUse(out IAction item)
if (ConfigurationHelper.BadStatus.Contains(ActionManager.Instance()->GetActionStatus(ActionType.Item, ID))
&& ConfigurationHelper.BadStatus.Contains(ActionManager.Instance()->GetActionStatus(ActionType.Item, ID + 1000000))) return false;

var remain = RecastTimeOneCharge - RecastTimeElapsed;
var remain = RecastTimeOneChargeRaw - RecastTimeElapsedRaw;

if(DataCenter.WeaponRemain > 0)
{
if (DataCenter.NextAbilityToNextGCD > AnimationLockTime + DataCenter.Ping) return false;

if (!CooldownHelper.RecastAfter(remain, DataCenter.ActionRemain, false)) return false;
if (remain > DataCenter.ActionRemain) return false;
}

if (OtherCheck != null && !OtherCheck()) return false;
Expand Down
12 changes: 9 additions & 3 deletions RotationSolver.Basic/Actions/IAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@ public interface IAction : ITexture, IEnouthLevel
{
uint ID { get; }
uint AdjustedID { get; }
float RecastTimeOneCharge { get; }

float AnimationLockTime { get; }
uint SortKey { get; }
public bool IsActionSequencer { get; }
bool IsActionSequencer { get; }

/// <summary>
/// Please don't use it.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
internal float RecastTimeElapsedRaw { get; }

/// <summary>
/// Please don't use it.
/// </summary>
[EditorBrowsable(EditorBrowsableState.Never)]
float RecastTimeElapsed { get; }
internal float RecastTimeOneChargeRaw { get; }

/// <summary>
/// Is action cooling down.
Expand Down
5 changes: 2 additions & 3 deletions RotationSolver.Basic/Actions/IBaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public interface IBaseAction : IAction
float EffectRange { get; }

[EditorBrowsable(EditorBrowsableState.Never)]
bool IsFriendly { get; }
internal bool IsFriendly { get; }

[EditorBrowsable(EditorBrowsableState.Never)]
bool IsEot { get; }
internal bool IsEot { get; }

EnemyPositional EnemyPositional { get; }

Expand Down Expand Up @@ -124,7 +124,6 @@ public interface IBaseAction : IAction
/// <param name="remain"></param>
/// <returns></returns>
bool WillHaveOneCharge(float remain);

#endregion

#region Target
Expand Down
7 changes: 5 additions & 2 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,9 @@ public static unsafe ushort FateId

public static float WeaponElapsed { get; internal set; }

public static float GCDTime(uint gcdCount = 0, float offset = 0)
=> WeaponTotal * gcdCount + offset;

/// <summary>
/// Time to the next action
/// </summary>
Expand All @@ -158,7 +161,7 @@ public static float AbilityRemain
get
{
var gcdRemain = WeaponRemain;
if ((gcdRemain - MinAnimationLock - Ping).IsLessThan(ActionRemain))
if (gcdRemain - MinAnimationLock - Ping <= ActionRemain)
{
return gcdRemain + MinAnimationLock + Ping;
}
Expand Down Expand Up @@ -190,7 +193,7 @@ public static void SetSpecialType(SpecialCommandType specialType)

public static bool InCombat { get; set; }

public static float CombatTime { get; set; }
internal static float CombatTimeRaw { get; set; }

public static IEnumerable<BattleChara> PartyMembers { get; internal set; } = Array.Empty<PlayerCharacter>();

Expand Down
50 changes: 0 additions & 50 deletions RotationSolver.Basic/Helpers/CooldownHelper.cs

This file was deleted.

13 changes: 4 additions & 9 deletions RotationSolver.Basic/Helpers/StatusHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,7 @@ internal record Burst2MinsInfo(StatusID Status, bool IsOnHostile, byte Level, pa
/// <param name="statusIDs"></param>
/// <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;
return CooldownHelper.RecastAfterGCD(remain, gcdCount, offset);
}
=> WillStatusEnd(obj, DataCenter.GCDTime(gcdCount, offset), isFromSelf, statusIDs);


/// <summary>
Expand All @@ -78,7 +72,8 @@ public static bool WillStatusEnd(this BattleChara obj, float time, bool isFromSe
{
if (DataCenter.HasApplyStatus(obj?.ObjectId ?? 0, statusIDs)) return false;
var remain = obj.StatusTime(isFromSelf, statusIDs);
return CooldownHelper.RecastAfter(remain, time);
if (remain < 0 && obj.HasStatus(isFromSelf, statusIDs)) return false;
return remain <= time;
}

/// <summary>
Expand All @@ -94,7 +89,7 @@ public static float StatusTime(this BattleChara obj, bool isFromSelf, params Sta
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();
return Math.Max(0, times.Min() - DataCenter.WeaponRemain);
}

private static IEnumerable<float> StatusTimes(this BattleChara obj, bool isFromSelf, params StatusID[] statusIDs)
Expand Down
3 changes: 1 addition & 2 deletions RotationSolver.Basic/Rotations/Basic/AST_Base.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using Dalamud.Interface.Animation;
using ECommons.DalamudServices;
using ECommons.ExcelServices;
using RotationSolver.Basic.Traits;
Expand All @@ -9,7 +8,7 @@ public abstract class AST_Base : CustomRotation
{
public override MedicineType MedicineType => MedicineType.Mind;

public sealed override Job[] Jobs => new [] { ECommons.ExcelServices.Job.AST };
public sealed override Job[] Jobs => new [] { Job.AST };

static ASTGauge JobGauge => Svc.Gauges.Get<ASTGauge>();

Expand Down
32 changes: 13 additions & 19 deletions RotationSolver.Basic/Rotations/Basic/BLM_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public abstract partial class BLM_Base : CustomRotation
{
public override MedicineType MedicineType => MedicineType.Intelligence;

public sealed override Job[] Jobs => new Job[] { ECommons.ExcelServices.Job.BLM, ECommons.ExcelServices.Job.THM };
public sealed override Job[] Jobs => new Job[] { Job.BLM, Job.THM };

#region Job Gauge
static BLMGauge JobGauge => Svc.Gauges.Get<BLMGauge>();
Expand All @@ -31,29 +31,23 @@ public abstract partial class BLM_Base : CustomRotation

protected static bool IsPolyglotStacksMaxed => Xenoglossy.EnoughLevel ? PolyglotStacks == 2 : PolyglotStacks == 1;

static float EnochianTime => JobGauge.EnochianTimer / 1000f;
static float EnochianTimeRaw => JobGauge.EnochianTimer / 1000f;

protected static bool EnchinaEndAfter(float time)
{
return EndAfter(EnochianTime, time);
}
protected static float EnochianTime => EnochianTimeRaw - DataCenter.WeaponRemain;

protected static bool EnchinaEndAfterGCD(uint gctCount = 0, float offset = 0)
{
return EndAfterGCD(EnochianTime, gctCount, offset);
}
protected static bool EnchinaEndAfter(float time) => EnochianTime <= time;

static float ElementTime => JobGauge.ElementTimeRemaining / 1000f;
protected static bool EnchinaEndAfterGCD(uint gcdCount = 0, float offset = 0)
=> EnchinaEndAfter(GCDTime(gcdCount, offset));

protected static bool ElementTimeEndAfter(float time)
{
return EndAfter(ElementTime, time);
}
static float ElementTimeRaw => JobGauge.ElementTimeRemaining / 1000f;
protected static float ElementTime => ElementTimeRaw - DataCenter.WeaponRemain;

protected static bool ElementTimeEndAfter(float time) => ElementTime <= time;

protected static bool ElementTimeEndAfterGCD(uint gctCount = 0, float offset = 0)
{
return EndAfterGCD(ElementTime, gctCount, offset);
}
=> ElementTimeEndAfter(GCDTime(gctCount, offset));


#endregion
protected static bool HasFire => Player.HasStatus(true, StatusID.Firestarter);
Expand Down Expand Up @@ -200,7 +194,7 @@ public override bool CanUse(out IAction act, CanUseOption option = CanUseOption.

public static IBaseAction Transpose { get; } = new BaseAction(ActionID.Transpose)
{
ActionCheck = (b, m) => DataCenter.ActionRemain.IsLessThan(ElementTime)
ActionCheck = (b, m) => DataCenter.ActionRemain <= ElementTimeRaw,
};

public static IBaseAction UmbralSoul { get; } = new BaseAction(ActionID.UmbralSoul)
Expand Down
Loading

0 comments on commit e16e9e7

Please sign in to comment.