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

Commit

Permalink
fix: add some comments for baseAction.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jan 20, 2023
1 parent d41a07c commit 16d9de2
Show file tree
Hide file tree
Showing 17 changed files with 157 additions and 127 deletions.
106 changes: 33 additions & 73 deletions RotationSolver/Actions/BaseAction/BaseAction_ActionInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,56 +15,34 @@ internal partial class BaseAction
{
private float Range => ActionManager.GetActionRange(ID);

/// <summary>
/// 如果之前是这些ID,那么就不会执行。
/// </summary>
public ActionID[] OtherIDsNot { private get; set; } = null;

/// <summary>
/// 如果之前不是这些ID中的某个,那么就不会执行。
/// </summary>
public ActionID[] OtherIDsCombo { private get; set; } = null;

/// <summary>
/// 使用了这个技能会得到的Buff,如果有这些Buff中的一种,那么就不会执行,这个buff是自己提供的。
/// </summary>
public ActionID[] ComboIdsNot { private get; set; } = null;

public ActionID[] ComboIds { private get; set; } = null;

public StatusID[] StatusProvide { get; set; } = null;

/// <summary>
/// 使用这个技能需要的前置Buff,有任何一个就好。
/// </summary>
public virtual StatusID[] StatusNeed { get; set; } = null;

/// <summary>
/// 如果有一些别的需要判断的,可以写在这里。True表示可以使用这个技能。
/// </summary>
public Func<BattleChara, bool> ActionCheck { get; set; } = null;

/// <summary>
/// 如果有一些别的需要判断的,可以写在这里。True表示可以使用这个技能。
/// </summary>
public Func<BattleChara, bool> ComboCheck { get; set; } = null;
public Func<BattleChara, bool> RotationCheck { get; set; } = null;

private bool WillCooldown
{
get
{
//如果首个CoolDown不是GCD技能,而且没法释放。
if (!IsGeneralGCD && IsCoolDown)
{
//会让GCD转的,充能一层的,看看来不来得及下个GCD
if (IsRealGCD)
{
if (!WillHaveOneChargeGCD()) return false;
}
else
{
//不是青魔,不能连续使用
if ((ClassJobID)Service.ClientState.LocalPlayer.ClassJob.Id != ClassJobID.BlueMage
&& ChoiceTarget != TargetFilter.FindTargetForMoving
&& Watcher.LastAction == (ActionID)AdjustedID) return false;

//冷却时间没超过一成且下一个Ability前不能转好
if (!WillHaveOneCharge(ActionUpdater.AbilityRemain, false)) return false;
}
}
Expand All @@ -73,79 +51,38 @@ private bool WillCooldown
}
}

/// <summary>
/// 判断是否需要使用这个技能
/// </summary>
/// <param name="act">返回的技能</param>
/// <param name="mustUse">必须使用,不判断提供的Buff<seealso cref="StatusProvide"/>和<seealso cref="TargetStatus">是否已提供,不判断AOE技能的敌人数量是否达标.</param>
/// <param name="emptyOrSkipCombo">如果有层数,放完所有层数,不判断是否为Combo<seealso cref="OtherIDsCombo"/><seealso cref="OtherIDsNot"/></param>
/// <returns>这个技能能不能用</returns>
public unsafe virtual bool ShouldUse(out IAction act, bool mustUse = false, bool emptyOrSkipCombo = false, bool skipDisable = false)
{
act = this;

//玩家都没有。。。
if (Service.ClientState.LocalPlayer == null) return false;
var player = Service.ClientState.LocalPlayer;

//用户不让用!
if (!skipDisable && !IsEnabled) return false;

//技能状态不对,可能是没学会。
if (ConfigurationHelper.BadStatus.Contains(ActionManager.Instance()->GetActionStatus(ActionType.Spell, AdjustedID)))
return false;

//等级不够
if (!EnoughLevel) return false;

//MP不够
if (Service.ClientState.LocalPlayer.CurrentMp < MPNeed) return false;

//没有前置Buff
if (StatusNeed != null)
{
if (!Service.ClientState.LocalPlayer.HasStatus(true, StatusNeed)) return false;
}

//已有提供的Buff的任何一种
if (StatusProvide != null && !mustUse)
{
if (Service.ClientState.LocalPlayer.HasStatus(true, StatusProvide)) return false;
}

//还冷却不下来呢,来不及。
if (!WillCooldown) return false;

if (IsGeneralGCD)
{
if (!emptyOrSkipCombo)
{
//如果有输入上次的数据,那么上次不能是上述的ID。
if (OtherIDsNot != null)
{
if (OtherIDsNot.Contains(ActionUpdater.LastComboAction)) return false;
}

//如果有Combo,有LastAction,而且上次不是连击,那就不触发。
var comboActions = _action.ActionCombo?.Row != 0
? new ActionID[] { (ActionID)_action.ActionCombo.Row }
: new ActionID[0];
if (OtherIDsCombo != null) comboActions = comboActions.Union(OtherIDsCombo).ToArray();
if (!emptyOrSkipCombo && !CheckForCombo()) return false;

if (comboActions.Length > 0)
{
if (comboActions.Contains(ActionUpdater.LastComboAction))
{
if (ActionUpdater.ComboTime < ActionUpdater.WeaponRemain) return false;
}
else
{
return false;
}
}
}

//如果是个法术需要咏唱,并且还在移动,也没有即刻相关的技能。
if (CastTime > 0 && MovingUpdater.IsMoving)
{
if (!player.HasStatus(true, CustomRotation.Swiftcast.StatusProvide))
Expand All @@ -156,22 +93,45 @@ public unsafe virtual bool ShouldUse(out IAction act, bool mustUse = false, bool
}
else
{
//如果是能力技能,还没填满。
if (!emptyOrSkipCombo && RecastTimeRemain > ActionUpdater.WeaponRemain + ActionUpdater.WeaponTotal)
return false;
}

//看看有没有目标,如果没有,就说明不符合条件。
if (!FindTarget(mustUse, out var target)) return false;

//用于自定义的要求没达到
if (ActionCheck != null && !ActionCheck(target)) return false;
if (!skipDisable && ComboCheck != null && !ComboCheck(target)) return false;
if (!skipDisable && RotationCheck != null && !RotationCheck(target)) return false;

Target = target;
return true;
}

private bool CheckForCombo()
{
if (ComboIdsNot != null)
{
if (ComboIdsNot.Contains(ActionUpdater.LastComboAction)) return false;
}

var comboActions = _action.ActionCombo?.Row != 0
? new ActionID[] { (ActionID)_action.ActionCombo.Row }
: new ActionID[0];
if (ComboIds != null) comboActions = comboActions.Union(ComboIds).ToArray();

if (comboActions.Length > 0)
{
if (comboActions.Contains(ActionUpdater.LastComboAction))
{
if (ActionUpdater.ComboTime < ActionUpdater.WeaponRemain) return false;
}
else
{
return false;
}
}
return true;
}

public unsafe bool Use()
{
var loc = new FFXIVClientStructs.FFXIV.Common.Math.Vector3() { X = _position.X, Y = _position.Y, Z = _position.Z };
Expand Down
11 changes: 2 additions & 9 deletions RotationSolver/Actions/BaseAction/BaseAction_BasicInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ internal partial class BaseAction : IBaseAction

public bool ShouldEndSpecial { private get; set; }

public bool IsTimeline { get; } = false;
/// <summary>
/// 玩家当前等级是否大于等于技能可用等级
/// </summary>
internal bool IsTimeline { get; } = false;

public bool EnoughLevel => Service.ClientState.LocalPlayer.Level >= _action.ClassJobLevel;
public string Name => _action.Name;

Expand Down Expand Up @@ -84,11 +82,6 @@ public bool IsEnabled

private byte CoolDownGroup { get; }

/// <summary>
/// 范围类技能至少需要多少个对象才释放
/// </summary>
public byte AOECount { private get; set; } = 3;

/// <summary>
/// 真实咏唱时间
/// </summary>
Expand Down
5 changes: 2 additions & 3 deletions RotationSolver/Actions/BaseAction/BaseAction_Target.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ namespace RotationSolver.Actions.BaseAction;

internal partial class BaseAction
{
public byte AOECount { private get; set; } = 3;

public bool IsTargetDying
{
get
Expand Down Expand Up @@ -47,9 +49,6 @@ private get

internal Func<IEnumerable<BattleChara>, IEnumerable<BattleChara>> FilterForTarget { private get; set; } = null;

/// <summary>
/// 给敌人造成的Debuff,如果有这些Debuff,那么不会执行,这个status是玩家赋予的。
/// </summary>
public StatusID[] TargetStatus { get; set; } = null;

internal static bool TankDefenseSelf(BattleChara chara)
Expand Down
67 changes: 65 additions & 2 deletions RotationSolver/Actions/IBaseAction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,66 @@ namespace RotationSolver.Actions
{
internal interface IBaseAction : IAction, IEnable
{
Func<BattleChara, bool> ActionCheck { get; set; }
Func<BattleChara, bool> ComboCheck { get; set; }
/// <summary>
/// If combo id is on this list, this aciton will not used.
/// </summary>
ActionID[] ComboIdsNot {set; }

/// <summary>
/// The combos that are not written on the action list.
/// </summary>
ActionID[] ComboIds { set; }

/// <summary>
/// If player has these statuses from player self, this aciton will not used.
/// </summary>
StatusID[] StatusProvide { get; set; }

/// <summary>
/// If player doesn't have these statuses from player self, this aciton will not used.
/// </summary>
StatusID[] StatusNeed { get; set; }

/// <summary>
/// Check for this action, but not for the rotation. It is some additional conditions for this action.
/// Input data is the target for this action.
/// </summary>
Func<BattleChara, bool> ActionCheck { get; set; }

/// <summary>
/// Check for rotation, you can add it for simplify the rotation file.
/// Input data is the target for this action.
Func<BattleChara, bool> RotationCheck { get; set; }

/// <summary>
/// Player's level is enough for this action's usage.
/// </summary>
bool EnoughLevel { get; }

/// <summary>
/// Should I use this action at this time. It will check a lot of things.
/// Level, Enabled, Action Status, MP, Player Status, Coll down, Combo, Moving (for casting), Charges, Target, etc.
/// </summary>
/// <param name="act"></param>
/// <param name="mustUse">AOE only need one target to use.
/// Moving action don't need to have enough distance to use.
/// Skip for <seealso cref="StatusProvide"/> and <seealso cref="TargetStatus"> cheking.</param>
/// <param name="emptyOrSkipCombo">Use all charges, no keeping.
/// Do not need to check the combo.</param>
/// <param name="skipDisable">skip the diable for emergency use.</param>
/// <returns>should I use.</returns>
bool ShouldUse(out IAction act, bool mustUse = false, bool emptyOrSkipCombo = false, bool skipDisable = false);

#region CoolDown

/// <summary>
/// Is cooling down.
/// </summary>
bool IsCoolDown { get; }

/// <summary>
/// The charges count.
/// </summary>
ushort CurrentCharges { get; }
ushort MaxCharges { get; }
bool ElapsedAfterGCD(uint gcdCount = 0, uint abilityCount = 0);
Expand All @@ -35,12 +82,28 @@ internal interface IBaseAction : IAction, IEnable
#endregion

#region Target

/// <summary>
/// If target has these statuses from player self, this aciton will not used.
/// </summary>
StatusID[] TargetStatus { get; set; }

BattleChara Target { get; }

/// <summary>
/// Is target a boss.
/// </summary>
bool IsTargetBoss { get; }

/// <summary>
/// Is target will die immediately.
/// </summary>
bool IsTargetDying { get; }

/// <summary>
/// If this is an aoe action, how many hostile target would want to attack on, when you use this action.
/// </summary>
byte AOECount { set; }
#endregion
}
}
24 changes: 19 additions & 5 deletions RotationSolver/Interfaces.cd
Original file line number Diff line number Diff line change
@@ -1,30 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<ClassDiagram MajorVersion="1" MinorVersion="1">
<Interface Name="RotationSolver.IEnable">
<Position X="4.75" Y="6" Width="1.5" />
<Position X="4.75" Y="7.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAgAAAAAAEAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>ITexture.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="RotationSolver.ITexture">
<Position X="2.75" Y="3.75" Width="1.5" />
<Position X="4.75" Y="6.25" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAgAAAAAAAQAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>ITexture.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="RotationSolver.Actions.IAction">
<Position X="2.75" Y="5.75" Width="1.5" />
<Position X="2.75" Y="6.25" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAgABAAAAAAQAAAAAEAAAAAAAAAgAAAAA=</HashCode>
<FileName>Actions\IAction.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="RotationSolver.Actions.IBaseAction">
<Position X="4" Y="9.75" Width="1.5" />
<Position X="4.25" Y="9.75" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<HashCode>AAAogAAAAAAABYAAAIAIADAAAACABIAAAAABAAAAgMA=</HashCode>
<FileName>Actions\IBaseAction.cs</FileName>
</TypeIdentifier>
</Interface>
Expand All @@ -42,5 +42,19 @@
<FileName>Rotations\CustomRotation\ICustomRotation.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="RotationSolver.Rotations.Basic.IBLUAction">
<Position X="3.25" Y="15.25" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAEAAAAA=</HashCode>
<FileName>Rotations\Basic\BLU_Base.cs</FileName>
</TypeIdentifier>
</Interface>
<Interface Name="RotationSolver.Rotations.Basic.INinAction">
<Position X="5.25" Y="15.25" Width="1.5" />
<TypeIdentifier>
<HashCode>AAAAAAAAAAAAAAAAAAAEAAAAAAAAAAAAAAAAAAAAAAA=</HashCode>
<FileName>Rotations\Basic\NIN_Base.cs</FileName>
</TypeIdentifier>
</Interface>
<Font Name="Segoe UI" Size="9" />
</ClassDiagram>
Loading

0 comments on commit 16d9de2

Please sign in to comment.