Selaa lähdekoodia

[PR] Fix `/phb next` not working sometimes

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.
Lilith Song 3 vuotta sitten
vanhempi
sitoutus
45804a5524
3 muutettua tiedostoa jossa 85 lisäystä ja 64 poistoa
  1. 3 3
      HuntBuddy/HuntBuddy.csproj
  2. 79 58
      HuntBuddy/Plugin.cs
  3. 3 3
      HuntBuddy/packages.lock.json

+ 3 - 3
HuntBuddy/HuntBuddy.csproj

@@ -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>
@@ -54,6 +54,6 @@
         </Reference>
     </ItemGroup>
     <ItemGroup>
-        <PackageReference Include="DalamudPackager" Version="2.1.10" />
+        <PackageReference Include="DalamudPackager" Version="2.1.11" />
     </ItemGroup>
 </Project>

+ 79 - 58
HuntBuddy/Plugin.cs

@@ -151,70 +151,91 @@ namespace HuntBuddy
 		[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());
 			}
 		}
 
@@ -325,4 +346,4 @@ namespace HuntBuddy
 			GC.SuppressFinalize(this);
 		}
 	}
-}
+}

+ 3 - 3
HuntBuddy/packages.lock.json

@@ -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=="
       }
     }
   }