diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.ScriptHook.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.ScriptHook.cs index 71ce66b..015b297 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.ScriptHook.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/BuffManager.ScriptHook.cs @@ -76,6 +76,9 @@ public partial class BuffManager if (LevelLacksComponents((int)spell)) return $"spell {spell} has no components (refused by the server; RynthAi uses a lower level)"; if (target == player) return null; var cm = _combatManager; + // Monster rule Priority 0 = never attacked: a drain at one is refused too, even when it is + // still the fight target (its rule changed before Think dropped it) or still scanned. + if (cm != null && cm.IsIgnored(unchecked((int)target))) return "the target is ignored (monster rule Priority 0)"; bool listed = cm != null && unchecked((uint)cm.activeTargetId) == target; if (!listed && cm != null) foreach (var t in cm.ScannedTargets) diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.ScriptHook.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.ScriptHook.cs index e0aeda2..d178a14 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.ScriptHook.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.ScriptHook.cs @@ -87,6 +87,10 @@ public partial class CombatManager return $"spell {spell} was refused by the server, parked for {(parked - DateTime.Now).TotalSeconds:0} s more"; uint player = _playerId != 0 ? _playerId : _host.GetPlayerId(); if (castTarget == player) return null; + // Monster rule Priority 0 = IGNORE: not a target for a script either, even one attacking us. + // Checked before the fight-target match: a fight target whose rule changed to 0 is still + // the active target until Think drops it. + if (IsIgnored((int)castTarget)) return "the target is ignored (monster rule Priority 0)"; bool listed = castTarget == unchecked((uint)activeTargetId); for (int i = 0; !listed && i < _scannedTargets.Count; i++) if (unchecked((uint)_scannedTargets[i].Id) == castTarget) listed = true; diff --git a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs index 1bffe3b..5875041 100644 --- a/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs +++ b/Plugins/RynthCore.Plugin.RynthAi/Combat/CombatManager.cs @@ -963,6 +963,13 @@ public partial class CombatManager : IDisposable // Dead but not yet reclassified as corpse — skip if (_worldFilter.GetHealthRatio(wo.Id) == 0f) continue; + // Monster rule Priority 0 = IGNORE, with no exception: even one attacking us is never + // attacked (a monster worth fighting back needs a rule above 0). Left out of the + // scan entirely, so it is neither a target nor a reason to hold nav, + // combat, looting or buffs: every consumer reads this list or _nearbyNoLos, and an + // ignored monster is not counted in either (it is dropped before the LOS check). + if (PriorityOf(wo.Id) <= 0) continue; + bool losBlocked = false; if (_settings.EnableRaycasting && RaycastInitialized && _raycastSystem?.TargetingFSM != null) { @@ -2791,6 +2798,12 @@ public partial class CombatManager : IDisposable if (blacklisted) DropTarget("blacklisted"); + else if (target != null && PriorityOf(activeTargetId) <= 0) + { + // The rule says ignore (it changed, or the rule cache caught up). + ForgetScanned(activeTargetId); + DropTarget("ignored (monster rule Priority 0)"); + } else if (target != null && IsSpellProjectileName(target.Name)) DropTarget("spell projectile (not a monster)"); else if (target != null && (int)target.ObjectClass != (int)AcObjectClass.Monster) @@ -3885,6 +3898,9 @@ public partial class CombatManager : IDisposable return progress != DateTime.MinValue && (now - progress).TotalMilliseconds <= UndamagedCommitmentMaxMs; } + /// True when the monster rule for says Priority 0 (never attacked). + internal bool IsIgnored(int id) => PriorityOf(id) <= 0; + /// The Priority of the monster rule that applies to (its own /// row by name or match expression, else the DEFAULT row; 1 when neither exists). Cached per /// monster for ; the cache empties when the rule list changes. diff --git a/README.md b/README.md index 904d0c4..64f6849 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,17 @@ A combat and navigation assistant for Asheron's Call, ported from the legacy Nex --- +## Monster rules + +Each row of the monster profile (edited in `Tools/RynthCore.MonsterEditor`) applies to the monsters whose name contains the row's Name (and whose Match expression is true, when one is set); the `Default` row applies to the rest. The **P** column is the row's Priority: + +- **Higher Priority is fought first.** When a monster of a higher Priority is in range, lower-priority monsters wait. +- **Priority 0 (or less) means IGNORE.** RynthAi never picks the monster as a target and does not count it as "a monster nearby": it does not hold up navigation, looting, buffing, resting, or the idle peace-mode switch. Use it for monsters that are not worth the time (for example an `Olthoi Grub` row at Priority 0). A `Default` row at 0 ignores every monster no other row names. +- **Priority 0 means never attacked, even if it attacks you.** There is no automatic exception: an ignored monster that hits you is still never targeted. The HP failsafe (Emergency Heal At) still protects you, and you can raise the row's Priority if a monster needs fighting. +- Meta conditions that count monsters by name or distance (`NoMonstersWithinDistance`, `MobsInDist_Priority`, name-count) are explicit conditions you wrote and still see ignored monsters. + +--- + ## Tools Cross-platform Avalonia editors built on the shared LootSdk. These target `net10.0` (no `-windows` suffix) and run on Windows, Linux, and macOS. diff --git a/Tools/RynthCore.MonsterEditor/MainWindow.axaml b/Tools/RynthCore.MonsterEditor/MainWindow.axaml index 5412c54..b029036 100644 --- a/Tools/RynthCore.MonsterEditor/MainWindow.axaml +++ b/Tools/RynthCore.MonsterEditor/MainWindow.axaml @@ -169,14 +169,19 @@ - + + + + - + VerticalAlignment="Center" + ToolTip.Tip="Priority: higher is fought first. 0 = IGNORE: never attacked, even if it attacks you, and it does not hold up nav, looting or buffs."/> - + diff --git a/Tools/RynthCore.MonsterEditor/Models.cs b/Tools/RynthCore.MonsterEditor/Models.cs index c16fa39..1069bf4 100644 --- a/Tools/RynthCore.MonsterEditor/Models.cs +++ b/Tools/RynthCore.MonsterEditor/Models.cs @@ -32,7 +32,12 @@ public class MonsterRule : INotifyPropertyChanged /// Empty = match by name only. Kept and editable here (before 2026-10-05 an editor save /// dropped it, so expression rules fell back to name-only). public string MatchExpression { get => _matchExpression; set { _matchExpression = value ?? ""; OnPropertyChanged(); } } - public int Priority { get => _priority; set { _priority = value; OnPropertyChanged(); } } + /// Target order: a higher Priority is fought first. 0 (or less) means IGNORE: RynthAi never targets the + /// monster, even one attacking the player, and does not wait on it. + public int Priority { get => _priority; set { _priority = value; OnPropertyChanged(); OnPropertyChanged(nameof(PriorityText)); } } + /// What the Priority column shows: the number, or "ign" for Priority 0 (ignore). + [JsonIgnore] + public string PriorityText => _priority <= 0 ? "ign" : _priority.ToString(); public string DamageType { get => _damageType; set { _damageType = value; OnPropertyChanged(); } } public int WeaponId { get => _weaponId; set { _weaponId = value; OnPropertyChanged(); } } public bool Fester { get => _fester; set { _fester = value; OnPropertyChanged(); } } diff --git a/Tools/RynthCore.RynthAiHostTests/Program.cs b/Tools/RynthCore.RynthAiHostTests/Program.cs index 833e88d..2135229 100644 --- a/Tools/RynthCore.RynthAiHostTests/Program.cs +++ b/Tools/RynthCore.RynthAiHostTests/Program.cs @@ -88,6 +88,7 @@ internal static class Program MonsterEditorTests.Register(runner); InstallPathsTests.Register(runner); PetRefillTests.Register(runner); + IgnoreMonsterTests.Register(runner); WorldCacheTypedTests.Register(runner); ItemInfoTests.Register(runner); NavOverlayTests.Register(runner); diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/CombatHookTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/CombatHookTests.cs index 942409b..7139e83 100644 --- a/Tools/RynthCore.RynthAiHostTests/Tests/CombatHookTests.cs +++ b/Tools/RynthCore.RynthAiHostTests/Tests/CombatHookTests.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; using RynthCore.Plugin.RynthAi; @@ -45,6 +46,9 @@ internal static class CombatHookTests r.Add("combat hook: a script attack spell the server refused is rejected next time (RynthAi's bolt instead)", AttackRefusalRemembered); r.Add("combat hook: a script heal the server had no components for is rejected next time (the kit instead)", HealRefusalRemembered); r.Add("combat hook: NOJUDGE keeps no-damage script casts out of the blacklist (without it the target is dropped)", NoJudgeSkipsBlacklist); + r.Add("combat hook: ctx.monsters leaves out a Priority 0 (ignored) monster, even one hitting us", HookScanSkipsIgnored); + r.Add("combat hook: a script answer at an ignored monster is rejected, even one hitting us (RynthAi casts its own)", HookRejectsIgnoredTarget); + r.Add("combat hook: a script heal (a drain) at a fight target whose rule turned to Priority 0 is rejected", HookHealRejectsIgnoredTarget); r.Add("combat hook: a script cast at the fight target is tagged for the Damage tab (element and tier from its spell)", ScriptCastAttribution); r.Add("combat hook: a heal request names the fight target and its health; a nil answer target still heals the player", HealRequestNamesFightTarget); r.Add("combat hook: a refusal after another cast (a heal) or after the script spell landed does not park the script spell", RefusalNotMisattributed); @@ -815,6 +819,103 @@ internal static class CombatHookTests Check.True(FakeHost.Logs.Any(l => l.Contains("rejected (spell " + heal + " has no components")), "logged why"); }); + // Monster rule Priority 0 = never attacked: the hook's view of the fight. + private static List Ignoring(string name) => new() + { + new MonsterRule { Name = "Default", DamageType = "Fire", UseBolt = true }, + new MonsterRule { Name = name, Priority = 0 }, + }; + + private static void Rescan(CombatManager c) + { + typeof(CombatManager).GetField("_lastScanTime", BindingFlags.NonPublic | BindingFlags.Instance)?.SetValue(c, DateTime.MinValue); + c.ScanNearbyTargets(); + } + + /// ctx.monsters as RynthLua gets it: RynthAi.Combat GetScanned (RynthAiPlugin.CombatHookScanned). + private static unsafe uint[] HookScanned(CombatManager c) + { + var plugin = new RynthAiPlugin(); + typeof(RynthAiPlugin).GetField("_combatManager", BindingFlags.NonPublic | BindingFlags.Instance)!.SetValue(plugin, c); + uint* ids = stackalloc uint[16]; + float* dist = stackalloc float[16]; + int n = plugin.CombatHookScanned(ids, dist, 16); + var list = new uint[Math.Min(n, 16)]; + for (int i = 0; i < list.Length; i++) list[i] = ids[i]; + return list; + } + + private static void HookScanSkipsIgnored() => Guard(() => + { + var control = new AttackRig(); + Check.True(HookScanned(control.C).Contains((uint)Other), "control: the Slinker is in ctx.monsters"); + + var rig = new AttackRig(); + rig.S.MonsterRules = Ignoring("Drudge Slinker"); + Rescan(rig.C); + uint[] seen = HookScanned(rig.C); + Check.True(seen.Contains((uint)Target), "the Skulker is in ctx.monsters"); + Check.False(seen.Contains((uint)Other), "the ignored Slinker is not"); + + rig.C.HandleChatForDamage("Drudge Slinker bites you for 3 points of piercing damage!"); + Rescan(rig.C); + Check.False(HookScanned(rig.C).Contains((uint)Other), "hitting us: the ignored Slinker is still not in ctx.monsters"); + }); + + private static void HookRejectsIgnoredTarget() => Guard(() => + { + int drain = Id("Drain Health Other V"); + + // The fight target's rule turned to Priority 0 before Think dropped it: a script answer at + // it (target 0 = the fight target) is rejected, and RynthAi casts its own choice instead. + var rig = new AttackRig(); + rig.S.MonsterRules = Ignoring("Drudge Skulker"); + Claim(Atk); + int rejects = CombatHook.Attack.Rejects; + ScriptCast(rig, drain); + Check.Eq(CombatHook.Attack.Rejects, rejects + 1, "rejected"); + Check.True(FakeHost.Logs.Any(l => l.Contains("the target is ignored (monster rule Priority 0)")), "logged why"); + Check.False(FakeHost.Casts.Any(c => c.SpellId == drain), "the script's drain is not cast"); + Check.Eq(rig.LastCast, "Flame Bolt VI", "RynthAi's own choice goes instead"); + + // Hitting us changes nothing (Priority 0 = never attacked, no exception): still rejected. + var hit = new AttackRig(); + hit.S.MonsterRules = Ignoring("Drudge Skulker"); + hit.C.HandleChatForDamage("Drudge Skulker bites you for 3 points of piercing damage!"); + Claim(Atk); + int rejects2 = CombatHook.Attack.Rejects; + ScriptCast(hit, drain); + Check.Eq(CombatHook.Attack.Rejects, rejects2 + 1, "hitting us: still rejected"); + Check.False(FakeHost.Casts.Any(c => c.SpellId == drain), "hitting us: the script's drain is not cast"); + }); + + private static void HookHealRejectsIgnoredTarget() => Guard(() => + { + int drain = Id("Drain Health Other V"); + + // Control: the same drain at the same fight target with no Priority 0 rule is cast. + var ok = new HealRig(); + ok.C.activeTargetId = Target; + Claim(HealKind); + ok.B.CheckVitals(); + CombatHook.Decide(OpenSeq(HealKind), HealKind, (uint)drain, (uint)Target, 0); + ok.B.CheckVitals(); + Check.Eq(FakeHost.Casts.Single(), ((uint)Target, drain), "control: the drain at the fight target goes out"); + + // The fight target's rule turned to Priority 0 (still locked and scanned): rejected. + var rig = new HealRig(); + rig.C.activeTargetId = Target; + rig.S.MonsterRules = Ignoring("Drudge Skulker"); + Claim(HealKind); + int rejects = CombatHook.Heal.Rejects; + rig.B.CheckVitals(); + CombatHook.Decide(OpenSeq(HealKind), HealKind, (uint)drain, (uint)Target, 0); + rig.B.CheckVitals(); + Check.Eq(CombatHook.Heal.Rejects, rejects + 1, "rejected"); + Check.True(FakeHost.Logs.Any(l => l.Contains("the target is ignored (monster rule Priority 0)")), "logged why"); + Check.False(FakeHost.Casts.Any(c => c.SpellId == drain), "the drain is not cast"); + }); + private static void NoJudgeSkipsBlacklist() => Guard(() => { int drain = Id("Drain Health Other V"); diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/IgnoreMonsterTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/IgnoreMonsterTests.cs new file mode 100644 index 0000000..0101f16 --- /dev/null +++ b/Tools/RynthCore.RynthAiHostTests/Tests/IgnoreMonsterTests.cs @@ -0,0 +1,215 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using RynthCore.Plugin.RynthAi; +using RynthCore.Plugin.RynthAi.LegacyUi; +using RynthCore.RynthAiHostTests.Fakes; +using RynthCore.RynthAiTests.Harness; + +namespace RynthCore.RynthAiHostTests.Tests; + +// Monster rule Priority 0 = IGNORE: never a target, not "a monster +// nearby" for nav / combat / loot / stance, with no exception: an ignored monster attacking the +// player is still never attacked. +internal static class IgnoreMonsterTests +{ + private const uint Player = 0x50000F01; + private const uint Lb = 0xA9B40000; + private const string Grub = "Olthoi Grub", Soldier = "Olthoi Soldier"; + private static readonly BindingFlags Any = BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; + + public static void Register(Runner r) + { + r.Add("monster ignore: a Priority 0 monster is never targeted", NotTargeted); + r.Add("monster ignore: a Priority 0 monster holds nothing up (nav, combat, close-threat gates)", HoldsNothingUp); + r.Add("monster ignore: the kill-shot swap does not count a Priority 0 monster as an alternate", KillShotAlternate); + r.Add("monster ignore: a Priority 0 monster hitting the player is still never targeted", NotTargetedWhenAttackingUs); + r.Add("monster ignore: Priority 1, no rule and the Default row behave as before", UnchangedForOtherPriorities); + } + + private static uint _next; + + private static void Place(uint id, string name, float north) + { + FakeHost.Names[id] = name; + FakeHost.Positions[id] = (Lb | 0x1C, 96f, 96f + north, 0f); + FakeHost.ItemTypes[id] = 0x10; + } + + /// A combat manager with the given monsters (name, metres north) and rules. + private static CombatManager World(List? rules, out List ids, params (string Name, float North)[] mobs) + { + FakeHost.Reset(); + FakeHost.Names[Player] = "Me"; + FakeHost.Positions[Player] = (Lb | 0x1C, 96f, 96f, 0f); + FakeHost.PlayerPose = (Lb | 0x1C, 96f, 96f, 0f); + ids = new List(); + foreach (var (name, north) in mobs) + { + uint id = 0x80000401 + _next++; + Place(id, name, north); + ids.Add(id); + } + var s = new LegacyUiSettings { MonsterRange = 30 }; + if (rules != null) s.MonsterRules = rules; + var host = FakeHost.Create(); + var cache = FakeHost.MakeCache(host, Player, ids); + var c = new CombatManager(host, s, cache); + c.SetPlayerId(Player); + c.SetDamageStores(null, new RynthCore.Plugin.RynthAi.CreatureData.MonsterDamageStore()); + Scan(c); + return c; + } + + private static void Scan(CombatManager c) + { + typeof(CombatManager).GetField("_lastScanTime", Any)?.SetValue(c, DateTime.MinValue); + c.ScanNearbyTargets(); + } + + private static List GrubIgnored(int defaultPriority = 1) => new() + { + new MonsterRule { Name = "Default", Priority = defaultPriority }, + new MonsterRule { Name = Grub, Priority = 0 }, + }; + + private static bool Scanned(CombatManager c, uint id) => c.ScannedTargets.Any(t => (uint)t.Id == id); + + // -- 1. not targeted ------------------------------------------------------- + + private static void NotTargeted() + { + // The grub is closer (3 m) than the soldier (8 m): without the rule it would be picked. + var c = World(GrubIgnored(), out var ids, (Grub, 3f), (Soldier, 8f)); + uint grub = ids[0], soldier = ids[1]; + Check.False(Scanned(c, grub), "the ignored grub is not in the scan list"); + Check.True(Scanned(c, soldier), "the soldier is"); + c.HandleCombatTrigger(); + Check.Eq((uint)c.activeTargetId, soldier, "the soldier is locked, not the nearer grub"); + + // Alone, the grub is not acquired at all. + var lone = World(GrubIgnored(), out var ids2, (Grub, 3f)); + lone.HandleCombatTrigger(); + Check.Eq(lone.activeTargetId, 0, "a lone ignored grub is never locked"); + Check.Eq(lone.ScannedTargets.Count, 0, "and the scan list is empty"); + + // A re-lock: the soldier dies (kill suppression), the next pick must not fall to the grub. + var c2 = World(GrubIgnored(), out var ids3, (Grub, 3f), (Soldier, 8f)); + c2.HandleCombatTrigger(); + Check.Eq((uint)c2.activeTargetId, ids3[1], "locked the soldier"); + c2.OnKillNotification("Olthoi Soldier's perforated corpse falls before you!"); + Scan(c2); + c2.HandleCombatTrigger(); + Check.Eq(c2.activeTargetId, 0, "after the soldier dies the next pick is nothing, not the grub"); + } + + // -- 2. holds nothing up --------------------------------------------------- + + private static void HoldsNothingUp() + { + var c = World(GrubIgnored(), out _, (Grub, 2f)); + Check.False(c.HasTargets, "HasTargets (corpse combat-urgent gates, nav hold)"); + Check.False(c.HasNearbyMonsters, "HasNearbyMonsters (nav hold, clear-the-room gating)"); + Check.False(c.HasEngageableTarget, "HasEngageableTarget (enter/stay in combat, stance switching, arbiter)"); + Check.False(c.IsUnderCloseAttack, "IsUnderCloseAttack"); + Check.False(c.HasCloseThreat(50), "HasCloseThreat (buff and rest gating, loot starvation)"); + Check.False(c.HasCloseThreat(5), "HasCloseThreat at the loot-starve radius"); + + // The control: the same grub with no rule is exactly what held everything up. + var held = World(null, out _, (Grub, 2f)); + Check.True(held.HasTargets && held.HasNearbyMonsters && held.HasEngageableTarget && held.HasCloseThreat(5), + "without the rule the same grub holds all of them"); + } + + // -- 3. kill-shot alternate ------------------------------------------------ + + private static void KillShotAlternate() + { + var c = World(GrubIgnored(), out var ids, (Soldier, 5f), (Grub, 3f)); + c.EngageForTest(unchecked((int)ids[0])); + var alt = typeof(CombatManager).GetMethod("HasAlternateTarget", Any)!; + bool HasAlt() => (bool)alt.Invoke(c, new object[] { unchecked((int)ids[0]) })!; + Check.False(HasAlt(), "the only other monster is an ignored grub: no alternate, keep casting at the soldier"); + + var open = World(null, out var ids2, (Soldier, 5f), (Grub, 3f)); + open.EngageForTest(unchecked((int)ids2[0])); + Check.True((bool)alt.Invoke(open, new object[] { unchecked((int)ids2[0]) })!, "control: an unruled grub is an alternate"); + } + + // -- 4. attacking us: still ignored ---------------------------------------- + + private static void NotTargetedWhenAttackingUs() + { + var c = World(GrubIgnored(), out var ids, (Grub, 3f), (Soldier, 8f)); + foreach (string line in new[] + { + "Olthoi Grub bites you for 3 points of piercing damage!", + "You evaded Olthoi Grub!", + "Olthoi Grub bites you for 4 points of piercing damage!", + }) + { + c.HandleChatForDamage(line); + Scan(c); + c.HandleCombatTrigger(); + Check.False(Scanned(c, ids[0]), $"after '{line}' the grub is still not a candidate"); + Check.Eq((uint)c.activeTargetId, ids[1], $"after '{line}' the soldier (farther) stays the target"); + } + + // Alone and hitting us: never locked, holds nothing. + var lone = World(GrubIgnored(), out _, (Grub, 2f)); + for (int i = 0; i < 5; i++) + { + lone.HandleChatForDamage("Olthoi Grub bites you for 3 points of piercing damage!"); + Scan(lone); + lone.HandleCombatTrigger(); + } + Check.Eq(lone.activeTargetId, 0, "a lone ignored grub hitting us is never locked"); + Check.False(lone.HasEngageableTarget || lone.HasTargets, "and holds nothing up"); + + // Control: the same lines with no rule, the grub (nearer) is the target. + var open = World(null, out var ids2, (Grub, 3f), (Soldier, 8f)); + open.HandleChatForDamage("Olthoi Grub bites you for 3 points of piercing damage!"); + Scan(open); + open.HandleCombatTrigger(); + Check.Eq((uint)open.activeTargetId, ids2[0], "control: an unruled grub is locked"); + } + // -- 5. unchanged ---------------------------------------------------------- + + private static void UnchangedForOtherPriorities() + { + // Priority 1 rule and Default row: targeted, nearest first. + var rules = new List + { + new MonsterRule { Name = "Default", Priority = 1 }, + new MonsterRule { Name = Grub, Priority = 1 }, + }; + var c = World(rules, out var ids, (Soldier, 6f), (Grub, 3f)); + Check.True(Scanned(c, ids[0]) && Scanned(c, ids[1]), "Priority 1 rule and the Default row: both scanned"); + c.HandleCombatTrigger(); + Check.Eq((uint)c.activeTargetId, ids[1], "nearest first, as before"); + + // No rules at all. + var none = World(null, out var ids2, (Soldier, 6f), (Grub, 3f)); + none.HandleCombatTrigger(); + Check.Eq((uint)none.activeTargetId, ids2[1], "no rules: nearest first"); + + // Strict tiers still hold: a Priority 2 soldier beats a nearer Priority 1 grub, which is still a target alone. + var tiers = World(new List + { + new MonsterRule { Name = "Default", Priority = 1 }, + new MonsterRule { Name = Soldier, Priority = 2 }, + }, out var ids3, (Soldier, 9f), (Grub, 3f)); + tiers.HandleCombatTrigger(); + Check.Eq((uint)tiers.activeTargetId, ids3[0], "Priority 2 outranks a nearer Priority 1"); + + // A Default row at 0 ignores monsters no row names, and only those. + var d0 = World(new List + { + new MonsterRule { Name = "Default", Priority = 0 }, + new MonsterRule { Name = Soldier, Priority = 1 }, + }, out var ids4, (Soldier, 9f), (Grub, 3f)); + Check.True(Scanned(d0, ids4[0]), "a named Priority 1 monster is scanned under a Default of 0"); + Check.False(Scanned(d0, ids4[1]), "an unnamed monster takes the Default row: ignored"); + } +} diff --git a/Tools/RynthCore.RynthAiHostTests/Tests/LootCorpseTests.cs b/Tools/RynthCore.RynthAiHostTests/Tests/LootCorpseTests.cs index 47aad8a..369e47a 100644 --- a/Tools/RynthCore.RynthAiHostTests/Tests/LootCorpseTests.cs +++ b/Tools/RynthCore.RynthAiHostTests/Tests/LootCorpseTests.cs @@ -46,6 +46,7 @@ internal static class LootCorpseTests r.Add("loot chain: 'My Kills Only' loots your kill and skips another player's", OwnershipModes); r.Add("loot starvation: a corpse waiting behind far-off combat gets a turn, a close monster keeps combat", LootStarvation); r.Add("loot logging: a corpse held by combat is logged once, with the reason", HeldByCombatLoggedOnce); + r.Add("monster ignore: a close Priority 0 monster neither holds combat nor starves the corpse", IgnoredMonsterDoesNotHoldLoot); r.Add("corpse close: a finished corpse is closed once (CloseContainer, API v76)", FinishedCorpseClosedOnce); r.Add("corpse close: an engine without CloseContainer leaves it to the next open (no close)", FinishedCorpseNotClosedOnOldEngine); r.Add("corpse close: an abandoned open corpse is closed once", AbandonedCorpseClosed); @@ -264,7 +265,7 @@ internal static class LootCorpseTests Check.True(Loot(Other), "All Corpses: anyone's kill is looted"); } - private static Bot StarvationWorld(float monsterMeters, out CombatManager combat) + private static Bot StarvationWorld(float monsterMeters, out CombatManager combat, Action? configure = null) { BaseWorld(corpsePositioned: true); FakeHost.Names[Monster] = "Ancient Water Elemental"; @@ -274,6 +275,7 @@ internal static class LootCorpseTests var bot = new Bot(host); bot.S.EnableCombat = true; bot.S.MonsterRange = 50; + configure?.Invoke(bot.S); bot.Cache.OnCreateObject(Corpse); _ = bot.Cache[unchecked((int)Monster)]; bot.Cache.OnUpdateHealth(Monster, 1f); @@ -328,6 +330,24 @@ internal static class LootCorpseTests Check.Eq(ActivityArbiter.Decide(in buffing), BotActivity.Buffing, "buffing still outranks a starved corpse"); } + private static void IgnoredMonsterDoesNotHoldLoot() + { + // The same close (2 m) Water Elemental that keeps combat in charge above, with its rule at Priority 0. + var bot = StarvationWorld(2f, out var combat, s => s.MonsterRules = new List + { + new MonsterRule { Name = "Default", Priority = 1 }, + new MonsterRule { Name = "Water Elemental", Priority = 0 }, + }); + Check.False(combat.HasTargets, "an ignored monster is not a target"); + Check.False(combat.HasNearbyMonsters, "and not a monster nearby"); + Check.False(combat.HasCloseThreat(RynthAiPlugin.LootStarveCloseYards), "nor a close threat that keeps the starved corpse waiting"); + Check.False(combat.HasEngageableTarget, "combat does not want the tick"); + AgeCorpse(bot, RynthAiPlugin.LootStarveMs + 1000); + Check.True(bot.HasLootWork(), "the corpse is lootable"); + var inputs = new ArbiterInputs(true, false, combat.HasEngageableTarget, true, false, true, combatEngaged: combat.HasEngageableTarget); + Check.Eq(ActivityArbiter.Decide(in inputs), BotActivity.Looting, "so looting has the tick without needing a starved turn"); + } + private static void HeldByCombatLoggedOnce() { var bot = StarvationWorld(15f, out _);