Skip to content

Commit

Permalink
v1.2.0.0 farm mode and commands
Browse files Browse the repository at this point in the history
  • Loading branch information
Jukkales committed Apr 12, 2024
1 parent 306fd89 commit 2e15788
Show file tree
Hide file tree
Showing 5 changed files with 97 additions and 15 deletions.
40 changes: 35 additions & 5 deletions HoardFarm/HoardFarm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,20 @@ public HoardFarm(DalamudPluginInterface? pluginInterface)
Achievements = achievementService;

PluginInterface.UiBuilder.Draw += DrawUI;
PluginInterface.UiBuilder.OpenMainUi += ShowMainWindow;
PluginInterface.UiBuilder.OpenMainUi += () => OnCommand();
PluginInterface.UiBuilder.OpenConfigUi += ShowConfigWindow;
Framework.Update += FrameworkUpdate;

PluginService.TaskManager = new TaskManager();


EzCmd.Add("/hoardfarm", (_, _) => ShowMainWindow() ,"Open the Hoard Farm window.");
EzCmd.Add("/hoardfarm", (_, args) => OnCommand(args) ,
"Opens the Hoard Farm window.\n" +
"/hoardfarm config | c → Open the config window.\n" +
"/hoardfarm enable | e → Enable farming mode.\n" +
"/hoardfarm disable | d → Disable farming mode.\n" +
"/hoardfarm toggle | t → Toggle farming mode.\n"
);

CultureInfo.DefaultThreadCurrentUICulture = ClientState.ClientLanguage switch
{
Expand All @@ -80,17 +86,41 @@ public void Dispose()
achievementService.Dispose();

Framework.Update -= FrameworkUpdate;
ECommonsMain.Dispose();
}

private void DrawUI()
{
WindowSystem.Draw();
}

public void ShowMainWindow()
public void OnCommand(string? args = null)
{
Achievements.UpdateProgress();
mainWindow.IsOpen = true;
args = args?.Trim().ToLower() ?? "";

switch (args)
{
case "c":
case "config":
ShowConfigWindow();
return;
case "e":
case "enable":
HoardService.HoardMode = true;
return;
case "d":
case "disable":
HoardService.HoardMode = false;
return;
case "t":
case "toggle":
HoardService.HoardMode = !HoardService.HoardMode;
return;
default:
Achievements.UpdateProgress();
mainWindow.IsOpen = true;
break;
}
}

public void ShowConfigWindow()
Expand Down
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.1.1.0</Version>
<Version>1.2.0.0</Version>
<Description>HoardFarm Dalamud Plugin</Description>
<PackageProjectUrl>https://github.com/Jukkales/HoardFarm</PackageProjectUrl>
</PropertyGroup>
Expand Down
1 change: 1 addition & 0 deletions HoardFarm/Model/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class Configuration : IPluginConfiguration
public int Version { get; set; } = 1;

public int HoardModeSave { get; set; }
public int HoardFarmMode { get; set; }
public int StopAfter { get; set; } = 50;
public int StopAfterMode { get; set; } = 1;
public int OverallRuns { get; set; }
Expand Down
23 changes: 15 additions & 8 deletions HoardFarm/Service/HoardFarmService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,11 @@ private void OnTimerUpdate(object? sender, ElapsedEventArgs e)
}
else
{
if (Config.HoardFarmMode == 1)
{
LeaveDuty();
return;
}
if (!hoardFound)
{
Enqueue(new UsePomanderTask(Pomander.Concealment), "Use Concealment");
Expand All @@ -217,24 +222,26 @@ private void OnTimerUpdate(object? sender, ElapsedEventArgs e)

if (hoardFound)
{
HoardModeStatus = "Leaving";
SessionRuns++;
Config.OverallRuns++;
Enqueue(new LeaveDutyTask(), "Leave Duty");
LeaveDuty();
}
}
else
{
HoardModeStatus = "Leaving";
SessionRuns++;
Config.OverallRuns++;
Enqueue(new LeaveDutyTask(), "Leave Duty");
LeaveDuty();
}
}
}
}
}

private void LeaveDuty()
{
HoardModeStatus = "Leaving";
SessionRuns++;
Config.OverallRuns++;
Enqueue(new LeaveDutyTask(), "Leave Duty");
}

private void FindHoardPosition()
{
if (hoardPosition == Vector3.Zero &&
Expand Down
46 changes: 45 additions & 1 deletion HoardFarm/Windows/MainWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

namespace HoardFarm.Windows;

public class MainWindow() : Window("Hoard Farm", ImGuiWindowFlags.AlwaysAutoResize), IDisposable
public class MainWindow() : Window($"Hoard Farm {P.GetType().Assembly.GetName().Version}###HoardFarm", ImGuiWindowFlags.AlwaysAutoResize), IDisposable
{
private readonly Configuration conf = Config;

Expand Down Expand Up @@ -56,6 +56,7 @@ public override void Draw()
}
ImGui.Separator();

ImGui.BeginGroup();
ImGui.Text("Savegame:");
ImGui.Indent(15);
var save = conf.HoardModeSave;
Expand All @@ -70,6 +71,49 @@ public override void Draw()
Config.Save();
}
ImGui.Unindent(15);
ImGui.EndGroup();

ImGui.SameLine(170);

ImGui.BeginGroup();
ImGui.Text("Farm Mode:");
ImGui.Indent(15);
var farmMode = conf.HoardFarmMode;
if (ImGui.RadioButton("Efficiency", ref farmMode, 0))
{
conf.HoardFarmMode = farmMode;
Config.Save();
}
ImGui.SameLine();
ImGui.PushFont(UiBuilder.IconFont);
ImGui.Text(FontAwesomeIcon.QuestionCircle.ToIconString());
ImGui.PopFont();
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Efficiency mode will search and try to find every hoard.\n" +
">20%% of the hoards are unreachable from start.\n" +
"It will take some seconds to find it.\n" +
"This mode is still recommended.");
}

if(ImGui.RadioButton("Time", ref farmMode, 1))
{
conf.HoardFarmMode = farmMode;
Config.Save();
}
ImGui.SameLine();
ImGui.PushFont(UiBuilder.IconFont);
ImGui.Text(FontAwesomeIcon.QuestionCircle.ToIconString());
ImGui.PopFont();
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Time mode will NOT search for hoards.\n" +
"It instantly leaves if the hoard is unreachable. \n" +
"Faster runs but you will miss a lot of hoards (and a bit safer)");
}
ImGui.Unindent(15);
ImGui.EndGroup();

ImGui.Separator();
ImGui.Text("Statistics:");

Expand Down

0 comments on commit 2e15788

Please sign in to comment.