Skip to content

Commit

Permalink
Got rid of dalamud wrappers in aicontroller.
Browse files Browse the repository at this point in the history
  • Loading branch information
awgil committed Aug 26, 2024
1 parent e08749a commit 2b174b6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
36 changes: 17 additions & 19 deletions BossMod/AI/AIController.cs
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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)
{
Expand All @@ -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
{
Expand All @@ -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);
}
}
2 changes: 1 addition & 1 deletion BossMod/AI/AIManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 2b174b6

Please sign in to comment.