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

Commit

Permalink
feat: add conditions for all command states.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Oct 21, 2023
1 parent a2040fa commit fe9f19e
Show file tree
Hide file tree
Showing 12 changed files with 211 additions and 72 deletions.
12 changes: 12 additions & 0 deletions RotationSolver.Basic/Configuration/Conditions/MajorConditionSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,18 @@ public Dictionary<uint, ConditionSet> DisableConditionDict
public Dictionary<PluginConfigBool, ConditionSet> ForceDisableConditions { get; private set; }
= new();

public ConditionSet HealAreaConditionSet { get; set; } = new ConditionSet();
public ConditionSet HealSingleConditionSet { get; set; } = new ConditionSet();
public ConditionSet DefenseAreaConditionSet { get; set; } = new ConditionSet();
public ConditionSet DefenseSingleConditionSet { get; set; } = new ConditionSet();
public ConditionSet EsunaStanceNorthConditionSet { get; set; } = new ConditionSet();
public ConditionSet RaiseShirkConditionSet { get; set; } = new ConditionSet();
public ConditionSet MoveForwardConditionSet { get; set; } = new ConditionSet();
public ConditionSet MoveBackConditionSet { get; set; } = new ConditionSet();
public ConditionSet AntiKnockbackConditionSet { get; set; } = new ConditionSet();
public ConditionSet BurstConditionSet { get; set; } = new ConditionSet();
public ConditionSet SpeedConditionSet { get; set; } = new ConditionSet();

public string Name;

