feat(rynthai): use the UB damage seed in the Auto element ranking
The Monster Editor's "Import UB damage insights" seed was loaded but never read by combat. CreatureWeakness.Rank now takes an optional seed list: appraisal > server table > learned element (+ type) > UB seed (+ type) > creature type alone The seed only orders elements (no multiplier, like the learned element), so it never outranks the server table or what this character learned; it replaces the generic creature-type average for monsters the seed knows. WeaponPlanner is unchanged: it walks the ranking as before. CombatManager.MobSeedLookup is set by the plugin from UbMobSeedStore; a missing or bad seed file leaves the ranking exactly as before. Metas (ExpressionEngine) keep the unseeded ranking. Unit test added. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
parent
09b14d4ed1
commit
7bcc954ecc
5 changed files with 100 additions and 6 deletions
|
|
@ -3594,13 +3594,23 @@ public partial class CombatManager : IDisposable
|
|||
return any ? CreatureWeakness.FromAppraisal(m) : null;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
internal Func<uint, string, IReadOnlyList<string>?>? MobSeedLookup { get; set; }
|
||||
|
||||
/// <summary>The same by wcid and name; <paramref name="objectId"/> (optional) reads a live creature type.</summary>
|
||||
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<string>? 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).
|
||||
|
|
|
|||
|
|
@ -58,10 +58,19 @@ internal static class CreatureWeakness
|
|||
/// <summary>
|
||||
/// 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
|
||||
/// (<paramref name="learnedBest"/>) ahead of the creature-type ranking, then the type
|
||||
/// ranking alone. <paramref name="creatureType"/> 0 = unknown (the name keywords decide).
|
||||
/// (<paramref name="learnedBest"/>) ahead of the creature-type ranking, then the
|
||||
/// UtilityBelt damage seed (<paramref name="seeded"/>, best first) ahead of the type
|
||||
/// ranking, then the type ranking alone. <paramref name="creatureType"/> 0 = unknown
|
||||
/// (the name keywords decide).
|
||||
/// </summary>
|
||||
public static Ranking? Rank(uint wcid, string? name, int creatureType, string? learnedBest)
|
||||
/// <param name="seeded">
|
||||
/// 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.
|
||||
/// </param>
|
||||
public static Ranking? Rank(uint wcid, string? name, int creatureType, string? learnedBest,
|
||||
IReadOnlyList<string>? 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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
private static Ranking? SeedRanking(IReadOnlyList<string>? seeded, TypeInfo? type)
|
||||
{
|
||||
if (seeded == null || seeded.Count == 0) return null;
|
||||
var r = new Ranking();
|
||||
var seen = new HashSet<string>(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;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The creature type the world-database table gives this monster (0 = not in it). Same match
|
||||
/// as <see cref="Rank"/>: the wcid's row when its name agrees (or no name is given); no wcid,
|
||||
|
|
|
|||
|
|
@ -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}"); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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).
|
||||
/// </summary>
|
||||
private IReadOnlyList<string>? 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<RynthCore.CreatureSeed.UbMobSeedElement>(ranked);
|
||||
ordered.Sort((a, b) => b.Score.CompareTo(a.Score));
|
||||
var elements = new List<string>(ordered.Count);
|
||||
foreach (var e in ordered) elements.Add(e.Element);
|
||||
return elements;
|
||||
}
|
||||
|
||||
/// <summary>Chat translator survives logout; session language resets on each login.</summary>
|
||||
private void EnsureTranslator()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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<string>();
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue