From 20f9eb3dcf93e63b6df882b8d107c2cddd90b83d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=8B=E6=B0=B4?= <1123993881@qq.com> Date: Thu, 18 May 2023 20:04:21 +0800 Subject: [PATCH] fix: removed the player. --- .../Actions/BaseAction_ActionInfo.cs | 9 +- .../Actions/BaseAction_BasicInfo.cs | 5 +- .../Actions/BaseAction_Cooldown.cs | 5 +- .../Actions/BaseAction_Target.cs | 23 ++-- RotationSolver.Basic/Actions/BaseItem.cs | 7 +- .../Actions/HealPotionItem.cs | 16 +-- RotationSolver.Basic/DataCenter.cs | 11 +- RotationSolver.Basic/Helpers/ObjectHelper.cs | 11 +- RotationSolver.Basic/Helpers/StatusHelper.cs | 10 +- RotationSolver.Basic/Helpers/TargetFilter.cs | 11 +- .../RotationSolver.Basic.csproj | 2 + .../Rotations/CustomRotation_OtherInfo.cs | 4 +- RotationSolver.Basic/Service.cs | 27 ----- .../ActionSequencer/ConditionHelper.cs | 6 +- .../ActionSequencer/RotationCondition.cs | 3 +- .../ActionSequencer/TargetCondition.cs | 9 +- RotationSolver/Commands/RSCommands_Actions.cs | 8 +- .../RSCommands_StateSpecialCommand.cs | 114 +++++++++--------- RotationSolver/UI/OverlayWindow.cs | 19 +-- .../UI/RotationConfigWindow_Debug.cs | 12 +- .../UI/RotationConfigWindow_Rotation.cs | 6 +- RotationSolver/Updaters/ActionUpdater.cs | 9 +- RotationSolver/Updaters/MajorUpdater.cs | 9 +- RotationSolver/Updaters/PreviewUpdater.cs | 5 +- RotationSolver/Updaters/RotationUpdater.cs | 3 +- RotationSolver/Updaters/SocialUpdater.cs | 10 +- RotationSolver/Updaters/TargetUpdater.cs | 25 ++-- RotationSolver/Watcher.cs | 11 +- 28 files changed, 194 insertions(+), 196 deletions(-) diff --git a/RotationSolver.Basic/Actions/BaseAction_ActionInfo.cs b/RotationSolver.Basic/Actions/BaseAction_ActionInfo.cs index f54a1a918..8d85d2c23 100644 --- a/RotationSolver.Basic/Actions/BaseAction_ActionInfo.cs +++ b/RotationSolver.Basic/Actions/BaseAction_ActionInfo.cs @@ -1,4 +1,5 @@ -using FFXIVClientStructs.FFXIV.Client.Game; +using ECommons.GameHelpers; +using FFXIVClientStructs.FFXIV.Client.Game; namespace RotationSolver.Basic.Actions; @@ -28,7 +29,7 @@ private bool WillCooldown } else { - if ((ClassJobID)Service.Player.ClassJob.Id != ClassJobID.BlueMage + if ((ClassJobID)Player.Object.ClassJob.Id != ClassJobID.BlueMage && ChoiceTarget != TargetFilter.FindTargetForMoving && DataCenter.LastAction == (ActionID)AdjustedID) return false; @@ -47,7 +48,7 @@ public unsafe virtual bool CanUse(out IAction act, CanUseOption option = CanUseO act = this; var mustUse = option.HasFlag(CanUseOption.MustUse); - var player = Service.Player; + var player = Player.Object; if (player == null) return false; if (!option.HasFlag(CanUseOption.SkipDisable) && !IsEnabled) return false; @@ -146,7 +147,7 @@ public unsafe bool Use() if (_action.TargetArea) { - return ActionManager.Instance()->UseActionLocation(ActionType.Spell, ID, Service.Player.ObjectId, &loc); + return ActionManager.Instance()->UseActionLocation(ActionType.Spell, ID, Player.Object.ObjectId, &loc); } else if(Service.ObjectTable.SearchById(_targetId) == null) { diff --git a/RotationSolver.Basic/Actions/BaseAction_BasicInfo.cs b/RotationSolver.Basic/Actions/BaseAction_BasicInfo.cs index 6c87efc2b..5bc751a21 100644 --- a/RotationSolver.Basic/Actions/BaseAction_BasicInfo.cs +++ b/RotationSolver.Basic/Actions/BaseAction_BasicInfo.cs @@ -1,4 +1,5 @@ -using FFXIVClientStructs.FFXIV.Client.Game; +using ECommons.GameHelpers; +using FFXIVClientStructs.FFXIV.Client.Game; using RotationSolver.Basic.Configuration; using Action = Lumina.Excel.GeneratedSheets.Action; @@ -23,7 +24,7 @@ public partial class BaseAction : IBaseAction /// /// EnoughLevel for using. /// - public bool EnoughLevel => Service.Player.Level >= Level; + public bool EnoughLevel => Player.Level >= Level; public byte Level => _action.ClassJobLevel; public string Name => _action.Name; diff --git a/RotationSolver.Basic/Actions/BaseAction_Cooldown.cs b/RotationSolver.Basic/Actions/BaseAction_Cooldown.cs index c3e1b7fe8..59c674a19 100644 --- a/RotationSolver.Basic/Actions/BaseAction_Cooldown.cs +++ b/RotationSolver.Basic/Actions/BaseAction_Cooldown.cs @@ -1,4 +1,5 @@ -using FFXIVClientStructs.FFXIV.Client.Game; +using ECommons.GameHelpers; +using FFXIVClientStructs.FFXIV.Client.Game; namespace RotationSolver.Basic.Actions; @@ -73,7 +74,7 @@ private bool WillHaveOneCharge(float remain, bool addWeaponRemain) /// /// 技能的最大层数 /// - public unsafe ushort MaxCharges => Math.Max(ActionManager.GetMaxCharges(AdjustedID, Service.Player.Level), (ushort)1); + public unsafe ushort MaxCharges => Math.Max(ActionManager.GetMaxCharges(AdjustedID, (uint)Player.Level), (ushort)1); /// /// 是否起码有一层技能 /// diff --git a/RotationSolver.Basic/Actions/BaseAction_Target.cs b/RotationSolver.Basic/Actions/BaseAction_Target.cs index 4117c6a94..e235e6d1a 100644 --- a/RotationSolver.Basic/Actions/BaseAction_Target.cs +++ b/RotationSolver.Basic/Actions/BaseAction_Target.cs @@ -1,5 +1,6 @@ using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Logging; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.Game; namespace RotationSolver.Basic.Actions; @@ -17,10 +18,10 @@ public partial class BaseAction /// /// The action's target. /// - public BattleChara Target { get; private set; } = Service.Player; + public BattleChara Target { get; private set; } = Player.Object; private Vector3 _position = default; - private uint _targetId = Service.Player?.ObjectId ?? 0; + private uint _targetId = Player.Object?.ObjectId ?? 0; private Func, bool, BattleChara> _choiceTarget = null; @@ -47,7 +48,7 @@ internal static bool TankBreakOtherCheck(ClassJobID id) var tankHealth = id.GetHealthForDyingTank(); return DataCenter.HasHostilesInRange - && Service.Player.GetHealthRatio() < tankHealth + && Player.Object.GetHealthRatio() < tankHealth && DataCenter.PartyMembersAverHP > tankHealth + 0.01f; } @@ -55,8 +56,8 @@ private bool FindTarget(bool mustUse, out BattleChara target) { int aoeCount = mustUse ? 1 : AOECount; - _position = Service.Player.Position; - var player = Service.Player; + _position = Player.Object.Position; + var player = Player.Object; float range = Range; @@ -128,15 +129,15 @@ private bool TargetAreaMove(float range, bool mustUse) { if (Service.Config.MoveAreaActionFarthest) { - Vector3 pPosition = Service.Player.Position; - float rotation = Service.Player.Rotation; + Vector3 pPosition = Player.Object.Position; + float rotation = Player.Object.Rotation; _position = new Vector3(pPosition.X + (float)Math.Sin(rotation) * range, pPosition.Y, pPosition.Z + (float)Math.Cos(rotation) * range); return true; } else { - var availableCharas = DataCenter.AllTargets.Where(b => b.ObjectId != Service.Player.ObjectId); + var availableCharas = DataCenter.AllTargets.Where(b => b.ObjectId != Player.Object.ObjectId); var target = TargetFilter.GetObjectInRadius(availableCharas, range).FindTargetForMoving(mustUse); if (target == null) return false; _position = target.Position; @@ -192,7 +193,7 @@ private bool TargetAreaFriend(float range, bool mustUse, PlayerCharacter player) private bool TargetPartyAndHostile(float range, bool mustUse, out BattleChara target) { var availableCharas = DataCenter.PartyMembers.Union(DataCenter.HostileTargets) - .Where(b => b.ObjectId != Service.Player.ObjectId); + .Where(b => b.ObjectId != Player.Object.ObjectId); availableCharas = TargetFilter.GetObjectInRadius(availableCharas, range).Where(CanUseTo); target = ChoiceTarget(availableCharas, mustUse); @@ -218,7 +219,7 @@ private bool TargetParty(float range, int aoeCount, bool mustUse, out BattleChar } if (!_action.CanTargetSelf) { - availableCharas = availableCharas.Where(p => p.ObjectId != Service.Player.ObjectId); + availableCharas = availableCharas.Where(p => p.ObjectId != Player.Object.ObjectId); } if (!availableCharas.Any()) { @@ -412,7 +413,7 @@ public bool CanGetTarget(BattleChara target, BattleChara subTarget) if (IsSingleTarget) return false; if (target.DistanceToPlayer() > Range) return false; - var pPos = Service.Player.Position; + var pPos = Player.Object.Position; Vector3 dir = target.Position - pPos; Vector3 tdir = subTarget.Position - pPos; diff --git a/RotationSolver.Basic/Actions/BaseItem.cs b/RotationSolver.Basic/Actions/BaseItem.cs index 5de406717..9aae61b09 100644 --- a/RotationSolver.Basic/Actions/BaseItem.cs +++ b/RotationSolver.Basic/Actions/BaseItem.cs @@ -1,4 +1,5 @@ -using FFXIVClientStructs.FFXIV.Client.Game; +using ECommons.GameHelpers; +using FFXIVClientStructs.FFXIV.Client.Game; using Lumina.Excel.GeneratedSheets; using RotationSolver.Basic.Configuration; @@ -111,10 +112,10 @@ public unsafe bool Use() if (InventoryManager.Instance()->GetInventoryItemCount(ID, true) > 0) { - return ActionManager.Instance()->UseAction(ActionType.Item, ID + 1000000, Service.Player.ObjectId, A4); + return ActionManager.Instance()->UseAction(ActionType.Item, ID + 1000000, Player.Object.ObjectId, A4); } - return ActionManager.Instance()->UseAction(ActionType.Item, ID, Service.Player.ObjectId, A4); + return ActionManager.Instance()->UseAction(ActionType.Item, ID, Player.Object.ObjectId, A4); } public override string ToString() => Name; diff --git a/RotationSolver.Basic/Actions/HealPotionItem.cs b/RotationSolver.Basic/Actions/HealPotionItem.cs index bfbdec5d5..bcb397ab8 100644 --- a/RotationSolver.Basic/Actions/HealPotionItem.cs +++ b/RotationSolver.Basic/Actions/HealPotionItem.cs @@ -1,4 +1,6 @@ -namespace RotationSolver.Basic.Actions; +using ECommons.GameHelpers; + +namespace RotationSolver.Basic.Actions; public class HealPotionItem : BaseItem { @@ -9,8 +11,8 @@ public uint MaxHealHp { get { - if (Service.Player == null) return 0; - return Math.Min((uint)(Service.Player.MaxHp * _percent), _maxHp); + if (!Player.Available) return 0; + return Math.Min((uint)(Player.Object.MaxHp * _percent), _maxHp); } } @@ -25,11 +27,11 @@ public HealPotionItem(uint row, float percent, uint maxHp, uint a4 = 65535) : ba public override bool CanUse(out IAction item) { item = null; - if (Service.Player == null) return false; - var job = (ClassJobID)Service.Player.ClassJob.Id; - if (Service.Player.GetHealthRatio() > job.GetHealSingleAbility() - + if (!Player.Available) return false; + var job = (ClassJobID)Player.Object.ClassJob.Id; + if (Player.Object.GetHealthRatio() > job.GetHealSingleAbility() - job.GetHealingOfTimeSubtractSingle()) return false; - if (Service.Player.MaxHp - Service.Player.CurrentHp < MaxHealHp) return false; + if (Player.Object.MaxHp - Player.Object.CurrentHp < MaxHealHp) return false; return base.CanUse(out item); } } diff --git a/RotationSolver.Basic/DataCenter.cs b/RotationSolver.Basic/DataCenter.cs index 58233ef63..964fbf56a 100644 --- a/RotationSolver.Basic/DataCenter.cs +++ b/RotationSolver.Basic/DataCenter.cs @@ -1,5 +1,6 @@ using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Logging; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game.Fate; using FFXIVClientStructs.FFXIV.Client.UI.Agent; @@ -82,8 +83,8 @@ public static TargetHostileType RightNowTargetToHostileType { get { - if (Service.Player == null) return 0; - var id = Service.Player.ClassJob.Id; + if (!Player.Available) return 0; + var id = Player.Object.ClassJob.Id; return GetTargetHostileType(Service.GetSheet().GetRow(id)); } } @@ -125,7 +126,7 @@ public static unsafe ushort FateId { if (Service.Config.ChangeTargetForFate && (IntPtr)FateManager.Instance() != IntPtr.Zero && (IntPtr)FateManager.Instance()->CurrentFate != IntPtr.Zero - && Service.Player.Level <= FateManager.Instance()->CurrentFate->MaxLevel) + && Player.Level <= FateManager.Instance()->CurrentFate->MaxLevel) { return FateManager.Instance()->CurrentFate->FateId; } @@ -255,7 +256,7 @@ public static float RatioOfMembersIn2minsBurst { var tar = burstInfo.IsOnHostile && Service.TargetManager.Target is BattleChara b ? b - : Service.Player; + : Player.Object; if (tar.HasStatus(false, burstInfo.Status) && !tar.WillStatusEndGCD(0, 0, false, burstInfo.Status)) { @@ -356,7 +357,7 @@ internal static unsafe void AddActionRec(Action act) case ActionCate.Ability: LastAction = LastAbility = id; - if (!act.IsRealGCD() && ActionManager.GetMaxCharges((uint)id, Service.Player?.Level ?? 1) < 2) + if (!act.IsRealGCD() && ActionManager.GetMaxCharges((uint)id, Player.Object?.Level ?? 1) < 2) { FetchTime = ActionManager.Instance()->GetRecastGroupDetail(act.CooldownGroup - 1)->Elapsed; } diff --git a/RotationSolver.Basic/Helpers/ObjectHelper.cs b/RotationSolver.Basic/Helpers/ObjectHelper.cs index 7274956f0..8c68317fe 100644 --- a/RotationSolver.Basic/Helpers/ObjectHelper.cs +++ b/RotationSolver.Basic/Helpers/ObjectHelper.cs @@ -1,4 +1,5 @@ using Dalamud.Game.ClientState.Objects.Enums; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.Game; using FFXIVClientStructs.FFXIV.Client.Game.Event; using Lumina.Excel.GeneratedSheets; @@ -145,7 +146,7 @@ public static EnemyPositional FindEnemyPositional(this GameObject enemy) float rotation = enemy.Rotation; Vector2 faceVec = new((float)Math.Cos(rotation), (float)Math.Sin(rotation)); - Vector3 dir = Service.Player.Position - pPosition; + Vector3 dir = Player.Object.Position - pPosition; Vector2 dirVec = new(dir.Z, dir.X); double angle = Math.Acos(Vector2.Dot(dirVec, faceVec) / dirVec.Length() / faceVec.Length()); @@ -157,10 +158,10 @@ public static EnemyPositional FindEnemyPositional(this GameObject enemy) public static uint GetHealthFromMulty(float mult) { - if (Service.Player == null) return 0; + if (!Player.Available) return 0; var role = Service.GetSheet().GetRow( - Service.Player.ClassJob.Id).GetJobRole(); + Player.Object.ClassJob.Id).GetJobRole(); float multi = mult * role switch { JobRole.Tank => 1, @@ -178,7 +179,7 @@ public static uint GetHealthFromMulty(float mult) multi *= 3.5f; } - return (uint)(multi * Service.Player.MaxHp); + return (uint)(multi * Player.Object.MaxHp); } /// @@ -189,7 +190,7 @@ public static uint GetHealthFromMulty(float mult) public static float DistanceToPlayer(this GameObject obj) { if (obj == null) return float.MaxValue; - var player = Service.Player; + var player = Player.Object; if (player == null) return float.MaxValue; var distance = Vector3.Distance(player.Position, obj.Position) - player.HitboxRadius; diff --git a/RotationSolver.Basic/Helpers/StatusHelper.cs b/RotationSolver.Basic/Helpers/StatusHelper.cs index 0512af4b4..e147acc93 100644 --- a/RotationSolver.Basic/Helpers/StatusHelper.cs +++ b/RotationSolver.Basic/Helpers/StatusHelper.cs @@ -1,5 +1,7 @@ using Dalamud.Game.ClientState.Statuses; using Dalamud.Logging; +using ECommons.Automation; +using ECommons.GameHelpers; using RotationSolver.Basic.Configuration; namespace RotationSolver.Basic.Helpers; @@ -127,8 +129,8 @@ public static bool HasStatus(this BattleChara obj, bool isFromSelf, params Statu public static void StatusOff(StatusID status) { - if (!Service.Player?.HasStatus(false, status) ?? true) return; - Service.SubmitToChat($"/statusoff {GetStatusName(status)}"); + if (!Player.Object?.HasStatus(false, status) ?? true) return; + Chat.Instance.SendMessage($"/statusoff {GetStatusName(status)}"); } internal static string GetStatusName(StatusID id) @@ -147,8 +149,8 @@ private static IEnumerable GetAllStatus(this BattleChara obj, bool isFro if (obj == null) return Array.Empty(); return obj.StatusList.Where(status => !isFromSelf - || status.SourceId == Service.Player.ObjectId - || status.SourceObject?.OwnerId == Service.Player.ObjectId); + || status.SourceId == Player.Object.ObjectId + || status.SourceObject?.OwnerId == Player.Object.ObjectId); } public static bool IsInvincible(this Status status) diff --git a/RotationSolver.Basic/Helpers/TargetFilter.cs b/RotationSolver.Basic/Helpers/TargetFilter.cs index 8fbb14379..8500e2aae 100644 --- a/RotationSolver.Basic/Helpers/TargetFilter.cs +++ b/RotationSolver.Basic/Helpers/TargetFilter.cs @@ -1,4 +1,5 @@ -using Lumina.Excel.GeneratedSheets; +using ECommons.GameHelpers; +using Lumina.Excel.GeneratedSheets; using System.Data; namespace RotationSolver.Basic.Helpers; @@ -88,8 +89,8 @@ internal static T FindTargetForMoving(this IEnumerable charas, bool mustUs const float DISTANCE_TO_MOVE = 3; private static T FindMoveTargetFaceDirection(IEnumerable charas) where T : GameObject { - Vector3 pPosition = Service.Player.Position; - float rotation = Service.Player.Rotation; + Vector3 pPosition = Player.Object.Position; + float rotation = Player.Object.Rotation; Vector2 faceVec = new((float)Math.Cos(rotation), (float)Math.Sin(rotation)); var tars = charas.Where(t => @@ -107,7 +108,7 @@ private static T FindMoveTargetFaceDirection(IEnumerable charas) where T : private static T FindMoveTargetScreenCenter(IEnumerable charas) where T : GameObject { - var pPosition = Service.Player.Position; + var pPosition = Player.Object.Position; if (!Service.WorldToScreen(pPosition, out var playerScrPos)) return null; var tars = charas.Where(t => @@ -166,7 +167,7 @@ internal static IEnumerable TankRangeTarget(IEnumerable internal static IEnumerable ProvokeTarget(IEnumerable inputCharas, bool needDistance = false) { - var loc = Service.Player.Position; + var loc = Player.Object.Position; var targets = inputCharas.Where(target => { diff --git a/RotationSolver.Basic/RotationSolver.Basic.csproj b/RotationSolver.Basic/RotationSolver.Basic.csproj index 57010e059..e43d65b1e 100644 --- a/RotationSolver.Basic/RotationSolver.Basic.csproj +++ b/RotationSolver.Basic/RotationSolver.Basic.csproj @@ -35,6 +35,8 @@ + + True \ diff --git a/RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs b/RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs index 67fc3a894..a5075667c 100644 --- a/RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs +++ b/RotationSolver.Basic/Rotations/CustomRotation_OtherInfo.cs @@ -8,12 +8,12 @@ public abstract partial class CustomRotation /// /// This is the player. /// - protected static PlayerCharacter Player => Service.Player; + protected static PlayerCharacter Player => ECommons.GameHelpers.Player.Object; /// /// The level of the player. /// - protected static byte Level => Player?.Level ?? 0; + protected static byte Level => (byte)ECommons.GameHelpers.Player.Level; /// /// Does player have swift cast, dual cast or triple cast. diff --git a/RotationSolver.Basic/Service.cs b/RotationSolver.Basic/Service.cs index ed6fd380e..b20ab443a 100644 --- a/RotationSolver.Basic/Service.cs +++ b/RotationSolver.Basic/Service.cs @@ -48,14 +48,9 @@ public class Service : IDisposable public static float CountDownTime { get; private set; } - private static GetChatBoxModuleDelegate GetChatBox { get; set; } public Service() { - //https://github.com/BardMusicPlayer/Hypnotoad-Plugin/blob/develop/HypnotoadPlugin/Offsets/Offsets.cs#L18 - GetChatBox = Marshal.GetDelegateForFunctionPointer( - SigScanner.ScanText("48 89 5C 24 ?? 57 48 83 EC 20 48 8B FA 48 8B D9 45 84 C9")); - SignatureHelper.Initialise(this); Framework.Update += Framework_Update; _countdownTimerHook?.Enable(); @@ -129,7 +124,6 @@ public unsafe static IEnumerable GetAddons() where T : struct .Where(ptr => ptr != IntPtr.Zero); } - public static PlayerCharacter Player => ClientState.LocalPlayer; [PluginService] public static ClientState ClientState { get; set; } @@ -179,25 +173,4 @@ public unsafe static IEnumerable GetAddons() where T : struct public static ClientLanguage Language => ClientState.ClientLanguage; - - private delegate void GetChatBoxModuleDelegate(IntPtr uiModule, IntPtr message, IntPtr unused, byte a4); - - - /// - /// Submit text/command to outgoing chat. - /// Can be used to enter chat commands. - /// - /// Text to submit. - public unsafe static void SubmitToChat(string text) - { - IntPtr uiModule = GameGui.GetUIModule(); - - using ChatPayload payload = new(text); - IntPtr mem1 = Marshal.AllocHGlobal(400); - Marshal.StructureToPtr(payload, mem1, false); - - GetChatBox(uiModule, mem1, IntPtr.Zero, 0); - - Marshal.FreeHGlobal(mem1); - } } diff --git a/RotationSolver/ActionSequencer/ConditionHelper.cs b/RotationSolver/ActionSequencer/ConditionHelper.cs index 5c3a7eef3..fb7fd9802 100644 --- a/RotationSolver/ActionSequencer/ConditionHelper.cs +++ b/RotationSolver/ActionSequencer/ConditionHelper.cs @@ -1,4 +1,6 @@ -namespace RotationSolver.ActionSequencer; +using ECommons.GameHelpers; + +namespace RotationSolver.ActionSequencer; public class ConditionHelper { @@ -8,7 +10,7 @@ public static bool CheckBaseAction(ICustomRotation rotation, ActionID id, ref Ba { action = rotation.AllBaseActions.OfType().FirstOrDefault(a => (ActionID)a.ID == id); } - if (action == null || Service.Player == null) return false; + if (action == null || !Player.Available) return false; return true; } diff --git a/RotationSolver/ActionSequencer/RotationCondition.cs b/RotationSolver/ActionSequencer/RotationCondition.cs index 58a2e56f1..584b42b36 100644 --- a/RotationSolver/ActionSequencer/RotationCondition.cs +++ b/RotationSolver/ActionSequencer/RotationCondition.cs @@ -1,4 +1,5 @@ using Dalamud.Interface.Colors; +using ECommons.GameHelpers; using RotationSolver.Localization; using RotationSolver.UI; @@ -34,7 +35,7 @@ public bool IsTrue(ICustomRotation rotation, bool isActionSequencer) { if (!isActionSequencer) return false; - if (Service.Player == null) return false; + if (!Player.Available) return false; UpdateInfo(rotation); switch (ComboConditionType) diff --git a/RotationSolver/ActionSequencer/TargetCondition.cs b/RotationSolver/ActionSequencer/TargetCondition.cs index 3690e0973..5c48acc1c 100644 --- a/RotationSolver/ActionSequencer/TargetCondition.cs +++ b/RotationSolver/ActionSequencer/TargetCondition.cs @@ -1,4 +1,5 @@ -using RotationSolver.Localization; +using ECommons.GameHelpers; +using RotationSolver.Localization; using RotationSolver.TextureItems; using RotationSolver.UI; @@ -33,7 +34,7 @@ private static StatusTexture[] AllStatus public bool IsTrue(ICustomRotation combo, bool isActionSequencer) { - if (Service.Player == null) return false; + if (!Player.Available) return false; BattleChara tar; if (_action != null) @@ -44,8 +45,8 @@ public bool IsTrue(ICustomRotation combo, bool isActionSequencer) } else { - tar = IsTarget ? Service.TargetManager.Target as BattleChara : Service.Player; - tar ??= Service.Player; + tar = IsTarget ? Service.TargetManager.Target as BattleChara : Player.Object; + tar ??= Player.Object; } if (tar == null) return false; diff --git a/RotationSolver/Commands/RSCommands_Actions.cs b/RotationSolver/Commands/RSCommands_Actions.cs index 7527d9578..6fbe43c56 100644 --- a/RotationSolver/Commands/RSCommands_Actions.cs +++ b/RotationSolver/Commands/RSCommands_Actions.cs @@ -1,6 +1,6 @@ using Dalamud.Game.ClientState.Conditions; using Dalamud.Logging; -using Lumina.Excel.GeneratedSheets; +using ECommons.GameHelpers; using RotationSolver.Helpers; using RotationSolver.Localization; using RotationSolver.Updaters; @@ -23,7 +23,7 @@ internal static unsafe void DoAnAction(bool isGCD) } _lastState = DataCenter.StateType; - if (Service.Player == null) return; + if (!Player.Available) return; //Do not click the button in random time. if (DateTime.Now - _fastClickStopwatch < TimeSpan.FromMilliseconds(new Random().Next( @@ -121,8 +121,8 @@ internal static void UpdateRotationState() CancelState(); } else if (Service.Config.AutoOffWhenDead - && Service.Player != null - && Service.Player.CurrentHp == 0) + && Player.Available + && Player.Object.CurrentHp == 0) { CancelState(); } diff --git a/RotationSolver/Commands/RSCommands_StateSpecialCommand.cs b/RotationSolver/Commands/RSCommands_StateSpecialCommand.cs index ad00972fe..808382c10 100644 --- a/RotationSolver/Commands/RSCommands_StateSpecialCommand.cs +++ b/RotationSolver/Commands/RSCommands_StateSpecialCommand.cs @@ -1,74 +1,74 @@ -using RotationSolver.Localization; +using ECommons.GameHelpers; +using RotationSolver.Localization; -namespace RotationSolver.Commands -{ - public static partial class RSCommands - { - private static string _stateString = "Off", _specialString = string.Empty; +namespace RotationSolver.Commands; - internal static string EntryString => _stateString + (DataCenter.SpecialTimeLeft < 0 ? string.Empty : $" - {_specialString}: {DataCenter.SpecialTimeLeft:F2}s"); +public static partial class RSCommands +{ + private static string _stateString = "Off", _specialString = string.Empty; - private static void UpdateToast() - { - if (!Service.Config.ShowInfoOnToast) return; + internal static string EntryString => _stateString + (DataCenter.SpecialTimeLeft < 0 ? string.Empty : $" - {_specialString}: {DataCenter.SpecialTimeLeft:F2}s"); - Service.ToastGui.ShowQuest(" " + EntryString, new Dalamud.Game.Gui.Toast.QuestToastOptions() - { - IconId = 101, - }); - } + private static void UpdateToast() + { + if (!Service.Config.ShowInfoOnToast) return; - private static unsafe void DoStateCommandType(StateCommandType stateType) => DoOneCommandType(EnumTranslations.ToSayout, role => + Service.ToastGui.ShowQuest(" " + EntryString, new Dalamud.Game.Gui.Toast.QuestToastOptions() { - if (DataCenter.StateType == StateCommandType.Auto - && stateType == StateCommandType.Auto) - { - Service.Config.TargetingIndex += 1; - Service.Config.TargetingIndex %= Service.Config.TargetingTypes.Count; - } - - if (Service.Config.ToggleManual - && DataCenter.StateType == StateCommandType.Manual - && stateType == StateCommandType.Manual) - { - stateType = StateCommandType.Cancel; - } - - DataCenter.StateType = stateType; - - UpdateStateNamePlate(); - - _stateString = stateType.ToStateString(role); - UpdateToast(); - return stateType; + IconId = 101, }); + } - public static unsafe void UpdateStateNamePlate() + private static unsafe void DoStateCommandType(StateCommandType stateType) => DoOneCommandType(EnumTranslations.ToSayout, role => + { + if (DataCenter.StateType == StateCommandType.Auto + && stateType == StateCommandType.Auto) { - if (Service.Player == null) return; - - Service.Player.SetNamePlateIcon( - DataCenter.StateType == StateCommandType.Cancel ? 0u : (uint)Service.Config.NamePlateIconId); + Service.Config.TargetingIndex += 1; + Service.Config.TargetingIndex %= Service.Config.TargetingTypes.Count; } - private static void DoSpecialCommandType(SpecialCommandType specialType, bool sayout = true) => DoOneCommandType(sayout ? EnumTranslations.ToSayout : (s, r) => string.Empty, role => + if (Service.Config.ToggleManual + && DataCenter.StateType == StateCommandType.Manual + && stateType == StateCommandType.Manual) { - _specialString = specialType.ToSpecialString(role); - DataCenter.SetSpecialType(specialType); - if (sayout) UpdateToast(); - return specialType; - }); + stateType = StateCommandType.Cancel; + } - private static void DoOneCommandType(Func sayout, Func doingSomething) - where T : struct, Enum - { - //Get job role. - var role = Service.Player.ClassJob.GameData.GetJobRole(); + DataCenter.StateType = stateType; - T type = doingSomething(role); + UpdateStateNamePlate(); - //Saying out. - if (Service.Config.SayOutStateChanged) SpeechHelper.Speak(sayout(type, role)); - } + _stateString = stateType.ToStateString(role); + UpdateToast(); + return stateType; + }); + + public static unsafe void UpdateStateNamePlate() + { + if (!Player.Available) return; + + Player.Object.SetNamePlateIcon( + DataCenter.StateType == StateCommandType.Cancel ? 0u : (uint)Service.Config.NamePlateIconId); + } + + private static void DoSpecialCommandType(SpecialCommandType specialType, bool sayout = true) => DoOneCommandType(sayout ? EnumTranslations.ToSayout : (s, r) => string.Empty, role => + { + _specialString = specialType.ToSpecialString(role); + DataCenter.SetSpecialType(specialType); + if (sayout) UpdateToast(); + return specialType; + }); + + private static void DoOneCommandType(Func sayout, Func doingSomething) + where T : struct, Enum + { + //Get job role. + var role = Player.Object.ClassJob.GameData.GetJobRole(); + + T type = doingSomething(role); + + //Saying out. + if (Service.Config.SayOutStateChanged) SpeechHelper.Speak(sayout(type, role)); } } diff --git a/RotationSolver/UI/OverlayWindow.cs b/RotationSolver/UI/OverlayWindow.cs index c6fe690e4..2e2a55ad0 100644 --- a/RotationSolver/UI/OverlayWindow.cs +++ b/RotationSolver/UI/OverlayWindow.cs @@ -1,4 +1,5 @@ using Dalamud.Interface; +using ECommons.GameHelpers; using RotationSolver.Updaters; namespace RotationSolver.UI; @@ -7,7 +8,7 @@ internal static class OverlayWindow { public static void Draw() { - if (Service.Player == null || !Service.Config.UseOverlayWindow) return; + if (!Player.Available || !Service.Config.UseOverlayWindow) return; if (Service.Conditions[Dalamud.Game.ClientState.Conditions.ConditionFlag.OccupiedInCutSceneEvent] || Service.Conditions[Dalamud.Game.ClientState.Conditions.ConditionFlag.BetweenAreas] @@ -45,14 +46,14 @@ private static void DrawTarget() if (act.Target == null) return; - if (act.Target != Service.Player) + if (act.Target != Player.Object) { var c = Service.Config.TargetColor; var Tcolor = ImGui.GetColorU32(new Vector4(c.X, c.Y, c.Z, 1)); DrawTarget(act.Target, Tcolor, 8, out _); } - if (DataCenter.HostileTargets.Contains(act.Target) || act.Target == Service.Player && !act.IsFriendly) + if (DataCenter.HostileTargets.Contains(act.Target) || act.Target == Player.Object && !act.IsFriendly) { var c = Service.Config.SubTargetColor; var Scolor = ImGui.GetColorU32(new Vector4(c.X, c.Y, c.Z, 1)); @@ -92,11 +93,11 @@ private unsafe static void DrawMoveTarget() var color = ImGui.GetColorU32(new Vector4(c.X, c.Y, c.Z, 1)); var tar = CustomRotation.MoveTarget; - if (tar == null || tar == Service.Player) return; + if (tar == null || tar == Player.Object) return; DrawTarget(tar, color, 8, out var scrPos); - if (Service.WorldToScreen(Service.Player.Position, out var plyPos)) + if (Service.WorldToScreen(Player.Object.Position, out var plyPos)) { var dir = scrPos - plyPos; @@ -122,8 +123,8 @@ private static void DrawTarget(BattleChara tar, uint color, float radius, out Ve const int COUNT = 20; private static void DrawPositional() { - if (!Service.Player.IsJobCategory(JobRole.Tank) - && !Service.Player.IsJobCategory(JobRole.Melee) ) return; + if (!Player.Object.IsJobCategory(JobRole.Tank) + && !Player.Object.IsJobCategory(JobRole.Melee) ) return; var target = ActionUpdater.NextGCDAction?.Target?.IsNPCEnemy() ?? false ? ActionUpdater.NextGCDAction.Target @@ -139,7 +140,7 @@ private static void DrawPositional() Vector3 pPosition = target.Position; Service.WorldToScreen(pPosition, out var scrPos); - float radius = target.HitboxRadius + Service.Player.HitboxRadius + 3; + float radius = target.HitboxRadius + Player.Object.HitboxRadius + 3; float rotation = target.Rotation; if (Service.Config.DrawMeleeOffset && DataCenter.StateType != StateCommandType.Cancel) @@ -159,7 +160,7 @@ private static void DrawPositional() List pts = new(4 * COUNT); bool wrong = target.DistanceToPlayer() > 3; - if (Service.Config.DrawPositional && !Service.Player.HasStatus(true, StatusID.TrueNorth)) + if (Service.Config.DrawPositional && !Player.Object.HasStatus(true, StatusID.TrueNorth)) { var shouldPos = ActionUpdater.NextGCDAction?.EnemyPositional ?? EnemyPositional.None; diff --git a/RotationSolver/UI/RotationConfigWindow_Debug.cs b/RotationSolver/UI/RotationConfigWindow_Debug.cs index 28ce28b1e..760469e6b 100644 --- a/RotationSolver/UI/RotationConfigWindow_Debug.cs +++ b/RotationSolver/UI/RotationConfigWindow_Debug.cs @@ -1,4 +1,4 @@ -using FFXIVClientStructs.FFXIV.Client.Game; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.Game.Fate; using RotationSolver.Updaters; @@ -8,8 +8,8 @@ internal partial class RotationConfigWindow { private void DrawDebugTab() { - if (Service.Player == null) return; - var str = SocialUpdater.EncryptString(Service.Player); + if (!Player.Available) return; + var str = SocialUpdater.EncryptString(Player.Object); ImGui.SetNextItemWidth(ImGui.CalcTextSize(str).X + 10); ImGui.InputText("That is your HASH", ref str, 100); @@ -60,9 +60,9 @@ private unsafe void DrawStatus() ImGui.Text("Count Down: " + Service.CountDownTime.ToString()); ImGui.Text("Fetch Time: " + DataCenter.FetchTime.ToString()); - foreach (var status in Service.Player.StatusList) + foreach (var status in Player.Object.StatusList) { - var source = status.SourceId == Service.Player.ObjectId ? "You" : Service.ObjectTable.SearchById(status.SourceId) == null ? "None" : "Others"; + var source = status.SourceId == Player.Object.ObjectId ? "You" : Service.ObjectTable.SearchById(status.SourceId) == null ? "None" : "Others"; ImGui.Text($"{status.GameData.Name}: {status.StatusId} From: {source}"); } } @@ -133,7 +133,7 @@ private unsafe void DrawTargetData() foreach (var status in b.StatusList) { - var source = status.SourceId == Service.Player.ObjectId ? "You" : Service.ObjectTable.SearchById(status.SourceId) == null ? "None" : "Others"; + var source = status.SourceId == Player.Object.ObjectId ? "You" : Service.ObjectTable.SearchById(status.SourceId) == null ? "None" : "Others"; ImGui.Text($"{status.GameData.Name}: {status.StatusId} From: {source}"); } } diff --git a/RotationSolver/UI/RotationConfigWindow_Rotation.cs b/RotationSolver/UI/RotationConfigWindow_Rotation.cs index 92cfddf48..1b2f4f79e 100644 --- a/RotationSolver/UI/RotationConfigWindow_Rotation.cs +++ b/RotationSolver/UI/RotationConfigWindow_Rotation.cs @@ -1,6 +1,6 @@ using Dalamud.Interface.Colors; using Dalamud.Utility; - +using ECommons.GameHelpers; using ImGuiNET; using RotationSolver.Data; @@ -61,8 +61,8 @@ private static void DrawRotations(CustomRotationGroup[] rotations) var group = rotations[i]; var rotation = RotationUpdater.GetChosenRotation(group); - var canAddButton = Service.Player != null - && rotation.JobIDs.Contains((ClassJobID)Service.Player.ClassJob.Id); + var canAddButton = Player.Available + && rotation.JobIDs.Contains((ClassJobID)Player.Object.ClassJob.Id); rotation.Display(group.Rotations, canAddButton); } diff --git a/RotationSolver/Updaters/ActionUpdater.cs b/RotationSolver/Updaters/ActionUpdater.cs index 74bd590dd..df78832be 100644 --- a/RotationSolver/Updaters/ActionUpdater.cs +++ b/RotationSolver/Updaters/ActionUpdater.cs @@ -1,6 +1,7 @@ using Dalamud.Game.ClientState.Conditions; using Dalamud.Game.ClientState.Objects.SubKinds; using Dalamud.Logging; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.Game; using RotationSolver.Commands; using RotationSolver.Localization; @@ -18,7 +19,7 @@ internal static class ActionUpdater internal static void UpdateNextAction() { - PlayerCharacter localPlayer = Service.Player; + PlayerCharacter localPlayer = Player.Object; if (localPlayer == null) return; try @@ -111,7 +112,7 @@ private unsafe static void UpdateTimeInfo() private static unsafe void UpdateWeaponTime() { - var player = Service.Player; + var player = Player.Object; if (player == null) return; var instance = ActionManager.Instance(); @@ -140,7 +141,7 @@ private static unsafe void UpdateWeaponTime() private static void UpdateMPTimer() { - var player = Service.Player; + var player = Player.Object; if (player == null) return; //不是黑魔不考虑啊 @@ -172,7 +173,7 @@ internal unsafe static void DoAction() || Service.Conditions[ConditionFlag.InFlight] || ActionManager.Instance()->ActionQueued && NextAction != null && ActionManager.Instance()->QueuedActionId != NextAction.AdjustedID - || Service.Player.CurrentHp == 0) return; + || Player.Object.CurrentHp == 0) return; var maxAhead = Math.Max(DataCenter.MinAnimationLock - DataCenter.Ping, 0.08f); var ahead = Math.Min(maxAhead, Service.Config.ActionAhead); diff --git a/RotationSolver/Updaters/MajorUpdater.cs b/RotationSolver/Updaters/MajorUpdater.cs index f4ae444ac..742a97a0e 100644 --- a/RotationSolver/Updaters/MajorUpdater.cs +++ b/RotationSolver/Updaters/MajorUpdater.cs @@ -1,13 +1,14 @@ using Dalamud.Game; using Dalamud.Game.ClientState.Conditions; using Dalamud.Logging; +using ECommons.GameHelpers; using RotationSolver.Commands; namespace RotationSolver.Updaters; internal static class MajorUpdater { - public static bool IsValid => Service.Conditions.Any() && Service.Player != null && !SocialUpdater.InPvp; + public static bool IsValid => Service.Conditions.Any() && Player.Available && !SocialUpdater.InPvp; public static bool ShouldPreventActions => Basic.Configuration.PluginConfiguration.GetValue(SettingsCommand.PreventActions) && Basic.Configuration.PluginConfiguration.GetValue(SettingsCommand.PreventActionsDuty) && Service.Conditions[ConditionFlag.BoundByDuty] @@ -30,14 +31,14 @@ private static void FrameworkUpdate(Framework framework) #if DEBUG //Get changed condition. - string[] enumNames = Enum.GetNames(typeof(Dalamud.Game.ClientState.Conditions.ConditionFlag)); - int[] indexs = (int[])Enum.GetValues(typeof(Dalamud.Game.ClientState.Conditions.ConditionFlag)); + string[] enumNames = Enum.GetNames(typeof(ConditionFlag)); + int[] indexs = (int[])Enum.GetValues(typeof(ConditionFlag)); if (enumNames.Length == indexs.Length) { for (int i = 0; i < enumNames.Length; i++) { string key = enumNames[i]; - bool newValue = Service.Conditions[(Dalamud.Game.ClientState.Conditions.ConditionFlag)indexs[i]]; + bool newValue = Service.Conditions[(ConditionFlag)indexs[i]]; if (_values.TryGetValue(i, out bool value) && value != newValue && indexs[i] != 48 && indexs[i] != 27) { //Service.ToastGui.ShowQuest(indexs[i].ToString() + " " + key + ": " + newValue.ToString()); diff --git a/RotationSolver/Updaters/PreviewUpdater.cs b/RotationSolver/Updaters/PreviewUpdater.cs index babf128f9..0fc9f8166 100644 --- a/RotationSolver/Updaters/PreviewUpdater.cs +++ b/RotationSolver/Updaters/PreviewUpdater.cs @@ -2,6 +2,7 @@ using Dalamud.Game.Gui.Dtr; using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.Game.UI; using FFXIVClientStructs.FFXIV.Client.Graphics; using FFXIVClientStructs.FFXIV.Client.System.Framework; @@ -61,7 +62,7 @@ private static void UpdateEntry() (Service.Config.StopCastingDelayMin, Service.Config.StopCastingDelayMax)); internal static void UpdateCastBarState() { - var tardead = Service.Config.UseStopCasting && Service.ObjectTable.SearchById(Service.Player.CastTargetObjectId) is BattleChara b + var tardead = Service.Config.UseStopCasting && Service.ObjectTable.SearchById(Player.Object.CastTargetObjectId) is BattleChara b && (b is PlayerCharacter ? b.HasStatus(false, StatusID.Raise) : b.CurrentHp == 0); _isTarNoNeedCast = _tarStopCastDelay.Delay(tardead); @@ -69,7 +70,7 @@ internal static void UpdateCastBarState() && !Service.Conditions[Dalamud.Game.ClientState.Conditions.ConditionFlag.Casting]; //For lock - var specialStatus = Service.Player.HasStatus(true, StatusID.PhantomFlurry, StatusID.TenChiJin); + var specialStatus = Player.Object.HasStatus(true, StatusID.PhantomFlurry, StatusID.TenChiJin); _canMove = !specialStatus && canMove; MovingController.IsMoving = _canMove; diff --git a/RotationSolver/Updaters/RotationUpdater.cs b/RotationSolver/Updaters/RotationUpdater.cs index 62e6b0268..8d96b4e24 100644 --- a/RotationSolver/Updaters/RotationUpdater.cs +++ b/RotationSolver/Updaters/RotationUpdater.cs @@ -1,4 +1,5 @@ using Dalamud.Logging; +using ECommons.GameHelpers; using RotationSolver.Data; using RotationSolver.Helpers; using RotationSolver.Localization; @@ -405,7 +406,7 @@ public static IEnumerable> AllGroupedActions public static void UpdateRotation() { - var nowJob = (ClassJobID)Service.Player.ClassJob.Id; + var nowJob = (ClassJobID)Player.Object.ClassJob.Id; foreach (var group in CustomRotations) { diff --git a/RotationSolver/Updaters/SocialUpdater.cs b/RotationSolver/Updaters/SocialUpdater.cs index 00297e647..e56d33b05 100644 --- a/RotationSolver/Updaters/SocialUpdater.cs +++ b/RotationSolver/Updaters/SocialUpdater.cs @@ -3,6 +3,7 @@ using Dalamud.Game.Text.SeStringHandling; using Dalamud.Game.Text.SeStringHandling.Payloads; using Dalamud.Logging; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.UI; using Lumina.Excel.GeneratedSheets; using RotationSolver.Commands; @@ -48,8 +49,7 @@ static bool CanSocial || Service.Conditions[ConditionFlag.BetweenAreas] || Service.Conditions[ConditionFlag.BetweenAreas51]) return false; - if(Service.Player == null) return false; - if (!Service.Player.IsTargetable()) return false; + if (!Player.Interactable) return false; return Service.Conditions[ConditionFlag.BoundByDuty]; } @@ -100,8 +100,8 @@ static void ClientState_TerritoryChanged(object sender, ushort e) static void DutyState_DutyStarted(object sender, ushort e) { - if(Service.Player == null) return; - if (!Service.Player.IsJobCategory(JobRole.Tank) && !Service.Player.IsJobCategory(JobRole.Healer)) return; + if (!Player.Available) return; + if (!Player.Object.IsJobCategory(JobRole.Tank) && !Player.Object.IsJobCategory(JobRole.Healer)) return; var territory = Service.GetSheet().GetRow(e); if (HighEndDuties.Any(t => t.RowId == territory.RowId)) @@ -135,7 +135,7 @@ static void DutyState_DutyStarted(object sender, ushort e) static void DutyState_DutyWiped(object sender, ushort e) { - if (Service.Player == null) return; + if (!Player.Available) return; DataCenter.ResetAllLastActions(); } diff --git a/RotationSolver/Updaters/TargetUpdater.cs b/RotationSolver/Updaters/TargetUpdater.cs index cf1ebc961..4715f2f28 100644 --- a/RotationSolver/Updaters/TargetUpdater.cs +++ b/RotationSolver/Updaters/TargetUpdater.cs @@ -1,5 +1,6 @@ using Dalamud.Game.ClientState.Objects.Enums; using Dalamud.Game.ClientState.Objects.SubKinds; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.UI; using FFXIVClientStructs.FFXIV.Client.UI.Agent; using Lumina.Excel.GeneratedSheets; @@ -47,9 +48,9 @@ private static float JobRange get { float radius = 25; - if (Service.Player == null) return radius; + if (!Player.Available) return radius; switch (Service.GetSheet().GetRow( - Service.Player.ClassJob.Id).GetJobRole()) + Player.Object.ClassJob.Id).GetJobRole()) { case JobRole.Tank: case JobRole.Melee: @@ -85,7 +86,7 @@ private unsafe static void UpdateHostileTargets(IEnumerable allTarg DataCenter.CanInterruptTargets.Delay(DataCenter.HostileTargets.Where(ObjectHelper.CanInterrupt)); - DataCenter.TarOnMeTargets = DataCenter.HostileTargets.Where(tar => tar.TargetObjectId == Service.Player.ObjectId); + DataCenter.TarOnMeTargets = DataCenter.HostileTargets.Where(tar => tar.TargetObjectId == Player.Object.ObjectId); DataCenter.NumberOfHostilesInRange = DataCenter.HostileTargets.Count(o => o.DistanceToPlayer() <= JobRange); @@ -133,8 +134,8 @@ private static IEnumerable GetHostileTargets(IEnumerable { if (ids.Contains(t.ObjectId)) return true; - if (t.TargetObject == Service.Player - || t.TargetObject?.OwnerId == Service.Player.ObjectId) return true; + if (t.TargetObject == Player.Object + || t.TargetObject?.OwnerId == Player.Object.ObjectId) return true; //Remove other's treasure. if (t.IsOthersPlayers()) return false; @@ -229,7 +230,7 @@ private unsafe static void UpdateFriends(IEnumerable allTargets) DataCenter.PartyMembers = GetPartyMembers(allTargets); DataCenter.AllianceMembers = allTargets.OfType(); - var mayPet = allTargets.OfType().Where(npc => npc.OwnerId == Service.Player.ObjectId); + var mayPet = allTargets.OfType().Where(npc => npc.OwnerId == Player.Object.ObjectId); DataCenter.HasPet = mayPet.Any(npc => npc.BattleNpcKind == BattleNpcSubKind.Pet); //DataCenter.HasPet = HasPet(); @@ -260,24 +261,24 @@ private unsafe static void UpdateFriends(IEnumerable allTargets) DataCenter.PartyMembersAverHP = DataCenter.PartyMembersDifferHP = 0; } - UpdateCanHeal(Service.Player); + UpdateCanHeal(Player.Object); _lastHp = DataCenter.PartyMembers.ToDictionary(p => p.ObjectId, p => p.CurrentHp); if (DataCenter.InEffectTime) { - var rightMp = Service.Player.CurrentMp; + var rightMp = Player.Object.CurrentMp; if(rightMp - _lastMp == DataCenter.MPGain) { DataCenter.MPGain = 0; } - DataCenter.CurrentMp = Math.Min(10000, Service.Player.CurrentMp + DataCenter.MPGain); + DataCenter.CurrentMp = Math.Min(10000, Player.Object.CurrentMp + DataCenter.MPGain); } else { - DataCenter.CurrentMp = Service.Player.CurrentMp; + DataCenter.CurrentMp = Player.Object.CurrentMp; } - _lastMp = Service.Player.CurrentMp; + _lastMp = Player.Object.CurrentMp; } private static float GetPartyMemberHPRatio(BattleChara member) @@ -309,7 +310,7 @@ private static IEnumerable GetPartyMembers(IEnumerable { var party = Service.PartyList.Select(p => p.GameObject).OfType().Where(b => b.DistanceToPlayer() <= 30); - if (!party.Any()) party = new BattleChara[] { Service.Player }; + if (!party.Any()) party = new BattleChara[] { Player.Object }; return party.Union(allTargets.Where(obj => obj.SubKind == 9)); } diff --git a/RotationSolver/Watcher.cs b/RotationSolver/Watcher.cs index 05e4d1240..78ba6c623 100644 --- a/RotationSolver/Watcher.cs +++ b/RotationSolver/Watcher.cs @@ -4,6 +4,7 @@ using Dalamud.Logging; using Dalamud.Plugin.Ipc; using Dalamud.Utility.Signatures; +using ECommons.GameHelpers; using FFXIVClientStructs.FFXIV.Client.Game; using RotationSolver.Basic.Configuration; using RotationSolver.Localization; @@ -46,7 +47,7 @@ private void UpdateRTTDetour(dynamic obj) private static unsafe void ReceiveAbilityEffect(uint sourceId, IntPtr sourceCharacter, Vector3* pos, ActionEffectHeader* effectHeader, ActionEffect* effectArray, ulong* effectTargets) { - if (Service.Player != null) + if (Player.Available) { try { @@ -74,13 +75,13 @@ private static void ActionFromEnemy(uint sourceId, ActionEffectSet set) if (Service.ObjectTable.SearchById(battle.ObjectId) is PlayerCharacter) return; var damageRatio = set.TargetEffects - .Where(e => e.Target == Service.Player) + .Where(e => e.Target == Player.Object) .SelectMany(e => new ActionEffect[] { e[0], e[1], e[2], e[3], e[4], e[5], e[6], e[7] }) .Where(e => e.Type == ActionEffectType.Damage) - .Sum(e => (float)e.Value / Service.Player.MaxHp); + .Sum(e => (float)e.Value / Player.Object.MaxHp); DataCenter.AddDamageRec(damageRatio); ShowStrEnemy = $"Damage Ratio: {damageRatio}\n{set}"; @@ -109,7 +110,7 @@ private static void ActionFromEnemy(uint sourceId, ActionEffectSet set) private static void ActionFromSelf(uint sourceId, ActionEffectSet set, uint id) { - if (sourceId != Service.Player.ObjectId) return; + if (sourceId != Player.Object.ObjectId) return; if (set.Type != ActionType.Spell && set.Type != ActionType.Item) return; if (set.Action == null) return; if ((ActionCate)set.Action.ActionCategory.Value.RowId == ActionCate.AutoAttack) return; @@ -133,7 +134,7 @@ private static void ActionFromSelf(uint sourceId, ActionEffectSet set, uint id) DataCenter.HealHP = set.GetSpecificTypeEffect(ActionEffectType.Heal); DataCenter.ApplyStatus = set.GetSpecificTypeEffect(ActionEffectType.ApplyStatusEffectTarget); - DataCenter.MPGain = (uint)set.GetSpecificTypeEffect(ActionEffectType.MpGain).Where(i => i.Key == Service.Player.ObjectId).Sum(i => i.Value); + DataCenter.MPGain = (uint)set.GetSpecificTypeEffect(ActionEffectType.MpGain).Where(i => i.Key == Player.Object.ObjectId).Sum(i => i.Value); DataCenter.EffectTime = DateTime.Now; DataCenter.EffectEndTime = DateTime.Now.AddSeconds(set.AnimationLock + 1);