diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs index b9d250b..0a64eec 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs @@ -3594,13 +3594,23 @@ public partial class CombatManager : IDisposable return any ? CreatureWeakness.FromAppraisal(m) : null; } + /// + /// Optional UtilityBelt damage seed lookup (wcid, name) → damage types best first, or null. + /// Set by the plugin when the seed store loads; null (default) leaves the ranking as before. + /// Called on the combat thread. + /// + internal Func?>? MobSeedLookup { get; set; } + /// The same by wcid and name; (optional) reads a live creature type. internal CreatureWeakness.Ranking? WeaknessFor(uint wcid, string? name, int objectId = 0) { name ??= ""; int ctype = CreatureTypeOf(wcid, name, objectId); string learned = wcid != 0 ? _damageStore?.GetBestElement(wcid) ?? "" : ""; - return CreatureWeakness.Rank(wcid, name, ctype, learned); + IReadOnlyList? seeded = null; + try { seeded = MobSeedLookup?.Invoke(wcid, name); } + catch { seeded = null; } // a bad seed file must never stop element choice + return CreatureWeakness.Rank(wcid, name, ctype, learned, seeded); } // Server replies seen when the last combat wield was sent (UseDone / WeenieError sequence). diff --git a/Plugins/RynthCore.Plugin.RynthAi/CreatureData/CreatureWeakness.cs b/Plugins/RynthCore.Plugin.RynthAi/CreatureData/CreatureWeakness.cs index bf64950..ceeee93 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/CreatureData/CreatureWeakness.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/CreatureData/CreatureWeakness.cs @@ -58,10 +58,19 @@ internal static class CreatureWeakness /// /// The elements that hurt this monster most, or null when nothing is known. Order of /// sources: the server table (wcid + name), then what the Damage tab learned - /// () ahead of the creature-type ranking, then the type - /// ranking alone. 0 = unknown (the name keywords decide). + /// () ahead of the creature-type ranking, then the + /// UtilityBelt damage seed (, best first) ahead of the type + /// ranking, then the type ranking alone. 0 = unknown + /// (the name keywords decide). /// - public static Ranking? Rank(uint wcid, string? name, int creatureType, string? learnedBest) + /// + /// Damage types other players landed best on this monster (Monster Editor "Import UB + /// damage insights"), best first; null or empty = no seed. It reflects what players + /// owned as much as the monster's weakness, so it never outranks the server table or + /// this character's learned element; it only beats the generic creature-type average. + /// + public static Ranking? Rank(uint wcid, string? name, int creatureType, string? learnedBest, + IReadOnlyList? seeded = null) { EnsureLoaded(); name ??= ""; @@ -86,11 +95,36 @@ internal static class CreatureWeakness if (!e.Element.Equals(learned, StringComparison.OrdinalIgnoreCase)) r.Order.Add(e); return r; } + Ranking? seed = SeedRanking(seeded, type); + if (seed != null) + return seed; if (type != null) return new Ranking { Source = Pretty(type.Name) + " type", Order = new(type.Order) }; return null; } + /// + /// The seed's elements (normalised, de-duplicated, no multiplier: only the order is known), + /// then the creature type's remaining elements. Null when the seed names no element. + /// + private static Ranking? SeedRanking(IReadOnlyList? seeded, TypeInfo? type) + { + if (seeded == null || seeded.Count == 0) return null; + var r = new Ranking(); + var seen = new HashSet(StringComparer.OrdinalIgnoreCase); + foreach (string raw in seeded) + { + string e = Normalize(raw); + if (e.Length > 0 && seen.Add(e)) r.Order.Add((e, double.NaN)); + } + if (r.Order.Count == 0) return null; + r.Source = type != null ? $"UB seed, then {Pretty(type.Name)} type" : "UB seed"; + if (type != null) + foreach (var e in type.Order) + if (seen.Add(e.Element)) r.Order.Add(e); + return r; + } + /// /// The creature type the world-database table gives this monster (0 = not in it). Same match /// as : the wcid's row when its name agrees (or no name is given); no wcid, diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.LocalFeatures.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.LocalFeatures.cs index ddd7d94..620439a 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.LocalFeatures.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.LocalFeatures.cs @@ -1,10 +1,11 @@ -// RynthAiPlugin.LocalFeatures.cs — ILT Hub, floating HUDs, chat translation, item info and the -// nav overlay. +// RynthAiPlugin.LocalFeatures.cs — ILT Hub, floating HUDs, chat translation, item info, the nav +// overlay and the UB damage seed. // // The engine draws the main panels. These features draw their own ImGui windows from // RynthPluginRender / RynthPluginRenderOverlay. Lifecycle methods on RynthAiPlugin call into // this file; they add to combat, loot and navigation and never replace them. using System; +using System.Collections.Generic; using ImGuiNET; using RynthCore.Plugin.RynthAi.LegacyUi; using RynthCore.PluginSdk; @@ -36,6 +37,23 @@ public sealed partial class RynthAiPlugin catch (Exception ex) { Host.Log($"[RynthAi] mob seed store failed: {ex.Message}"); } } + /// + /// CombatManager.MobSeedLookup: the seed's damage types for a monster, best first (highest + /// Score), or null when the seed has nothing for it. Feeds the Auto element ranking only + /// after the server table and the learned element (see CreatureWeakness.Rank). + /// + private IReadOnlyList? LookupMobSeed(uint wcid, string name) + { + var store = _mobSeedStore; + if (store == null || !store.TryGetRanked(wcid, name, out var ranked) || ranked.Count == 0) + return null; + var ordered = new List(ranked); + ordered.Sort((a, b) => b.Score.CompareTo(a.Score)); + var elements = new List(ordered.Count); + foreach (var e in ordered) elements.Add(e.Element); + return elements; + } + /// Chat translator survives logout; session language resets on each login. private void EnsureTranslator() { diff --git a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs index c45ef23..98976bc 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/RynthAiPlugin.cs @@ -625,6 +625,7 @@ public sealed partial class RynthAiPlugin : RynthPluginBase _combatManager.SetCharacterSkills(_charSkills); _combatManager.SetPlayerId(_playerId); _combatManager.SetDamageStores(_creatureStore, _damageStore); + _combatManager.MobSeedLookup = LookupMobSeed; _combatManager.SetAwakenedTier(_tier); // The raycast init thread may already have finished (warm dats): hand it over now. WireRaycastIntoCombat(); diff --git a/Tools/RynthCore.RynthAiTests/Tests/CreatureWeaknessTests.cs b/Tools/RynthCore.RynthAiTests/Tests/CreatureWeaknessTests.cs index c529267..8eff481 100644 --- a/Tools/RynthCore.RynthAiTests/Tests/CreatureWeaknessTests.cs +++ b/Tools/RynthCore.RynthAiTests/Tests/CreatureWeaknessTests.cs @@ -25,6 +25,7 @@ internal static class CreatureWeaknessTests r.Add("weakness: server table ranks most damage first", ServerTable); r.Add("weakness: type keyword is a whole word", TypeKeyword); r.Add("weakness: learned element goes first, then the type order", LearnedFirst); + r.Add("weakness: UB seed ranks after server data and learned, before the type", SeedBeforeType); } private static void Normalize() @@ -130,4 +131,34 @@ internal static class CreatureWeaknessTests Check.Eq(alone?.Order.Count, 1, "only the learned element"); Check.Eq(alone?.Describe(), "Fire", "describe without a multiplier"); } + + private static void SeedBeforeType() + { + var type = CreatureWeakness.Rank(0, OlthoiByKeyword, 0, null); + var r = CreatureWeakness.Rank(0, OlthoiByKeyword, 0, null, new[] { "Electric", "fire", "Holy", "Fire" }); + Check.NotNull(r, "ranking with a seed"); + if (r == null || type == null) return; + Check.Eq(r.Source, "UB seed, then Olthoi type", "source"); + Check.Eq(r.Order[0].Element, "Lightning", "seed order first (normalised)"); + Check.Eq(r.Order[1].Element, "Fire", "second seed element"); + Check.True(double.IsNaN(r.Order[1].Mult), "seed elements have no multiplier"); + Check.Eq(r.Order.Count, 8, "unknown names dropped, no element listed twice"); + var rest = new List(); + foreach (var (e, _) in type.Order) if (e != "Lightning" && e != "Fire") rest.Add(e); + for (int i = 0; i < rest.Count; i++) + Check.Eq(r.Order[i + 2].Element, rest[i], $"then the type order at {i + 2}"); + + var learned = CreatureWeakness.Rank(0, OlthoiByKeyword, 0, "Cold", new[] { "Fire" }); + Check.Eq(learned?.Source, "learned, then Olthoi type", "learned element beats the seed"); + Check.Eq(learned?.Order[0].Element, "Cold", "learned element first"); + + var row = FirstServerRow(); + if (row is { } sr) + Check.Eq(CreatureWeakness.Rank(sr.Wcid, sr.Name, 0, null, new[] { "Nether" })?.Source, "server data", "server table beats the seed"); + + var alone = CreatureWeakness.Rank(0, Unknown, 0, null, new[] { "Acid" }); + Check.Eq(alone?.Source, "UB seed", "seed with no type"); + Check.Eq(alone?.Order.Count, 1, "only the seed element"); + Check.True(CreatureWeakness.Rank(0, Unknown, 0, null, new[] { "Holy" }) == null, "a seed with no element is ignored"); + } }