Snapshot for release 2026.10.17.1 (internal 759f36d)

This commit is contained in:
Tom Bohar 2026-10-17 00:41:03 -04:00
commit c7807b6e1c
18 changed files with 1151 additions and 108 deletions

View file

@ -126,6 +126,7 @@ internal static class Program
LootPacingTests.Register(runner);
CorpseCloseTests.Register(runner);
VTankHotkeyTests.Register(runner);
OneTouchHealTests.Register(runner);
SaveFailureTests.Register(runner);
DoorTests.Register(runner);
ServerPolicyTests.Register(runner);

View file

@ -1250,8 +1250,8 @@ internal static class CombatHookTests
RunPacer(own.Host, 3500);
Check.Eq(FakeHost.TapJumps, 0, "control: no jump before the refusal");
RefuseAnother(own.Host);
RunPacer(own.Host, 200);
Check.Eq(FakeHost.TapJumps, 1, "control: a 0x1D past 3 s jumps RynthAi's own cast at once");
RunPacer(own.Host, 600);
Check.Eq(FakeHost.TapJumps, 1, "control: a 0x1D past its cycle + 1 s (4 s) jumps RynthAi's own cast at once");
}
finally { PaceOff(); }

View file

@ -33,6 +33,8 @@ internal static class ManaStoneChoiceTests
r.Add("mana tapping: one item at a time - the stone first, then one item, drained before the next", OneTapItemAtATime);
r.Add("mana tapping: no drain until the pickup is confirmed in the pack", NoDrainBeforeArrival);
r.Add("mana tapping: a drain that never completes keeps the item's place, tries the next stone, then gives up", FailedDrainKeepsPlace);
r.Add("mana tapping: only a stone in the client's pack is used or counted (not one on a corpse, not a stale id)", StoneMustBeInPack);
r.Add("mana tapping: a stone that failed two drains stays parked though it reads empty", FailedStoneStaysParked);
}
private const uint ChargeA = 0x80400031, ChargeB = 0x80400032, ChargeC = 0x80400033;
@ -227,10 +229,11 @@ internal static class ManaStoneChoiceTests
/// <param name="identify">The engine can identify objects (RequestId).</param>
public Rig(bool tapping, (uint Id, int? Mana)[] stones, bool ringToDrain = false,
string stoneName = "Moderate Mana Stone", int maceMana = 0, bool identify = true,
bool ringArrived = true)
bool ringArrived = true, bool contents = false)
{
FakeHost.Reset();
FakeHost.UseOnCalls = true;
FakeHost.ContentsCalls = contents; // the client's pack walk (GetContainerContents)
FakeHost.WeaponCalls = identify; // RequestId, HasAppraisalData
FakeHost.Names[Player] = "Stone Tester";
_stoneName = stoneName;
@ -375,6 +378,38 @@ internal static class ManaStoneChoiceTests
Check.True(FakeHost.Chat.Any(c => c.Contains("would not drain")), "the player is told");
}
// 2026-10-16: Drakkon drained with a Major Mana Stone still on the corpse and with a stone id
// the client no longer knew. The cache files objects without a world position as inventory,
// so both counted as empty stones in the pack: no drain completed and the looter went on
// taking items to tap.
private static void StoneMustBeInPack()
{
using var rig = new Rig(tapping: true, new (uint, int?)[] { (StoneA, 0) }, ringToDrain: true, maceMana: 5000, contents: true);
FakeHost.Containers.Remove(StoneA); // gone from the client's pack; the cache still has it
rig.Run(3000);
Check.Eq(rig.OnRing.Count, 0, "no drain with a stone that is not in the pack");
Check.Eq(rig.M.CountEmptyStones(), 0, "it is not counted as an empty stone");
rig.AddStone(StoneB, 0);
System.Threading.Thread.Sleep(1100); // the cache walks the pack again after 1 s of real time
rig.Run(2000);
Check.Eq(rig.OnRing.Count, 1, "a stone that is in the pack drains the ring");
Check.Eq(rig.OnRing[0], StoneB, "stone B");
}
// 2026-10-16: the 30-minute park after a stone's second failed drain was undone on the next
// think tick because the stone reads empty: one stone failed 36 drains in a row.
private static void FailedStoneStaysParked()
{
using var rig = new Rig(tapping: true, new (uint, int?)[] { (StoneA, 0) }, ringToDrain: true, maceMana: 5000, contents: true);
rig.Run(1000);
Check.Eq(rig.OnRing.Count, 1, "first try");
rig.Run(9000 + 21_000);
Check.Eq(rig.OnRing.Count, 2, "second try, the same (only) stone");
rig.Run(9000 + 60_000);
Check.Eq(rig.OnRing.Count, 2, "failed twice: the stone stays parked though it reads empty");
Check.Eq(rig.M.CountEmptyStones(), 0, "and no item is looted for it");
}
private static void KnownChargedRefills()
{
using var rig = new Rig(tapping: true, new (uint, int?)[] { (StoneA, null), (StoneB, null) }, ringToDrain: true);

View file

@ -37,6 +37,8 @@ internal static class OffhandTests
r.Add("swap speed: a weapon in hand -> one use of the wand (the client swaps); the pack move only as the fallback", CasterDirectSwap);
r.Add("swap speed: the gate lets the next step go once the server is done, else after 3 s", SwapGateSettles);
r.Add("offhand: dual wield with the Dual Wield skill", DualWield);
r.Add("offhand: the weapon in hand is the main hand's when the wielded slot reads 0 (the weenie's wielder record)", InHandFromWielderInfo);
r.Add("weapons: a weapon refused 'skill too low' is left out of the choice (the off hand stays)", SkillTooLowLeftOut);
r.Add("offhand: no Dual Wield skill -> the shield", NoSkillShield);
r.Add("offhand: None -> hands off (a worn shield is never taken off)", NoneHandsOff);
r.Add("offhand: an unlisted shield is never wielded", UnlistedNeverUsed);
@ -118,10 +120,12 @@ internal static class OffhandTests
private readonly MethodInfo _equip = typeof(CombatManager).GetMethod("EquipWeaponAndSetStance", BindingFlags.Instance | BindingFlags.NonPublic)!;
private readonly FieldInfo _lastEquip = typeof(CombatManager).GetField("_lastEquipTime", BindingFlags.Instance | BindingFlags.NonPublic)!;
public Rig(bool dualWieldSkill = false, bool shieldOn = false, bool wieldCalls = true)
public Rig(bool dualWieldSkill = false, bool shieldOn = false, bool wieldCalls = true, bool wielderInfo = false, bool weenieErrors = false)
{
FakeHost.Reset();
FakeHost.WeaponCalls = true;
FakeHost.SalvageCalls = wielderInfo; // GetObjectWielderInfo (answering FakeHost.Wielded)
FakeHost.WeenieErrorCalls = weenieErrors;
FakeHost.WieldCalls = wieldCalls;
FakeHost.CombatModeValue = CombatMode.Melee;
Item(Sword, "Long Sword", 0x1, MeleeSlot, combatUse: 1);
@ -138,7 +142,7 @@ internal static class OffhandTests
if (shieldOn) Wield(Shield, ShieldSlot);
FakeHost.Wcids[Monster] = Wcid;
FakeHost.Skills[(Player, 49)] = dualWieldSkill ? (220, 2) : (10, 1);
var host = FakeHost.Create();
var host = FakeHost.Create(wielderInfo ? Player : 0);
var cache = FakeHost.MakeCache(host, Player, new[] { Sword, Dagger, Great, Shield, Round, Bow, Arrows, Wand });
C = new CombatManager(host, S, cache);
C.SetPlayerId(Player);
@ -427,6 +431,41 @@ internal static class OffhandTests
Check.Eq(rig2.ShieldWields(Dagger), 1, "Monsters rule 'Offhand weapon': the dagger");
}
// 2026-10-16: Drakkon dual wielding two Hand Wraps; CurrentWieldedLocation read 0, so both
// counted as in hand and the later listed one (the off hand's) was taken for the main weapon.
private static void InHandFromWielderInfo()
{
var rig = new Rig(dualWieldSkill: true, wielderInfo: true);
rig.List(Sword, Dagger);
Rig.Unwield(Sword); // the slot reads 0 for both
FakeHost.Wielded[Sword] = (uint)MeleeSlot;
FakeHost.Wielded[Dagger] = (uint)ShieldSlot;
rig.C.InHandOverride = null;
Check.Eq(unchecked((uint)rig.C.InHandWeaponId(fresh: true)), Sword, "the main hand: the sword, not the off-hand dagger");
Check.Eq(unchecked((uint)rig.C.OffhandInSlot(fresh: true)), Dagger, "the off hand: the dagger");
}
// 2026-10-16: a Nodachi the character lacked the skill for was chosen whenever a monster was
// weak to Slash: refused three times, then again two minutes later, the off hand dequipped each time.
private static void SkillTooLowLeftOut()
{
var rig = new Rig(dualWieldSkill: true, weenieErrors: true);
rig.List(Sword, Great);
rig.Store.SetManualWeapon(Wcid, Great);
rig.Tick();
Check.True(FakeHost.Uses.Contains(Great), "the greatsword's wield goes out");
FakeHost.WeenieError(CombatManager.SkillTooLowErr, 0x00A0, Great);
rig.Unpace();
rig.Tick();
Check.True(rig.C.SkillTooLowFor(unchecked((int)Great)), "refused 'skill too low': left out");
Check.True(FakeHost.Logs.Any(l => l.Contains("skill is too low to wield it")), "logged");
Check.True(FakeHost.Chat.Any(c => c.Contains("skill is too low")), "the player is told");
int uses = FakeHost.Uses.Count(u => u == Great);
for (int i = 0; i < 5; i++) { rig.Unpace(); rig.Tick(); }
Check.Eq(FakeHost.Uses.Count(u => u == Great), uses, "never sent again");
Check.False(rig.C.ListedCandidates().Any(c => c.Id == unchecked((int)Great)), "not a candidate");
}
private static void NoSkillShield()
{
var rig = new Rig(dualWieldSkill: false);

View file

@ -0,0 +1,327 @@
using System;
using System.Linq;
using System.Reflection;
using System.Threading;
using RynthCore.Plugin.RynthAi;
using RynthCore.Plugin.RynthAi.LegacyUi;
using RynthCore.Plugin.Shared;
using RynthCore.PluginCore;
using RynthCore.PluginSdk;
using RynthCore.RynthAiHostTests.Fakes;
using RynthCore.RynthAiTests.Harness;
namespace RynthCore.RynthAiHostTests.Tests;
// One-touch heal / stamina / mana (BuffManager.OneTouch.cs; /ra heal, /ra stam, /ra mana, and RynthCore's
// "One-touch" hotkeys): one request uses the best kit, spell or potion for that vital now, whatever
// the Heal At / Top Off lines say, with the macro off. The choice is the vitals step's own
// (AttemptHealChain, AttemptStaminaChain, AttemptManaRefill), so these tests check the order and the
// waiting, not the individual attempts (VitalsTests, RecoveryRetryTests, ...).
internal static class OneTouchHealTests
{
private const uint Player = 0x50000C01;
private const uint Kit = 0x80004C01, StamKit = 0x80004C02, HealPotion = 0x80004C03, StamPotion = 0x80004C04;
private const uint STypeLife = 33;
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
public static void Register(Runner r)
{
r.Add("one-touch: a vital that is full says so and sends nothing", FullSaysSo);
r.Add("one-touch: heal ignores the lines and casts Heal Self in Magic stance, macro off", HealCastsInMagic);
r.Add("one-touch: heal with a weapon out takes the kit, then the potion, before the spell (no wand swap)", HealItemsBeforeSpellInMelee);
r.Add("one-touch: heal in Magic stance keeps the vitals step's order: Heal Self before the potion", HealSpellBeforePotionInMagic);
r.Add("one-touch: heal falls to Stamina to Health only when that feature is on and stamina is over its floor", HealStaminaToHealthLast);
r.Add("one-touch: with nothing to heal with it says why for the kit, the spell and the potion", HealNothingSaysWhy);
r.Add("one-touch: a request waits out a kit in flight, then goes; a second press while waiting is not a second heal", HealWaitsForKit);
r.Add("one-touch: a request that stays blocked gives up after OneTouchWaitMs and says why", HealGivesUp);
r.Add("one-touch: stamina takes a stamina kit, a listed potion out of Magic stance, else Revitalize", StaminaChoice);
r.Add("one-touch: mana casts Stamina to Mana; with stamina at the floor it refills stamina first", ManaChoice);
r.Add("one-touch: /ra heal, /ra stam and /ra mana request a pass (and say so before login)", Commands);
}
private sealed class Rig
{
public BuffManager B = null!;
public LegacyUiSettings S = null!;
public PlayerVitalsCache V = null!;
public RynthCoreHost Host;
}
/// <summary>A character with every spell known, Life Magic trained, the macro off and every line at 0 (so no
/// vitals step would act): the one-touch request is the only thing that can.</summary>
private static Rig Make(int mode, uint hp = 40, uint st = 100, uint mn = 100, bool spells = true, bool kit = false,
bool stamKit = false, bool healPotion = false, bool stamPotion = false, byte lifeTraining = 2, Action<LegacyUiSettings>? tweak = null)
{
FakeHost.Reset();
FakeHost.WeaponCalls = true;
FakeHost.UseOnCalls = true;
FakeHost.CombatModeValue = mode;
if (spells) foreach (var row in SpellTable.Rows) FakeHost.Spellbook.Add((uint)row.Id);
FakeHost.Skills[(Player, STypeLife)] = (400, lifeTraining);
var ids = new System.Collections.Generic.List<uint>();
if (kit) { FakeHost.Names[Kit] = "Peerless Healing Kit"; ids.Add(Kit); }
if (stamKit) { FakeHost.Names[StamKit] = "Greater Stamina Kit"; ids.Add(StamKit); }
if (healPotion) { FakeHost.Names[HealPotion] = "Health Tincture"; ids.Add(HealPotion); }
if (stamPotion) { FakeHost.Names[StamPotion] = "Stamina Tincture"; ids.Add(StamPotion); }
var host = FakeHost.Create(Player);
var s = new LegacyUiSettings
{
IsMacroRunning = false, HealAt = 0, TopOffHP = 0, EmergencyHealAt = 0, StaminaToHealthAt = 0,
RestamAt = 0, TopOffStam = 0, GetManaAt = 0, TopOffMana = 0, UsePotions = healPotion || stamPotion,
KitMinSuccessPct = 0, PeaceModeForKits = false, UseKitsInMagicMode = true, EnableBuffing = false,
};
if (healPotion) s.ConsumableRules.Add(new ConsumableRule { Id = unchecked((int)HealPotion), Name = "Health Tincture", Type = "HealthPotion" });
if (stamPotion) s.ConsumableRules.Add(new ConsumableRule { Id = unchecked((int)StamPotion), Name = "Stamina Tincture", Type = "Stamina" });
tweak?.Invoke(s);
var skills = new CharacterSkills(host);
skills.SetPlayerId(Player);
var sm = new SpellManager(host, s);
sm.InitializeNatively();
sm.SetCharacterSkills(skills);
var v = new PlayerVitalsCache { MaxHealth = 100, CurrentHealth = hp, MaxStamina = 100, CurrentStamina = st, MaxMana = 100, CurrentMana = mn };
var b = new BuffManager(host, s, sm, v);
b.SetCharacterSkills(skills);
b.SetWorldObjectCache(FakeHost.MakeCache(host, Player, ids));
ActionPacer.Reset();
return new Rig { B = b, S = s, V = v, Host = host };
}
/// <summary>Heartbeats until the request is taken (or 400 ms): what the pump does after the command.</summary>
private static void Pump(BuffManager b, OneTouchVital v)
{
for (int i = 0; i < 40 && b.OneTouchPending(v); i++) { b.OnHeartbeat(); Thread.Sleep(10); }
}
private static bool Said(string part) => FakeHost.Chat.Any(c => c.Contains(part, StringComparison.Ordinal));
private static string AllChat => string.Join(" | ", FakeHost.Chat);
/// <summary>The cast spell is a level of the family of <paramref name="levelOne"/> (top levels have names of their own).</summary>
private static bool IsFamily(int spellId, string levelOne) =>
SpellTableStub.GetById(spellId)?.Family == SpellTableStub.GetById(SpellTable.Rows.First(r => r.Name == levelOne).Id)?.Family;
private static void FullSaysSo()
{
var r = Make(CombatMode.Magic, hp: 100, st: 100, mn: 100);
foreach (var v in new[] { OneTouchVital.Health, OneTouchVital.Stamina, OneTouchVital.Mana })
{
r.B.RequestOneTouch(v);
Check.True(r.B.OneTouchPending(v), v + ": pending until a heartbeat");
Pump(r.B, v);
Check.False(r.B.OneTouchPending(v), v + ": taken");
}
Check.Eq(FakeHost.Casts.Count, 0, "nothing cast");
Check.Eq(FakeHost.UsesOn.Count + FakeHost.Uses.Count, 0, "nothing used");
Check.True(Said("Heal: health is full") && Said("Stamina: stamina is full") && Said("Mana: mana is full"), AllChat);
}
private static void HealCastsInMagic()
{
// 95% health: over Heal At and Top Off HP (both 0 here, and 90 in a real setup): no vitals step would act.
var r = Make(CombatMode.Magic, hp: 95);
Check.False(r.B.CheckVitals(), "the normal step does nothing at 95%");
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.Eq(FakeHost.Casts.Count, 1, "one cast");
Check.True(IsFamily(FakeHost.Casts[0].SpellId, "Heal Self I"), "a Heal Self (the top level known)");
Check.True(Said("Heal: casting "), AllChat);
Check.False(r.S.IsMacroRunning, "the macro stayed off");
}
private static void HealItemsBeforeSpellInMelee()
{
// Melee, kit and potion and every spell: the kit goes, no cast (the wand swap is seconds).
var r = Make(CombatMode.Melee, hp: 60, kit: true, healPotion: true);
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.True(FakeHost.UsesOn.Any(u => u.Source == Kit && u.Target == Player), "the kit is used on yourself");
Check.Eq(FakeHost.Casts.Count, 0, "no cast");
Check.False(FakeHost.Uses.Contains(HealPotion), "and no potion on top of it");
Check.True(Said("Heal: using a healing kit"), AllChat);
// No kit: the potion, still before the spell.
r = Make(CombatMode.Melee, hp: 60, healPotion: true);
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.True(FakeHost.Uses.Contains(HealPotion), "melee, no kit: the potion is drunk");
Check.Eq(FakeHost.Casts.Count, 0, "melee: no Heal Self (a wand swap) while a potion can do it");
Check.True(Said("Heal: drinking a potion"), AllChat);
// Neither: the spell (the wand swap / Magic stance steps are the vitals step's).
r = Make(CombatMode.Melee, hp: 60);
r.B.RequestOneTouch(OneTouchVital.Health);
for (int i = 0; i < 40 && r.B.OneTouchPending(OneTouchVital.Health) && FakeHost.Casts.Count == 0; i++) { r.B.OnHeartbeat(); Thread.Sleep(10); }
// Either the cast went out or a stance step is in flight (still pending); never a "nothing could heal".
Check.False(Said("nothing could heal"), "a spell is possible: " + AllChat);
}
private static void HealSpellBeforePotionInMagic()
{
var r = Make(CombatMode.Magic, hp: 60, healPotion: true);
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.Eq(FakeHost.Casts.Count, 1, "Magic stance: the spell, as the vitals step does");
Check.False(FakeHost.Uses.Contains(HealPotion), "the potion is the fallback, not the first choice");
// A kit still goes before the spell when kits are allowed in Magic mode (the step's own order) ...
r = Make(CombatMode.Magic, hp: 60, kit: true);
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.True(FakeHost.UsesOn.Any(u => u.Source == Kit), "Use Kits in Magic Mode on: the kit first");
Check.Eq(FakeHost.Casts.Count, 0, "and no cast on top of it");
// ... and not when they are not.
r = Make(CombatMode.Magic, hp: 60, kit: true, tweak: s => s.UseKitsInMagicMode = false);
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.Eq(FakeHost.UsesOn.Count, 0, "Use Kits in Magic Mode off: no kit");
Check.Eq(FakeHost.Casts.Count, 1, "the spell instead");
}
private static void HealStaminaToHealthLast()
{
// Only Stamina to Health Self is known: used when the feature is on and stamina is over its floor.
static Rig OnlyStamToHealth(uint stamina, int at)
{
var r = Make(CombatMode.Magic, hp: 70, st: stamina, spells: false, tweak: s => { s.StaminaToHealthAt = at; s.StaminaToHealthMinStamina = 20; });
foreach (var row in SpellTable.Rows.Where(x => x.Name.StartsWith("Stamina to Health Self"))) FakeHost.Spellbook.Add((uint)row.Id);
return r;
}
var r = OnlyStamToHealth(80, 30);
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.Eq(FakeHost.Casts.Count, 1, "Stamina to Health Self is cast");
Check.True(IsFamily(FakeHost.Casts[0].SpellId, "Stamina to Health Self I"), "Stamina to Health Self");
r = OnlyStamToHealth(10, 30);
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.Eq(FakeHost.Casts.Count, 0, "stamina under its floor: not cast");
Check.True(Said("stamina 10% is not over 20%"), AllChat);
r = OnlyStamToHealth(80, 0);
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.Eq(FakeHost.Casts.Count, 0, "Stamina To Health At 0 (off): not cast");
Check.True(Said("Stamina to Health: not on"), AllChat);
}
private static void HealNothingSaysWhy()
{
var r = Make(CombatMode.Magic, hp: 40, lifeTraining: 1); // Life Magic untrained
r.B.RequestOneTouch(OneTouchVital.Health);
Pump(r.B, OneTouchVital.Health);
Check.Eq(FakeHost.Casts.Count + FakeHost.UsesOn.Count + FakeHost.Uses.Count, 0, "nothing sent");
Check.True(Said("Heal: nothing could heal (health 40%"), AllChat);
Check.True(Said("kit: no healing kit") && Said("Heal Self: Life Magic not usable") && Said("potion: Use Potions is off"), AllChat);
Check.False(r.B.OneTouchPending(OneTouchVital.Health), "and the request is over");
}
private static void HealWaitsForKit()
{
var r = Make(CombatMode.Magic, hp: 40);
r.B.MarkKitUsed(); // a kit went out a moment ago and its result hasn't come
r.B.RequestOneTouch(OneTouchVital.Health);
r.B.RequestOneTouch(OneTouchVital.Health); // pressed again: still one request
for (int i = 0; i < 10; i++) { r.B.OnHeartbeat(); Thread.Sleep(10); }
Check.True(r.B.OneTouchPending(OneTouchVital.Health), "waiting for the kit");
Check.Eq(FakeHost.Casts.Count, 0, "nothing cast meanwhile");
r.B.OnChatWindowText("You heal yourself for 30 Health points.", 0);
Thread.Sleep(800); // the vitals' grace after the result line
Pump(r.B, OneTouchVital.Health);
Check.False(r.B.OneTouchPending(OneTouchVital.Health), "taken once the kit is done");
Check.Eq(FakeHost.Casts.Count, 1, "one heal, not two");
Check.Eq(FakeHost.Chat.Count(c => c.StartsWith("[RynthAi] Heal:")), 1, "said once: " + AllChat);
}
private static void HealGivesUp()
{
var r = Make(CombatMode.Magic, hp: 40);
r.B.MarkKitUsed();
r.B.RequestOneTouch(OneTouchVital.Health);
// Make the request old, as if it had been waiting OneTouchWaitMs.
var at = (long[])typeof(BuffManager).GetField("_oneTouchAt", Any)!.GetValue(r.B)!;
at[(int)OneTouchVital.Health] = Environment.TickCount64 - BuffManager.OneTouchWaitMs - 100;
r.B.OnHeartbeat();
Check.False(r.B.OneTouchPending(OneTouchVital.Health), "given up");
Check.True(Said("Heal: not done, the character stayed busy (a kit is in flight)"), AllChat);
Check.Eq(FakeHost.Casts.Count, 0, "nothing cast");
}
private static void StaminaChoice()
{
// A stamina kit first.
var r = Make(CombatMode.Magic, st: 40, stamKit: true);
r.B.RequestOneTouch(OneTouchVital.Stamina);
Pump(r.B, OneTouchVital.Stamina);
Check.True(FakeHost.UsesOn.Any(u => u.Source == StamKit && u.Target == Player), "the stamina kit is used");
Check.Eq(FakeHost.Casts.Count, 0, "no Revitalize");
Check.True(Said("Stamina: using a stamina kit"), AllChat);
// Melee with a listed potion and no kit: the potion, not Revitalize (a wand swap).
r = Make(CombatMode.Melee, st: 40, stamPotion: true);
r.B.RequestOneTouch(OneTouchVital.Stamina);
Pump(r.B, OneTouchVital.Stamina);
Check.True(FakeHost.Uses.Contains(StamPotion), "melee: the stamina potion");
Check.Eq(FakeHost.Casts.Count, 0, "melee: no Revitalize");
// Magic stance, nothing else: Revitalize.
r = Make(CombatMode.Magic, st: 40);
r.B.RequestOneTouch(OneTouchVital.Stamina);
Pump(r.B, OneTouchVital.Stamina);
Check.Eq(FakeHost.Casts.Count, 1, "Revitalize Self");
Check.True(IsFamily(FakeHost.Casts[0].SpellId, "Revitalize Self I"), "Revitalize Self");
}
private static void ManaChoice()
{
var r = Make(CombatMode.Magic, st: 100, mn: 20);
r.B.RequestOneTouch(OneTouchVital.Mana);
Pump(r.B, OneTouchVital.Mana);
Check.Eq(FakeHost.Casts.Count, 1, "one cast");
Check.True(IsFamily(FakeHost.Casts[0].SpellId, "Stamina to Mana Self I"), "Stamina to Mana Self");
Check.True(Said("Mana: casting "), AllChat);
// Stamina at the floor: a stamina kit first, so Stamina to Mana has something to spend.
r = Make(CombatMode.Magic, st: 10, mn: 20, stamKit: true);
r.B.RequestOneTouch(OneTouchVital.Mana);
Pump(r.B, OneTouchVital.Mana);
Check.True(FakeHost.UsesOn.Any(u => u.Source == StamKit), "stamina kit first");
Check.Eq(FakeHost.Casts.Count, 0, "no Stamina to Mana yet");
Check.True(Said("stamina first, for Stamina to Mana"), AllChat);
}
private static void Commands()
{
var r = Make(CombatMode.Magic, hp: 40);
var p = new RynthAiPlugin();
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(p, new object[] { FakeHost.LastApi });
typeof(RynthAiPlugin).GetField("_buffManager", Any)!.SetValue(p, r.B);
void Ra(string line)
{
string[] parts = line.Split(' ', StringSplitOptions.RemoveEmptyEntries);
typeof(RynthAiPlugin).GetMethod("DispatchRaCommand", Any)!.Invoke(p, new object[] { parts[1].ToLowerInvariant(), parts, 0 });
}
foreach (var (line, vital) in new[]
{
("/ra heal", OneTouchVital.Health), ("/ra stam", OneTouchVital.Stamina), ("/ra mana", OneTouchVital.Mana),
("/ra stamina", OneTouchVital.Stamina), ("/ra healme", OneTouchVital.Health),
})
{
Ra(line);
Check.True(r.B.OneTouchPending(vital), line + " requests " + vital);
r.B.RequestOneTouch(vital);
// Drain it without a heartbeat: the requests are plain flags.
var at = (long[])typeof(BuffManager).GetField("_oneTouchAt", Any)!.GetValue(r.B)!;
at[(int)vital] = 0;
}
// Before login there is no buff manager: said, not thrown.
typeof(RynthAiPlugin).GetField("_buffManager", Any)!.SetValue(p, null);
FakeHost.Chat.Clear();
Ra("/ra heal");
Check.True(Said("Buff manager not ready"), AllChat);
}
}

View file

@ -23,9 +23,10 @@ internal static class StuckCastTests
{
r.Add("stuck cast: after a 'too busy' UseDone nothing starts until the server answers; no timer re-send while our cast is open", NoResendAfterTooBusy);
r.Add("stuck cast: with no cast of ours open, one probe after 1.5 s, then doubling; a UseDone(0) clears", ProbeWhenNothingOpen);
r.Add("stuck cast: a held cast is turned to its target at cycle + 1 s, broken by a jump at cycle + 2 s; a normal 4 s cast trips neither", TurnThenJump);
r.Add("stuck cast: a held cast is turned to its target at cycle + 1 s, broken by a jump TurnGraceMs after the turn; a normal 4 s cast trips neither", TurnThenJump);
r.Add("stuck cast: already facing the target (no turn), the jump is at cycle + 2 s", JumpWithoutTurn);
r.Add("stuck cast: no starts in the air; after landing, no UseDone in 3 s -> Peace mode, 3 s more -> going on", AfterTheJump);
r.Add("stuck cast: a 'too busy' answer while our cast is open past 3 s breaks it at once; before 3 s it does not", RefusalWhileOpen);
r.Add("stuck cast: a 'too busy' answer while our cast is open past its cycle + 1 s (and 3 s) breaks it at once; before, it does not", RefusalWhileOpen);
r.Add("stuck cast: StuckCastMs 0 turns nothing and breaks nothing; no TapJump -> Peace mode", BreakerOffAndNoJump);
r.Add("move settle: no start in the tick of a movement change; 150 ms and a clear motion queue (or 600 ms) let it go", MoveSettle);
r.Add("stuck cast: the HP failsafe's forced break jumps once and holds starts until landed", ForcedBreak);
@ -46,8 +47,8 @@ internal static class StuckCastTests
FakeHost.Names[Player] = "Mira";
FakeHost.PlayerPose = Me0;
FakeHost.Positions[Player] = Me0;
FakeHost.HeadingDeg = 0; // facing north
FakeHost.Positions[Monster] = (Me0.Cell, Me0.X + 10f, Me0.Y, Me0.Z); // due east: 90 deg off
FakeHost.HeadingDeg = 90; // facing east: no held-cast turn (TurnThenJump faces north)
FakeHost.Positions[Monster] = (Me0.Cell, Me0.X + 10f, Me0.Y, Me0.Z); // due east
var host = FakeHost.Create(Player);
_t = 90_000_000;
ActionPacer.Reset();
@ -197,7 +198,8 @@ internal static class StuckCastTests
Check.Eq(FakeHost.Turns + FakeHost.TapJumps + FakeHost.CombatModeRequests.Count, 0, "a normal 4 s cast: no turn, no jump, no mode change");
Check.Eq(ActionPacer.NormalCycleMs(DrainHealthOtherI), 4000L, "the cycle learned from it");
// The next one is held open: turn at 4 + 1 s, jump at 4 + 2 s.
// The next one is held open, facing north (90 deg off): turn at 4 + 1 s, jump TurnGraceMs later.
FakeHost.HeadingDeg = 0;
Cast(host);
long sent = _t;
while (_t - sent < 4900) { _t += 100; May(host); }
@ -206,11 +208,12 @@ internal static class StuckCastTests
Check.Eq(FakeHost.Turns, 1, "turned at cycle + 1 s");
Check.Near(FakeHost.HeadingDeg, 90.0, 0.5, "to face the target (east)");
Check.True(FakeHost.Logs.Any(l => l.Contains("held cast:") && l.Contains("turning 90 deg to face 0x80116781")), "logged");
while (_t - sent < 5900) { _t += 100; Check.False(May(host), "held"); }
Check.Eq(FakeHost.TapJumps, 0, "no jump before cycle + 2 s");
// 2026-10-16: the jump came 1 s after a 91 deg turn, 0.2 s before the cast's answer.
while (_t - sent < 5000 + ActionPacer.TurnGraceMs - 100) { _t += 100; Check.False(May(host), "held"); }
Check.Eq(FakeHost.TapJumps, 0, "no jump while the turn has its time (cycle + 2 s is past)");
_t += 100; May(host);
Check.Eq(FakeHost.TapJumps, 1, "the breaker jump at cycle + 2 s");
Check.True(FakeHost.Logs.Any(l => l.Contains("[Pace] stuck cast broken by jump after 6000 ms")), "logged with the time");
Check.Eq(FakeHost.TapJumps, 1, "the breaker jump TurnGraceMs after the turn");
Check.True(FakeHost.Logs.Any(l => l.Contains($"[Pace] stuck cast broken by jump after {5000 + ActionPacer.TurnGraceMs} ms")), "logged with the time");
Run(host, 2000);
Check.Eq(FakeHost.TapJumps, 1, "one jump");
Check.Eq(FakeHost.Turns, 1, "one turn");
@ -222,6 +225,22 @@ internal static class StuckCastTests
finally { Done(); }
}
private static void JumpWithoutTurn()
{
var host = Setup();
try
{
// Facing the monster (Setup): no turn goes out.
Check.True(May(host), "free");
Cast(host);
long sent = _t;
while (FakeHost.TapJumps == 0 && _t - sent < 10_000) { _t += 100; May(host); }
Check.Eq(FakeHost.Turns, 0, "no turn");
Check.Eq(_t - sent, ActionPacer.DefaultCycleMs + ActionPacer.JumpAfterMs, "the jump at cycle + 2 s");
}
finally { Done(); }
}
private static void AfterTheJump()
{
var host = Setup();
@ -279,7 +298,9 @@ internal static class StuckCastTests
_t += 100; May(host);
Check.Eq(FakeHost.TapJumps, 0, "a 0x1D at 2 s: no jump");
_t += 900; May(host);
Check.Eq(FakeHost.TapJumps, 1, "past RefusalBreakMinMs with a 0x1D in: jump at once (before cycle + 2 s)");
Check.Eq(FakeHost.TapJumps, 0, "3 s with a 0x1D in, not yet RefusalPastCycleMs past its cycle: no jump (it may have landed, its UseDone due)");
_t += ActionPacer.RefusalPastCycleMs; May(host);
Check.Eq(FakeHost.TapJumps, 1, "past cycle + 1 s with a 0x1D in: jump at once (before cycle + 2 s)");
Check.True(FakeHost.Logs.Any(l => l.Contains("was refused 'too busy' while it was open")), "the reason is logged");
}
finally { Done(); }

View file

@ -36,6 +36,10 @@ internal static class WeaponTests
r.Add("element choice: a matching rending wins for its element", ChoiceRending);
r.Add("element choice: a wand always casts its own element (rule, Damage tab, no match)", ChoiceWandCastsOwn);
r.Add("element choice: elements the character can't cast are skipped", ChoiceCastable);
r.Add("preferred damage: Melee/Missile/War/Void picks the pool; Auto keeps the first listed kind", PreferredPicksPool);
r.Add("preferred damage: War never casts Nether, Void nothing else; an unusable preference falls back to Auto", PreferredSchools);
r.Add("preferred damage: other-kind slayers, the Default row's weapon and the rule's element obey it; the monster's own pick doesn't", PreferredVsOtherSteps);
r.Add("preferred damage: names parse tolerantly; a new rule is Auto", PreferredParse);
r.Add("slayer: beats the weakness and the Monsters rule's damage type", SlayerBeatsWeaknessAndRule);
r.Add("slayer: only this monster's own Damage tab weapon beats it, not the DEFAULT row's", SlayerVsDamageTab);
r.Add("slayer (owner's rule 2026-10-05): a Slash slayer beats a Pierce weapon the monster is weaker to", SlayerBeatsLowerResist);
@ -231,6 +235,116 @@ internal static class WeaponTests
private static bool All(string e) => true;
private static WeaponCandidate Weapon(int id, int kind, string elem = "", bool inHand = false)
=> new(id, "Weapon " + id, kind, elem, "", inHand);
private static void PreferredPicksPool()
{
// A sword listed first, a bow, a fire wand and a nether wand: Auto fights with the first kind (melee).
var list = new List<WeaponCandidate>
{
Weapon(1, CombatMode.Melee, "Slash"), Weapon(2, CombatMode.Missile, "Pierce"),
Weapon(3, CombatMode.Magic, "Fire"), Weapon(4, CombatMode.Magic, "Nether"),
};
var weak = Rank(("Fire", 1.5), ("Nether", 1.4), ("Slash", 1.0), ("Pierce", 1.0));
Check.Eq(WeaponPlanner.Choose(list, "", weak, All).WeaponId, 1, "Auto: the first listed kind (melee), the Slash sword");
Check.Eq(WeaponPlanner.Choose(list, "", weak, All, preferredDamage: "Auto").WeaponId, 1, "Auto spelled out");
var melee = WeaponPlanner.Choose(list, "", weak, All, preferredDamage: "Melee");
Check.Eq(melee.WeaponId, 1, "Melee: the sword");
Check.True(melee.Source.EndsWith("prefers Melee"), "Melee: the source says why (" + melee.Source + ")");
var missile = WeaponPlanner.Choose(list, "", weak, All, preferredDamage: "Missile");
Check.Eq(missile.WeaponId, 2, "Missile: the bow, though the monster is weaker to Fire and Nether");
var war = WeaponPlanner.Choose(list, "", weak, All, preferredDamage: "War Magic");
Check.Eq(war.WeaponId, 3, "War Magic: the fire wand");
Check.Eq(war.Element, "Fire", "casting Fire");
var voidP = WeaponPlanner.Choose(list, "", weak, All, preferredDamage: "Void Magic");
Check.Eq(voidP.WeaponId, 4, "Void Magic: the nether wand");
Check.Eq(voidP.Element, "Nether", "casting Nether");
// Weakness unknown: the weapon in hand within the pool, else the first of the pool.
var hand = new List<WeaponCandidate>
{
Weapon(1, CombatMode.Melee, "Slash", inHand: true), Weapon(2, CombatMode.Magic, "Fire"), Weapon(3, CombatMode.Magic, "Cold"),
};
Check.Eq(WeaponPlanner.Choose(hand, "", null, All, preferredDamage: "War Magic").WeaponId, 2, "unknown weakness: the first War wand, not the sword in hand");
}
private static void PreferredSchools()
{
// A wand with no element: War casts the weakest non-Nether element, Void casts Nether.
var plain = new List<WeaponCandidate> { Weapon(1, CombatMode.Magic, "", inHand: true) };
var weak = Rank(("Nether", 1.6), ("Fire", 1.4), ("Cold", 1.0));
Check.Eq(WeaponPlanner.Choose(plain, "", weak, All).Element, "Nether", "Auto: the weakest castable, Nether");
Check.Eq(WeaponPlanner.Choose(plain, "", weak, All, preferredDamage: "War Magic").Element, "Fire", "War Magic: Nether is out, Fire");
var voidPlain = WeaponPlanner.Choose(plain, "", weak, All, preferredDamage: "Void Magic");
Check.Eq(voidPlain.WeaponId, 1, "an element-less wand is a War wand: no Void pool, so Auto keeps the same wand");
Check.False(voidPlain.Source.Contains("prefers"), "and the source doesn't claim the preference");
// An unusable preference falls back to Auto and doesn't claim the preference.
var mixed = new List<WeaponCandidate> { Weapon(1, CombatMode.Melee, "Slash"), Weapon(2, CombatMode.Magic, "Fire") };
var noVoid = WeaponPlanner.Choose(mixed, "", null, All, preferredDamage: "Void Magic");
Check.Eq(noVoid.WeaponId, 1, "no nether wand listed: Auto, the first kind");
Check.False(noVoid.Source.Contains("prefers"), "and the source doesn't claim the preference");
var noVoidSkill = WeaponPlanner.Choose(
new List<WeaponCandidate> { Weapon(1, CombatMode.Melee, "Slash"), Weapon(2, CombatMode.Magic, "Nether") }, "", null,
e => e != "Nether", preferredDamage: "Void Magic");
Check.Eq(noVoidSkill.WeaponId, 1, "a nether wand but no Void Magic: Auto");
var noWarSkill = WeaponPlanner.Choose(mixed, "", null, e => false, preferredDamage: "War Magic");
Check.Eq(noWarSkill.WeaponId, 1, "a fire wand but nothing castable: Auto");
var noMissile = WeaponPlanner.Choose(mixed, "", null, All, preferredDamage: "Missile");
Check.Eq(noMissile.WeaponId, 1, "no launcher listed: Auto");
Check.Eq(WeaponPlanner.Choose(new List<WeaponCandidate>(), "", null, All, preferredDamage: "Melee").WeaponId, 0, "nothing listed: nothing");
}
private static void PreferredVsOtherSteps()
{
var list = new List<WeaponCandidate>
{
Weapon(1, CombatMode.Melee, "Slash"), Weapon(2, CombatMode.Magic, "Fire"), Weapon(3, CombatMode.Magic, "Nether"),
};
// A slayer of another kind is not a candidate (like a melee slayer for a mage).
var slayer = new List<WeaponCandidate>
{
new(1, "Sword", CombatMode.Melee, "Slash", "", false, SlayerType: 5, SlayerBonus: 2),
Weapon(2, CombatMode.Magic, "Fire"),
};
Check.Eq(WeaponPlanner.Choose(slayer, "", null, All, creatureType: 5).WeaponId, 1, "Auto: the melee slayer");
Check.Eq(WeaponPlanner.Choose(slayer, "", null, All, creatureType: 5, preferredDamage: "War Magic").WeaponId, 2, "War Magic: the slayer isn't used");
// The Default row's weapon (fixedIsDefault) only when it is of the preferred kind.
Check.Eq(WeaponPlanner.Choose(list, "", null, All, fixedWeaponId: 1, fixedIsDefault: true, preferredDamage: "War Magic").WeaponId, 2,
"Default row's sword, War Magic preferred: a wand");
Check.Eq(WeaponPlanner.Choose(list, "", null, All, fixedWeaponId: 2, fixedIsDefault: true, preferredDamage: "War Magic").WeaponId, 2,
"Default row's fire wand, War Magic preferred: kept");
Check.Eq(WeaponPlanner.Choose(list, "", null, All, fixedWeaponId: 1, fixedIsDefault: true).WeaponId, 1, "Auto: the Default row's sword");
// The monster's own Damage tab weapon is the player's explicit pick: it wins.
Check.Eq(WeaponPlanner.Choose(list, "", null, All, fixedWeaponId: 1, fixedIsDefault: false, preferredDamage: "War Magic").WeaponId, 1,
"this monster's own sword pick, War Magic preferred: the sword");
// The rule's element picks within the preferred kind; none of it there: stay in the kind.
var cast = WeaponPlanner.Choose(list, "Nether", null, All, preferredDamage: "Void Magic");
Check.Eq(cast.WeaponId, 3, "rule Nether + Void Magic: the nether wand");
var other = WeaponPlanner.Choose(list, "Slash", null, All, preferredDamage: "War Magic");
Check.Eq(other.WeaponId, 2, "rule Slash + War Magic: no Slash wand, so the war wand, not the sword");
}
private static void PreferredParse()
{
Check.Eq(DamageStyles.Parse("war magic"), DamageStyle.War, "lower case with a space");
Check.Eq(DamageStyles.Parse("WarMagic"), DamageStyle.War, "joined");
Check.Eq(DamageStyles.Parse("Void"), DamageStyle.Void, "short form");
Check.Eq(DamageStyles.Parse("Void Magic"), DamageStyle.Void, "panel name");
Check.Eq(DamageStyles.Parse("Melee"), DamageStyle.Melee, "melee");
Check.Eq(DamageStyles.Parse("Missile"), DamageStyle.Missile, "missile");
Check.Eq(DamageStyles.Parse(null), DamageStyle.Auto, "null");
Check.Eq(DamageStyles.Parse("Fire"), DamageStyle.Auto, "unknown");
foreach (string n in DamageStyles.Names) Check.Eq(DamageStyles.Name(DamageStyles.Parse(n)), n, "round trip " + n);
Check.Eq(new MonsterRule().PreferredDamage, "Auto", "a new rule is Auto");
}
private static void ChoiceRule()
{
var wands = new List<WeaponCandidate> { Wand(1, "Fire", inHand: true), Wand(2, "Cold") };