diff --git a/BossMod/AI/AIController.cs b/BossMod/AI/AIController.cs index 95c797306f..2416bfb616 100644 --- a/BossMod/AI/AIController.cs +++ b/BossMod/AI/AIController.cs @@ -1,6 +1,6 @@ using Dalamud.Game.ClientState.Conditions; -using Dalamud.Game.ClientState.Objects.Types; using FFXIVClientStructs.FFXIV.Client.Game.Control; +using FFXIVClientStructs.FFXIV.Client.Game.Object; namespace BossMod.AI; @@ -45,7 +45,7 @@ public void SetFocusTarget(Actor? actor) Service.TargetManager.FocusTarget = actor != null ? Service.ObjectTable.SearchById((uint)actor.InstanceID) : null; } - public void Update(Actor? player, AIHints hints) + public void Update(Actor? player, AIHints hints, DateTime now) { if (player == null || player.IsDead || InCutscene) { @@ -67,7 +67,7 @@ public void Update(Actor? player, AIHints hints) var y = NaviTargetVertical != null && IsVerticalAllowed ? NaviTargetVertical.Value : player.PosRot.Y; desiredPosition = new(NaviTargetPos.Value.X, y, NaviTargetPos.Value.Z); if (WantJump) - ExecuteJump(); + ExecuteJump(now); } else { @@ -77,28 +77,26 @@ public void Update(Actor? player, AIHints hints) if (hints.ForcedMovement == null && desiredPosition != null) hints.ForcedMovement = desiredPosition.Value - player.PosRot.XYZ(); - if (hints.InteractWithTarget is Actor tar && Service.TargetManager.Target is IGameObject obj && obj.EntityId == tar.InstanceID && player.DistanceToHitbox(tar) <= 3) - ExecuteInteract(obj); + if (hints.InteractWithTarget is Actor tar && player.DistanceToHitbox(tar) <= 3) + ExecuteInteract(now, tar); } - private unsafe void ExecuteInteract(IGameObject obj) + private unsafe void ExecuteInteract(DateTime now, Actor target) { - if (_amex.EffectiveAnimationLock > 0) + if (_amex.EffectiveAnimationLock > 0 || now < _nextInteract) return; - - if (DateTime.Now >= _nextInteract) - { - TargetSystem.Instance()->OpenObjectInteraction((FFXIVClientStructs.FFXIV.Client.Game.Object.GameObject*)obj.Address); - _nextInteract = DateTime.Now.AddMilliseconds(100); - } + var obj = GameObjectManager.Instance()->Objects.IndexSorted[target.SpawnIndex].Value; + if (obj == null || obj->GetGameObjectId() != target.InstanceID) + return; + TargetSystem.Instance()->OpenObjectInteraction(obj); + _nextInteract = now.AddMilliseconds(100); } - private unsafe void ExecuteJump() + private unsafe void ExecuteJump(DateTime now) { - if (DateTime.Now >= _nextJump) - { - FFXIVClientStructs.FFXIV.Client.Game.ActionManager.Instance()->UseAction(FFXIVClientStructs.FFXIV.Client.Game.ActionType.GeneralAction, 2); - _nextJump = DateTime.Now.AddMilliseconds(100); - } + if (now < _nextJump) + return; + FFXIVClientStructs.FFXIV.Client.Game.ActionManager.Instance()->UseAction(FFXIVClientStructs.FFXIV.Client.Game.ActionType.GeneralAction, 2); + _nextJump = now.AddMilliseconds(100); } } diff --git a/BossMod/AI/AIManager.cs b/BossMod/AI/AIManager.cs index b0b97cdf74..0bf7c18c23 100644 --- a/BossMod/AI/AIManager.cs +++ b/BossMod/AI/AIManager.cs @@ -86,7 +86,7 @@ public void Update() _controller.Clear(); } - _controller.Update(player, _autorot.Hints); + _controller.Update(player, _autorot.Hints, WorldState.CurrentTime); _aiStatus = $"AI: {(Behaviour != null ? $"on, {(_config.FollowTarget && target != null ? $"target={target.Name}" : $"master={master?.Name}[{((int)_config.FollowSlot) + 1}]")}" : "off")}"; _naviStatus = $"Navi={_controller.NaviTargetPos} / {_controller.NaviTargetRot}{(_controller.ForceFacing ? " forced" : "")}"; _ui.IsOpen = player != null && _config.DrawUI;