Skip to content

Commit

Permalink
Merge pull request #541 from FFXIV-CombatReborn/mergeWIP
Browse files Browse the repository at this point in the history
some fixes and slash command additions
  • Loading branch information
CarnifexOptimus authored Jan 4, 2025
2 parents 0a24d87 + 17e85b9 commit 87ad87b
Show file tree
Hide file tree
Showing 12 changed files with 267 additions and 88 deletions.
2 changes: 1 addition & 1 deletion BossMod/AI/AIBehaviour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public async Task Execute(Actor player, Actor master)
var hadNavi = _naviDecision.Destination != null;

Targeting target = new();
if (!forbidActions && (AIPreset != null || autorot.Preset != null))
if (!forbidActions && AIPreset != null && (!_config.ForbidAIMovementMounted || _config.ForbidAIMovementMounted && player.MountId == 0))
{
target = SelectPrimaryTarget(player, master);
if (_config.ManualTarget)
Expand Down
2 changes: 1 addition & 1 deletion BossMod/AI/AIConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ sealed class AIConfig : ConfigNode
[PropertyDisplay("Movement decision delay", tooltip: "Only change this at your own risk and keep this value low! Too high and it won't move in time for some mechanics. Make sure to readjust the value for different content.")]
public float MoveDelay = 0;

[PropertyDisplay("Forbid AI movement while mounted")]
[PropertyDisplay("Idle while mounted")]
public bool ForbidAIMovementMounted = false;

public string? AIAutorotPresetName;
Expand Down
55 changes: 22 additions & 33 deletions BossMod/AI/AIManagementWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ sealed class AIManagementWindow : UIWindow
private readonly EventSubscriptions _subscriptions;
private const string _title = $"AI: off{_windowID}";
private const string _windowID = "###AI debug window";
DateTime? saveConfigIn;

public AIManagementWindow(AIManager manager) : base(_windowID, false, new(100, 100))
{
Expand Down Expand Up @@ -51,7 +50,7 @@ public override void Draw()
ImGui.SameLine();
configModified |= ImGui.Checkbox("Forbid movement", ref _config.ForbidMovement);
ImGui.SameLine();
configModified |= ImGui.Checkbox("Forbid mounted movement", ref _config.ForbidAIMovementMounted);
configModified |= ImGui.Checkbox("Idle while mounted", ref _config.ForbidAIMovementMounted);
ImGui.SameLine();
configModified |= ImGui.Checkbox("Follow during combat", ref _config.FollowDuringCombat);
ImGui.Spacing();
Expand Down Expand Up @@ -79,11 +78,9 @@ public override void Draw()
{
if (ImGui.Selectable(p.Name, _manager.MasterSlot == i))
{
var cfg = _config.FollowSlot;
_manager.SwitchToFollow(i);
_config.FollowSlot = i;
if (cfg != _config.FollowSlot)
configModified = true;
configModified = true;
}
}
ImGui.EndCombo();
Expand All @@ -96,10 +93,8 @@ public override void Draw()
var positionalIndex = (int)_config.DesiredPositional;
if (ImGui.Combo("##DesiredPositional", ref positionalIndex, positionalOptions, positionalOptions.Length))
{
var cfg = _config.DesiredPositional;
_config.DesiredPositional = (Positional)positionalIndex;
if (cfg != _config.DesiredPositional)
configModified = true;
configModified = true;
}
ImGui.SameLine();
ImGui.Text("Max distance - to targets");
Expand All @@ -111,10 +106,8 @@ public override void Draw()
maxDistanceTargetStr = maxDistanceTargetStr.Replace(',', '.');
if (float.TryParse(maxDistanceTargetStr, NumberStyles.Float, CultureInfo.InvariantCulture, out var maxDistance))
{
var cfg = _config.MaxDistanceToTarget;
_config.MaxDistanceToTarget = maxDistance;
if (cfg != _config.MaxDistanceToTarget)
configModified = true;
configModified = true;
}
}
ImGui.SameLine();
Expand All @@ -127,10 +120,8 @@ public override void Draw()
maxDistanceSlotStr = maxDistanceSlotStr.Replace(',', '.');
if (float.TryParse(maxDistanceSlotStr, NumberStyles.Float, CultureInfo.InvariantCulture, out var maxDistance))
{
var cfg = _config.MaxDistanceToSlot;
_config.MaxDistanceToSlot = maxDistance;
if (cfg != _config.MaxDistanceToTarget)
configModified = true;
configModified = true;
}
}

Expand All @@ -143,10 +134,8 @@ public override void Draw()
movementDelayStr = movementDelayStr.Replace(',', '.');
if (float.TryParse(movementDelayStr, NumberStyles.Float, CultureInfo.InvariantCulture, out var delay))
{
var cfg = _config.MoveDelay;
_config.MoveDelay = delay;
if (cfg != _config.MoveDelay)
configModified = true;
configModified = true;
}
}
ImGui.SameLine();
Expand All @@ -156,38 +145,38 @@ public override void Draw()
ImGui.SetNextWindowSizeConstraints(default, new Vector2(float.MaxValue, ImGui.GetTextLineHeightWithSpacing() * 50));
var aipreset = _config.AIAutorotPresetName;
var presets = _manager.Autorot.Database.Presets.VisiblePresets;
var presetNames = presets.Select(p => p.Name).ToList();

var count = presets.Count;
List<string> presetNames = new(count + 1);
for (var i = 0; i < count; ++i)
{
presetNames.Add(presets[i].Name);
}

if (aipreset != null)
presetNames.Add("Deactivate");

var countnames = presetNames.Count;
var selectedIndex = presetNames.IndexOf(aipreset ?? "");
if (selectedIndex == -1 && _manager.AiPreset == null)
selectedIndex = -1;
if (ImGui.Combo("##AI preset", ref selectedIndex, [.. presetNames], presetNames.Count))

if (ImGui.Combo("##AI preset", ref selectedIndex, [.. presetNames], countnames))
{
var cfg = _config.AIAutorotPresetName;
if (selectedIndex == presetNames.Count - 1 && aipreset != null)
if (selectedIndex == countnames - 1 && aipreset != null)
{
_manager.SetAIPreset(null);
_config.AIAutorotPresetName = null;
configModified = true;
selectedIndex = -1;
}
else if (selectedIndex >= 0 && selectedIndex < presets.Count())
else if (selectedIndex >= 0 && selectedIndex < count)
{
var selectedPreset = presets.ElementAt(selectedIndex);
var selectedPreset = presets[selectedIndex];
_manager.SetAIPreset(selectedPreset);
_config.AIAutorotPresetName = selectedPreset.Name;
}
if (cfg != _config.AIAutorotPresetName)
configModified = true;
}
}
if (configModified)
saveConfigIn = DateTime.Now.AddSeconds(10); // delay config saving to potentially save multiple setting changes in a batch
if (saveConfigIn <= DateTime.Now)
{
_config.Modified.Fire();
saveConfigIn = null;
}
}

public override void OnClose() => SetVisible(false);
Expand Down
Loading

0 comments on commit 87ad87b

Please sign in to comment.