public ConditionSet GetCondition(uint id)
Expand Down
4 changes: 2 additions & 2 deletions RotationSolver.Basic/Data/IconSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,8 @@ public static bool GetTexture(uint id, out IDalamudTextureWrap texture, uint @de
/// <returns></returns>
public static bool GetTexture(string path, out IDalamudTextureWrap texture)
=> ThreadLoadImageHandler.TryGetTextureWrap(path, out texture)
|| (path.StartsWith("http:", StringComparison.OrdinalIgnoreCase) || path.StartsWith("https:", StringComparison.OrdinalIgnoreCase))
&& GetTexture("ui/uld/image2.tex", out texture); // loading pics.
|| ThreadLoadImageHandler.TryGetTextureWrap("ui/uld/image2.tex", out texture)
|| ThreadLoadImageHandler.TryGetIconTextureWrap(0, false, out texture); // loading pics.

private static readonly Dictionary<uint, uint> _actionIcons = new();

Expand Down
19 changes: 16 additions & 3 deletions RotationSolver.Basic/DataCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -205,12 +205,25 @@ public static float AbilityRemain

static DateTime _specialStateStartTime = DateTime.MinValue;
private static double SpecialTimeElapsed => (DateTime.Now - _specialStateStartTime).TotalSeconds;
public static double SpecialTimeLeft => WeaponTotal == 0 || WeaponElapsed == 0 ? Service.Config.GetValue(Configuration.PluginConfigFloat.SpecialDuration) - SpecialTimeElapsed :
Math.Ceiling((Service.Config.GetValue(Configuration.PluginConfigFloat.SpecialDuration) + WeaponElapsed - SpecialTimeElapsed) / WeaponTotal) * WeaponTotal - WeaponElapsed;
public static double SpecialTimeLeft => WeaponTotal == 0 || WeaponElapsed == 0 ? Service.Config.GetValue(PluginConfigFloat.SpecialDuration) - SpecialTimeElapsed :
Math.Ceiling((Service.Config.GetValue(PluginConfigFloat.SpecialDuration) + WeaponElapsed - SpecialTimeElapsed) / WeaponTotal) * WeaponTotal - WeaponElapsed;

static SpecialCommandType _specialType = SpecialCommandType.EndSpecial;
public static SpecialCommandType SpecialType =>
internal static SpecialCommandType SpecialType =>
SpecialTimeLeft < 0 ? SpecialCommandType.EndSpecial : _specialType;

public static bool IsHealArea => SpecialType == SpecialCommandType.HealArea || RightSet.HealAreaConditionSet.IsTrue(RightNowRotation);
public static bool IsHealSingle => SpecialType == SpecialCommandType.HealSingle || RightSet.HealSingleConditionSet.IsTrue(RightNowRotation);
public static bool IsDefenseArea => SpecialType == SpecialCommandType.DefenseArea || RightSet.DefenseAreaConditionSet.IsTrue(RightNowRotation);
public static bool IsDefenseSingle => SpecialType == SpecialCommandType.DefenseSingle || RightSet.DefenseSingleConditionSet.IsTrue(RightNowRotation);
public static bool IsEsunaStanceNorth => SpecialType == SpecialCommandType.EsunaStanceNorth || RightSet.EsunaStanceNorthConditionSet.IsTrue(RightNowRotation);
public static bool IsRaiseShirk => SpecialType == SpecialCommandType.RaiseShirk || RightSet.RaiseShirkConditionSet.IsTrue(RightNowRotation);
public static bool IsMoveForward => SpecialType == SpecialCommandType.MoveForward || RightSet.MoveForwardConditionSet.IsTrue(RightNowRotation);
public static bool IsMoveBack => SpecialType == SpecialCommandType.MoveBack || RightSet.MoveBackConditionSet.IsTrue(RightNowRotation);
public static bool IsAntiKnockback => SpecialType == SpecialCommandType.AntiKnockback || RightSet.AntiKnockbackConditionSet.IsTrue(RightNowRotation);
public static bool IsBurst => SpecialType == SpecialCommandType.Burst || RightSet.BurstConditionSet.IsTrue(RightNowRotation);
public static bool IsSpeed => SpecialType == SpecialCommandType.Speed || RightSet.SpeedConditionSet.IsTrue(RightNowRotation);

public static bool State { get; set; } = false;

public static bool IsManual { get; set; } = false;
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Rotations/Basic/BLU_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ protected override bool EmergencyGCD(out IAction act)
if (BlueId == BLUID.Healer)
{
//Esuna
if (DataCenter.SpecialType == SpecialCommandType.EsunaStanceNorth && DataCenter.WeakenPeople.Any() || DataCenter.DyingPeople.Any())
if (DataCenter.IsEsunaStanceNorth && DataCenter.WeakenPeople.Any() || DataCenter.DyingPeople.Any())
{
if (Exuviation.CanUse(out act, CanUseOption.MustUse)) return true;
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Rotations/Basic/BRD_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ protected static bool SongEndAfterGCD(uint gctCount = 0, float offset = 0)
protected override bool EmergencyAbility(IAction nextGCD, out IAction act)
{
//Esuna
if (DataCenter.SpecialType == SpecialCommandType.EsunaStanceNorth && DataCenter.WeakenPeople.Any() || DataCenter.DyingPeople.Any())
if (DataCenter.IsEsunaStanceNorth && DataCenter.WeakenPeople.Any() || DataCenter.DyingPeople.Any())
{
if (WardensPaean.CanUse(out act, CanUseOption.MustUse)) return true;
}
Expand Down
58 changes: 19 additions & 39 deletions RotationSolver.Basic/Rotations/CustomRotation_Ability.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,30 +27,28 @@ private bool Ability(IAction nextGCD, out IAction act, bool helpDefenseAOE, bool

if (InterruptAbility(role, out act)) return true;

var specialType = DataCenter.SpecialType;
if (ShirkOrShield(role, out act)) return true;
if (DataCenter.IsAntiKnockback && AntiKnockback(role, out act)) return true;

if (ShirkOrShield(role, specialType, out act)) return true;
if (AntiKnockback(role, specialType, out act)) return true;

if (specialType == SpecialCommandType.EsunaStanceNorth && role == JobRole.Melee)
if (DataCenter.IsEsunaStanceNorth && role == JobRole.Melee)
{
if (TrueNorth.CanUse(out act)) return true;
}

if (GeneralHealAbility(specialType, out act)) return true;
if(specialType == SpecialCommandType.Speed && SpeedAbility(out act)) return true;
if (GeneralHealAbility(out act)) return true;
if (DataCenter.IsSpeed && SpeedAbility(out act)) return true;

if (AutoDefense(role, helpDefenseAOE, helpDefenseSingle, out act)) return true;

BaseAction.OtherOption |= CanUseOption.EmptyOrSkipCombo;
if (MovingAbility(specialType, out act)) return true;
if (MovingAbility(out act)) return true;
BaseAction.OtherOption &= ~CanUseOption.EmptyOrSkipCombo;

if (GeneralUsingAbility(role, out act)) return true;

if (DataCenter.HPNotFull && InCombat)
{
if (DataCenter.SpecialType == SpecialCommandType.HealSingle || CanHealSingleAbility)
if (DataCenter.IsHealSingle || CanHealSingleAbility)
{
if (UseHealPotion(out act)) return true;
}
Expand Down Expand Up @@ -90,24 +88,16 @@ private static bool InterruptAbility(JobRole role, out IAction act)
return false;
}

private bool ShirkOrShield(JobRole role, SpecialCommandType specialType, out IAction act)
private bool ShirkOrShield(JobRole role, out IAction act)
{
act = null;
if (role != JobRole.Tank)
{
return DataCenter.SetAutoStatus(AutoStatus.TankStance, false);
}

switch (specialType)
{
case SpecialCommandType.RaiseShirk:
if (Shirk.CanUse(out act)) return true;
break;

case SpecialCommandType.EsunaStanceNorth:
if (TankStance.CanUse(out act)) return true;
break;
}
if (DataCenter.IsRaiseShirk && Shirk.CanUse(out act)) return true;
if (DataCenter.IsEsunaStanceNorth && TankStance.CanUse(out act)) return true;

if (DataCenter.SetAutoStatus(AutoStatus.TankStance, Service.Config.GetValue(PluginConfigBool.AutoTankStance)
&& !DataCenter.AllianceTanks.Any(t => t.CurrentHp != 0 && t.HasStatus(false, StatusHelper.TankStanceStatus))
Expand All @@ -119,12 +109,9 @@ private bool ShirkOrShield(JobRole role, SpecialCommandType specialType, out IAc
return false;
}

private static bool AntiKnockback(JobRole role, SpecialCommandType specialType, out IAction act)
private static bool AntiKnockback(JobRole role, out IAction act)
{
act = null;

if (specialType != SpecialCommandType.AntiKnockback) return false;

switch (role)
{
case JobRole.Tank:
Expand All @@ -145,26 +132,19 @@ private static bool AntiKnockback(JobRole role, SpecialCommandType specialType,
return false;
}

private bool GeneralHealAbility(SpecialCommandType specialType, out IAction act)
private bool GeneralHealAbility(out IAction act)
{
act = null;

BaseAction.OtherOption |= CanUseOption.MustUse;
switch (specialType)
{
case SpecialCommandType.DefenseArea:
if (DefenseAreaAbility(out act)) return true;
break;
if (DataCenter.IsDefenseArea && DefenseAreaAbility(out act)) return true;
if (DataCenter.IsDefenseSingle && DefenseSingleAbility(out act)) return true;

case SpecialCommandType.DefenseSingle:
if (DefenseSingleAbility(out act)) return true;
break;
}
BaseAction.OtherOption &= ~CanUseOption.MustUse;

if ((DataCenter.HPNotFull || ClassJob.GetJobRole() != JobRole.Healer) && InCombat)
{
if (DataCenter.SpecialType == SpecialCommandType.HealArea)
if (DataCenter.IsHealArea)
{
if (HealAreaAbility(out act)) return true;
}
Expand All @@ -174,7 +154,7 @@ private bool GeneralHealAbility(SpecialCommandType specialType, out IAction act)
if (HealAreaAbility(out act)) return true;
BaseAction.AutoHealCheck = false;
}
if (DataCenter.SpecialType == SpecialCommandType.HealSingle)
if (DataCenter.IsHealSingle)
{
if (HealSingleAbility(out act)) return true;
}
Expand Down Expand Up @@ -250,11 +230,11 @@ private bool AutoDefense(JobRole role, bool helpDefenseAOE, bool helpDefenseSing
return false;
}

private bool MovingAbility(SpecialCommandType specialType, out IAction act)
private bool MovingAbility(out IAction act)
{
act = null;
if (specialType == SpecialCommandType.MoveForward && MoveForwardAbility(out act)) return true;
else if (specialType == SpecialCommandType.MoveBack && MoveBackAbility(out act)) return true;
if (DataCenter.IsMoveForward && MoveForwardAbility(out act)) return true;
else if (DataCenter.IsMoveBack && MoveBackAbility(out act)) return true;
return false;
}

Expand Down
22 changes: 10 additions & 12 deletions RotationSolver.Basic/Rotations/CustomRotation_GCD.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ private IAction GCD(bool helpDefenseAOE, bool helpDefenseSingle)

if (EmergencyGCD(out act)) return act;

var specialType = DataCenter.SpecialType;
if (RaiseSpell(out act, false)) return act;

if (RaiseSpell(specialType, out act, false)) return act;

if (specialType == SpecialCommandType.MoveForward && MoveForwardGCD(out act))
if (DataCenter.IsMoveForward && MoveForwardGCD(out act))
{
if (act is IBaseAction b && ObjectHelper.DistanceToPlayer(b.Target) > 5) return act;
}
Expand All @@ -28,7 +26,7 @@ private IAction GCD(bool helpDefenseAOE, bool helpDefenseSingle)
if ((DataCenter.HPNotFull || ClassJob.GetJobRole() != JobRole.Healer)
&& (DataCenter.InCombat || Service.Config.GetValue(PluginConfigBool.HealOutOfCombat)))
{
if (specialType == SpecialCommandType.HealArea)
if (DataCenter.IsHealArea)
{
if( HealAreaGCD(out act)) return act;
}
Expand All @@ -38,7 +36,7 @@ private IAction GCD(bool helpDefenseAOE, bool helpDefenseSingle)
if (HealAreaGCD(out act)) return act;
BaseAction.AutoHealCheck = false;
}
if (specialType == SpecialCommandType.HealSingle)
if (DataCenter.IsHealSingle)
{
if (HealSingleGCD(out act)) return act;
}
Expand All @@ -49,15 +47,15 @@ private IAction GCD(bool helpDefenseAOE, bool helpDefenseSingle)
BaseAction.AutoHealCheck = false;
}
}
if (specialType == SpecialCommandType.DefenseArea && DefenseAreaGCD(out act)) return act;
if (specialType == SpecialCommandType.DefenseSingle && DefenseSingleGCD(out act)) return act;
if (DataCenter.IsDefenseArea && DefenseAreaGCD(out act)) return act;
if (DataCenter.IsDefenseSingle && DefenseSingleGCD(out act)) return act;

//Auto Defense
if (DataCenter.SetAutoStatus(AutoStatus.DefenseArea, helpDefenseAOE) && DefenseAreaGCD(out act)) return act;
if (DataCenter.SetAutoStatus(AutoStatus.DefenseSingle, helpDefenseSingle) && DefenseSingleGCD(out act)) return act;

//Esuna
if (DataCenter.SetAutoStatus(AutoStatus.Esuna, (specialType == SpecialCommandType.EsunaStanceNorth
if (DataCenter.SetAutoStatus(AutoStatus.Esuna, (DataCenter.IsEsunaStanceNorth
|| !HasHostilesInRange || Service.Config.GetValue(PluginConfigBool.EsunaAll))
&& DataCenter.WeakenPeople.Any() || DataCenter.DyingPeople.Any()))
{
Expand Down Expand Up @@ -87,15 +85,15 @@ private IAction GCD(bool helpDefenseAOE, bool helpDefenseSingle)
}
}

if (Service.Config.GetValue(PluginConfigBool.RaisePlayerByCasting) && RaiseSpell(specialType, out act, true)) return act;
if (Service.Config.GetValue(PluginConfigBool.RaisePlayerByCasting) && RaiseSpell(out act, true)) return act;

return null;
}

private bool RaiseSpell(SpecialCommandType specialType, out IAction act, bool mustUse)
private bool RaiseSpell(out IAction act, bool mustUse)
{
act = null;
if (specialType == SpecialCommandType.RaiseShirk && DataCenter.DeathPeopleAll.Any())
if (DataCenter.IsRaiseShirk && DataCenter.DeathPeopleAll.Any())
{
if (RaiseAction(out act)) return true;
}
Expand Down
2 changes: 1 addition & 1 deletion RotationSolver.Basic/Rotations/CustomRotation_Invoke.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private void UpdateActions(JobRole role)
JobRole.Tank => Shirk.CanUse(out act) ? act : null,
_ => null,
};
AntiKnockbackAbility = AntiKnockback(role, SpecialCommandType.AntiKnockback, out act) ? act : null;
AntiKnockbackAbility = AntiKnockback(role, out act) ? act : null;

BaseAction.OtherOption |= CanUseOption.EmptyOrSkipCombo;

Expand Down
62 changes: 56 additions & 6 deletions RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -197,11 +197,66 @@ public static bool IsLongerThan(float time)
#endregion

#region Command
/// <summary>
/// Is in burst right now? Usually it used with team support actions. Please use <see cref="IsBurst"/> instead.
/// </summary>
[Obsolete("It will be removed in the future version", true)]
public static bool InBurst => IsBurst;

/// <summary>
/// Is in burst right now? Usually it used with team support actions.
/// </summary>
public static bool InBurst => DataCenter.SpecialType == SpecialCommandType.Burst || Service.Config.GetValue(Configuration.PluginConfigBool.AutoBurst);
public static bool IsBurst => DataCenter.IsBurst || Service.Config.GetValue(Configuration.PluginConfigBool.AutoBurst);

/// <summary>
/// Is in the command heal area.
/// </summary>
public static bool IsHealArea => DataCenter.IsHealArea;

/// <summary>
/// Is in the command heal single.
/// </summary>
public static bool IsHealSingle => DataCenter.IsHealSingle;

/// <summary>
/// Is in the command defense area.
/// </summary>
public static bool IsDefenseArea => DataCenter.IsDefenseArea;

/// <summary>
/// Is in the command defense single.
/// </summary>
public static bool IsDefenseSingle => DataCenter.IsDefenseSingle;

/// <summary>
/// Is in the command Esuna Stance North.
/// </summary>
public static bool IsEsunaStanceNorth => DataCenter.IsEsunaStanceNorth;

/// <summary>
/// Is in the command Raise Shirk.
/// </summary>
public static bool IsRaiseShirk => DataCenter.IsRaiseShirk;

/// <summary>
/// Is in the command move forward.
/// </summary>
public static bool IsMoveForward => DataCenter.IsMoveForward;

/// <summary>
/// Is in the command move back.
/// </summary>
public static bool IsMoveBack => DataCenter.IsMoveBack;

/// <summary>
/// Is in the command anti knockback.
/// </summary>
public static bool IsAntiKnockback => DataCenter.IsAntiKnockback;

/// <summary>
/// Is in the command speed.
/// </summary>
public static bool IsSpeed => DataCenter.IsSpeed;

private bool CanUseHealAction =>
//Job
Expand Down Expand Up @@ -229,11 +284,6 @@ public static bool IsLongerThan(float time)
/// </summary>
public virtual bool CanHealSingleSpell => DataCenter.CanHealSingleSpell && CanUseHealAction;

/// <summary>
///
/// </summary>
protected static SpecialCommandType SpecialType => DataCenter.SpecialType;

/// <summary>
/// True for On, false for off.
/// </summary>
Expand Down
Loading

0 comments on commit fe9f19e

Please sign in to comment.