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

Commit

Permalink
Merge pull request #1402 from Taurenkey/main
Browse files Browse the repository at this point in the history
Fix cooldown data
  • Loading branch information
Taurenkey authored Jun 30, 2024
2 parents daec388 + e1e226c commit 49d192f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 113 deletions.
2 changes: 1 addition & 1 deletion XIVSlothCombo/Combos/JobHelpers/RDM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal class RDM
static float GetBuffRemainingTime(ushort effectid) => CustomComboFunctions.GetBuffRemainingTime(effectid);
static bool LevelChecked(uint id) => CustomComboFunctions.LevelChecked(id);
static float GetActionCastTime(uint actionID) => CustomComboFunctions.GetActionCastTime(actionID);
static ushort GetRemainingCharges(uint actionID) => CustomComboFunctions.GetRemainingCharges(actionID);
static uint GetRemainingCharges(uint actionID) => CustomComboFunctions.GetRemainingCharges(actionID);
static float GetCooldownRemainingTime(uint actionID) => CustomComboFunctions.GetCooldownRemainingTime(actionID);
static bool ActionReady(uint id) => CustomComboFunctions.ActionReady(id);
static bool CanSpellWeave(uint id) => CustomComboFunctions.CanSpellWeave(id);
Expand Down
2 changes: 1 addition & 1 deletion XIVSlothCombo/Combos/PvE/BRD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,7 @@ protected override uint Invoke(uint actionID, uint lastComboMove, float comboTim

if (LevelChecked(Bloodletter) && ((!openerFinished && IsOnCooldown(RagingStrikes)) || openerFinished))
{
ushort bloodletterCharges = GetRemainingCharges(Bloodletter);
uint bloodletterCharges = GetRemainingCharges(Bloodletter);

if (IsEnabled(CustomComboPreset.BRD_Simple_Pooling) && LevelChecked(WanderersMinuet))
{
Expand Down
2 changes: 1 addition & 1 deletion XIVSlothCombo/CustomCombo/Functions/Cooldown.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ internal abstract partial class CustomComboFunctions
/// <summary> Get the current number of charges remaining for an action. </summary>
/// <param name="actionID"> Action ID to check. </param>
/// <returns> Number of charges. </returns>
public static ushort GetRemainingCharges(uint actionID) => GetCooldown(actionID).RemainingCharges;
public static uint GetRemainingCharges(uint actionID) => GetCooldown(actionID).RemainingCharges;

/// <summary> Get the maximum number of charges for an action. </summary>
/// <param name="actionID"> Action ID to check. </param>
Expand Down
93 changes: 17 additions & 76 deletions XIVSlothCombo/Data/CooldownData.cs
Original file line number Diff line number Diff line change
@@ -1,114 +1,55 @@
using System.Runtime.InteropServices;
using FFXIVClientStructs.FFXIV.Client.Game;
using XIVSlothCombo.Services;

namespace XIVSlothCombo.Data
{
/// <summary> Internal cooldown data. </summary>
[StructLayout(LayoutKind.Explicit)]
internal struct CooldownData
internal class CooldownData
{
[FieldOffset(0x0)]
private readonly bool isCooldown;

[FieldOffset(0x4)]
private readonly uint actionID;

[FieldOffset(0x8)]
private readonly float cooldownElapsed;

[FieldOffset(0xC)]
private float cooldownTotal;

/// <summary> Gets a value indicating whether the action is on cooldown. </summary>
public readonly bool IsCooldown
public bool IsCooldown
{
get
{
var (cur, max) = Service.ComboCache.GetMaxCharges(ActionID);
return cur == max
? isCooldown
: cooldownElapsed < CooldownTotal;
return RemainingCharges == MaxCharges
? false
: CooldownElapsed < CooldownTotal;
}
}

/// <summary> Gets the action ID on cooldown. </summary>
public readonly uint ActionID => actionID;
public uint ActionID;

/// <summary> Gets the elapsed cooldown time. </summary>
public readonly float CooldownElapsed
{
get
{
if (cooldownElapsed == 0)
return 0;

if (cooldownElapsed > CooldownTotal)
return 0;

return cooldownElapsed;
}
}
public unsafe float CooldownElapsed => ActionManager.Instance()->GetRecastGroupDetail(ActionManager.Instance()->GetRecastGroup(1, ActionID))->Elapsed;

/// <summary> Gets the total cooldown time. </summary>
public float CooldownTotal
{
readonly get
{
if (cooldownTotal == 0)
return 0;

var (cur, max) = Service.ComboCache.GetMaxCharges(ActionID);

if (cur == max)
return cooldownTotal;

// Rebase to the current charge count
float total = cooldownTotal / max * cur;

return cooldownElapsed > total
? 0
: total;
}
set
{
cooldownTotal = value;
}
}
public unsafe float CooldownTotal => (ActionManager.GetAdjustedRecastTime(ActionType.Action, ActionID) / 1000f) * MaxCharges;

/// <summary> Gets the cooldown time remaining. </summary>
public readonly float CooldownRemaining => IsCooldown ? CooldownTotal - CooldownElapsed : 0;
public unsafe float CooldownRemaining => CooldownTotal - CooldownElapsed;

/// <summary> Gets the maximum number of charges for an action at the current level. </summary>
/// <returns> Number of charges. </returns>
public readonly ushort MaxCharges => Service.ComboCache.GetMaxCharges(ActionID).Current;
public ushort MaxCharges => Service.ComboCache.GetMaxCharges(ActionID);

/// <summary> Gets a value indicating whether the action has charges, not charges available. </summary>
public readonly bool HasCharges => MaxCharges > 1;
public bool HasCharges => MaxCharges > 1;

/// <summary> Gets the remaining number of charges for an action. </summary>
public readonly ushort RemainingCharges
{
get
{
var (cur, _) = Service.ComboCache.GetMaxCharges(ActionID);

return !IsCooldown
? cur
: (ushort)(CooldownElapsed / (CooldownTotal / MaxCharges));
}
}
public unsafe uint RemainingCharges => ActionManager.Instance()->GetCurrentCharges(ActionID);

/// <summary> Gets the cooldown time remaining until the next charge. </summary>
public readonly float ChargeCooldownRemaining
public float ChargeCooldownRemaining
{
get
{
if (!IsCooldown)
return 0;

var (cur, _) = Service.ComboCache.GetMaxCharges(ActionID);
var maxCharges = ActionManager.GetMaxCharges(ActionID, 100);
var timePerCharge = CooldownTotal / maxCharges;

return CooldownRemaining % (CooldownTotal / cur);
return CooldownRemaining % (CooldownTotal / MaxCharges);
}
}
}
Expand Down
40 changes: 6 additions & 34 deletions XIVSlothCombo/Data/CustomComboCache.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,46 +81,18 @@ internal unsafe CooldownData GetCooldown(uint actionID)
if (actionManager == null)
return cooldownCache[actionID] = default;

byte cooldownGroup = GetCooldownGroup(actionID);

RecastDetail* cooldownPtr = actionManager->GetRecastGroupDetail(cooldownGroup - 1);
if (cooldownPtr is null)
CooldownData data = new()
{
CooldownData data = new()
{
CooldownTotal = -1
};

return cooldownCache[actionID] = data;
}
ActionID = actionID,
};

cooldownPtr->ActionId = actionID;

return cooldownCache[actionID] = *(CooldownData*)cooldownPtr;
return cooldownCache[actionID] = data;
}

/// <summary> Get the maximum number of charges for an action. </summary>
/// <param name="actionID"> Action ID to check. </param>
/// <returns> Max number of charges at current and max level. </returns>
internal unsafe (ushort Current, ushort Max) GetMaxCharges(uint actionID)
{
IPlayerCharacter? player = Service.ClientState.LocalPlayer;
if (player == null)
return (0, 0);

uint job = player.ClassJob.Id;
byte level = player.Level;
if (job == 0 || level == 0)
return (0, 0);

var key = (actionID, job, level);
if (chargesCache.TryGetValue(key, out var found))
return found;

ushort cur = ActionManager.GetMaxCharges(actionID, 0);
ushort max = ActionManager.GetMaxCharges(actionID, 90);
return chargesCache[key] = (cur, max);
}
/// <returns> Max number of charges at current level. </returns>
internal unsafe ushort GetMaxCharges(uint actionID) => ActionManager.GetMaxCharges(actionID, 0);

/// <summary> Get the resource cost of an action. </summary>
/// <param name="actionID"> Action ID to check. </param>
Expand Down
1 change: 1 addition & 0 deletions XIVSlothCombo/Window/Tabs/Debug.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Linq;
using System.Numerics;
using XIVSlothCombo.Combos;
using XIVSlothCombo.Combos.PvE;
using XIVSlothCombo.CustomComboNS;
using XIVSlothCombo.CustomComboNS.Functions;
using XIVSlothCombo.Data;
Expand Down

0 comments on commit 49d192f

Please sign in to comment.