Skip to content

Commit

Permalink
overlay, updates and safety features
Browse files Browse the repository at this point in the history
  • Loading branch information
Jukkales committed Apr 14, 2024
1 parent d201a96 commit 3ca055d
Show file tree
Hide file tree
Showing 13 changed files with 399 additions and 28 deletions.
17 changes: 13 additions & 4 deletions HoardFarm/HoardFarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public sealed class HoardFarm : IDalamudPlugin
private readonly AchievementService achievementService;
private readonly MainWindow mainWindow;
private readonly ConfigWindow configWindow;
private readonly DeepDungeonMenuOverlay deepDungeonMenuOverlay;
public WindowSystem WindowSystem = new("HoardFarm");

public HoardFarm(DalamudPluginInterface? pluginInterface)
Expand All @@ -37,9 +38,11 @@ public HoardFarm(DalamudPluginInterface? pluginInterface)

mainWindow = new MainWindow();
configWindow = new ConfigWindow();
deepDungeonMenuOverlay = new DeepDungeonMenuOverlay();

WindowSystem.AddWindow(mainWindow);
WindowSystem.AddWindow(configWindow);
WindowSystem.AddWindow(deepDungeonMenuOverlay);

hoardFarmService = new HoardFarmService();
HoardService = hoardFarmService;
Expand Down Expand Up @@ -80,8 +83,6 @@ private void FrameworkUpdate(IFramework framework)
public void Dispose()
{
WindowSystem.RemoveAllWindows();
mainWindow.Dispose();
configWindow.Dispose();
hoardFarmService.Dispose();
achievementService.Dispose();

Expand Down Expand Up @@ -120,8 +121,7 @@ public void OnCommand(string? args = null)
HoardService.HoardMode = !HoardService.HoardMode;
return;
default:
Achievements.UpdateProgress();
mainWindow.IsOpen = true;
ShowMainWindow();
break;
}
}
Expand All @@ -130,4 +130,13 @@ public void ShowConfigWindow()
{
configWindow.IsOpen = true;
}

public void ShowMainWindow()
{
if (!mainWindow.IsOpen)
{
Achievements.UpdateProgress();
mainWindow.IsOpen = true;
}
}
}
2 changes: 1 addition & 1 deletion HoardFarm/HoardFarm.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Authors>Jukkales</Authors>
<Version>1.2.0.1</Version>
<Version>1.3.0.0</Version>
<Description>HoardFarm Dalamud Plugin</Description>
<PackageProjectUrl>https://github.com/Jukkales/HoardFarm</PackageProjectUrl>
</PropertyGroup>
Expand Down
90 changes: 90 additions & 0 deletions HoardFarm/ImGuiEx/ImGuiEx.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
using System.Numerics;
using System.Runtime.InteropServices;
using Dalamud.Interface;
using Dalamud.Interface.Internal.Notifications;
using Dalamud.Interface.Utility;
using ECommons.ImGuiMethods;
using ImGuiNET;

namespace HoardFarm.ImGuiEx;

// https://github.com/UnknownX7/Hypostasis/blob/ccaf819cb755d022790d8955d4283c95a0c10fec/ImGui/Header.cs
public static partial class ImGuiEx
{
[LibraryImport("cimgui")]
[UnmanagedCallConv(CallConvs = [typeof(System.Runtime.CompilerServices.CallConvCdecl)])]
private static partial nint igGetCurrentWindow();
public static unsafe ImGuiWindow* GetCurrentWindow() => (ImGuiWindow*)igGetCurrentWindow();
public static unsafe ImGuiWindowFlags GetCurrentWindowFlags() => GetCurrentWindow()->Flags;
public static unsafe bool CurrentWindowHasCloseButton() => GetCurrentWindow()->HasCloseButton != 0;
public record HeaderIconOptions
{
public Vector2 Offset { get; init; } = Vector2.Zero;
public ImGuiMouseButton MouseButton { get; init; } = ImGuiMouseButton.Left;
public string Tooltip { get; init; } = string.Empty;
public uint Color { get; init; } = 0xFFFFFFFF;
public bool ToastTooltipOnClick { get; init; } = false;
public ImGuiMouseButton ToastTooltipOnClickButton { get; init; } = ImGuiMouseButton.Left;
}

private static uint headerLastWindowID = 0;
private static ulong headerLastFrame = 0;
private static uint headerCurrentPos = 0;
private static float headerImGuiButtonWidth = 0;

public static bool AddHeaderIcon(string id, FontAwesomeIcon icon, HeaderIconOptions options = null)

Check warning on line 35 in HoardFarm/ImGuiEx/ImGuiEx.cs

View workflow job for this annotation

GitHub Actions / build

Cannot convert null literal to non-nullable reference type.
{
if (ImGui.IsWindowCollapsed()) return false;

var scale = ImGuiHelpers.GlobalScale;
var currentID = ImGui.GetID(0);
if (currentID != headerLastWindowID || headerLastFrame != PluginInterface.UiBuilder.FrameCount)
{
headerLastWindowID = currentID;
headerLastFrame = PluginInterface.UiBuilder.FrameCount;
headerCurrentPos = 0;
headerImGuiButtonWidth = 0f;
if (CurrentWindowHasCloseButton())
headerImGuiButtonWidth += 17 * scale;
if (!GetCurrentWindowFlags().HasFlag(ImGuiWindowFlags.NoCollapse))
headerImGuiButtonWidth += 17 * scale;
}

options ??= new();
var prevCursorPos = ImGui.GetCursorPos();
var buttonSize = new Vector2(20 * scale);
var buttonPos = new Vector2(ImGui.GetWindowWidth() - buttonSize.X - headerImGuiButtonWidth - 20 * headerCurrentPos++ * scale - ImGui.GetStyle().FramePadding.X * 2, ImGui.GetScrollY() + 1);
ImGui.SetCursorPos(buttonPos);
var drawList = ImGui.GetWindowDrawList();
drawList.PushClipRectFullScreen();

var pressed = false;
ImGui.InvisibleButton(id, buttonSize);
var itemMin = ImGui.GetItemRectMin();
var itemMax = ImGui.GetItemRectMax();
var halfSize = ImGui.GetItemRectSize() / 2;
var center = itemMin + halfSize;
if (ImGui.IsWindowHovered() && ImGui.IsMouseHoveringRect(itemMin, itemMax, false))
{
if (!string.IsNullOrEmpty(options.Tooltip))
ImGui.SetTooltip(options.Tooltip);
ImGui.GetWindowDrawList().AddCircleFilled(center, halfSize.X, ImGui.GetColorU32(ImGui.IsMouseDown(ImGuiMouseButton.Left) ? ImGuiCol.ButtonActive : ImGuiCol.ButtonHovered));
if (ImGui.IsMouseReleased(options.MouseButton))
pressed = true;
if (options.ToastTooltipOnClick && ImGui.IsMouseReleased(options.ToastTooltipOnClickButton))
PluginInterface.UiBuilder.AddNotification(options.Tooltip!, null, NotificationType.Info);

Check warning on line 75 in HoardFarm/ImGuiEx/ImGuiEx.cs

View workflow job for this annotation

GitHub Actions / build

'UiBuilder.AddNotification(string, string?, NotificationType, uint)' is obsolete: 'Use INotificationManager.'
}

ImGui.SetCursorPos(buttonPos);
ImGui.PushFont(UiBuilder.IconFont);
var iconString = icon.ToIconString();
drawList.AddText(UiBuilder.IconFont, ImGui.GetFontSize(), itemMin + halfSize - ImGui.CalcTextSize(iconString) / 2 + options.Offset, options.Color, iconString);
ImGui.PopFont();

ImGui.PopClipRect();
ImGui.SetCursorPos(prevCursorPos);

return pressed;
}

}
3 changes: 3 additions & 0 deletions HoardFarm/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ public class Configuration : IPluginConfiguration
public int OverallRuns { get; set; }
public int OverallFoundHoards { get; set; }
public int OverallTime { get; set; }
public bool ShowOverlay { get; set; } = true;
public bool ParanoidMode { get; set; } = false;


public void Save()
{
Expand Down
45 changes: 43 additions & 2 deletions HoardFarm/Service/HoardFarmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ namespace HoardFarm.Service;
public class HoardFarmService : IDisposable
{
public string HoardModeStatus = "";
public string HoardModeError = "";
private bool hoardModeActive;
private readonly Timer updateTimer;
public int SessionRuns;
Expand Down Expand Up @@ -84,6 +85,7 @@ private void EnableFarm()
SessionFoundHoards = 0;
updateTimer.Enabled = true;
HoardModeStatus = "Running";
HoardModeError = "";
ChatGui.ChatMessage += OnChatMessage;
}

Expand Down Expand Up @@ -146,6 +148,7 @@ private void OnTimerUpdate(object? sender, ElapsedEventArgs e)
HoardModeStatus = "Waiting Navmesh";
return;
}

if (searchMode && hoardPosition == Vector3.Zero)
{
if (!SearchLogic())
Expand All @@ -161,6 +164,14 @@ private void OnTimerUpdate(object? sender, ElapsedEventArgs e)
FinishRun = true;
return;
}
if (Player.Territory == HoHMapId1)
{
HoardModeStatus = "Please prepare";
HoardModeError = "Please prepare before starting.\nFloor One is not supported.";
FinishRun = true;
Enqueue(new LeaveDutyTask(), "Leave Duty");
return;
}
if (!InHoH && !InRubySea && NotBusy() && !KyuseiInteractable())
{
HoardModeStatus = "Moving to HoH";
Expand All @@ -176,15 +187,31 @@ private void OnTimerUpdate(object? sender, ElapsedEventArgs e)
return;
}
HoardModeStatus = "Entering HoH";
if (Config.ParanoidMode)
{
EnqueueWait(Random.Shared.Next(3000, 6000));
}
Enqueue(new EnterHeavenOnHigh(), "Enter HoH");
}

if (InHoH && NotBusy())
{
if (!CheckMinimalSetup())
{
HoardModeStatus = "Please prepare";
HoardModeError = "Please prepare before starting.\nYou need at least one Intuition Pomander\nand one Concealment.";
FinishRun = true;
Enqueue(new LeaveDutyTask(), "Leave Duty");
return;
}

if (!intuitionUsed)
{
Enqueue(new UsePomanderTask(Pomander.Intuition), "Use Intuition");
intuitionUsed = true;
if (CanUsePomander(Pomander.Intuition))
{
Enqueue(new UsePomanderTask(Pomander.Intuition), "Use Intuition");
intuitionUsed = true;
}
}
else
{
Expand Down Expand Up @@ -234,6 +261,20 @@ private void OnTimerUpdate(object? sender, ElapsedEventArgs e)
}
}

private bool CheckMinimalSetup()
{
if (!CanUsePomander(Pomander.Intuition))
{
return false;
}
if (CanUsePomander(Pomander.Concealment))
{
return true;
}

return CanUsePomander(Pomander.Safety) && CanUseMagicite();
}

private void LeaveDuty()
{
HoardModeStatus = "Leaving";
Expand Down
28 changes: 25 additions & 3 deletions HoardFarm/Tasks/EnterHeavenOnHigh.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,22 @@ namespace HoardFarm.Tasks;

public class EnterHeavenOnHigh : IBaseTask
{
public bool? Run()
public unsafe bool? Run()
{
TryGetAddonByName<AtkUnitBase>("DeepDungeonMenu", out var menu);
TryGetAddonByName<AtkUnitBase>("DeepDungeonSaveData", out var save);
Enqueue(WaitForYesAlreadyDisabledTask, "Disable Yes Already");
Enqueue(InteractKyusei, "Interact Kyusei");
Enqueue(EnterDuty, "Enter Heaven on High");
PluginLog.Information("menu: {menu}, save: {save}");
if (menu == null && save == null)
{
Enqueue(InteractKyusei, "Interact Kyusei");
}

if ((menu == null && save == null) || (menu != null && save == null))
{
Enqueue(EnterDuty, "Enter Heaven on High");
}

Enqueue(SelectSave, "Select Save");
Enqueue(new SelectYesnoTask(ConfirmPartyKoMessageId), "Confirm Party KO");
Enqueue(ConfirmDuty, "Confirm Duty");
Expand Down Expand Up @@ -62,6 +73,17 @@ public class EnterHeavenOnHigh : IBaseTask

return false;
}

private static unsafe bool VerifySave()
{
if (TryGetAddonByName<AtkUnitBase>("DeepDungeonSaveData", out var menu) && IsAddonReady(menu))
{
var saveId = (uint)(Config.HoardModeSave == 0 ? 21002 : 21001);
GetNodeByIDChain(menu->GetRootNode(), [6, 2]);
}

return false;
}

private static unsafe bool? ConfirmDuty()
{
Expand Down
30 changes: 30 additions & 0 deletions HoardFarm/Tasks/UseMagiciteTask.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using ECommons.Automation;
using ECommons.Throttlers;
using FFXIVClientStructs.FFXIV.Client.UI.Agent;
using FFXIVClientStructs.FFXIV.Component.GUI;

namespace HoardFarm.Tasks;

public class UseMagiciteTask() : IBaseTask
{
public unsafe bool? Run()
{
if (TryGetAddonByName<AtkUnitBase>("DeepDungeonStatus", out var addon) && IsAddonReady(addon))
{
if (CanUseMagicite())
{
Callback.Fire(addon, true, 12, 0);
EnqueueWaitImmediate(3000);
}

return true;
}

if (EzThrottler.Throttle("OpenDeepDungeonStatus", 2000)) {
AgentDeepDungeonStatus.Instance()->AgentInterface.Show();
}

return false;
}

}
7 changes: 5 additions & 2 deletions HoardFarm/Tasks/UsePomanderTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,11 @@ public class UsePomanderTask(Pomander pomander) : IBaseTask
{
if (TryGetAddonByName<AtkUnitBase>("DeepDungeonStatus", out var addon) && IsAddonReady(addon))
{
Callback.Fire(addon, true, 11, (int)pomander);
EnqueueWaitImmediate(2000);
if (CanUsePomander(pomander))
{
Callback.Fire(addon, true, 11, (int)pomander);
EnqueueWaitImmediate(2000);
}
return true;
}

Expand Down
6 changes: 6 additions & 0 deletions HoardFarm/Utils/DataIDs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public static class DataIDs
public static readonly Vector3 KyuseiLocation = new(-2.02948f, 3.0059814f, -611.3528f);

public const ushort RubySeaMapId = 613;
public const ushort HoHMapId1 = 770;
public const ushort HoHMapId11 = 771;
public const ushort HoHMapId21 = 772;

Expand All @@ -25,4 +26,9 @@ public static class DataIDs
public static readonly HashSet<uint> ChestIDs =
[1036, 1037, 1038, 1039, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 2007357, 2007358];

public static readonly uint[] ConcealmentChain = [1, 16, 18, 31, 2];
public static readonly uint[] SafetyChain = [1, 16, 18, 19, 2];
public static readonly uint[] IntuitionChain = [1, 16, 18, 32, 2];

public static readonly uint[] MagiciteChain = [1, 54, 56, 57, 2];
}
Loading

0 comments on commit 3ca055d

Please sign in to comment.