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

Commit

Permalink
style: change the target updating.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArchiDog1998 committed Jan 31, 2023
1 parent 9157d96 commit 9902932
Show file tree
Hide file tree
Showing 13 changed files with 215 additions and 261 deletions.
54 changes: 24 additions & 30 deletions RotationSolver/Actions/BaseAction/BaseAction_Target.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Game.ClientState.Objects.SubKinds;
using Dalamud.Game.ClientState.Objects.Types;
using Dalamud.Logging;
using RotationSolver.Commands;
using RotationSolver.Data;
Expand Down Expand Up @@ -78,7 +79,8 @@ private bool FindTarget(bool mustUse, out BattleChara target)
}
else if (_action.TargetArea)
{
return TargetArea(range, mustUse, aoeCount, out target);
target = player;
return TargetArea(range, mustUse, aoeCount, player);
}
//如果能对友方和敌方都能选中
else if (_action.CanTargetParty && _action.CanTargetHostile)
Expand All @@ -103,49 +105,44 @@ private bool FindTarget(bool mustUse, out BattleChara target)
}
else
{
target = Service.TargetManager.Target is BattleChara battle ? battle : Service.ClientState.LocalPlayer;
target = Service.TargetManager.Target is BattleChara battle ? battle : player;
return true;
}
}

#region TargetArea
private bool TargetArea(float range, bool mustUse, int aoeCount, out BattleChara target)
private bool TargetArea(float range, bool mustUse, int aoeCount, PlayerCharacter player)
{
//移动
if (_action.EffectRange == 1 && range >= 15)
{
return TargetAreaMove(range, mustUse, out target);
return TargetAreaMove(range, mustUse);
}
//其他友方
else if (_isFriendly)
{
return TargetAreaFriend(range, mustUse, out target);
return TargetAreaFriend(range, mustUse, player);
}
//敌方
else
{
return TargetAreaHostile(aoeCount, out target);
return TargetAreaHostile(aoeCount);
}
}

private bool TargetAreaHostile(int aoeCount, out BattleChara target)
private bool TargetAreaHostile(int aoeCount)
{
target = GetMostObjects(TargetUpdater.HostileTargets, aoeCount)
var target = GetMostObjects(TargetUpdater.HostileTargets, aoeCount)
.OrderByDescending(ObjectHelper.GetHealthRatio).FirstOrDefault();
if (target == null)
{
target = Service.ClientState.LocalPlayer;
return false;
}
if (target == null) return false;
_position = target.Position;
return true;
}

private bool TargetAreaMove(float range, bool mustUse, out BattleChara target)
private bool TargetAreaMove(float range, bool mustUse)
{
if (Service.Configuration.MoveAreaActionFarthest)
{
target = null;
Vector3 pPosition = Service.ClientState.LocalPlayer.Position;
float rotation = Service.ClientState.LocalPlayer.Rotation;
_position = new Vector3(pPosition.X + (float)Math.Sin(rotation) * range, pPosition.Y,
Expand All @@ -154,53 +151,50 @@ private bool TargetAreaMove(float range, bool mustUse, out BattleChara target)
}
else
{
var availableCharas = Service.ObjectTable.Where(b => b.ObjectId != Service.ClientState.LocalPlayer.ObjectId).OfType<BattleChara>();
target = TargetFilter.GetObjectInRadius(availableCharas, range).FindTargetForMoving(mustUse);

var availableCharas = TargetUpdater.AllTargets.Where(b => b.ObjectId != Service.ClientState.LocalPlayer.ObjectId);
var target = TargetFilter.GetObjectInRadius(availableCharas, range).FindTargetForMoving(mustUse);
if (target == null) return false;
_position = target.Position;
return true;
}
}

private bool TargetAreaFriend(float range, bool mustUse, out BattleChara target)
private bool TargetAreaFriend(float range, bool mustUse, PlayerCharacter player)
{
target = null;
//如果用户不想使用自动友方地面放置功能
if (!Service.Configuration.UseGroundBeneficialAbility) return false;

//如果当前目标是Boss且有身位,放他身上。
if (Service.TargetManager.Target is BattleChara b && b.DistanceToPlayer() < range && b.IsBoss() && b.HasPositional())
{
target = b;
_position = target.Position;
_position = b.Position;
return true;
}
//计算玩家和被打的T之间的关系。
else
{
var attackT = TargetFilter.FindAttackedTarget(TargetUpdater.PartyTanks.GetObjectInRadius(range + _action.EffectRange), mustUse);

target = Service.ClientState.LocalPlayer;

if (attackT == null)
{
_position = target.Position;
_position = player.Position;
}
else
{
var disToTankRound = Math.Max(range, Vector3.Distance(target.Position, attackT.Position) + attackT.HitboxRadius);
var disToTankRound = Math.Max(range, Vector3.Distance(player.Position, attackT.Position) + attackT.HitboxRadius);

if (disToTankRound < _action.EffectRange
|| disToTankRound > 2 * _action.EffectRange - target.HitboxRadius
|| disToTankRound > 2 * _action.EffectRange - player.HitboxRadius
|| disToTankRound > range)
{
_position = target.Position;
_position = player.Position;
}
else
{
Vector3 directionToTank = attackT.Position - target.Position;
Vector3 directionToTank = attackT.Position - player.Position;
var MoveDirection = directionToTank / directionToTank.Length() * (disToTankRound - _action.EffectRange);
_position = target.Position + MoveDirection;
_position = player.Position + MoveDirection;
}
}
return true;
Expand Down
1 change: 1 addition & 0 deletions RotationSolver/Configuration/PluginConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ public class PluginConfiguration : IPluginConfiguration

public Dictionary<ClassJobID, float> HealthForDyingTanks { get; set; } = new Dictionary<ClassJobID, float>();
public float InterruptibleTime = 0.5f;
public bool InterruptibleMoreCheck = true;
public float SpecialDuration = 3;
public float WeaponInterval = 0.67f;
public float WeaponFaster = 0.08f;
Expand Down
18 changes: 18 additions & 0 deletions RotationSolver/Helpers/ObjectHelper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Dalamud.Game.ClientState.Objects.Types;
using FFXIVClientStructs.FFXIV.Client.Game;
using Lumina.Excel.GeneratedSheets;
using RotationSolver.Data;
using RotationSolver.Updaters;
Expand Down Expand Up @@ -28,6 +29,23 @@ internal static unsafe uint FateId(this GameObject obj)
internal static unsafe bool IsTargetable(this GameObject obj)
=> ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)obj.Address)->GetIsTargetable();

internal static bool CanInterrupt(this BattleChara b)
{
var baseCheck = b.IsCasting && b.IsCastInterruptible && b.TotalCastTime >= 2
&& b.CurrentCastTime >= Service.Configuration.InterruptibleTime;

if (!baseCheck) return false;
if (!Service.Configuration.InterruptibleMoreCheck) return true;

var act = Service.DataManager.GetExcelSheet<Lumina.Excel.GeneratedSheets.Action>().GetRow(b.CastActionId);
if (act == null) return false;

//跳过扇形圆型
if (act.CastType is 3 or 4) return false;
if (ActionManager.GetActionRange(b.CastActionId) < 8) return false;
return true;
}

/// <summary>
/// Is character a boss? Max HP exceeds a certain amount.
/// </summary>
Expand Down
10 changes: 10 additions & 0 deletions RotationSolver/Helpers/StatusHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,16 @@ namespace RotationSolver.Helpers;

internal static class StatusHelper
{
public static StatusID[] AreaHots { get; } = new StatusID[]
{
StatusID.AspectedHelios, StatusID.Medica2, StatusID.TrueMedica2
};

public static StatusID[] SingleHots { get; } = new StatusID[]
{
StatusID.AspectedBenefic, StatusID.Regen1, StatusID.Regen2, StatusID.Regen3
};

public static StatusID[] SheildStatus { get; } = new StatusID[]
{
StatusID.Grit, StatusID.RoyalGuard, StatusID.IronWill, StatusID.Defiance
Expand Down
20 changes: 6 additions & 14 deletions RotationSolver/Helpers/TargetFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ internal static BattleChara DefaultFindHostile(IEnumerable<BattleChara> availabl
.OrderBy(DistanceToPlayer).First();
}

internal static BattleChara FindTargetForMoving(this IEnumerable<BattleChara> charas, bool mustUse)
internal static GameObject FindTargetForMoving(this IEnumerable<GameObject> charas, bool mustUse)
{
if (mustUse)
{
Expand All @@ -78,7 +78,7 @@ internal static BattleChara FindTargetForMoving(this IEnumerable<BattleChara> ch
}

const float DISTANCE_TO_MOVE = 3;
private static BattleChara FindMoveTargetFaceDirection(IEnumerable<BattleChara> charas)
private static GameObject FindMoveTargetFaceDirection(IEnumerable<GameObject> charas)
{
Vector3 pPosition = Service.ClientState.LocalPlayer.Position;
float rotation = Service.ClientState.LocalPlayer.Rotation;
Expand All @@ -97,7 +97,7 @@ private static BattleChara FindMoveTargetFaceDirection(IEnumerable<BattleChara>
return tars.FirstOrDefault();
}

private static BattleChara FindMoveTargetScreenCenter(IEnumerable<BattleChara> charas)
private static GameObject FindMoveTargetScreenCenter(IEnumerable<GameObject> charas)
{
var pPosition = Service.ClientState.LocalPlayer.Position;
if (!Service.GameGui.WorldToScreen(pPosition, out var playerScrPos)) return null;
Expand Down Expand Up @@ -228,17 +228,10 @@ internal static BattleChara GetDeathPeople(IEnumerable<BattleChara> deathAll, IE
return null;
}

internal unsafe static IEnumerable<BattleChara> GetTargetable(IEnumerable<BattleChara> charas)
{
return charas.Where(item => ((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)(void*)item.Address)->GetIsTargetable());
}

internal unsafe static IEnumerable<BattleChara> GetDeath(this IEnumerable<BattleChara> charas)
{
charas = GetTargetable(charas);

return charas.Where(item =>
internal unsafe static IEnumerable<BattleChara> GetDeath(this IEnumerable<BattleChara> charas) => charas.Where(item =>
{
if (!item.IsTargetable()) return false;

//如果还有血,就算了。
if (item.CurrentHp != 0) return false;

Expand All @@ -253,7 +246,6 @@ internal unsafe static IEnumerable<BattleChara> GetDeath(this IEnumerable<Battle

return true;
});
}

internal static IEnumerable<BattleChara> GetJobCategory(this IEnumerable<BattleChara> objects, params JobRole[] roles)
{
Expand Down
31 changes: 2 additions & 29 deletions RotationSolver/Rotations/Basic/DNC_Base.cs
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ internal abstract class DNC_Base : CustomRotation.CustomRotation
/// <summary>
/// 标准舞步结束
/// </summary>
private static IBaseAction StandardFinish { get; } = new BaseAction(ActionID.StandardFinish)
protected static IBaseAction StandardFinish { get; } = new BaseAction(ActionID.StandardFinish)
{
StatusNeed = new[] { StatusID.StandardStep },
ActionCheck = b => IsDancing && JobGauge.CompletedSteps == 2,
Expand All @@ -218,7 +218,7 @@ internal abstract class DNC_Base : CustomRotation.CustomRotation
/// <summary>
/// 技巧舞步结束
/// </summary>
private static IBaseAction TechnicalFinish { get; } = new BaseAction(ActionID.TechnicalFinish)
protected static IBaseAction TechnicalFinish { get; } = new BaseAction(ActionID.TechnicalFinish)
{
StatusNeed = new[] { StatusID.TechnicalStep },
ActionCheck = b => IsDancing && JobGauge.CompletedSteps == 4,
Expand Down Expand Up @@ -290,33 +290,6 @@ internal abstract class DNC_Base : CustomRotation.CustomRotation
StatusNeed = new[] { StatusID.FlourishingFinish },
};

/// <summary>
/// 结束舞步
/// </summary>
/// <param name="act"></param>
/// <returns></returns>
protected static bool FinishStepGCD(out IAction act)
{
act = null;
if (!IsDancing) return false;

//标准舞步结束
if (Player.HasStatus(true, StatusID.StandardStep) && Player.WillStatusEnd(1, true, StatusID.StandardStep) || StandardFinish.CanUse(out _, mustUse: true))
{
act = StandardStep;
return true;
}

//技巧舞步结束
if (Player.HasStatus(true, StatusID.TechnicalStep) && Player.WillStatusEnd(1, true, StatusID.TechnicalStep) || TechnicalFinish.CanUse(out _, mustUse: true))
{
act = TechnicalStep;
return true;
}

return false;
}

/// <summary>
/// 执行舞步
/// </summary>
Expand Down
25 changes: 23 additions & 2 deletions RotationSolver/Rotations/RangedPhysicial/DNC/DNC_Default.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ private protected override IAction CountDownAction(float remainTime)
{
if (remainTime <= 15)
{
if (StandardStep.CanUse(out _, mustUse: true)) return StandardStep;
IAction act;
if (StandardStep.CanUse(out var act, mustUse: true)) return act;
if (ExcutionStepGCD(out act)) return act;
}
return base.CountDownAction(remainTime);
Expand Down Expand Up @@ -213,4 +212,26 @@ private bool UseClosedPosition(out IAction act)
act = null;
return false;
}

private static bool FinishStepGCD(out IAction act)
{
act = null;
if (!IsDancing) return false;

//标准舞步结束
if (Player.HasStatus(true, StatusID.StandardStep) && Player.WillStatusEnd(1, true, StatusID.StandardStep) || StandardFinish.CanUse(out _, mustUse: true))
{
act = StandardStep;
return true;
}

//技巧舞步结束
if (Player.HasStatus(true, StatusID.TechnicalStep) && Player.WillStatusEnd(1, true, StatusID.TechnicalStep) || TechnicalFinish.CanUse(out _, mustUse: true))
{
act = TechnicalStep;
return true;
}

return false;
}
}
3 changes: 1 addition & 2 deletions RotationSolver/Updaters/MajorUpdater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,7 @@ private unsafe static void FrameworkUpdate(Framework framework)

ActionUpdater.UpdateActionInfo();

TargetUpdater.UpdateHostileTargets();
TargetUpdater.UpdateFriends();
TargetUpdater.UpdateTarget();

MovingUpdater.UpdateLocation();

Expand Down
Loading

0 comments on commit 9902932

Please sign in to comment.