Skip to content

Commit

Permalink
[PR] Fix /phb next not working sometimes
Browse files Browse the repository at this point in the history
The `/phb next` command should no longer break when only one mark is
found outside of the current zone, and should handle elite marks in a
sane and safe way that prioritises them last in the current zone, rather
than risking breaking because they don't have location data.

Also bumped DalamudPackager to latest (2.1.11) at the same time.
  • Loading branch information
PrincessRTFM committed Jul 2, 2023
1 parent 5a92e0e commit 45804a5
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 64 deletions.
6 changes: 3 additions & 3 deletions HuntBuddy/HuntBuddy.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<PropertyGroup>
<TargetFramework>net7.0-windows</TargetFramework>
<Nullable>enable</Nullable>
<AssemblyVersion>1.0.1.0</AssemblyVersion>
<FileVersion>1.0.1.0</FileVersion>
<AssemblyVersion>1.0.2.0</AssemblyVersion>
<FileVersion>$(AssemblyVersion)</FileVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RootNamespace>HuntBuddy</RootNamespace>
<IsPackable>false</IsPackable>
Expand Down Expand Up @@ -54,6 +54,6 @@
</Reference>
</ItemGroup>
<ItemGroup>
<PackageReference Include="DalamudPackager" Version="2.1.10" />
<PackageReference Include="DalamudPackager" Version="2.1.11" />
</ItemGroup>
</Project>
137 changes: 79 additions & 58 deletions HuntBuddy/Plugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,70 +151,91 @@ private void Dispose(bool disposing)
[HelpMessage("Toggles UI\nArguments:\nreload - Reloads data\nlocal - Toggles the local hunt marks window\nnext - Flags the next hunt target to find")]
public unsafe void PluginCommand(string command, string args)
{
switch (args.Trim().ToLower()) {
case "reload":
this.MobHuntEntriesReady = false;
Task.Run(this.ReloadData);
break;
case "local":
this.Configuration.ShowLocalHunts = !this.Configuration.ShowLocalHunts;
this.Configuration.Save();
break;
case "next":
if (this.MobHuntEntries.Count > 0)
{
var openType = Location.OpenType.None;
var playerLocation = Plugin.ClientState.LocalPlayer!.Position;
var map = Plugin.DataManager.GetExcelSheet<TerritoryType>()!.GetRow(Plugin.ClientState.TerritoryType)!.Map!.Value!;
var playerVec2 = MapUtil.WorldToMap(new Vector2(playerLocation.X, playerLocation.Z), map);
var chosen = this.CurrentAreaMobHuntEntries
.Where(entry => this.MobHuntStruct->CurrentKills[entry.CurrentKillsOffset] < entry.NeededKills)
.OrderBy(entry => Vector2.Distance(Location.Database[entry.MobHuntId].Coordinate, playerVec2))
.FirstOrDefault();
if (chosen == null)
try
{
switch (args.Trim().ToLower()) {
case "reload":
this.MobHuntEntriesReady = false;
Task.Run(this.ReloadData);
break;
case "local":
this.Configuration.ShowLocalHunts = !this.Configuration.ShowLocalHunts;
this.Configuration.Save();
break;
case "next":
if (this.MobHuntEntries.Count > 0)
{
PluginLog.Information("No marks in current zone, looking in current expansion");
openType = this.Configuration.IncludeAreaOnMap ? Location.OpenType.ShowOpen : Location.OpenType.MarkerOpen;
var expansion = Plugin.DataManager.Excel.GetSheet<TerritoryType>()!.GetRow(Plugin.ClientState.TerritoryType)!.ExVersion.Value!.Name;
PluginLog.Information($"Player is in a zone from {expansion}; known expansions are {string.Join(", ", this.MobHuntEntries.Keys)}");
var candidates = this.MobHuntEntries.ContainsKey(expansion)
? this.MobHuntEntries[expansion]
.Values
.SelectMany(l => l)
.Where(entry => this.MobHuntStruct->CurrentKills[entry.CurrentKillsOffset] < entry.NeededKills)
.ToList()
: new List<MobHuntEntry>();
if (candidates.Count == 0)
var filterPredicate = (MobHuntEntry entry) => entry.IsEliteMark || this.MobHuntStruct->CurrentKills[entry.CurrentKillsOffset] < entry.NeededKills;
var openType = Location.OpenType.None;
var playerLocation = Plugin.ClientState.LocalPlayer!.Position;
var map = Plugin.DataManager.GetExcelSheet<TerritoryType>()!.GetRow(Plugin.ClientState.TerritoryType)!.Map!.Value!;
var playerVec2 = MapUtil.WorldToMap(new Vector2(playerLocation.X, playerLocation.Z), map);
var chosen = this.CurrentAreaMobHuntEntries
.Where(filterPredicate)
.OrderBy(entry => entry.IsEliteMark ? float.MaxValue : Vector2.Distance(Location.Database[entry.MobHuntId].Coordinate, playerVec2))
.FirstOrDefault();
if (chosen == null)
{
PluginLog.Information("Nothing in current expansion, looking globally");
candidates =
this.MobHuntEntries.Values
.SelectMany(dict => dict.Values)
PluginLog.Information("No marks in current zone, looking in current expansion");
openType = this.Configuration.IncludeAreaOnMap ? Location.OpenType.ShowOpen : Location.OpenType.MarkerOpen;
var expansion = Plugin.DataManager.Excel.GetSheet<TerritoryType>()!.GetRow(Plugin.ClientState.TerritoryType)!.ExVersion.Value!.Name;
PluginLog.Information($"Player is in a zone from {expansion}; known expansions are {string.Join(", ", this.MobHuntEntries.Keys)}");
var candidates = this.MobHuntEntries.ContainsKey(expansion)
? this.MobHuntEntries[expansion]
.Values
.SelectMany(l => l)
.Where(entry => this.MobHuntStruct->CurrentKills[entry.CurrentKillsOffset] < entry.NeededKills)
.ToList();
.Where(filterPredicate)
.ToList()
: new List<MobHuntEntry>();
if (candidates.Count == 0)
{
PluginLog.Information("Nothing available in current expansion, looking globally");
candidates =
this.MobHuntEntries.Values
.SelectMany(dict => dict.Values)
.SelectMany(l => l)
.Where(filterPredicate)
.ToList();
}
if (candidates.Count >= 1)
{
PluginLog.Information($"Found {candidates.Count}");
chosen = candidates[new Random().Next(candidates.Count)];
}
}
if (candidates.Count > 1)
if (chosen != null)
{
PluginLog.Information($"Found {candidates.Count} marks");
chosen = candidates[new Random().Next(candidates.Count)];
if (chosen.IsEliteMark)
{
Chat.Print($"Hunting elite mark {chosen.Name} in {chosen.TerritoryName}");
}
else
{
var remaining = chosen.NeededKills - this.MobHuntStruct->CurrentKills[chosen.CurrentKillsOffset];
Chat.Print($"Hunting {remaining}x {chosen.Name} in {chosen.TerritoryName}");
Location.CreateMapMarker(
chosen.TerritoryType,
chosen.MapId,
chosen.MobHuntId,
chosen.Name,
openType);
}
}
else
{
PluginLog.Information("Unable to find a hunt mark to target");
Chat.Print("Couldn't find any hunt marks. Either you have no bills, or this is a bug.");
}
}
if (chosen != null)
{
Chat.Print($"Hunting {chosen.Name} in {chosen.TerritoryName}");
Location.CreateMapMarker(
chosen.TerritoryType,
chosen.MapId,
chosen.MobHuntId,
chosen.Name,
openType);
}
}
break;
default:
this.OpenConfigUi();
break;
break;
default:
this.OpenConfigUi();
break;
}
}
catch (Exception e)
{
PluginLog.Error("Error in command handler: " + e.ToString());
}
}

Expand Down Expand Up @@ -325,4 +346,4 @@ public void Dispose()
GC.SuppressFinalize(this);
}
}
}
}
6 changes: 3 additions & 3 deletions HuntBuddy/packages.lock.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
"net7.0-windows7.0": {
"DalamudPackager": {
"type": "Direct",
"requested": "[2.1.10, )",
"resolved": "2.1.10",
"contentHash": "S6NrvvOnLgT4GDdgwuKVJjbFo+8ZEj+JsEYk9ojjOR/MMfv1dIFpT8aRJQfI24rtDcw1uF+GnSSMN4WW1yt7fw=="
"requested": "[2.1.11, )",
"resolved": "2.1.11",
"contentHash": "9qlAWoRRTiL/geAvuwR/g6Bcbrd/bJJgVnB/RurBiyKs6srsP0bvpoo8IK+Eg8EA6jWeM6/YJWs66w4FIAzqPw=="
}
}
}
Expand Down

0 comments on commit 45804a5

Please sign in to comment.