RynthSuite as of 2026-11-17 (internal d924ac04): release 2026.11.17.1
This commit is contained in:
parent
04add6c51b
commit
88f0aac49a
72 changed files with 7910 additions and 172 deletions
|
|
@ -87,7 +87,15 @@ internal static class Program
|
|||
PatrolSettingsTests.Register(runner);
|
||||
PatrolPocketTests.Register(runner);
|
||||
PatrolPortalTests.Register(runner);
|
||||
LedgeTests.Register(runner);
|
||||
DunNavToTests.Register(runner);
|
||||
StraightenTests.Register(runner);
|
||||
HoleTests.Register(runner);
|
||||
StuckOpeningTests.Register(runner);
|
||||
BlockedDoorwayTests.Register(runner);
|
||||
StackedStepTests.Register(runner);
|
||||
DunRouteTests.Register(runner);
|
||||
DunExploreTests.Register(runner);
|
||||
BuffTests.Register(runner);
|
||||
BuffItemsTests.Register(runner);
|
||||
SpellCatalogTests.Register(runner);
|
||||
|
|
@ -159,6 +167,7 @@ internal static class Program
|
|||
WorldCacheTypedTests.Register(runner);
|
||||
VendorFlagTests.Register(runner);
|
||||
LootByNameTests.Register(runner);
|
||||
NearbyChestTests.Register(runner);
|
||||
NavOverlayTests.Register(runner);
|
||||
ActionPacingTests.Register(runner);
|
||||
HazardEscapeTests.Register(runner);
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ internal static class AttackLatencyTests
|
|||
r.Add("attack latency: the first cast at a new target skips the Attack Spell Delay only with the server gates", NewTargetInterval);
|
||||
r.Add("attack latency: a killed monster isn't locked again from the old scan list", NoRelockOfTheDead);
|
||||
r.Add("attack latency: [CombatLatency] charges each wait, one line per engagement, throttled", LatencyLine);
|
||||
r.Add("attack latency (R-20261115-165857-1de7): time the arbiter gave another activity is 'held ... by', not 'other'", LatencyHeld);
|
||||
}
|
||||
|
||||
// ── Busy leftovers ────────────────────────────────────────────────────────
|
||||
|
|
@ -165,6 +166,27 @@ internal static class AttackLatencyTests
|
|||
Check.True(t.OnAttack(6, 6100, "Melee", null) == null, "dropped before attacking: nothing");
|
||||
}
|
||||
|
||||
// 2026-11-15, R-20261115-165857-1de7: "lock->attack 3687 ms (... other 3281)" was a healing kit the
|
||||
// arbiter ran in the Buffing slot while combat didn't tick; the line said "other".
|
||||
private static void LatencyHeld()
|
||||
{
|
||||
var t = new CombatLatencyTracker();
|
||||
t.OnLock(1, 1000);
|
||||
t.OnTick(1, 1033, CombatLatencyTracker.Wait.Busy);
|
||||
t.OnHeld(1, 2033, "Buffing");
|
||||
t.OnHeld(1, 4033, "Buffing");
|
||||
t.OnTick(1, 4066, CombatLatencyTracker.Wait.Busy);
|
||||
Check.Eq(t.Held, 3000.0, "the held ticks' time is the hold's");
|
||||
Check.Eq(t.Waited(CombatLatencyTracker.Wait.Other), 0.0, "not other's");
|
||||
string? line = t.OnAttack(1, 4100, "Magic", "Kirit");
|
||||
Check.Eq(line, "[CombatLatency] lock->attack 3100 ms (stance 0, face 0, busy 66, cast 0, interval 0, other 34, held 3000 ms by Buffing) Magic 'Kirit'",
|
||||
"the line names the holder");
|
||||
|
||||
t.OnLock(2, 9000);
|
||||
string? plain = t.OnAttack(2, 9100, "Magic", null);
|
||||
Check.False((plain ?? "").Contains("held"), "a lock nobody held: the line as before");
|
||||
}
|
||||
|
||||
// ── Helpers ───────────────────────────────────────────────────────────────
|
||||
|
||||
private static CombatManager MakeCombat(LegacyUiSettings s)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,96 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Doorways a dungeon's placed objects stand across (DungeonPathfinder.Blocked.cs, 2026-11-16). DreamWeave
|
||||
// Thread 0x5456 places twelve spider webs (model 0x02000D34) in its doorways; the map had them open and the
|
||||
// explore walked into one after another. The map now closes them; dungeons without such things lose nothing.
|
||||
internal static class BlockedDoorwayTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("blocked doorways: Thread 0x5456's spider webs close their doorways (every cell pair) on the real dats; the explore keeps out of them; other dungeons lose none, 0x039B its round room's floor-level way (if the dats are here)", RealDats);
|
||||
}
|
||||
|
||||
private static void RealDats()
|
||||
{
|
||||
string acDir = DunRouteTests.AcDir;
|
||||
if (!Directory.Exists(acDir)) { Console.WriteLine(" (no dats on this PC: skipped)"); return; }
|
||||
var loader = new GeometryLoader();
|
||||
if (!loader.Initialize(acDir)) { Console.WriteLine(" (geometry loader failed: " + loader.StatusMessage + ")"); return; }
|
||||
var before = DungeonPathfinder.StaticMeshSource;
|
||||
try
|
||||
{
|
||||
DungeonPathfinder.StaticMeshSource = lb => loader.GetDungeonStaticMeshes(lb);
|
||||
ulong K(uint a, uint b) => DungeonPathfinder.OpeningKey(a, b);
|
||||
|
||||
// 0x5456: the three doorways the character was stuck in (both cell pairs of each) are among them, all webs.
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var raw = DungeonPathfinder.GetGraph(0x5456, loader.CellDat);
|
||||
var copy = raw.ToDictionary(kv => kv.Key, kv => new DungeonNavNode { CellId = kv.Value.CellId, NS = kv.Value.NS, EW = kv.Value.EW, Z = kv.Value.Z, Neighbors = { } });
|
||||
foreach (var (id, n) in raw) copy[id].Neighbors.AddRange(n.Neighbors);
|
||||
var geo = DungeonPathfinder.GetGeometry(0x5456, loader.CellDat, loader.DungeonLOS)!;
|
||||
var blocked = DungeonPathfinder.FindBlockedDoorways(copy, geo, loader.GetDungeonStaticMeshes(0x5456));
|
||||
var keys = blocked.Select(x => K(x.A, x.B)).ToHashSet();
|
||||
Console.WriteLine($" 0x5456: {blocked.Count} pair(s): {string.Join(" ", blocked.Select(x => $"{x.A & 0xFFFF:X4}>{x.B & 0xFFFF:X4}"))}; {DungeonPathfinder.BlockedNote}");
|
||||
foreach (var (a, b) in new[] { (0x5456014Fu, 0x54560148u), (0x54560150u, 0x54560148u), (0x54560158u, 0x54560157u),
|
||||
(0x54560159u, 0x54560157u), (0x54560173u, 0x54560177u), (0x54560174u, 0x54560177u) })
|
||||
Check.True(keys.Contains(K(a, b)), $"{a:X8}>{b:X8} (a doorway it was stuck in) is closed");
|
||||
Check.True(blocked.All(x => x.Setups.All(m => m is 0x02000D34 or 0x02000CCE)),
|
||||
"by the web model 0x02000D34, or 0x02000CCE (five 3.8 m blocks filling the way down to the one-cell room 0100)");
|
||||
int all = DungeonPathfinder.ReachableCells(copy, 0x545602A0, null).Count, left = DungeonPathfinder.ReachableCells(raw, 0x545602A0, null).Count;
|
||||
Console.WriteLine($" 0x5456 from 02A0: {all} cells reachable as the map was, {left} with the webs closed");
|
||||
Check.True(DungeonPathfinder.BlockedNote is { } note && note.Contains("0x02000D34"), "the build log names the model");
|
||||
Check.False(raw[0x5456014F].Neighbors.Contains(0x54560148) || raw[0x54560150].Neighbors.Contains(0x54560148), "the cached graph has the web doorway closed");
|
||||
|
||||
// The explore laid from where the run started: no step through a closed doorway.
|
||||
var route = DungeonPathfinder.BuildExploreRoute(raw, 0x545602A0, null, geo, null, null, (16239.0, 16492.0, 0.0), null, out _);
|
||||
int through = 0;
|
||||
for (int i = 0; i + 1 < route.Points.Count; i++)
|
||||
{
|
||||
uint c0 = DungeonPathfinder.CellAt(raw, geo, route.Points[i]), c1 = DungeonPathfinder.CellAt(raw, geo, route.Points[i + 1]);
|
||||
if (c0 != 0 && c1 != 0 && keys.Contains(K(c0, c1))) through++;
|
||||
}
|
||||
Console.WriteLine($" explore from 02A0: {route.Points.Count} points, {through} step(s) through a web");
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
Check.Eq(through, 0, "the explore walk takes no step through a web's doorway");
|
||||
|
||||
// Dungeons the explore has walked: nothing closed. 0x039B aside: a 9.2 m model 6.2 m tall fills its round
|
||||
// room from the floor (-12) to the corridor (-6), and the one doorway into it at floor level meets its side.
|
||||
foreach (uint lb in new uint[] { 0x0289, 0x0192, 0x6346, 0x0199, 0x01F5, 0x039B })
|
||||
{
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var g = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
var before39 = lb == 0x039B ? DungeonPathfinder.ReachableCells(g, 0x039B0177, null) : new HashSet<uint>();
|
||||
int reachBefore = before39.Count;
|
||||
var gg = DungeonPathfinder.GetGeometry(lb, loader.CellDat, loader.DungeonLOS);
|
||||
if (gg == null) continue;
|
||||
Console.WriteLine($" 0x{lb:X4}: {(DungeonPathfinder.BlockedNote ?? "nothing closed")}");
|
||||
if (lb == 0x039B)
|
||||
{
|
||||
Check.True(DungeonPathfinder.BlockedNote is { } n39 && n39.Contains("0x010000EE") && !n39.Contains(", 0x"), "0x039B: only by the round room's 9 m model");
|
||||
var full = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
var after39 = DungeonPathfinder.ReachableCells(full, 0x039B0177, null);
|
||||
int reach = after39.Count;
|
||||
Console.WriteLine($" 0x039B from 0177: {reachBefore} cells reachable as the map was, {reach} with it closed");
|
||||
// The cells under the 9 m model's floor-level side (012C-012F at -12, 010A-010F at -18 past them).
|
||||
Check.True(after39.Contains(0x039B0141) && !after39.Contains(0x039B012E) && reachBefore - reach == 11,
|
||||
$"0x039B: the round room stays, the 11 cells only past the model's side are left out ({reachBefore - reach})");
|
||||
}
|
||||
else Check.Eq(DungeonPathfinder.BlockedNote, null, $"0x{lb:X4}: nothing closed");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
DungeonPathfinder.StaticMeshSource = before;
|
||||
loader.Dispose();
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -53,6 +53,8 @@ internal static class CombatHookTests
|
|||
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("blacklist: casts answered 'too busy' (UseDone 0x1D) are not no-damage casts (answered 0: the target is dropped)", RefusedCastsNotJudged);
|
||||
r.Add("ghost (R-20261115-172110-9e6a): two casts answered 'target not acquired' (UseDone 0x42C) mark the target a ghost and stop the casting", NotAcquiredMarksGhost);
|
||||
r.Add("blacklist (2026-11-15): melee landing nothing across a building's wall (one inside, one out) keeps the target off 5 min; elsewhere the usual timeout", AcrossWallBlacklistLonger);
|
||||
r.Add("loot jump: Think sends no cast while in the air after a loot jump; it casts on the landing, or at the cap", LootJumpHoldsAttack);
|
||||
r.Add("loot jump: a swing refused in the air (WeenieError 0x4EB) is not a no-damage attack (without it: a miss)", MeleeInAirNotJudged);
|
||||
r.Add("combat hook: ctx.pending is the cast in flight; ctx.last the last resolved one, err its first UseDone (final; -1 when missed or after 7 s)", LastErrIsTheCastsAnswer);
|
||||
|
|
@ -1082,6 +1084,79 @@ internal static class CombatHookTests
|
|||
}
|
||||
});
|
||||
|
||||
// 2026-11-15, R-20261115-172110-9e6a: every Blade Arc at a target the server didn't have came back
|
||||
// UseDone 0x42C about 70 ms after the send, and combat cast again at once (13 casts in 0.85 s, the
|
||||
// hourglass going round), never dropping it.
|
||||
private static void NotAcquiredMarksGhost() => Guard(() =>
|
||||
{
|
||||
var rig = new AttackRig(setup: () => { FakeHost.ServerGates = true; FakeHost.LastUseDoneCalls = true; });
|
||||
rig.S.EnableRaycasting = false;
|
||||
rig.Attack();
|
||||
Check.Eq(FakeHost.Casts.Count, 1, "the first cast goes out");
|
||||
FakeHost.UseDone(CombatManager.TargetNotAcquiredErr);
|
||||
rig.Attack();
|
||||
Check.Eq(FakeHost.Casts.Count, 2, "one 'target not acquired' could be a death on the way: one more cast");
|
||||
Check.False(rig.C.Ghosts.IsGhost(Target), "not a ghost yet");
|
||||
FakeHost.UseDone(CombatManager.TargetNotAcquiredErr);
|
||||
rig.Attack();
|
||||
Check.Eq(FakeHost.Casts.Count, 2, "the second answer: no third cast at it");
|
||||
Check.True(rig.C.Ghosts.IsGhost(Target), "it is a ghost");
|
||||
Check.Eq(rig.C.activeTargetId, 0, "and dropped");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("[Ghost]") && l.Contains("'target not acquired' (UseDone 0x42C)") && !l.Contains("it hasn't moved")),
|
||||
"logged with the server's answer as the evidence: " + FakeHost.Logs.LastOrDefault(l => l.Contains("[Ghost]")));
|
||||
SetField(rig.C, "_lastScanTime", DateTime.MinValue); // the scan's own throttle
|
||||
rig.C.ScanNearbyTargets();
|
||||
Check.False(rig.C.ScannedTargets.Any(t => t.Id == Target), "the scan skips it");
|
||||
|
||||
// An answer in between that isn't 0x42C (the server has it after all): the count starts over.
|
||||
var real = new AttackRig(setup: () => { FakeHost.ServerGates = true; FakeHost.LastUseDoneCalls = true; });
|
||||
real.S.EnableRaycasting = false;
|
||||
real.Attack();
|
||||
FakeHost.UseDone(CombatManager.TargetNotAcquiredErr);
|
||||
real.Attack();
|
||||
FakeHost.UseDone(0);
|
||||
real.Attack();
|
||||
FakeHost.UseDone(CombatManager.TargetNotAcquiredErr);
|
||||
real.Attack();
|
||||
Check.Eq(FakeHost.Casts.Count, 4, "not two in a row: every cast goes");
|
||||
Check.False(real.C.Ghosts.IsGhost(Target), "and it is no ghost");
|
||||
Check.Eq(real.C.activeTargetId, Target, "the target stays");
|
||||
});
|
||||
|
||||
// A Thread, 2026-11-15: the character in a building, a mage 2.5 m off outside it, no raycast blocking
|
||||
// it: three swings for nothing, blacklisted 30 s, locked again, round and round.
|
||||
private static void AcrossWallBlacklistLonger() => Guard(() =>
|
||||
{
|
||||
foreach (bool across in new[] { true, false })
|
||||
{
|
||||
string what = across ? "inside a building, the target outside" : "both outside";
|
||||
var rig = new AttackRig(setup: () => { FakeHost.WeaponCalls = true; FakeHost.CombatModeValue = CombatMode.Melee; });
|
||||
rig.S.BlacklistAttempts = 3;
|
||||
rig.S.EnableRaycasting = false;
|
||||
var bm = Field<RynthCore.Plugin.RynthAi.Raycasting.BlacklistManager>(rig.C, "_blacklistManager");
|
||||
bm.TimeoutSeconds = 30;
|
||||
FakeHost.PlayerPose = (across ? 0x01010105u : 0x0101001Bu, 0f, 0f, 0f);
|
||||
FakeHost.Positions[Player] = FakeHost.PlayerPose;
|
||||
var tp = FakeHost.Positions[Target];
|
||||
FakeHost.Positions[Target] = (0x0101001Cu, tp.Item2, tp.Item3, tp.Item4);
|
||||
SetField(rig.C, "_pendingJudgeTargetId", (int)Target);
|
||||
SetField(rig.C, "_damageSincePendingCast", false);
|
||||
SetField(rig.C, "_consecutiveCastMisses", 2);
|
||||
SetField(rig.C, "_pendingJudgeCastAt", DateTime.Now.AddSeconds(-30));
|
||||
CallPrivate(rig.C, "JudgePendingCast");
|
||||
var exp = Field<Dictionary<int, DateTime>>(bm, "_blacklistExpirations");
|
||||
Check.True(exp.TryGetValue((int)Target, out DateTime until), what + ": blacklisted after the third swing for nothing");
|
||||
double secs = (until - DateTime.Now).TotalSeconds;
|
||||
if (across)
|
||||
{
|
||||
Check.True(secs > CombatManager.AcrossWallBlacklistSec - 10, $"{what}: off {secs:0} s (5 min)");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("across a building's wall")), what + ": logged");
|
||||
}
|
||||
else
|
||||
Check.True(secs < 40, $"{what}: off {secs:0} s (the usual 30)");
|
||||
}
|
||||
});
|
||||
|
||||
// A jump-loot pickup's jump (ActionPacer.NoteLootJump) holds the attack until the landing.
|
||||
// ACE refuses a cast, swing or shot in the air (Player_Magic/Melee/Missile: IsJumping).
|
||||
private static void LootJumpHoldsAttack() => Guard(() =>
|
||||
|
|
|
|||
854
Tools/RynthCore.RynthAiHostTests/Tests/DunExploreTests.cs
Normal file
854
Tools/RynthCore.RynthAiHostTests/Tests/DunExploreTests.cs
Normal file
|
|
@ -0,0 +1,854 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.RynthAi.Meta;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// The dungeon explore (2026-11-13): /ra dunnav-explore walks through every room of the dungeon once,
|
||||
// then stops (DungeonPathfinder.Explore.cs, RynthAiPlugin.DunExplore.cs). On DunRouteTests' hand-built
|
||||
// dungeon (a 3x3 hall, a corridor north to a nook with the Surface Portal, east to a side room with the
|
||||
// Portal to the Depths, west to a room):
|
||||
// - the walk is a Once route that enters every room it can walk to, once, and ends in the last one
|
||||
// (no walk back), keeping out of both portals (the nook behind the Surface Portal is left out);
|
||||
// - rooms already entered are left out when it is laid again; without the map it goes cell by cell;
|
||||
// - a closet next door is entered before moving on;
|
||||
// - the plugin: the command starts it with the macro on, rooms count as the character walks in, a
|
||||
// portal coming into view lays the rest again, rooms passed by are gone back for, the end is done
|
||||
// with navigation off and the macro left on; stop, another route and leaving the dungeon end it;
|
||||
// - radunexplore[] and the counts;
|
||||
// - Tiny Hive on the real dats, when they are on this PC.
|
||||
internal static class DunExploreTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("dun explore: a Once walk into every room once, ending in the last (no walk back), out of both portals", EveryRoomOnce);
|
||||
r.Add("dun explore: rooms already entered are left out when the walk is laid again", EnteredLeftOut);
|
||||
r.Add("dun explore: without the dungeon map the walk goes cell by cell, every cell once", CellWalk);
|
||||
r.Add("dun explore: a closet next door is entered before moving on", ClosetFirst);
|
||||
r.Add("dun explore: plugin: started with the macro on, rooms counted, relaid round a new portal, missed rooms gone back for, done", PluginRun);
|
||||
r.Add("dun explore: plugin: stop, another route, leaving the dungeon and the server's word end it", PluginEnds);
|
||||
r.Add("dun explore: plugin: stuck for good in an opening (something not on the map in it): the opening is closed, the rest laid round it", PluginStuckOpening);
|
||||
r.Add("dun patrol: stuck for good in an opening: the opening is closed and the patrol laid round it; kept in that dungeon", PatrolStuckOpening);
|
||||
r.Add("dun explore (2026-11-16, a hall 0x01F5): stuck for good in a room, away from the doorway on its way: no opening closed, the spot ahead of it walked round", PluginStuckSpot);
|
||||
r.Add("dun explore: plugin: a spider web in a doorway closes it before the walk; one in the open is left alone; one seen mid-walk relays it", PluginWebInDoorway);
|
||||
r.Add("dun explore: plugin: stuck in a doorway, what stands in it is named and learned: another of that name in a doorway is walked round", PluginStuckLearnsName);
|
||||
r.Add("dun explore: plugin: enter and scan - waits at room middles; when the walk is over a monster still in the dungeon is walked to, then done", PluginLeftoverMonster);
|
||||
r.Add("dun explore: Thread 0x00B5 on the real dats - the walk goes into the boss's 6-cell dead end and waits at its middle (if the dats are here)", Real00B5BossRoom);
|
||||
r.Add("dun explore: a door you can't use is shut: walked round, the rooms behind it counted; the walk ends waiting at it", PluginShutDoor);
|
||||
r.Add("dun explore: lever errands: one behind the door can't be walked to, a button that opens nothing, a lever that opens it (through it first)", PluginLeverErrands);
|
||||
r.Add("dun explore: a Thread puzzle gate is a shut door to the walk; its puzzle lever is never pulled", PluginPuzzleGate);
|
||||
r.Add("dun explore: done at the doors, a door that opens by itself, the door opener giving up on a door, resume", PluginDoorsMore);
|
||||
r.Add("dun explore: radunexplore[], radunexplorerooms[], radunexplorevisited[]", Expressions);
|
||||
r.Add("dun explore: Tiny Hive 0x0289 on the real dats: every room, out of the Surface Portal (if the dats are here)", TinyHiveRealDats);
|
||||
}
|
||||
|
||||
private const double Ox = DunRouteTests.Ox, Oy = DunRouteTests.Oy;
|
||||
|
||||
private static (double X, double Y, double Z) Mid(DunRouteTests.Sample d, uint cell)
|
||||
{
|
||||
var n = d.Graph[cell];
|
||||
return (DungeonGeometry.NavToWorld(n.EW), DungeonGeometry.NavToWorld(n.NS), n.Z);
|
||||
}
|
||||
|
||||
/// <summary>The rooms the walk's legs pass through (each leg looked at every half metre).</summary>
|
||||
private static HashSet<int> RoomsWalked(List<NavPoint> pts, Dictionary<uint, DungeonNavNode> graph, DungeonGeometry? geo, ExplorePlan plan)
|
||||
{
|
||||
var rooms = new HashSet<int>();
|
||||
for (int i = 0; i < pts.Count; i++)
|
||||
{
|
||||
var a = pts[i];
|
||||
var b = i + 1 < pts.Count ? pts[i + 1] : a;
|
||||
double len = Math.Sqrt(Math.Pow(DungeonGeometry.NavToWorld(b.EW) - DungeonGeometry.NavToWorld(a.EW), 2)
|
||||
+ Math.Pow(DungeonGeometry.NavToWorld(b.NS) - DungeonGeometry.NavToWorld(a.NS), 2));
|
||||
int n = Math.Max(1, (int)Math.Ceiling(len / 0.5));
|
||||
for (int k = 0; k <= n; k++)
|
||||
{
|
||||
double t = (double)k / n;
|
||||
var q = new NavPoint { NS = a.NS + (b.NS - a.NS) * t, EW = a.EW + (b.EW - a.EW) * t, Z = a.Z + (b.Z - a.Z) * t };
|
||||
int r = plan.RoomOf(DungeonPathfinder.CellAt(graph, geo, q));
|
||||
if (r >= 0) rooms.Add(r);
|
||||
}
|
||||
}
|
||||
return rooms;
|
||||
}
|
||||
|
||||
private static void EveryRoomOnce()
|
||||
{
|
||||
var d = new DunRouteTests.Sample();
|
||||
var geo = d.Geo();
|
||||
var portals = new List<PatrolPortal> { d.Surface(), d.Depths() };
|
||||
var route = DungeonPathfinder.BuildExploreRoute(d.Graph, d.Start, null, geo, null, portals, Mid(d, d.Start), null, out var plan);
|
||||
|
||||
Check.Eq(route.RouteType, NavRouteType.Once, "a Once route");
|
||||
Check.True(plan.ByRoom, "laid on the map's rooms");
|
||||
Check.True(route.Points.Count >= 6, $"points laid ({route.Points.Count})");
|
||||
int hall = plan.RoomOf(d.Start);
|
||||
Check.True(Enumerable.Range(0, 3).All(i => Enumerable.Range(0, 3).All(j => plan.RoomOf(d.Hall[i, j]) == hall)), "the 3x3 hall is one room");
|
||||
Check.False(plan.PlanRooms.Contains(plan.RoomOf(d.Nook)), "the nook behind the Surface Portal is left out");
|
||||
foreach (uint c in new[] { d.C1, d.E1, d.Side, d.W1, d.West })
|
||||
Check.True(plan.PlanRooms.Contains(plan.RoomOf(c)), $"room of cell {c:X8} is in the plan");
|
||||
|
||||
var walked = RoomsWalked(route.Points, d.Graph, geo, plan);
|
||||
Check.True(plan.PlanRooms.IsSubsetOf(walked), $"every room is walked into: plan {string.Join(",", plan.PlanRooms)}, walked {string.Join(",", walked)}");
|
||||
Check.Eq(plan.Order.Count, plan.PlanRooms.Count - 1, "each room but the start once in the order");
|
||||
Check.Eq(plan.Order.Distinct().Count(), plan.Order.Count, "none twice");
|
||||
int lastRoom = plan.RoomOf(DungeonPathfinder.CellAt(d.Graph, geo, route.Points[^1]));
|
||||
Check.Eq(lastRoom, plan.Order[^1], "it ends in the last new room, not back at the start");
|
||||
foreach (var p in portals)
|
||||
{
|
||||
double near = DungeonPathfinder.NearestApproach(route.Points, closed: false, p);
|
||||
Check.True(near >= p.Radius - 0.05, $"keeps out of {p.Name} ({near:F1} m, radius {p.Radius:F1})");
|
||||
}
|
||||
}
|
||||
|
||||
private static void EnteredLeftOut()
|
||||
{
|
||||
var d = new DunRouteTests.Sample();
|
||||
var geo = d.Geo();
|
||||
var portals = new List<PatrolPortal> { d.Surface(), d.Depths() };
|
||||
var visited = new HashSet<uint> { d.Start, d.W1, d.West };
|
||||
var route = DungeonPathfinder.BuildExploreRoute(d.Graph, d.Start, null, geo, null, portals, Mid(d, d.Start), visited, out var plan);
|
||||
int west = plan.RoomOf(d.West), w1 = plan.RoomOf(d.W1);
|
||||
Check.True(plan.DoneRooms.Contains(west) && plan.DoneRooms.Contains(w1), "the west rooms count as done");
|
||||
Check.False(plan.Order.Contains(west) || plan.Order.Contains(w1), "and aren't in the order: " + string.Join(",", plan.Order));
|
||||
Check.False(RoomsWalked(route.Points, d.Graph, geo, plan).Contains(west), "the walk doesn't go into the west room");
|
||||
Check.True(plan.Order.Contains(plan.RoomOf(d.Side)) && plan.Order.Contains(plan.RoomOf(d.C1)), "the rest still is");
|
||||
|
||||
var all = new HashSet<uint>(d.Graph.Keys);
|
||||
var none = DungeonPathfinder.BuildExploreRoute(d.Graph, d.Start, null, geo, null, portals, Mid(d, d.Start), all, out var p2);
|
||||
Check.Eq(none.Points.Count, 0, "everything entered: nothing to walk");
|
||||
Check.Eq(p2.Order.Count, 0, "and no rooms in the order");
|
||||
}
|
||||
|
||||
private static void CellWalk()
|
||||
{
|
||||
var d = new DunRouteTests.Sample();
|
||||
var route = DungeonPathfinder.BuildExploreRoute(d.Graph, d.Start, null, null, null, null, null, null, out var plan);
|
||||
Check.False(plan.ByRoom, "no map: cells");
|
||||
Check.Eq(route.RouteType, NavRouteType.Once, "a Once route");
|
||||
Check.Eq(plan.PlanRooms.Count, d.Graph.Count, "every cell (no portals given: the nook too)");
|
||||
Check.Eq(plan.Order.Count, d.Graph.Count - 1, "every cell but the start once");
|
||||
Check.True(route.Points.Count > 0, "points laid");
|
||||
}
|
||||
|
||||
private static void ClosetFirst()
|
||||
{
|
||||
// A hub H with a closet K, and a branch B1-B2-B3 off it; start in H.
|
||||
var g = new Dictionary<uint, DungeonNavNode>();
|
||||
void Link(uint a, uint b)
|
||||
{
|
||||
foreach (uint c in new[] { a, b })
|
||||
if (!g.ContainsKey(c)) g[c] = new DungeonNavNode { CellId = c, NS = (c & 0xFF) * 0.01, EW = (c >> 8 & 0xFF) * 0.01 };
|
||||
g[a].Neighbors.Add(b); g[b].Neighbors.Add(a);
|
||||
}
|
||||
const uint H = 0x7E7E0101, K = 0x7E7E0202, B1 = 0x7E7E0303, B2 = 0x7E7E0404, B3 = 0x7E7E0505;
|
||||
Link(H, B1); Link(B1, B2); Link(B2, B3); Link(H, K);
|
||||
DungeonPathfinder.BuildExploreRoute(g, H, null, null, null, null, null, null, out var plan);
|
||||
var order = plan.Order.Select(r => plan.Rooms.Cells[r][0]).ToList();
|
||||
Check.Eq(string.Join(",", order.Select(c => c.ToString("X8"))), string.Join(",", new[] { K, B1, B2, B3 }.Select(c => c.ToString("X8"))),
|
||||
"closet first, then the branch to its end (no walk back for the closet)");
|
||||
}
|
||||
|
||||
// ── The plugin ───────────────────────────────────────────────────────────
|
||||
|
||||
private static object Status(DunRouteTests.Rig rig) => rig.Call("DunExploreStatus")!;
|
||||
private static (int State, int Rooms, int Visited) St(DunRouteTests.Rig rig) => ((int State, int Rooms, int Visited))Status(rig);
|
||||
private static void Tick(DunRouteTests.Rig rig) => rig.Call("TickDunExplore");
|
||||
private static string Show(List<string> lines) => lines.Count == 0 ? "(nothing)" : string.Join(" | ", lines);
|
||||
|
||||
private static List<string> Said(Action a)
|
||||
{
|
||||
int before = FakeHost.Chat.Count;
|
||||
a();
|
||||
return FakeHost.Chat.Skip(before).ToList();
|
||||
}
|
||||
|
||||
private static void StandIn(DunRouteTests.Rig rig, uint cell)
|
||||
{
|
||||
var (x, y, _) = Mid(rig.D, cell);
|
||||
rig.At(x - Ox, y - Oy, cell);
|
||||
}
|
||||
|
||||
/// <summary>In cell <paramref name="a"/>, a metre short of its doorway into <paramref name="b"/> (stuck in that opening).</summary>
|
||||
private static void StandAtDoorway(DunRouteTests.Rig rig, uint a, uint b)
|
||||
{
|
||||
var geo = rig.D.Geo()!;
|
||||
Check.True(geo.TryGetDoorway(a, b, out var d), $"a doorway {a:X8}>{b:X8}");
|
||||
var (nx, ny) = d.NormalFrom(a);
|
||||
rig.At(d.X - nx * 1.0 - Ox, d.Y - ny * 1.0 - Oy, a);
|
||||
}
|
||||
|
||||
private static void Finish(DunRouteTests.Rig rig)
|
||||
{
|
||||
// What NavigationEngine.CompleteOnceRoute does at the end of a Once route.
|
||||
rig.S.ActiveNavIndex = rig.S.CurrentRoute.Points.Count;
|
||||
rig.S.EnableNavigation = false;
|
||||
}
|
||||
|
||||
private static void PluginRun()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-explore");
|
||||
// Only the Depths portal known at the start: the Surface Portal comes into view later.
|
||||
rig.Cache.OnDeleteObject(DunRouteTests.SurfaceId);
|
||||
rig.Cache.Tick();
|
||||
var said = rig.Typed("/ra dunnav-explore");
|
||||
Check.True(said.Count == 1 && said[0].StartsWith("[RynthAi] DunNav-Explore: ") && said[0].Contains("room(s) to walk through") && said[0].Contains("exploring"),
|
||||
"it answers: " + Show(said));
|
||||
Check.True(said[0].Contains("kept out of 1 portal(s)"), "with the one portal known: " + said[0]);
|
||||
var first = rig.S.CurrentRoute;
|
||||
Check.Eq(first.RouteType, NavRouteType.Once, "a Once route installed");
|
||||
Check.True(rig.S.IsMacroRunning && rig.S.EnableNavigation, "macro and navigation on");
|
||||
var s = St(rig);
|
||||
Check.Eq(s.State, 1, "exploring");
|
||||
Check.Eq(s.Visited, 1, "the start room counts as entered");
|
||||
int rooms = s.Rooms;
|
||||
Check.True(rooms >= 5, $"rooms to walk through ({rooms})");
|
||||
|
||||
said = rig.Typed("/ra dunnav-explore");
|
||||
Check.True(said.Count == 1 && said[0].Contains("already exploring, 1 of"), "again: already exploring: " + Show(said));
|
||||
Check.True(ReferenceEquals(rig.S.CurrentRoute, first), "and the walk is the same");
|
||||
|
||||
StandIn(rig, rig.D.W1);
|
||||
Tick(rig);
|
||||
StandIn(rig, rig.D.West);
|
||||
Tick(rig);
|
||||
Check.Eq(St(rig).Visited, 3, "w1 and the west room entered");
|
||||
|
||||
// The Surface Portal comes into view: the rest is laid again round it (the west rooms left out).
|
||||
rig.Cache.OnCreateObject(DunRouteTests.SurfaceId);
|
||||
rig.Cache.Tick();
|
||||
var run = rig.Get("_dunExplore")!;
|
||||
run.GetType().GetField("NextCheckAt")!.SetValue(run, 0L);
|
||||
Tick(rig);
|
||||
Check.False(ReferenceEquals(rig.S.CurrentRoute, first), "relaid when the portal came into view");
|
||||
Check.Eq(rig.S.CurrentRoute.RouteType, NavRouteType.Once, "still a Once route");
|
||||
Check.Eq(St(rig).Visited, 3, "the rooms entered are kept");
|
||||
Check.True(St(rig).Rooms <= rooms, $"the nook is out now ({St(rig).Rooms} rooms)");
|
||||
var surface = rig.D.Surface();
|
||||
surface.Radius = 3.5;
|
||||
Check.True(DungeonPathfinder.NearestApproach(rig.S.CurrentRoute.Points, closed: false, surface) >= surface.Radius - 0.1, "kept out of the Surface Portal");
|
||||
|
||||
// The walk ends with rooms not entered (the character was carried past them): it goes back once.
|
||||
Finish(rig);
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Any(l => l.Contains("passed by without going in → going back for them")), "missed rooms gone back for: " + Show(said));
|
||||
Check.True(rig.S.EnableNavigation && rig.S.CurrentRoute.Points.Count > 0, "a walk for them");
|
||||
Check.Eq(St(rig).State, 1, "still exploring");
|
||||
|
||||
// Walk into every room, then the walk ends: done.
|
||||
foreach (uint c in rig.D.Graph.Keys.Where(c => c != rig.D.Nook)) { StandIn(rig, c); Tick(rig); }
|
||||
s = St(rig);
|
||||
Check.Eq(s.Visited, s.Rooms, $"every room entered ({s.Visited} of {s.Rooms})");
|
||||
Finish(rig);
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Count == 1 && said[0].Contains($"DunNav-Explore: done, {s.Rooms} of {s.Rooms} rooms") && said[0].Contains("the macro is still on"),
|
||||
"done: " + Show(said));
|
||||
Check.Eq(St(rig).State, 3, "done");
|
||||
Check.True(!rig.S.EnableNavigation && rig.S.CurrentRoute.Points.Count == 0, "navigation off, the walk taken off");
|
||||
Check.True(rig.S.IsMacroRunning, "the macro left on");
|
||||
said = rig.Typed("/ra dunnav-explore status");
|
||||
Check.True(said[0].Contains("done in dungeon 0x7E7E") && said[0].Contains($"{s.Rooms} of {s.Rooms} rooms"), "status: " + Show(said));
|
||||
}
|
||||
|
||||
private static void PluginEnds()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-explore-ends");
|
||||
var said = rig.Typed("/ra dunnav-explore stop");
|
||||
Check.True(said.Count == 1 && said[0].Contains("nothing to stop"), "stop with none running: " + Show(said));
|
||||
said = rig.Typed("/ra dunnav-explore sideways");
|
||||
Check.True(said.Count == 1 && said[0].Contains("Usage: /ra dunnav-explore"), "a wrong word: the usage: " + Show(said));
|
||||
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
said = rig.Typed("/ra dunnav-explore stop");
|
||||
Check.True(said.Count == 1 && said[0].Contains("DunNav-Explore stopped (you stopped it): 1 of"), "stopped: " + Show(said));
|
||||
Check.True(!rig.S.EnableNavigation && rig.S.CurrentRoute.Points.Count == 0, "navigation off, the walk taken off");
|
||||
Check.Eq(St(rig).State, 4, "stopped");
|
||||
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
var other = new NavRouteParser { RouteType = NavRouteType.Circular };
|
||||
other.Points.Add(new NavPoint { Type = NavPointType.Point, NS = 1, EW = 1 });
|
||||
rig.S.CurrentRoute = other;
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Count == 1 && said[0].Contains("stopped (another route is the route now)"), "another route: " + Show(said));
|
||||
Check.True(ReferenceEquals(rig.S.CurrentRoute, other), "that route stays");
|
||||
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
rig.At(42.1, 33.6, 0xA9B4002Fu);
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Count == 1 && said[0].Contains("stopped (you left the dungeon)"), "left the dungeon: " + Show(said));
|
||||
Check.True(!rig.S.EnableNavigation, "navigation off");
|
||||
said = rig.Typed("/ra dunnav-explore");
|
||||
Check.True(said.Count == 1 && said[0].Contains("dunnav-explore requires you to be inside a dungeon"), "outdoors: refused: " + Show(said));
|
||||
|
||||
var thread = new DunRouteTests.Rig("NavProfiles-explore-thread", world: "DreamWeave");
|
||||
ServerPolicy.NoteChat("[REALM] id=0 inst=7841 eph=1 name=Base World", thread.D.Start);
|
||||
said = thread.Typed("/ra dunnav-explore");
|
||||
Check.True(said.Count == 1 && said[0].Contains("turned off in Threads"), "in a Thread on DreamWeave: refused with the policy's line: " + Show(said));
|
||||
Check.False(thread.S.IsMacroRunning || thread.S.EnableNavigation, "nothing started");
|
||||
ServerPolicy.Forget();
|
||||
}
|
||||
|
||||
// 2026-11-14 on DreamWeave, 0x5456: a spider web in a doorway (then not on the map); the engine's detours
|
||||
// went back through it and then it only tried its escapes. Here: heading down the east corridor for the
|
||||
// side room when every detour is used up and it is still stuck.
|
||||
private static void PluginStuckOpening()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-explore-stuck");
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
int rooms = St(rig).Rooms;
|
||||
StandAtDoorway(rig, rig.D.E1, rig.D.Side);
|
||||
Tick(rig);
|
||||
var before = rig.S.CurrentRoute;
|
||||
var geo = rig.D.Geo();
|
||||
int toSide = before.Points.FindIndex(p => DungeonPathfinder.CellAt(rig.D.Graph, geo, p) == rig.D.Side);
|
||||
Check.True(toSide >= 0, "the walk goes into the side room");
|
||||
rig.S.ActiveNavIndex = toSide;
|
||||
|
||||
Check.True(Said(() => Tick(rig)).Count == 0 && ReferenceEquals(rig.S.CurrentRoute, before), "not stuck: nothing happens");
|
||||
bool stuck = true;
|
||||
rig.P.ExploreStuckProbe = () => stuck;
|
||||
var said = Said(() => Tick(rig));
|
||||
stuck = false;
|
||||
Check.True(said.Any(l => l.Contains($"couldn't get past something between cells {rig.D.E1:X8} and {rig.D.Side:X8}") && l.Contains("going round it")),
|
||||
"it says which opening it gives up: " + Show(said));
|
||||
Check.False(ReferenceEquals(rig.S.CurrentRoute, before), "the rest laid again");
|
||||
Check.Eq(St(rig).State, 1, "still exploring");
|
||||
Check.Eq(St(rig).Rooms, rooms - 1, "the side room (only that way) is left out");
|
||||
var run = rig.Get("_dunExplore")!;
|
||||
Check.Eq(((HashSet<ulong>)run.GetType().GetField("StuckEdges")!.GetValue(run)!).Count, 1, "one opening closed");
|
||||
Check.False(rig.S.CurrentRoute.Points.Any(p => DungeonPathfinder.CellAt(rig.D.Graph, geo, p) == rig.D.Side), "and the new walk doesn't go in there");
|
||||
Check.True(Said(() => Tick(rig)).Count == 0, "unstuck: nothing more");
|
||||
}
|
||||
|
||||
// 2026-11-16, a DreamWeave hall (0x01F5): stuck for good 5 and 11 m from the doorway on its way, three openings
|
||||
// were closed one after another and it stood stuck as before. Now the spot just ahead of it is walked round.
|
||||
private static void PluginStuckSpot()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-explore-stuckspot");
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
int rooms = St(rig).Rooms;
|
||||
StandIn(rig, rig.D.E1);
|
||||
Tick(rig);
|
||||
var before = rig.S.CurrentRoute;
|
||||
var geo = rig.D.Geo();
|
||||
int toSide = before.Points.FindIndex(p => DungeonPathfinder.CellAt(rig.D.Graph, geo, p) == rig.D.Side);
|
||||
Check.True(toSide >= 0, "the walk goes into the side room");
|
||||
rig.S.ActiveNavIndex = toSide;
|
||||
var (mx, my, _) = Mid(rig.D, rig.D.E1);
|
||||
Check.True(geo!.TryGetDoorway(rig.D.E1, rig.D.Side, out var d) && Math.Sqrt((d.X - mx) * (d.X - mx) + (d.Y - my) * (d.Y - my)) > RynthAiPlugin.StuckAtDoorwayMeters,
|
||||
"it stands in the middle of its cell, away from the doorway");
|
||||
|
||||
bool stuck = true;
|
||||
rig.P.ExploreStuckProbe = () => stuck;
|
||||
int logs = FakeHost.Logs.Count;
|
||||
var said = Said(() => Tick(rig));
|
||||
stuck = false;
|
||||
Check.True(said.Any(l => l.Contains($"couldn't get past something at a spot in cell {rig.D.E1:X8}") && l.Contains("walking round that spot")),
|
||||
"it says it walks round the spot: " + Show(said));
|
||||
Check.True(Logged(logs, "from the doorway on its way: walking round the spot"), "and logs where");
|
||||
var run = rig.Get("_dunExplore")!;
|
||||
Check.Eq(((HashSet<ulong>)run.GetType().GetField("StuckEdges")!.GetValue(run)!).Count, 0, "no opening closed");
|
||||
var spots = (List<PatrolPortal>)run.GetType().GetField("StuckSpots")!.GetValue(run)!;
|
||||
Check.Eq(spots.Count, 1, "one spot");
|
||||
Check.Eq(St(rig).Rooms, rooms, "no room left out");
|
||||
Check.False(ReferenceEquals(rig.S.CurrentRoute, before), "the rest laid again");
|
||||
var sp = spots[0];
|
||||
var pts = rig.S.CurrentRoute.Points;
|
||||
double Dist(double x, double y) => Math.Sqrt((x - sp.X) * (x - sp.X) + (y - sp.Y) * (y - sp.Y));
|
||||
bool inside = false;
|
||||
for (int i = 0; i + 1 < pts.Count; i++)
|
||||
{
|
||||
double ax = DungeonGeometry.NavToWorld(pts[i].EW), ay = DungeonGeometry.NavToWorld(pts[i].NS);
|
||||
double bx = DungeonGeometry.NavToWorld(pts[i + 1].EW), by = DungeonGeometry.NavToWorld(pts[i + 1].NS);
|
||||
for (int k = 0; k <= 20; k++)
|
||||
{
|
||||
double t = k / 20.0;
|
||||
if (Dist(ax + (bx - ax) * t, ay + (by - ay) * t) < sp.Radius - 0.05) inside = true;
|
||||
}
|
||||
}
|
||||
Check.False(inside, "the new walk keeps out of the spot's circle");
|
||||
Check.True(pts.Any(p => DungeonPathfinder.CellAt(rig.D.Graph, geo, p) == rig.D.Side), "and still goes into the side room");
|
||||
}
|
||||
|
||||
// The same web, for the dungeon patrol (Tom: "This same change needs to be made in patrol").
|
||||
private static void PatrolStuckOpening()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-patrol-stuck");
|
||||
var said = rig.Typed("/ra dunnav-patrol");
|
||||
Check.True(said.Any(l => l.Contains("circular patrol started")), "the patrol starts: " + Show(said));
|
||||
var before = rig.S.CurrentRoute;
|
||||
var geo = rig.D.Geo();
|
||||
bool InSide(NavPoint p) => DungeonPathfinder.CellAt(rig.D.Graph, geo, p) == rig.D.Side;
|
||||
Check.Eq(before.RouteType, NavRouteType.Circular, "a circular patrol");
|
||||
int toSide = before.Points.FindIndex(InSide);
|
||||
Check.True(toSide >= 0, "its lap goes into the side room (coverage Everything)");
|
||||
StandAtDoorway(rig, rig.D.E1, rig.D.Side);
|
||||
rig.S.ActiveNavIndex = toSide;
|
||||
|
||||
Check.True(Said(() => rig.Call("TickDunPatrolHazardReroute")).Count == 0 && ReferenceEquals(rig.S.CurrentRoute, before), "not stuck: nothing happens");
|
||||
bool stuck = true;
|
||||
rig.P.ExploreStuckProbe = () => stuck;
|
||||
said = Said(() => rig.Call("TickDunPatrolHazardReroute"));
|
||||
stuck = false;
|
||||
Check.True(said.Any(l => l.Contains($"DunNav-Patrol: couldn't get past something between cells {rig.D.E1:X8} and {rig.D.Side:X8}") && l.Contains("patrolling round it")),
|
||||
"it says which opening it gives up: " + Show(said));
|
||||
Check.False(ReferenceEquals(rig.S.CurrentRoute, before), "the patrol laid again");
|
||||
Check.Eq(rig.S.CurrentRoute.RouteType, NavRouteType.Circular, "still a circular patrol");
|
||||
Check.False(rig.S.CurrentRoute.Points.Any(InSide), "and its lap keeps out of the side room");
|
||||
Check.True(rig.S.IsMacroRunning && rig.S.EnableNavigation, "still running");
|
||||
Check.True(Said(() => rig.Call("TickDunPatrolHazardReroute")).Count == 0, "unstuck: nothing more");
|
||||
|
||||
rig.At(15, 15, rig.D.Start);
|
||||
rig.Typed("/ra dunnav-patrol");
|
||||
Check.False(rig.S.CurrentRoute.Points.Any(InSide), "started again in this dungeon: the opening stays closed");
|
||||
}
|
||||
|
||||
// ── Things in doorways (2026-11-16) ──────────────────────────────────────
|
||||
// A web a server puts in a doorway is on no map (Thread 0x5456's are the cells' own: BlockedDoorwayTests). One named so
|
||||
// closes its doorway before the walk is laid; one in the open is left alone; one that comes into view
|
||||
// mid-walk gets the walk laid again; and the name of a thing in a doorway it got stuck in is learned.
|
||||
|
||||
private const uint WebId = 0x80E0E001, OpenWebId = 0x80E0E002, LateWebId = 0x80E0E003, StrandsId = 0x80E0E004, Strands2Id = 0x80E0E005;
|
||||
|
||||
private static void Place(DunRouteTests.Rig rig, uint id, string name, uint cell, float lx, float ly)
|
||||
{
|
||||
FakeHost.Names[id] = name;
|
||||
FakeHost.ItemTypes[id] = 0x80; // TYPE_MISC
|
||||
FakeHost.Positions[id] = (cell, lx, ly, 0f);
|
||||
rig.Cache.OnCreateObject(id);
|
||||
for (int i = 0; i < 3; i++) rig.Cache.Tick();
|
||||
}
|
||||
|
||||
private static bool Logged(int from, string text) => FakeHost.Logs.Skip(from).Any(l => l.Contains(text));
|
||||
|
||||
private static void PluginWebInDoorway()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-explore-web");
|
||||
var geo = rig.D.Geo();
|
||||
bool InSide(NavPoint p) => DungeonPathfinder.CellAt(rig.D.Graph, geo, p) == rig.D.Side;
|
||||
Place(rig, WebId, "Spider Web", rig.D.E1, 39.6f, 5.2f); // in the doorway e1 > side room (x 40)
|
||||
Place(rig, OpenWebId, "Spider Web", rig.D.Start, 15f, 15f); // the hall's middle: no doorway there
|
||||
int logs = FakeHost.Logs.Count;
|
||||
var said = rig.Typed("/ra dunnav-explore");
|
||||
Check.True(said.Any(l => l.Contains($"Spider Web in the doorway between cells") && l.Contains("going round it")),
|
||||
"it says which doorway the web closes: " + Show(said));
|
||||
Check.True(said.Any(l => l.Contains("exploring")), "and explores: " + Show(said));
|
||||
Check.False(rig.S.CurrentRoute.Points.Any(InSide), "the walk keeps out of the side room (only through the web's doorway)");
|
||||
Check.True(Logged(logs, $"0x{OpenWebId:X8} 'Spider Web'") && Logged(logs, "stands in no doorway: left alone"), "the web in the open is left alone");
|
||||
var run = Run(rig);
|
||||
Check.Eq(((Dictionary<uint, string>)run.GetType().GetField("Blockers")!.GetValue(run)!).Count, 1, "one web in a doorway");
|
||||
|
||||
// A web that comes into view mid-walk, in the doorway hall > w1 (x 0): the walk is laid again round it.
|
||||
var first = rig.S.CurrentRoute;
|
||||
bool InWest(NavPoint p) { uint c = DungeonPathfinder.CellAt(rig.D.Graph, geo, p); return c == rig.D.W1 || c == rig.D.West; }
|
||||
Check.True(first.Points.Any(InWest), "the walk goes into the west rooms");
|
||||
Place(rig, LateWebId, "Spider Web", rig.D.Hall[0, 2], 0.4f, 25f);
|
||||
run.GetType().GetField("NextCheckAt")!.SetValue(run, 0L);
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Any(l => l.Contains("Spider Web in the doorway")), "the new web is said: " + Show(said));
|
||||
Check.False(ReferenceEquals(rig.S.CurrentRoute, first), "the walk laid again");
|
||||
Check.False(rig.S.CurrentRoute.Points.Any(InWest), "round the new web (the west rooms are only that way)");
|
||||
Check.Eq(St(rig).State, 1, "still exploring");
|
||||
Check.True(Said(() => { run.GetType().GetField("NextCheckAt")!.SetValue(run, 0L); Tick(rig); }).Count == 0, "the same webs again: nothing new");
|
||||
}
|
||||
|
||||
private static void PluginStuckLearnsName()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-explore-strands");
|
||||
var geo = rig.D.Geo();
|
||||
// Not named like a web: not known to block until it got stuck on one.
|
||||
Place(rig, StrandsId, "Thick Strands", rig.D.E1, 39.6f, 5.2f);
|
||||
Place(rig, Strands2Id, "Thick Strands", rig.D.Hall[0, 2], 0.4f, 25f);
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
StandAtDoorway(rig, rig.D.E1, rig.D.Side);
|
||||
Tick(rig);
|
||||
var before = rig.S.CurrentRoute;
|
||||
bool InWest(NavPoint p) { uint c = DungeonPathfinder.CellAt(rig.D.Graph, geo, p); return c == rig.D.W1 || c == rig.D.West; }
|
||||
Check.True(before.Points.Any(InWest), "at first the walk goes through both (no web by name)");
|
||||
int toSide = before.Points.FindIndex(p => DungeonPathfinder.CellAt(rig.D.Graph, geo, p) == rig.D.Side);
|
||||
Check.True(toSide >= 0, "the walk goes into the side room");
|
||||
rig.S.ActiveNavIndex = toSide;
|
||||
|
||||
bool stuck = true;
|
||||
rig.P.ExploreStuckProbe = () => stuck;
|
||||
int logs = FakeHost.Logs.Count;
|
||||
Tick(rig);
|
||||
stuck = false;
|
||||
Check.True(Logged(logs, $"in it: 0x{StrandsId:X8} 'Thick Strands'"), "the stuck line names what stands in the doorway");
|
||||
Check.True(Logged(logs, "'Thick Strands' stood in the doorway it couldn't get through"), "and learns its name");
|
||||
|
||||
var run = Run(rig);
|
||||
run.GetType().GetField("NextCheckAt")!.SetValue(run, 0L);
|
||||
var said = Said(() => Tick(rig));
|
||||
Check.True(said.Any(l => l.Contains("Thick Strands in the doorway between cells")), "the other one of that name closes its doorway: " + Show(said));
|
||||
Check.False(rig.S.CurrentRoute.Points.Any(InWest), "and the walk keeps out of the west rooms");
|
||||
}
|
||||
|
||||
// ── Enter and scan (2026-11-16) ─────────────────────────────────────────
|
||||
// DreamWeave Thread 0x00B5: the boss stood in a 6-cell dead end; the walk touched its doorway and turned back, the
|
||||
// client had no position for the boss yet, and the explore went on without it. The walk now goes into every dead
|
||||
// end and waits at the middles it walks to; when the walk is over, a monster still known in the dungeon is walked to.
|
||||
|
||||
private const uint LeftMobId = 0x80E0E101;
|
||||
|
||||
private static void PluginLeftoverMonster()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-explore-leftover");
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
Check.True(rig.S.CurrentRoute.Points.Any(p => p.Type == NavPointType.Pause && p.PauseTimeMs == DungeonPathfinder.ExploreScanMs),
|
||||
"the walk waits at the room middles it walks to");
|
||||
foreach (uint c in rig.D.Graph.Keys.Where(c => c != rig.D.Nook)) { StandIn(rig, c); Tick(rig); }
|
||||
|
||||
// A monster the walk went past, still in the west room when the walk is over.
|
||||
FakeHost.Names[LeftMobId] = "Dread Test Commander";
|
||||
FakeHost.ItemTypes[LeftMobId] = 0x10;
|
||||
FakeHost.Wcids[LeftMobId] = 99001;
|
||||
FakeHost.Positions[LeftMobId] = (rig.D.West, -18f, 25f, 0f);
|
||||
rig.Cache.OnCreateObject(LeftMobId);
|
||||
for (int i = 0; i < 3; i++) rig.Cache.Tick();
|
||||
StandIn(rig, rig.D.Start);
|
||||
FakeHost.Positions[DunRouteTests.Player] = FakeHost.PlayerPose; // combat's hunt list reads the player's own position
|
||||
// Combat's hunt list (alive, attackable, on the monster list; the rig has no combat manager): the monster, while alive.
|
||||
bool alive = true;
|
||||
rig.P.LeftoverMonstersProbe = () => alive
|
||||
? new List<OutdoorHunt.Candidate> { new(unchecked((int)LeftMobId), "Dread Test Commander", new OutdoorHunt.Vec(Ox - 18, Oy + 25, 0), 30, 1, rig.D.West) }
|
||||
: new List<OutdoorHunt.Candidate>();
|
||||
Finish(rig);
|
||||
var said = Said(() => Tick(rig));
|
||||
Check.True(said.Any(l => l.Contains("Dread Test Commander is still in the dungeon") && l.Contains("going after it")),
|
||||
"the walk over, it goes after the monster still here: " + Show(said));
|
||||
Check.Eq(St(rig).State, 1, "still exploring");
|
||||
var geo = rig.D.Geo();
|
||||
var pts = rig.S.CurrentRoute.Points;
|
||||
Check.True(rig.S.EnableNavigation && pts.Count > 0 && DungeonPathfinder.CellAt(rig.D.Graph, geo, pts[^1]) == rig.D.West,
|
||||
"a walk to it, ending in the west room");
|
||||
|
||||
// Walked there, the monster dead: nothing left, done.
|
||||
alive = false;
|
||||
StandIn(rig, rig.D.West);
|
||||
FakeHost.Positions[DunRouteTests.Player] = FakeHost.PlayerPose;
|
||||
Finish(rig);
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Any(l => l.Contains("DunNav-Explore: done,")), "then done: " + Show(said));
|
||||
Check.Eq(St(rig).State, 3, "done");
|
||||
}
|
||||
|
||||
// On the real dats: the walk from where that run started goes to the middle of the boss's dead end and waits there.
|
||||
private static void Real00B5BossRoom()
|
||||
{
|
||||
string acDir = DunRouteTests.AcDir;
|
||||
if (!Directory.Exists(acDir)) { Console.WriteLine(" (no dats on this PC: skipped)"); return; }
|
||||
var loader = new GeometryLoader();
|
||||
if (!loader.Initialize(acDir)) { Console.WriteLine(" (geometry loader failed: " + loader.StatusMessage + ")"); return; }
|
||||
try
|
||||
{
|
||||
const uint lb = 0x00B5;
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var graph = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
var geo = DungeonPathfinder.GetGeometry(lb, loader.CellDat, loader.DungeonLOS)!;
|
||||
var route = DungeonPathfinder.BuildExploreRoute(graph, 0x00B501FF, null, geo, null, null, null, null, out var plan);
|
||||
int bossRoom = plan.RoomOf(0x00B5012A);
|
||||
var cells = plan.Rooms.Cells[bossRoom];
|
||||
var mid = DungeonPathfinder.RoomMiddle(graph, geo, cells, DungeonPathfinder.WallClearance, out _)!;
|
||||
var pts = route.Points;
|
||||
int at = pts.FindIndex(p => p.Type == NavPointType.Point && Math.Abs(p.NS - mid.NS) * 240 < 0.3 && Math.Abs(p.EW - mid.EW) * 240 < 0.3);
|
||||
Console.WriteLine($" 0x00B5: {pts.Count} points, {pts.Count(p => p.Type == NavPointType.Pause)} waits; the boss room ({cells.Count} cells) middle at [{at}]; {DungeonPathfinder.MainRouteNote}");
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
Check.True(at >= 0, "the walk goes to the middle of the boss's dead end");
|
||||
Check.True(at >= 0 && at + 1 < pts.Count && pts[at + 1].Type == NavPointType.Pause, "and waits there");
|
||||
}
|
||||
finally
|
||||
{
|
||||
loader.Dispose();
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
}
|
||||
}
|
||||
|
||||
// ── Shut doors and levers (2026-11-14) ───────────────────────────────────
|
||||
// A door in the opening between the hall and the west corridor (x 0, y 25) that can't be used (ItemUseable
|
||||
// No, as every lever door in ACE's data), a lever in the hall that opens it, a button in the hall that
|
||||
// opens nothing.
|
||||
|
||||
private const uint DoorId = 0x7E7E9003, LeverId = 0x7E7E9004, ButtonId = 0x7E7E9005, FarLeverId = 0x7E7E9006;
|
||||
private const uint BfDoor = 0x1000, DoorClosed = 0x00010018, DoorEthereal = 0x4;
|
||||
|
||||
// A Thread puzzle gate (DreamWeave wcid 1006850: a spawned door, locked until its levers' puzzle is solved) in the
|
||||
// doorway e1 > side room: a shut door to the walk. Its lever (wcid 1006851) is never pulled: three wrong pulls in an
|
||||
// hour ban the connection from Threads.
|
||||
private const uint PuzzleGateId = 0x80E0E201, PuzzleLeverId = 0x80E0E202;
|
||||
|
||||
private static void PluginPuzzleGate()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-explore-puzzle", beforeCreate: () =>
|
||||
{
|
||||
FakeHost.Wcids[PuzzleGateId] = 1006850;
|
||||
FakeHost.Wcids[PuzzleLeverId] = 1006851;
|
||||
FakeHost.ObjectStates[PuzzleGateId] = DoorClosed;
|
||||
});
|
||||
FakeHost.Names[PuzzleGateId] = "Warded Gate";
|
||||
FakeHost.ItemTypes[PuzzleGateId] = 0x80;
|
||||
FakeHost.Positions[PuzzleGateId] = (rig.D.E1, 39.7f, 5f, 0f);
|
||||
FakeHost.Names[PuzzleLeverId] = "Puzzle Lever";
|
||||
FakeHost.ItemTypes[PuzzleLeverId] = 0x80;
|
||||
FakeHost.Positions[PuzzleLeverId] = (rig.D.E1, 35f, 5f, 0f);
|
||||
foreach (uint id in new[] { PuzzleGateId, PuzzleLeverId }) rig.Cache.OnCreateObject(id);
|
||||
for (int i = 0; i < 3; i++) rig.Cache.Tick();
|
||||
|
||||
int logs = FakeHost.Logs.Count;
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
Check.True(Logged(logs, $"shut door 0x{PuzzleGateId:X8} 'Warded Gate' (a Thread puzzle gate)"), "the puzzle gate is a shut door to the walk");
|
||||
var geo = rig.D.Geo();
|
||||
Check.False(rig.S.CurrentRoute.Points.Any(p => DungeonPathfinder.CellAt(rig.D.Graph, geo, p) == rig.D.Side), "the walk keeps out of the room behind it");
|
||||
|
||||
int uses = FakeHost.Uses.Count;
|
||||
var said = rig.Typed($"/ra dunnav-explore lever {PuzzleLeverId:X8} door {PuzzleGateId:X8}");
|
||||
Check.True(said.Any(l => l.Contains("is a Thread puzzle lever: the explore never pulls one")), "a puzzle lever is refused: " + Show(said));
|
||||
Check.False(FakeHost.Uses.Skip(uses).Contains(PuzzleLeverId), "and never used");
|
||||
Check.True(Info(rig).GetProperty("last").GetString()!.StartsWith($"puzzle {PuzzleLeverId:X8}"), "puzzle, in radunexploreinfo[]");
|
||||
}
|
||||
|
||||
private static DunRouteTests.Rig LeverRig(string folder, int doorUsable = 1)
|
||||
{
|
||||
// UseObject, the object bitfields and the physics states are the host's only when asked for at Create().
|
||||
var rig = new DunRouteTests.Rig(folder, beforeCreate: () =>
|
||||
{
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.Bitfields[DoorId] = BfDoor;
|
||||
FakeHost.ObjectStates[DoorId] = DoorClosed;
|
||||
});
|
||||
FakeHost.Names[DoorId] = "Door";
|
||||
FakeHost.Positions[DoorId] = (rig.D.Hall[0, 2], 0.3f, 25f, 0f);
|
||||
FakeHost.Ints[(DoorId, 16u)] = doorUsable;
|
||||
FakeHost.Names[LeverId] = "Lever";
|
||||
FakeHost.Positions[LeverId] = (rig.D.Hall[0, 2], 5f, 25f, 0f);
|
||||
FakeHost.Names[ButtonId] = "Button";
|
||||
FakeHost.Positions[ButtonId] = (rig.D.Hall[2, 2], 25f, 25f, 0f);
|
||||
foreach (uint id in new[] { DoorId, LeverId, ButtonId }) rig.Cache.OnCreateObject(id);
|
||||
for (int i = 0; i < 3; i++) rig.Cache.Tick();
|
||||
return rig;
|
||||
}
|
||||
|
||||
private static System.Text.Json.JsonElement Info(DunRouteTests.Rig rig)
|
||||
=> System.Text.Json.JsonDocument.Parse((string)rig.Call("DunExploreInfoJson")!).RootElement.Clone();
|
||||
|
||||
private static object Run(DunRouteTests.Rig rig) => rig.Get("_dunExplore")!;
|
||||
private static string Pts(IEnumerable<NavPoint> pts) => string.Join(" ", pts.Select(p => $"({DungeonGeometry.NavToWorld(p.EW) - Ox:F1},{DungeonGeometry.NavToWorld(p.NS) - Oy:F1})"));
|
||||
|
||||
/// <summary>Stands in every cell but those given (and the nook), a tick in each.</summary>
|
||||
private static void WalkAllBut(DunRouteTests.Rig rig, params uint[] skip)
|
||||
{
|
||||
foreach (uint c in rig.D.Graph.Keys.Where(c => c != rig.D.Nook && !skip.Contains(c))) { StandIn(rig, c); Tick(rig); }
|
||||
}
|
||||
|
||||
private static void PluginShutDoor()
|
||||
{
|
||||
var rig = LeverRig("NavProfiles-explore-door");
|
||||
var said = rig.Typed("/ra dunnav-explore");
|
||||
Check.True(said.Count == 1 && said[0].Contains("round 1 shut door(s)"), "it starts round the shut door: " + Show(said));
|
||||
var geo = rig.D.Geo();
|
||||
bool Behind(NavPoint p) { uint c = DungeonPathfinder.CellAt(rig.D.Graph, geo, p); return c == rig.D.W1 || c == rig.D.West; }
|
||||
Check.False(rig.S.CurrentRoute.Points.Any(Behind), "the walk doesn't go through it");
|
||||
var info = Info(rig);
|
||||
Check.Eq(info.GetProperty("state").GetInt32(), 1, "exploring");
|
||||
var door = info.GetProperty("doors")[0];
|
||||
Check.Eq(door.GetProperty("id").GetString(), "7E7E9003", "the door in radunexploreinfo[]");
|
||||
Check.Eq(door.GetProperty("why").GetString(), "can't be used", "why it's shut");
|
||||
Check.Eq(door.GetProperty("rooms").GetInt32(), 2, "two rooms behind it (the west corridor and room)");
|
||||
Check.Near(door.GetProperty("x").GetDouble(), 0.3, 0.01, "landblock-local x");
|
||||
|
||||
WalkAllBut(rig, rig.D.W1, rig.D.West);
|
||||
Finish(rig);
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Count == 1 && said[0].Contains("every room it can walk to is done") && said[0].Contains("behind 1 shut door(s): Door 0x7E7E9003 (2)"),
|
||||
"the walk over: it waits at the door: " + Show(said));
|
||||
Check.Eq(St(rig).State, 5, "waiting at the doors");
|
||||
Check.True(!rig.S.EnableNavigation && rig.S.CurrentRoute.Points.Count == 0, "navigation off, an empty route of its own");
|
||||
Check.True(rig.S.IsMacroRunning, "the macro left on");
|
||||
Check.True(Said(() => Tick(rig)).Count == 0, "it waits quietly");
|
||||
said = rig.Typed("/ra dunnav-explore status");
|
||||
Check.True(said[0].Contains("waiting at shut doors") && said[0].Contains("2 room(s) behind 1 shut door(s)"), "status: " + Show(said));
|
||||
}
|
||||
|
||||
private static void PluginLeverErrands()
|
||||
{
|
||||
var rig = LeverRig("NavProfiles-explore-lever");
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
WalkAllBut(rig, rig.D.W1, rig.D.West);
|
||||
Finish(rig);
|
||||
Tick(rig);
|
||||
Check.Eq(St(rig).State, 5, "at the door");
|
||||
|
||||
// A lever on the far side: no way there through the shut door.
|
||||
var said = rig.Typed("/ra dunnav-explore lever 7E7E9006 door 7E7E9003 at -17 25 0");
|
||||
Check.True(said.Any(l => l.Contains("can't be walked to from here")), "a lever behind the door: " + Show(said));
|
||||
Check.True(Info(rig).GetProperty("last").GetString()!.StartsWith("unreachable 7E7E9006 7E7E9003"), "unreachable, in radunexploreinfo[]");
|
||||
Check.Eq(St(rig).State, 5, "still at the door");
|
||||
|
||||
// The button: walked to, used, nothing opens.
|
||||
int usesBefore = FakeHost.Uses.Count;
|
||||
said = rig.Typed("/ra dunnav-explore lever 7E7E9005 door 7E7E9003");
|
||||
Check.True(said.Count == 1 && said[0].Contains("going to pull Button 0x7E7E9005 for Door 0x7E7E9003 (2 room(s) behind it)"), "the errand starts: " + Show(said));
|
||||
Check.Eq(St(rig).State, 6, "at a lever");
|
||||
Check.True(rig.S.EnableNavigation && rig.S.CurrentRoute.RouteType == NavRouteType.Once && rig.S.CurrentRoute.Points.Count > 0, "walking to it");
|
||||
Check.Eq(Info(rig).GetProperty("errand").GetProperty("phase").GetString(), "walking", "walking, in radunexploreinfo[]");
|
||||
rig.At(24.5, 25, rig.D.Hall[2, 2]);
|
||||
Tick(rig);
|
||||
Check.True(FakeHost.Uses.Skip(usesBefore).Contains(ButtonId), "used when there");
|
||||
Check.False(rig.S.EnableNavigation, "navigation off while it watches");
|
||||
Check.Eq(Info(rig).GetProperty("errand").GetProperty("phase").GetString(), "waiting", "watching the door");
|
||||
var errand = Run(rig).GetType().GetField("Errand")!.GetValue(Run(rig))!;
|
||||
// One pull, then the door watched: a door shows open ~4.5 s after (Thread 0x5873, 2026-11-16), and a second
|
||||
// pull before then flips it shut. Not again at 3 s; again after 8 s; given up after 12 s.
|
||||
int pulls() => FakeHost.Uses.Skip(usesBefore).Count(u => u == ButtonId);
|
||||
errand.GetType().GetField("PhaseAt")!.SetValue(errand, Environment.TickCount64 - 3000);
|
||||
Tick(rig);
|
||||
Check.Eq(pulls(), 1, "not pulled again 3 s on (the door may still be opening)");
|
||||
errand.GetType().GetField("PhaseAt")!.SetValue(errand, Environment.TickCount64 - 9000);
|
||||
Tick(rig);
|
||||
Check.Eq(pulls(), 2, "pulled again 9 s on, the door still shut");
|
||||
errand.GetType().GetField("PhaseAt")!.SetValue(errand, Environment.TickCount64 - 13000);
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Any(l => l.Contains("Button 0x7E7E9005 didn't open door 0x7E7E9003")), "nothing opened: " + Show(said));
|
||||
Check.Eq(Info(rig).GetProperty("last").GetString(), "notopened 7E7E9005 7E7E9003", "notopened, in radunexploreinfo[]");
|
||||
Check.Eq(St(rig).State, 5, "back at the door");
|
||||
|
||||
// The lever: used, the door opens, the walk goes through it first.
|
||||
said = rig.Typed("/ra dunnav-explore lever 7E7E9004 door 7E7E9003");
|
||||
Check.True(said[0].Contains("going to pull Lever 0x7E7E9004"), "the lever: " + Show(said));
|
||||
rig.At(5.5, 25, rig.D.Hall[0, 2]);
|
||||
Tick(rig);
|
||||
Check.True(FakeHost.Uses.Contains(LeverId), "pulled");
|
||||
FakeHost.ObjectStates[DoorId] = DoorClosed | DoorEthereal;
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Any(l => l.Contains("Lever 0x7E7E9004 opened Door 0x7E7E9003 → through it first (2 room(s) behind it)")), "opened: " + Show(said));
|
||||
Check.Eq(St(rig).State, 1, "exploring again");
|
||||
Check.Eq(Info(rig).GetProperty("last").GetString(), "opened 7E7E9003 7E7E9004", "opened, in radunexploreinfo[]");
|
||||
Check.Eq(Info(rig).GetProperty("doors").GetArrayLength(), 0, "no shut door left");
|
||||
var geo = rig.D.Geo();
|
||||
// Along its legs (the west corridor is one run between two openings in line: no point in it).
|
||||
var pts = rig.S.CurrentRoute.Points;
|
||||
var cells = new HashSet<uint>();
|
||||
for (int i = 0; i + 1 < pts.Count; i++)
|
||||
for (int k = 0; k <= 20; k++)
|
||||
{
|
||||
double f = k / 20.0;
|
||||
cells.Add(DungeonPathfinder.CellAt(rig.D.Graph, geo, new NavPoint { NS = pts[i].NS + (pts[i + 1].NS - pts[i].NS) * f, EW = pts[i].EW + (pts[i + 1].EW - pts[i].EW) * f }));
|
||||
}
|
||||
Check.True(cells.Contains(rig.D.W1) && cells.Contains(rig.D.West), "the walk goes through the door, the corridor and into the west room: " + Pts(pts));
|
||||
Check.True(rig.S.EnableNavigation && rig.S.IsMacroRunning, "walking");
|
||||
StandIn(rig, rig.D.W1); Tick(rig);
|
||||
StandIn(rig, rig.D.West); Tick(rig);
|
||||
Finish(rig);
|
||||
said = Said(() => Tick(rig));
|
||||
var s = St(rig);
|
||||
Check.True(said.Count == 1 && said[0].Contains($"done, {s.Rooms} of {s.Rooms} rooms") && !said[0].Contains("shut door"), "done, every room: " + Show(said));
|
||||
}
|
||||
|
||||
private static void PluginDoorsMore()
|
||||
{
|
||||
// Done at the doors: the rooms behind them said.
|
||||
var rig = LeverRig("NavProfiles-explore-doors-done");
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
WalkAllBut(rig, rig.D.W1, rig.D.West);
|
||||
Finish(rig);
|
||||
Tick(rig);
|
||||
var said = rig.Typed("/ra dunnav-explore done");
|
||||
Check.True(said.Count == 1 && said[0].Contains("2 more behind 1 shut door(s)"), "done at the doors: " + Show(said));
|
||||
Check.Eq(St(rig).State, 3, "done");
|
||||
said = rig.Typed("/ra dunnav-explore done");
|
||||
Check.True(said[0].Contains("none is"), "done again: nothing waits: " + Show(said));
|
||||
|
||||
// A shut door that opens by itself while it waits: through it.
|
||||
rig = LeverRig("NavProfiles-explore-doors-self");
|
||||
rig.Typed("/ra dunnav-explore");
|
||||
WalkAllBut(rig, rig.D.W1, rig.D.West);
|
||||
Finish(rig);
|
||||
Tick(rig);
|
||||
FakeHost.ObjectStates[DoorId] = DoorClosed | DoorEthereal;
|
||||
Run(rig).GetType().GetField("NextCheckAt")!.SetValue(Run(rig), 0L);
|
||||
said = Said(() => Tick(rig));
|
||||
Check.True(said.Any(l => l.Contains("Door 0x7E7E9003 is open → through it first")), "an open door: " + Show(said));
|
||||
Check.Eq(St(rig).State, 1, "exploring again");
|
||||
|
||||
// A door it could use, that the door opener gave up on (locked, no picks): shut from then on.
|
||||
rig = LeverRig("NavProfiles-explore-doors-locked", doorUsable: 0x20);
|
||||
said = rig.Typed("/ra dunnav-explore");
|
||||
Check.False(said[0].Contains("shut door"), "a door you can use isn't shut: " + Show(said));
|
||||
rig.Call("NoteExploreDoorRefused", DoorId, "locked");
|
||||
Tick(rig);
|
||||
var info = Info(rig);
|
||||
Check.True(info.GetProperty("doors").GetArrayLength() == 1 && info.GetProperty("doors")[0].GetProperty("why").GetString() == "locked",
|
||||
"the door opener gave up on it: shut (locked): " + info.GetRawText());
|
||||
|
||||
// Resume: stopped, then carried on with the rooms entered kept.
|
||||
int entered = St(rig).Visited;
|
||||
StandIn(rig, rig.D.E1); Tick(rig);
|
||||
rig.Typed("/ra dunnav-explore stop");
|
||||
Check.Eq(St(rig).State, 4, "stopped");
|
||||
said = rig.Typed("/ra dunnav-explore resume");
|
||||
Check.True(said.Count == 1 && said[0].Contains("exploring again"), "resumed: " + Show(said));
|
||||
Check.True(St(rig).State == 1 && St(rig).Visited >= entered + 1, "the rooms entered kept");
|
||||
said = rig.Typed("/ra dunnav-explore resume");
|
||||
Check.True(said[0].Contains("already exploring"), "resume while exploring: " + Show(said));
|
||||
}
|
||||
|
||||
private static void Expressions()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
var host = FakeHost.Create();
|
||||
var m = new MetaManager(new LegacyUiSettings(), host, new PlayerVitalsCache());
|
||||
Check.Eq(m.Expressions.Evaluate("radunexplore[]"), "0", "not wired: 0");
|
||||
Check.Eq(m.Expressions.Evaluate("radunexplorerooms[]"), "0", "rooms 0");
|
||||
m.SetDunExploreStatus(() => (1, 12, 5));
|
||||
Check.Eq(m.Expressions.Evaluate("radunexplore[]"), "1", "exploring");
|
||||
Check.Eq(m.Expressions.Evaluate("radunexplorerooms[]"), "12", "rooms");
|
||||
Check.Eq(m.Expressions.Evaluate("radunexplorevisited[]"), "5", "entered");
|
||||
}
|
||||
|
||||
private static void TinyHiveRealDats()
|
||||
{
|
||||
if (!Directory.Exists(DunRouteTests.AcDir)) { Console.WriteLine(" (no dats on this PC: skipped)"); return; }
|
||||
var loader = new GeometryLoader();
|
||||
if (!loader.Initialize(DunRouteTests.AcDir)) { Console.WriteLine(" (geometry loader failed: " + loader.StatusMessage + ")"); return; }
|
||||
try
|
||||
{
|
||||
const uint lb = 0x0289, start = 0x028902A5, nook = 0x028902BA;
|
||||
var graph = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
var geo = DungeonPathfinder.GetGeometry(lb, loader.CellDat, loader.DungeonLOS);
|
||||
Check.True(graph.Count > 400 && geo != null, $"Tiny Hive loaded ({graph.Count} cells)");
|
||||
var s = graph[start];
|
||||
var p = new PatrolPortal { Id = 0x7028905D, Name = "Surface Portal", Cell = nook, X = 2 * 192 + 110, Y = 0x89 * 192 - 3.77927, Z = -23.995 };
|
||||
var at = (DungeonGeometry.NavToWorld(s.EW), DungeonGeometry.NavToWorld(s.NS), (double)s.Z);
|
||||
var clock = System.Diagnostics.Stopwatch.StartNew();
|
||||
var route = DungeonPathfinder.BuildExploreRoute(graph, start, null, geo, null, new List<PatrolPortal> { p }, at, null, out var plan);
|
||||
double ms = clock.Elapsed.TotalMilliseconds;
|
||||
var walked = RoomsWalked(route.Points, graph, geo, plan);
|
||||
var missed = plan.PlanRooms.Where(r => !walked.Contains(r)).ToList();
|
||||
double yards = 0;
|
||||
for (int i = 0; i + 1 < route.Points.Count; i++)
|
||||
yards += Math.Sqrt(Math.Pow(route.Points[i + 1].NS - route.Points[i].NS, 2) + Math.Pow(route.Points[i + 1].EW - route.Points[i].EW, 2)) * 240.0;
|
||||
var lap = DungeonPathfinder.BuildPatrolRoute(graph, start, null, geo, new DungeonPatrolOptions { Coverage = PatrolCoverage.Everything }, new List<PatrolPortal> { p }, at);
|
||||
double lapYards = 0;
|
||||
for (int i = 0; i < lap.Points.Count; i++)
|
||||
{
|
||||
var a = lap.Points[i]; var b = lap.Points[(i + 1) % lap.Points.Count];
|
||||
lapYards += Math.Sqrt(Math.Pow(b.NS - a.NS, 2) + Math.Pow(b.EW - a.EW, 2)) * 240.0;
|
||||
}
|
||||
Console.WriteLine($" explore: {plan.PlanRooms.Count} rooms, {route.Points.Count} points, {yards:F0} yd, laid in {ms:F0} ms; "
|
||||
+ $"the patrol's Everything lap: {lap.Points.Count} points, {lapYards:F0} yd; rooms the legs miss: {missed.Count}");
|
||||
Check.True(plan.ByRoom && plan.PlanRooms.Count > 10, $"rooms ({plan.PlanRooms.Count})");
|
||||
Check.Eq(plan.Order.Count, plan.PlanRooms.Count - 1, "each room but the start in the order");
|
||||
Check.True(missed.Count == 0, "every room walked into; missed: " + string.Join(",", missed.Select(r => plan.Rooms.Cells[r][0].ToString("X8"))));
|
||||
double near = DungeonPathfinder.NearestApproach(route.Points, closed: false, p);
|
||||
Check.True(near >= p.Radius - 0.05, $"keeps out of the Surface Portal ({near:F1} m)");
|
||||
}
|
||||
finally { DungeonPathfinder.InvalidateCache(); }
|
||||
}
|
||||
}
|
||||
77
Tools/RynthCore.RynthAiHostTests/Tests/DunNavToTests.cs
Normal file
77
Tools/RynthCore.RynthAiHostTests/Tests/DunNavToTests.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// /ra dunnav-to <object id> (2026-11-15): a walk on the dungeon map to an object's own cell (any
|
||||
// floor), for a script's walks to the monsters still to be killed after an explore.
|
||||
// On DunRouteTests' sample dungeon (the start in the hall's middle, the west room two rooms away).
|
||||
internal static class DunNavToTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("dunnav-to: walks to an object's cell on the dungeon map, the macro on; refuses an unknown one or one outside the dungeon", WalksToObject);
|
||||
}
|
||||
|
||||
private const uint Rat = 0x7E7E9101, Outside = 0x7E7E9102, Unknown = 0x7E7E9103;
|
||||
|
||||
private static void WalksToObject()
|
||||
{
|
||||
var rig = new DunRouteTests.Rig("NavProfiles-dunnav-to");
|
||||
FakeHost.Names[Rat] = "Threadbound Rat";
|
||||
FakeHost.Positions[Rat] = (rig.D.West, -17f, 25f, 0f);
|
||||
rig.S.IsMacroRunning = false;
|
||||
|
||||
var said = rig.Typed("/ra dunnav-to 0x7E7E9101");
|
||||
Check.True(said.Count == 1 && said[0].StartsWith("[RynthAi] DunNav-To: 'Threadbound Rat' 0x7E7E9101") && said[0].Contains("walking there"),
|
||||
"it answers: " + string.Join(" | ", said));
|
||||
var pts = rig.S.CurrentRoute.Points;
|
||||
Check.True(pts.Count >= 2, $"a walk ({pts.Count} points)");
|
||||
Check.Eq(rig.S.CurrentRoute.RouteType, NavRouteType.Once, "a Once walk");
|
||||
Check.True(rig.S.IsMacroRunning && rig.S.EnableNavigation && rig.S.ActiveNavIndex == 0, "macro and navigation on, from its start");
|
||||
var last = pts[^1];
|
||||
double lx = DungeonGeometry.NavToWorld(last.EW) - DunRouteTests.Ox, ly = DungeonGeometry.NavToWorld(last.NS) - DunRouteTests.Oy;
|
||||
Check.True(Math.Abs(lx - -17) < 3 && Math.Abs(ly - 25) < 3, $"it ends at the rat ({lx:F1}, {ly:F1})");
|
||||
// Through w1 (x -10..0, y 22.35..27.65), the one way into the west room: a leg crosses x = -5 inside it.
|
||||
bool throughW1 = false;
|
||||
double X(NavPoint p) => DungeonGeometry.NavToWorld(p.EW) - DunRouteTests.Ox;
|
||||
double Y(NavPoint p) => DungeonGeometry.NavToWorld(p.NS) - DunRouteTests.Oy;
|
||||
for (int i = 0; i + 1 < pts.Count; i++)
|
||||
{
|
||||
double ax = X(pts[i]), bx = X(pts[i + 1]);
|
||||
if ((ax - -5) * (bx - -5) > 0 || Math.Abs(bx - ax) < 1e-6) continue;
|
||||
double y = Y(pts[i]) + (Y(pts[i + 1]) - Y(pts[i])) * ((-5 - ax) / (bx - ax));
|
||||
throughW1 |= y > 22.35 && y < 27.65;
|
||||
}
|
||||
Check.True(throughW1, "through w1, the way to the west room");
|
||||
|
||||
// Decimal ids work too; an unknown object, or one outside the dungeon, is refused (nothing changed).
|
||||
var before = rig.S.CurrentRoute;
|
||||
said = rig.Typed("/ra dunnav-to " + Unknown.ToString());
|
||||
Check.True(said.Count == 1 && said[0].Contains("has no position the client knows"), "unknown: " + string.Join(" | ", said));
|
||||
FakeHost.Positions[Outside] = (0xA9B40020, 10f, 10f, 0f);
|
||||
said = rig.Typed("/ra dunnav-to 0x7E7E9102");
|
||||
Check.True(said.Count == 1 && said[0].Contains("isn't in this dungeon"), "outside: " + string.Join(" | ", said));
|
||||
said = rig.Typed("/ra dunnav-to");
|
||||
Check.True(said.Count == 1 && said[0].Contains("Usage: /ra dunnav-to <object id>"), "no id: the usage");
|
||||
Check.True(ReferenceEquals(rig.S.CurrentRoute, before), "the walk in hand is left alone");
|
||||
|
||||
// In a Thread on DreamWeave it is off, as the patrol and the explore are.
|
||||
var thread = new DunRouteTests.Rig("NavProfiles-dunnav-to-thread", world: "DreamWeave");
|
||||
FakeHost.Names[Rat] = "Threadbound Rat";
|
||||
FakeHost.Positions[Rat] = (thread.D.West, -17f, 25f, 0f);
|
||||
thread.S.IsMacroRunning = false;
|
||||
ServerPolicy.NoteChat("[REALM] id=0 inst=7841 eph=1 name=Base World", thread.D.Start);
|
||||
var routeBefore = thread.S.CurrentRoute;
|
||||
said = thread.Typed("/ra dunnav-to 0x7E7E9101");
|
||||
Check.True(said.Count == 1 && said[0].Contains("turned off in Threads"), "in a Thread on DreamWeave: refused: " + string.Join(" | ", said));
|
||||
Check.False(thread.S.IsMacroRunning || thread.S.EnableNavigation, "nothing started");
|
||||
Check.True(ReferenceEquals(thread.S.CurrentRoute, routeBefore), "no walk laid");
|
||||
ServerPolicy.Forget();
|
||||
}
|
||||
}
|
||||
|
|
@ -62,12 +62,12 @@ internal static class DunRouteTests
|
|||
|
||||
// ── The sample dungeon ───────────────────────────────────────────────────
|
||||
|
||||
private const uint Lb = 0x7E7E;
|
||||
private const double Ox = 0x7E * 192.0, Oy = 0x7E * 192.0;
|
||||
private const uint SurfaceId = 0x7E7E9001, DepthsId = 0x7E7E9002;
|
||||
internal const uint Lb = 0x7E7E;
|
||||
internal const double Ox = 0x7E * 192.0, Oy = 0x7E * 192.0;
|
||||
internal const uint SurfaceId = 0x7E7E9001, DepthsId = 0x7E7E9002;
|
||||
|
||||
/// <summary>A hand-built dungeon in landblock 0x7E7E; positions are landblock-local metres.</summary>
|
||||
private sealed class Sample
|
||||
internal sealed class Sample
|
||||
{
|
||||
public readonly Dictionary<uint, DungeonNavNode> Graph = new();
|
||||
public readonly List<(uint, V3[])> Portals = new(), Floors = new(), Walls = new();
|
||||
|
|
@ -409,7 +409,7 @@ internal static class DunRouteTests
|
|||
|
||||
// ── Files ────────────────────────────────────────────────────────────────
|
||||
|
||||
private static string Fresh(string sub)
|
||||
internal static string Fresh(string sub)
|
||||
{
|
||||
string dir = Path.Combine(Program.TempRoot, sub);
|
||||
if (Directory.Exists(dir)) Directory.Delete(dir, true);
|
||||
|
|
@ -769,9 +769,9 @@ internal static class DunRouteTests
|
|||
// ── The plugin ───────────────────────────────────────────────────────────
|
||||
|
||||
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
private const uint Player = 0x50000E01;
|
||||
internal const uint Player = 0x50000E01;
|
||||
|
||||
private sealed class Rig
|
||||
internal sealed class Rig
|
||||
{
|
||||
public readonly RynthAiPlugin P = new();
|
||||
public readonly LegacyUiSettings S = new();
|
||||
|
|
@ -779,7 +779,7 @@ internal static class DunRouteTests
|
|||
public readonly DungeonGeometry Geo;
|
||||
public readonly WorldObjectCache Cache;
|
||||
|
||||
public Rig(string folder, string world = "", double lx = 15, double ly = 15, bool namedExit = true)
|
||||
public Rig(string folder, string world = "", double lx = 15, double ly = 15, bool namedExit = true, Action? beforeCreate = null)
|
||||
{
|
||||
FakeHost.Reset();
|
||||
ServerPolicy.Forget();
|
||||
|
|
@ -794,6 +794,7 @@ internal static class DunRouteTests
|
|||
FakeHost.Names[DepthsId] = "Portal to the Depths";
|
||||
FakeHost.ItemTypes[DepthsId] = 0x00010000;
|
||||
FakeHost.Positions[DepthsId] = (D.Side, 45f, 5f, 0f);
|
||||
beforeCreate?.Invoke(); // FakeHost options read when the host is made (WeaponCalls: UseObject)
|
||||
var host = FakeHost.Create(Player);
|
||||
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(P, new object[] { FakeHost.LastApi });
|
||||
var dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
|
||||
|
|
@ -1301,7 +1302,7 @@ internal static class DunRouteTests
|
|||
|
||||
// ── Tiny Hive on the real dats ───────────────────────────────────────────
|
||||
|
||||
private const string AcDir = @"C:\Turbine\Asheron's Call";
|
||||
internal const string AcDir = @"C:\Turbine\Asheron's Call";
|
||||
|
||||
private static void TinyHiveRealDats()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ internal static class HazardFloorTests
|
|||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("hazard floors: a polygon facing up at FloorZ or more is floor; walls, ceilings, steep slopes are not", WalkableFloor);
|
||||
r.Add("hazard floors (2026-11-16): kept out of where that shuts the walk in (stands on one, or most of the dungeon behind them); a side pool isn't", ShutIn);
|
||||
r.Add("hazard floors: a cell's floor surfaces are its floor polygons', not its walls', ceiling's or portals'", FloorSurfaces);
|
||||
r.Add("hazard floors: a hazard texture on a cell's wall doesn't make it a hazard; on its floor it does", WallVersusFloor);
|
||||
r.Add("hazard floors: learnhere takes a rare floor texture, never a wall texture", LearnIgnoresWalls);
|
||||
|
|
@ -223,4 +224,27 @@ internal static class HazardFloorTests
|
|||
}
|
||||
finally { ResetSet(); }
|
||||
}
|
||||
|
||||
// A Thread arrived on lava: 14 of its cells reachable round 9 lava cells, the explore "done" with 8 of 75 rooms.
|
||||
private static void ShutIn()
|
||||
{
|
||||
// A corridor 1-2-3-4-5-6, and a side room 7 off 2.
|
||||
var g = new Dictionary<uint, DungeonNavNode>();
|
||||
void Link(uint a, uint b)
|
||||
{
|
||||
if (!g.TryGetValue(a, out var na)) g[a] = na = new DungeonNavNode { CellId = a };
|
||||
if (!g.TryGetValue(b, out var nb)) g[b] = nb = new DungeonNavNode { CellId = b };
|
||||
na.Neighbors.Add(b); nb.Neighbors.Add(a);
|
||||
}
|
||||
Link(1, 2); Link(2, 3); Link(3, 4); Link(4, 5); Link(5, 6); Link(2, 7);
|
||||
var lava = new HashSet<uint> { 3 };
|
||||
Check.True(DungeonPathfinder.HazardFloorsShutIn(g, 1, lava, lava, out int r, out int j), $"lava across the corridor: shut in ({r} of {j})");
|
||||
Check.Eq(r, 3, "1, 2 and the side room reachable");
|
||||
Check.Eq(j, 7, "of the 7 the openings join");
|
||||
var under = new HashSet<uint> { 1 };
|
||||
Check.True(DungeonPathfinder.HazardFloorsShutIn(g, 1, under, under, out _, out _), "standing on lava: shut in");
|
||||
var side = new HashSet<uint> { 7 };
|
||||
Check.False(DungeonPathfinder.HazardFloorsShutIn(g, 1, side, side, out r, out j), $"a pool in the side room: kept out of ({r} of {j})");
|
||||
Check.False(DungeonPathfinder.HazardFloorsShutIn(g, 1, lava, null, out _, out _), "no floor cells: nothing to walk");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
73
Tools/RynthCore.RynthAiHostTests/Tests/HoleTests.cs
Normal file
73
Tools/RynthCore.RynthAiHostTests/Tests/HoleTests.cs
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// The explore walked over a hole (DungeonPathfinder.Holes.cs, 2026-11-15). DreamWeave Thread 0x039B:
|
||||
// a walkway at z 6 through two square rooms, each with a 5 x 5 m pit in the middle (down to the z -6
|
||||
// rooms) and a 2 m rim; the walk went doorway to doorway over both pits. And a corridor at -6 that
|
||||
// opens into a round room whose floor (-12) is its other cells' (a floorless cell at the opening):
|
||||
// a 6 m ledge the ledge finder didn't see.
|
||||
internal static class HoleTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("holes: Thread 0x039B on the real dats - the explore walks round the walkway's two pits, not over them; its 6 m ledge is seen (if the dats are here)", Real039B);
|
||||
}
|
||||
|
||||
private static void Real039B()
|
||||
{
|
||||
string acDir = DunRouteTests.AcDir;
|
||||
if (!Directory.Exists(acDir)) { Console.WriteLine(" (no dats on this PC: skipped)"); return; }
|
||||
var loader = new GeometryLoader();
|
||||
if (!loader.Initialize(acDir)) { Console.WriteLine(" (geometry loader failed: " + loader.StatusMessage + ")"); return; }
|
||||
try
|
||||
{
|
||||
const uint lb = 0x039B;
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var graph = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
var geo = DungeonPathfinder.GetGeometry(lb, loader.CellDat, loader.DungeonLOS)!;
|
||||
Check.NotNull(geo, "geometry");
|
||||
var ledges = DungeonPathfinder.FindLedges(graph, geo);
|
||||
Check.True(ledges.Exists(l => (l.High & 0xFFFF) == 0x014F && (l.Low & 0xFFFF) == 0x0143),
|
||||
$"the corridor's 6 m ledge into the round room is seen ({ledges.Count} ledge(s))");
|
||||
|
||||
var exit = new PatrolPortal { Id = 0x7039B3EB, Name = "Thread Exit", Cell = 0x039B015E, X = 665.9, Y = 29689.7, Z = -6.1 };
|
||||
foreach (bool holes in new[] { false, true })
|
||||
{
|
||||
DungeonPathfinder.HolesEnabled = holes;
|
||||
var route = DungeonPathfinder.BuildExploreRoute(graph, 0x039B0177, null, geo, null, new[] { exit }, (606.0, 29720.0, 6.0), null, out _);
|
||||
int over = 0;
|
||||
var pts = route.Points;
|
||||
for (int i = 0; i + 1 < pts.Count; i++)
|
||||
{
|
||||
double x0 = DungeonGeometry.NavToWorld(pts[i].EW), y0 = DungeonGeometry.NavToWorld(pts[i].NS), z0 = pts[i].Z * 240.0;
|
||||
double x1 = DungeonGeometry.NavToWorld(pts[i + 1].EW), y1 = DungeonGeometry.NavToWorld(pts[i + 1].NS);
|
||||
if (z0 < 4 || pts[i + 1].Z * 240.0 < 4) continue; // legs along the walkway (z 6), not down its ramp
|
||||
double len = Math.Sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0));
|
||||
int n = Math.Max(1, (int)Math.Ceiling(len / 0.5));
|
||||
for (int s = 1; s < n; s++)
|
||||
{
|
||||
double t = (double)s / n, x = x0 + (x1 - x0) * t, y = y0 + (y1 - y0) * t;
|
||||
if (!geo.TryFloorHeight(x, y, 6.0, 1.0, out _)) { over++; break; }
|
||||
}
|
||||
}
|
||||
Console.WriteLine($" holes {(holes ? "on" : "off")}: {pts.Count} points, {over} walkway leg(s) over missing floor; {DungeonPathfinder.MainRouteNote}");
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
if (holes) Check.Eq(over, 0, "no walkway leg over a pit");
|
||||
else Check.True(over >= 2, $"as laid, the walk went over both pits ({over})");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
DungeonPathfinder.HolesEnabled = true;
|
||||
loader.Dispose();
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -27,6 +27,7 @@ internal static class HuntBuildingTests
|
|||
r.Add("hunt buildings: of a building's two doors, the one giving the shorter walk (the other's way round never asked for)", NearerDoor);
|
||||
r.Add("hunt buildings: from inside, a monster outdoors is walked to out through the nearer door, then on RynthNav's map", OutOfBuilding);
|
||||
r.Add("hunt buildings: inside a building with no door known (or none known at all): back out the way in", NoDoorFallsBack);
|
||||
r.Add("hunt buildings (2026-11-16): inside, no door it can walk to from here, or no way on from any: back out the way in, no monster left out", NoDoorFromHere);
|
||||
r.Add("hunt buildings: one in the same building through its rooms; one in another building out of one door and in by another", SameAndOtherBuilding);
|
||||
r.Add("hunt buildings: a door whose step out isn't on the ground is never used; a building it doesn't know is left alone", DoorOffTheGround);
|
||||
r.Add("building map: a hand-built house: its door faces out, a window and a slit are no doors, a shared opening joins two buildings", HandBuiltHouse);
|
||||
|
|
@ -202,6 +203,44 @@ internal static class HuntBuildingTests
|
|||
Check.True(d.Act == OutdoorHunt.Act.Walk && h2.WalkingOut, "no building map at all: the same");
|
||||
}
|
||||
|
||||
// A Thread: after a kill in a building every monster outside was "left out for 120 s: no door of
|
||||
// building 1747#1 it can walk to" and the hunt stood 2 min. Where it stands is the trouble, not them.
|
||||
private static void NoDoorFromHere()
|
||||
{
|
||||
// The house's only door is in the east room, and the west room (where it stands) doesn't join it.
|
||||
var house = House(East(RoomE, 1030, 1000));
|
||||
house.Apart.Add((RoomW, RoomE));
|
||||
var h = new OutdoorHunt();
|
||||
h.Start(T0, V(990, 1000));
|
||||
h.Track(V(1018, 1000), indoors: false);
|
||||
h.Track(V(1020, 1000), indoors: true);
|
||||
h.Track(V(1022, 1000), indoors: true);
|
||||
var me = V(1022, 1000);
|
||||
var d = h.Tick(T0, me, RoomW, true, Sorted(C(1, V(990, 1000), me), C(2, V(1000, 1030), me)), new Nav().Path, house);
|
||||
Check.True(d.Act == OutdoorHunt.Act.Walk && h.WalkingOut && h.Note.Contains("back out the way in"), $"no door from here: back out the way in ({d.Act}, {h.Note})");
|
||||
Check.False(h.IsSkipped(1, T0.AddSeconds(5)) || h.IsSkipped(2, T0.AddSeconds(5)), "no monster left out for it");
|
||||
|
||||
// A door it can walk to, but RynthNav finds no way on from its step to either monster.
|
||||
var house2 = House(West(RoomW, 1020, 1000));
|
||||
var nav = new Nav();
|
||||
nav.Overrides[(990, 1000)] = new(OutdoorHunt.PathStatus.NoPath, Array.Empty<Vec>(), 0, 0);
|
||||
nav.Overrides[(1000, 1030)] = new(OutdoorHunt.PathStatus.NoPath, Array.Empty<Vec>(), 0, 0);
|
||||
var h2 = new OutdoorHunt();
|
||||
h2.Start(T0, V(990, 1000));
|
||||
h2.Track(V(1018, 1000), indoors: false);
|
||||
h2.Track(V(1022, 1000), indoors: true);
|
||||
d = h2.Tick(T0, me, RoomW, true, Sorted(C(1, V(990, 1000), me), C(2, V(1000, 1030), me)), nav.Path, house2);
|
||||
Check.True(d.Act == OutdoorHunt.Act.Walk && h2.WalkingOut, $"no way on from its door: back out the way in ({d.Act}, {h2.Note})");
|
||||
Check.False(h2.IsSkipped(1, T0.AddSeconds(5)) || h2.IsSkipped(2, T0.AddSeconds(5)), "none left out for that either");
|
||||
|
||||
// Outdoors again, one RynthNav can't reach is left out as before.
|
||||
var h3 = new OutdoorHunt();
|
||||
h3.Start(T0, V(990, 1000));
|
||||
var out1 = V(1000, 1000);
|
||||
d = h3.Tick(T0, out1, Outdoors, true, Sorted(C(1, V(990, 1000), out1)), nav.Path, house2);
|
||||
Check.True(h3.IsSkipped(1, T0.AddSeconds(5)), "outdoors, an unreachable one is still left out");
|
||||
}
|
||||
|
||||
private static void SameAndOtherBuilding()
|
||||
{
|
||||
var me = V(1022, 1000);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ internal static class KeepHuntingAfterDeathTests
|
|||
r.Add("keep hunting (11-13): a meta's route loaded after the death, or the macro stopped: not started again, said in chat", Dropped);
|
||||
r.Add("keep hunting (11-13): /ra hunt death answers, sets it, says why not with the usage", Command);
|
||||
r.Add("keep hunting (11-13): KeepHuntingAfterDeath is off by default and round-trips (saved, copied)", Setting);
|
||||
r.Add("hunt (2026-11-16): a walk that ran out leaves nav on with no walk left, not off until the next walk", NavStaysOn);
|
||||
}
|
||||
|
||||
private static void Decide()
|
||||
|
|
@ -87,6 +88,33 @@ internal static class KeepHuntingAfterDeathTests
|
|||
public string All => string.Join(" | ", FakeHost.Chat);
|
||||
}
|
||||
|
||||
private static void NavStaysOn()
|
||||
{
|
||||
var g = new Rig();
|
||||
g.Hunting();
|
||||
var walk = (NavRouteParser)g.Get("_huntRoute")!;
|
||||
walk.Points.Add(new NavPoint { Type = NavPointType.Point, NS = 1, EW = 1 });
|
||||
g.S.ActiveNavIndex = 1; // walked off its end
|
||||
g.S.EnableNavigation = false; // what the nav engine does then (CompleteOnceRoute)
|
||||
Check.True(g.S.NavRouteFinished(), "the walk is a finished Once route");
|
||||
g.Call("TickOutdoorHunt");
|
||||
Check.True(g.S.EnableNavigation, "nav on again at once");
|
||||
Check.True(ReferenceEquals(g.S.CurrentRoute, g.Get("_huntRoute")) && g.S.CurrentRoute.Points.Count == 0,
|
||||
"with an empty walk: nothing for the arbiter to hold Navigating for");
|
||||
Check.True(g.P.HuntActive, "and the hunt still on");
|
||||
|
||||
// The player turning nav off mid-walk is left alone (a walk still to go: not finished).
|
||||
var h = new Rig();
|
||||
h.Hunting();
|
||||
var w2 = (NavRouteParser)h.Get("_huntRoute")!;
|
||||
w2.Points.Add(new NavPoint { Type = NavPointType.Point, NS = 1, EW = 1 });
|
||||
w2.Points.Add(new NavPoint { Type = NavPointType.Point, NS = 2, EW = 2 });
|
||||
h.S.ActiveNavIndex = 1;
|
||||
h.S.EnableNavigation = false;
|
||||
h.Call("TickOutdoorHunt");
|
||||
Check.False(h.S.EnableNavigation, "nav off mid-walk: left off");
|
||||
}
|
||||
|
||||
private static void PauseAndRestart()
|
||||
{
|
||||
var g = new Rig();
|
||||
|
|
|
|||
182
Tools/RynthCore.RynthAiHostTests/Tests/LedgeTests.cs
Normal file
182
Tools/RynthCore.RynthAiHostTests/Tests/LedgeTests.cs
Normal file
|
|
@ -0,0 +1,182 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
using V3 = RynthCore.Plugin.RynthAi.Raycasting.Vector3;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Ledges (DungeonPathfinder.Ledges.cs, 2026-11-15). DreamWeave Thread 0x0192: the explore walked over
|
||||
// a 6 m ledge (019201C4, floor 0 -> 019201C6, floor -6), which AC won't walk a character off (it slides
|
||||
// along the edge) and nobody walks up; it snagged there every time. Now an opening whose floors are more
|
||||
// than LedgeMeters apart is closed in the dungeon graph (walked round), unless it is the only way on.
|
||||
// - a high room and a low room joined by a ledge and by stairs round: the ledge is found (the stairs
|
||||
// aren't one) and closed, and the way from one to the other goes by the stairs;
|
||||
// - the same with no stairs: the ledge is the only way and stays open;
|
||||
// - 0x0192 on the real dats: its twelve ledges are closed, every cell still reached, and the explore's
|
||||
// walk never steps across one.
|
||||
internal static class LedgeTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("ledges: a ledge with stairs round is found (the stairs aren't one) and closed; the way goes by the stairs", LedgeWithStairs);
|
||||
r.Add("ledges: a ledge that is the only way on stays open", LedgeOnlyWay);
|
||||
r.Add("ledges: Thread 0x0192 on the real dats: 12 ledges closed, every cell reached, the explore never steps over one (if the dats are here)", Real0192);
|
||||
}
|
||||
|
||||
private sealed class Dungeon
|
||||
{
|
||||
public readonly Dictionary<uint, DungeonNavNode> Graph = new();
|
||||
public readonly List<(uint, V3[])> Portals = new();
|
||||
public readonly List<(uint, V3[])> Floors = new();
|
||||
public readonly List<(uint, V3[])> Walls = new();
|
||||
private uint _next = 0x7E7E0100;
|
||||
|
||||
public uint Cell(double x0, double y0, double x1, double y1, double z = 0)
|
||||
{
|
||||
uint id = _next++;
|
||||
Graph[id] = new DungeonNavNode { CellId = id, EW = DungeonGeometry.WorldToNav((x0 + x1) / 2), NS = DungeonGeometry.WorldToNav((y0 + y1) / 2), Z = (float)z };
|
||||
Floors.Add((id, new[] { new V3((float)x0, (float)y0, (float)z), new V3((float)x1, (float)y0, (float)z), new V3((float)x1, (float)y1, (float)z), new V3((float)x0, (float)y1, (float)z) }));
|
||||
return id;
|
||||
}
|
||||
|
||||
// An opening from floor z up 3 m (the high side's floor for a ledge).
|
||||
public void OpenX(uint a, uint b, double x, double y0, double y1, double z = 0) => Open(a, b, Quad(x, y0, x, y1, z));
|
||||
public void OpenY(uint a, uint b, double y, double x0, double x1, double z = 0) => Open(a, b, Quad(x0, y, x1, y, z));
|
||||
|
||||
private void Open(uint a, uint b, V3[] quad)
|
||||
{
|
||||
Graph[a].Neighbors.Add(b);
|
||||
Graph[b].Neighbors.Add(a);
|
||||
Portals.Add((a, quad));
|
||||
Portals.Add((b, quad.Reverse().ToArray()));
|
||||
}
|
||||
|
||||
private static V3[] Quad(double x0, double y0, double x1, double y1, double z) => new[]
|
||||
{
|
||||
new V3((float)x0, (float)y0, (float)z), new V3((float)x1, (float)y1, (float)z),
|
||||
new V3((float)x1, (float)y1, (float)z + 3f), new V3((float)x0, (float)y0, (float)z + 3f),
|
||||
};
|
||||
|
||||
public DungeonGeometry Geo() => DungeonGeometry.Build(Graph, Portals, Floors, Walls);
|
||||
}
|
||||
|
||||
// A high room (floor 0) south of a low room (floor -6), a ledge between them; with stairs, a way
|
||||
// round east: six 1 m steps down, then a corridor back west into the low room.
|
||||
private static (Dungeon D, uint High, uint Low) Build(bool stairs)
|
||||
{
|
||||
var d = new Dungeon();
|
||||
uint high = d.Cell(0, 0, 10, 10, 0);
|
||||
uint low = d.Cell(0, 10, 10, 20, -6);
|
||||
d.OpenY(high, low, 10, 3, 7, 0);
|
||||
if (stairs)
|
||||
{
|
||||
uint prev = high;
|
||||
double x = 10;
|
||||
for (int i = 1; i <= 6; i++)
|
||||
{
|
||||
uint step = d.Cell(x, 2, x + 3, 8, -i);
|
||||
d.OpenX(prev, step, x, 2, 8, -i + 1);
|
||||
prev = step;
|
||||
x += 3;
|
||||
}
|
||||
uint up = d.Cell(x - 3, 8, x, 20, -6);
|
||||
d.OpenY(prev, up, 8, x - 3, x, -6);
|
||||
uint corr = d.Cell(10, 12, x - 3, 18, -6);
|
||||
d.OpenX(corr, up, x - 3, 12, 18, -6);
|
||||
d.OpenX(low, corr, 10, 12, 18, -6);
|
||||
}
|
||||
return (d, high, low);
|
||||
}
|
||||
|
||||
private static void LedgeWithStairs()
|
||||
{
|
||||
var (d, high, low) = Build(stairs: true);
|
||||
var geo = d.Geo();
|
||||
var ledges = DungeonPathfinder.FindLedges(d.Graph, geo);
|
||||
Check.Eq(ledges.Count, 1, "one ledge (the 1 m stairs are not ledges)");
|
||||
Check.True(ledges[0].High == high && ledges[0].Low == low, $"high {ledges[0].High:X8} -> low {ledges[0].Low:X8}");
|
||||
Check.Near(ledges[0].Step, 6.0, 0.01, "6 m");
|
||||
Check.True(DungeonPathfinder.FindPath(high, low, d.Graph).Count == 2, "before: straight over the ledge");
|
||||
|
||||
var kept = DungeonPathfinder.CloseLedges(d.Graph, ledges, out int closed);
|
||||
Check.Eq(closed, 1, "closed");
|
||||
Check.Eq(kept.Count, 0, "none kept open");
|
||||
Check.False(d.Graph[high].Neighbors.Contains(low) || d.Graph[low].Neighbors.Contains(high), "the ledge is gone both ways");
|
||||
var path = DungeonPathfinder.FindPath(high, low, d.Graph);
|
||||
Check.True(path.Count > 8, $"after: down the stairs and round ({path.Count} cells)");
|
||||
}
|
||||
|
||||
private static void LedgeOnlyWay()
|
||||
{
|
||||
var (d, high, low) = Build(stairs: false);
|
||||
var geo = d.Geo();
|
||||
var ledges = DungeonPathfinder.FindLedges(d.Graph, geo);
|
||||
Check.Eq(ledges.Count, 1, "the ledge");
|
||||
var kept = DungeonPathfinder.CloseLedges(d.Graph, ledges, out int closed);
|
||||
Check.Eq(closed, 0, "not closed");
|
||||
Check.Eq(kept.Count, 1, "kept: the only way on");
|
||||
Check.True(d.Graph[high].Neighbors.Contains(low) && d.Graph[low].Neighbors.Contains(high), "still linked both ways");
|
||||
}
|
||||
|
||||
private static void Real0192()
|
||||
{
|
||||
string acDir = DunRouteTests.AcDir;
|
||||
if (!Directory.Exists(acDir)) { Console.WriteLine(" (no dats on this PC: skipped)"); return; }
|
||||
var loader = new GeometryLoader();
|
||||
if (!loader.Initialize(acDir)) { Console.WriteLine(" (geometry loader failed: " + loader.StatusMessage + ")"); return; }
|
||||
try
|
||||
{
|
||||
const uint lb = 0x0192, start = 0x019201A8;
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var graph = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
int linksBefore = graph.Values.Sum(n => n.Neighbors.Count);
|
||||
var geo = DungeonPathfinder.GetGeometry(lb, loader.CellDat, loader.DungeonLOS);
|
||||
Check.NotNull(geo, "geometry");
|
||||
Console.WriteLine(" " + DungeonPathfinder.LedgeNote);
|
||||
Check.True(DungeonPathfinder.LedgeNoteLandblock == lb && DungeonPathfinder.LedgeNote != null
|
||||
&& DungeonPathfinder.LedgeNote.StartsWith("12 ledge(s)") && DungeonPathfinder.LedgeNote.Contains("12 closed"), "12 ledges, 12 closed");
|
||||
Check.False(graph[0x019201C4].Neighbors.Contains(0x019201C6), "019201C4 -> 019201C6 (the report's) closed");
|
||||
Check.True(graph.Values.Sum(n => n.Neighbors.Count) < linksBefore, "links gone from the cached graph");
|
||||
Check.True(ReferenceEquals(graph, DungeonPathfinder.GetGraph(lb, loader.CellDat)), "the cached graph itself");
|
||||
|
||||
// Every cell walkable before is still reached.
|
||||
var seen = new HashSet<uint> { start };
|
||||
var q = new Queue<uint>(); q.Enqueue(start);
|
||||
while (q.Count > 0)
|
||||
{
|
||||
var c = q.Dequeue();
|
||||
foreach (var nb in graph[c].Neighbors)
|
||||
if (graph.TryGetValue(nb, out var o) && !DungeonPathfinder.IsDropEdge(graph[c], o) && seen.Add(nb)) q.Enqueue(nb);
|
||||
}
|
||||
Check.Eq(seen.Count, 194, "all 194 cells still reached from the start");
|
||||
|
||||
// The explore's walk never steps from one side of a ledge to the other.
|
||||
var ledgeCells = new HashSet<(uint, uint)>
|
||||
{
|
||||
(0x01920133, 0x01920135), (0x01920133, 0x01920136), (0x0192013B, 0x0192013D), (0x0192013B, 0x0192013E),
|
||||
(0x01920143, 0x01920145), (0x01920143, 0x01920146), (0x019201C4, 0x019201C6), (0x019201C4, 0x019201C7),
|
||||
(0x019201CA, 0x019201CC), (0x019201CA, 0x019201CD), (0x019201D0, 0x019201D2), (0x019201D0, 0x019201D3),
|
||||
};
|
||||
var n0 = graph[start];
|
||||
var route = DungeonPathfinder.BuildExploreRoute(graph, start, null, geo, null, Array.Empty<PatrolPortal>(),
|
||||
(DungeonGeometry.NavToWorld(n0.EW), DungeonGeometry.NavToWorld(n0.NS), n0.Z), null, out var plan);
|
||||
Check.True(route.Points.Count > 50, $"an explore ({route.Points.Count} points)");
|
||||
int over = 0;
|
||||
for (int i = 0; i + 1 < route.Points.Count; i++)
|
||||
{
|
||||
uint a = DungeonPathfinder.CellAt(graph, geo, route.Points[i]), b = DungeonPathfinder.CellAt(graph, geo, route.Points[i + 1]);
|
||||
if (ledgeCells.Contains((a, b)) || ledgeCells.Contains((b, a))) over++;
|
||||
}
|
||||
Check.Eq(over, 0, "no leg steps over a ledge");
|
||||
}
|
||||
finally
|
||||
{
|
||||
loader.Dispose();
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -48,11 +48,12 @@ internal static class LootCorpseTests
|
|||
r.Add("loot chain: an item the cache never saw created is found in the corpse's contents and looted", UnseenItemRescued);
|
||||
r.Add("loot chain: without GetContainerContents an unseen item stays unseen (no crash)", UnseenItemOldEngine);
|
||||
r.Add("loot starvation: a corpse waiting behind far-off combat gets a turn, a close monster keeps combat", LootStarvation);
|
||||
r.Add("loot starvation (R-20261115-165857-1de7): a starved open waits for combat's first attack at a fresh lock, at most 3 s", StarvedOpenWaitsForFirstAttack);
|
||||
r.Add("loot logging: a corpse held by combat is logged once, with the reason", HeldByCombatLoggedOnce);
|
||||
r.Add("boost loot: our kill holds the next target until its corpse is looted (one kill, one loot)", BoostLootOneKillOneLoot);
|
||||
r.Add("boost loot: the wait ends after BoostLootKillWaitMs, for a close monster, and with Boost Loot off", BoostLootHoldLimits);
|
||||
r.Add("boost loot: looting the kill's corpse ends the wait; an older corpse does not", BoostLootWaitEndsOnKillCorpse);
|
||||
r.Add("death wait (11-08): Looting on, our kill holds the next target for the learned death + 1 s; Looting gets the tick", DeathWaitUsesLearnedTime);
|
||||
r.Add("death wait (11-08, R-20261115-165857-1de7): the learned death + 1 s keeps nav off; a monster in range is locked at once", DeathWaitUsesLearnedTime);
|
||||
r.Add("death wait (11-08): not learned yet: 2.5 s + 1 s; the corpse's coming is timed and learned", DeathWaitDefaultAndLearns);
|
||||
r.Add("death wait (11-08): looting the kill's corpse ends it at once; a corpse the rules don't take ends it soon after it came", DeathWaitEndsOnLoot);
|
||||
r.Add("death wait (11-08): no corpse in the time: it carries on; a close attacker is fought; Looting off changes nothing", DeathWaitLimits);
|
||||
|
|
@ -389,6 +390,53 @@ internal static class LootCorpseTests
|
|||
Check.Eq(ActivityArbiter.Decide(in buffing), BotActivity.Buffing, "buffing still outranks a starved corpse");
|
||||
}
|
||||
|
||||
// 2026-11-15, R-20261115-165857-1de7: a corpse claimed with nothing about, then a monster locked at
|
||||
// 15.5 m. The starved turn kept Looting and the open went out 0.3 s after the lock, ahead of the
|
||||
// first cast; the server didn't answer it for 5 s and combat stood behind it ("Combat" showing).
|
||||
private static void StarvedOpenWaitsForFirstAttack()
|
||||
{
|
||||
DateTime now = new(2026, 11, 15, 11, 57, 33);
|
||||
RynthClock.TestNow = () => now;
|
||||
try
|
||||
{
|
||||
var bot = StarvationWorld(15f, out var combat);
|
||||
AgeCorpse(bot, RynthAiPlugin.LootStarveMs + 1000);
|
||||
Check.True(bot.HasLootWork(), "the corpse is lootable");
|
||||
Check.True((bool)bot.Call("IsLootStarvedTurn", true, true)!, "starved, nothing within 5 yd: a loot turn");
|
||||
combat.HandleCombatTrigger();
|
||||
Check.Eq(combat.activeTargetId, unchecked((int)Monster), "combat locks the monster (15 m)");
|
||||
Check.True(combat.FirstAttackPendingMs >= 0, "its first attack hasn't gone out");
|
||||
|
||||
bot.Set("_lootStarveTurn", true);
|
||||
bot.Tick(BotActivity.Looting);
|
||||
Check.Eq(bot.Get<int>("_targetCorpseId"), unchecked((int)Corpse), "the starved corpse is claimed");
|
||||
Check.False(FakeHost.Uses.Contains(Corpse), "but not opened ahead of the fight's first attack");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains($"open of 0x{Corpse:X8} waits for combat's first attack")), "and says so");
|
||||
|
||||
// The first cast goes out ([CombatLatency]'s engagement): the open follows.
|
||||
object latency = typeof(CombatManager).GetField("_latency", Any)!.GetValue(combat)!;
|
||||
latency.GetType().GetMethod("OnAttack")!.Invoke(latency, new object?[] { combat.activeTargetId, (double)Environment.TickCount64, "Magic", null });
|
||||
Check.Eq(combat.FirstAttackPendingMs, -1.0, "attacked: nothing pending");
|
||||
bot.Tick(BotActivity.Looting);
|
||||
Check.True(FakeHost.Uses.Contains(Corpse), "now the corpse is opened");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains($"attempting open for 0x{Corpse:X8} (d=") && l.Contains("combat locked on")),
|
||||
"the open line gives the distance and the fight: " + FakeHost.Logs.LastOrDefault(l => l.Contains("attempting open")));
|
||||
|
||||
// A lock that can't attack doesn't stop the starved turn for good.
|
||||
var stuck = StarvationWorld(15f, out var combat2);
|
||||
AgeCorpse(stuck, RynthAiPlugin.LootStarveMs + 1000);
|
||||
stuck.HasLootWork();
|
||||
combat2.HandleCombatTrigger();
|
||||
stuck.Set("_lootStarveTurn", true);
|
||||
stuck.Tick(BotActivity.Looting);
|
||||
Check.False(FakeHost.Uses.Contains(Corpse), "held while the lock is fresh");
|
||||
now = now.AddMilliseconds(RynthAiPlugin.StarvedOpenYieldsMs + 1);
|
||||
stuck.Tick(BotActivity.Looting);
|
||||
Check.True(FakeHost.Uses.Contains(Corpse), "past StarvedOpenYieldsMs the open goes");
|
||||
}
|
||||
finally { RynthClock.TestNow = null; }
|
||||
}
|
||||
|
||||
private static void IgnoredMonsterDoesNotHoldLoot()
|
||||
{
|
||||
// The same close (2 m) Water Elemental that keeps combat in charge above, with its rule at Priority 0.
|
||||
|
|
@ -647,16 +695,28 @@ internal static class LootCorpseTests
|
|||
Check.Eq(bot.Get<long>("_deathWaitMs"), 2500L, "the learned 1.5 s and 1 s more");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("waiting up to 2.5 s for the corpse of 'Ancient Water Elemental'") && l.Contains("learned over 1 kill")),
|
||||
"said once, plainly: " + FakeHost.Logs.LastOrDefault());
|
||||
combat.HandleCombatTrigger();
|
||||
Check.Eq(combat.activeTargetId, 0, "the next monster (15 m) is not locked while the corpse comes");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("[CombatTarget] next target waits: the kill's corpse comes first")), "combat says why");
|
||||
Check.Eq(Arbiter(bot, combat), BotActivity.Looting, "Looting has the tick (no nav, no hunt walk)");
|
||||
now += 2400;
|
||||
Check.Eq(Arbiter(bot, combat), BotActivity.Looting, "still at 2.4 s");
|
||||
now += 200;
|
||||
Check.Eq(Arbiter(bot, combat), BotActivity.Combat, "at 2.6 s, no corpse: it carries on");
|
||||
// 2026-11-15, R-20261115-165857-1de7: the next monster was held for the death + 1 s while the
|
||||
// looter, which claims no corpse with combat targets in range, waited for the fight: 3.6 s
|
||||
// standing until the monster walked within 5 yd. Combat locks it at once now.
|
||||
combat.HandleCombatTrigger();
|
||||
Check.Eq(combat.activeTargetId, unchecked((int)Monster), "and the next monster is locked");
|
||||
Check.Eq(combat.activeTargetId, unchecked((int)Monster), "the next monster (15 m) is locked at once");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("[CombatTarget] next target waits")), "nothing holds it");
|
||||
Check.Eq(Arbiter(bot, combat), BotActivity.Combat, "and fought");
|
||||
Check.True(bot.Get<long>("_deathWaitAt") != 0, "the wait itself goes on (for when the fight is over)");
|
||||
|
||||
// No fight left (the owner's case: the last kill): the wait keeps nav off for the death + 1 s.
|
||||
BotActivity Calm()
|
||||
{
|
||||
bool wantLoot = bot.HasLootWork();
|
||||
var inputs = new ArbiterInputs(true, false, false, wantLoot, false, true, deathWait: wantLoot && bot.Get<bool>("_deathWaitHeld"));
|
||||
return ActivityArbiter.Decide(in inputs);
|
||||
}
|
||||
Check.Eq(Calm(), BotActivity.Looting, "nothing to fight: Looting holds the tick, nav waits");
|
||||
now += 2400;
|
||||
Check.Eq(Calm(), BotActivity.Looting, "still at 2.4 s");
|
||||
now += 200;
|
||||
Check.Eq(Calm(), BotActivity.Navigating, "at 2.6 s, no corpse: nav carries on");
|
||||
}
|
||||
finally { RestoreCorpseClock(); }
|
||||
}
|
||||
|
|
@ -750,9 +810,11 @@ internal static class LootCorpseTests
|
|||
// No corpse ever: the wait ends at its time, once.
|
||||
var bot = DeathWorld(15f, out var combat, () => now);
|
||||
bot.Call("StartDeathWait", Elemental);
|
||||
Check.True((bool)bot.Call("LootHoldsNewTarget")!, "holding");
|
||||
Check.True(bot.HasLootWork() && bot.Get<bool>("_deathWaitHeld"), "holding (nav)");
|
||||
Check.False((bool)bot.Call("LootHoldsNewTarget")!, "but not combat's next target (2026-11-15)");
|
||||
now += RynthAiPlugin.DeathWaitDefaultMs + RynthAiPlugin.DeathWaitExtraMs;
|
||||
Check.False((bool)bot.Call("LootHoldsNewTarget")!, "past the time: no hold");
|
||||
bot.HasLootWork();
|
||||
Check.False(bot.Get<bool>("_deathWaitHeld"), "past the time: no hold");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("no corpse came in 3.5 s")), 1, "said once");
|
||||
combat.HandleCombatTrigger();
|
||||
Check.Eq(combat.activeTargetId, unchecked((int)Monster), "the next monster is locked");
|
||||
|
|
|
|||
665
Tools/RynthCore.RynthAiHostTests/Tests/NearbyChestTests.cs
Normal file
665
Tools/RynthCore.RynthAiHostTests/Tests/NearbyChestTests.cs
Normal file
|
|
@ -0,0 +1,665 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
using System.Threading;
|
||||
using RynthCore.Loot;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.RynthAi.Loot;
|
||||
using RynthCore.Plugin.RynthAi.Meta;
|
||||
using RynthCore.PluginCore;
|
||||
using RynthCore.PluginSdk;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Loot Nearby Chests (2026-11-14): with the setting on, the macro running, Looting on and no fight, a
|
||||
// chest in loot range is walked to (the server walks: every step is a use), opened and looted by the
|
||||
// loot profile, then left alone until it resets. Locked: a carried key that fits, else a lockpick when
|
||||
// the Lockpick skill gives 50% or better, else skipped for 10 minutes. The state machine
|
||||
// (NearbyChestLooter.cs) runs on a fake environment with a clock the test moves; the plugin glue
|
||||
// (which objects are chests, the loot hand-over, the setting) runs on the fake host.
|
||||
internal static class NearbyChestTests
|
||||
{
|
||||
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("nearby chests: an unlocked chest is appraised, opened and looted, then left alone until the re-lock wait passes", UnlockedHappyPath);
|
||||
r.Add("nearby chests: the nearest chest not left alone; nothing while fighting; a fight drops a chest nothing was sent to", CandidateSelection);
|
||||
r.Add("nearby chests: locked, a carried key fits -> the key, then the open", LockedKeyFits);
|
||||
r.Add("nearby chests: locked, a key that doesn't fit (0x4B2) -> the next key; a key that didn't fit is never tried on that chest again", LockedKeyDoesntFit);
|
||||
r.Add("nearby chests: locked, no key fits, skill good enough -> the lockpick (a failed pick is tried again, up to 3)", LockpickEnoughSkill);
|
||||
r.Add("nearby chests: locked, skill too low, untrained or an unpickable lock -> skipped, no lockpick spent", LockpickNotEnoughSkill);
|
||||
r.Add("nearby chests: locked, no key fits and no lockpick -> skipped 10 minutes, then tried again", NoLockpickSkipThenRetry);
|
||||
r.Add("nearby chests: a looted locked chest is ready when it reads locked again; still unlocked after the wait = another wait; gone = forgotten", RespawnTimer);
|
||||
r.Add("nearby chests: a chest that won't open is taken as locked; unknown resistance picks at most twice", WontOpenTakenAsLocked);
|
||||
r.Add("nearby chests: off -> nothing is scanned or sent", OffNothing);
|
||||
r.Add("nearby chests: 'skill good enough' is ACE's GetSkillChance at 50% or better (the server's own percent first)", PickRuleMath);
|
||||
r.Add("nearby chests: what is a chest (stuck container in the world; not a corpse, vendor, player, door, house storage, pack or held)", ChestRule);
|
||||
r.Add("nearby chests plugin: off by default; off -> no loot work, no appraisal, no use", PluginOffNothing);
|
||||
r.Add("nearby chests plugin: in range and eligible only (house storage, a vendor, a dropped pack, a far chest are passed by)", PluginCandidates);
|
||||
r.Add("nearby chests plugin: a closed chest in range is appraised, opened and looted by the loot profile, then left alone", PluginLootsChest);
|
||||
r.Add("nearby chests plugin: no chest work while combat has a target", PluginSkippedWhileFighting);
|
||||
r.Add("nearby chests plugin: the setting reaches the engine, an engine save without it leaves it, the meta option sets it; /ra chests answers", PluginSettingPlumbing);
|
||||
}
|
||||
|
||||
// ── The fake environment ────────────────────────────────────────────────
|
||||
|
||||
private sealed class Env : INearbyChestEnv
|
||||
{
|
||||
public long T = 1_000_000;
|
||||
public long Now => T;
|
||||
public bool Enabled { get; set; } = true;
|
||||
public bool Fighting { get; set; }
|
||||
public readonly List<NearbyChest> Chests = new() { new NearbyChest(1, "Chest", 4) };
|
||||
public readonly HashSet<int> Gone = new();
|
||||
public string? Hold;
|
||||
public bool CanAppraise { get; set; } = true;
|
||||
public bool AppraisalAnswers = true;
|
||||
public readonly Dictionary<int, long> Stamps = new();
|
||||
public readonly Dictionary<int, bool> LockedMap = new();
|
||||
public readonly Dictionary<int, int> Resist = new();
|
||||
public readonly Dictionary<int, int> Pct = new();
|
||||
public bool SkillKnown = true, Trained = true;
|
||||
public int Skill = 300;
|
||||
public readonly List<ChestTool> KeyList = new();
|
||||
public ChestTool? Pick;
|
||||
public bool HasUseDone { get; set; } = true;
|
||||
public int Seq;
|
||||
public uint LastErr;
|
||||
public readonly List<string> Sent = new(), Logs = new();
|
||||
public readonly Dictionary<int, long> Opened = new();
|
||||
public int LootingId;
|
||||
public long LootEnd;
|
||||
/// <summary>The server's script for a use with a tool: (error, chat line, unlocks). Null = no answer.</summary>
|
||||
public Func<ChestTool, (uint Err, string? Chat, bool Unlocks)?>? OnUseWith;
|
||||
/// <summary>The chest opens on the open (default: when it isn't locked).</summary>
|
||||
public Func<int, bool>? OnOpen;
|
||||
public NearbyChestLooter L = null!;
|
||||
private int _pendingAppraisal;
|
||||
|
||||
public IReadOnlyList<NearbyChest> ScanChests() => Chests.Where(c => !Gone.Contains(c.Id)).ToList();
|
||||
public bool InWorld(int id) => !Gone.Contains(id);
|
||||
public bool StillEligible(int id, out string why) { why = ""; return true; }
|
||||
public string? HoldReason() => Hold;
|
||||
public bool RequestAppraisal(int chestId) { Sent.Add("id " + chestId); if (AppraisalAnswers) _pendingAppraisal = chestId; return true; }
|
||||
public long AppraisalStamp(int chestId) => Stamps.TryGetValue(chestId, out long s) ? s : 0;
|
||||
public bool? Locked(int chestId) => LockedMap.TryGetValue(chestId, out bool b) ? b : null;
|
||||
public int? LockResistance(int chestId) => Resist.TryGetValue(chestId, out int v) ? v : null;
|
||||
public int? PickSuccessPercent(int chestId) => Pct.TryGetValue(chestId, out int v) ? v : null;
|
||||
public bool LockpickSkill(out int buffed, out bool trained) { buffed = Skill; trained = Trained; return SkillKnown; }
|
||||
public IReadOnlyList<ChestTool> Keys() => KeyList;
|
||||
public ChestTool? Lockpick() => Pick;
|
||||
public int UseDoneSeq() => Seq;
|
||||
public bool LastUseDone(out int seq, out uint error) { seq = Seq; error = LastErr; return true; }
|
||||
public bool SendUseWith(int toolId, int chestId, string why)
|
||||
{
|
||||
var tool = KeyList.Concat(Pick is { } p ? new[] { p } : Array.Empty<ChestTool>()).First(t => t.Id == toolId);
|
||||
Sent.Add("use " + tool.Name);
|
||||
var ans = OnUseWith?.Invoke(tool);
|
||||
if (ans is { } a)
|
||||
{
|
||||
if (a.Chat != null) L.OnChat(a.Chat);
|
||||
if (a.Unlocks) LockedMap[chestId] = false;
|
||||
LastErr = a.Err; Seq++;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
public bool SendOpen(int chestId)
|
||||
{
|
||||
Sent.Add("open " + chestId);
|
||||
bool opens = OnOpen?.Invoke(chestId) ?? Locked(chestId) != true;
|
||||
if (opens) { Opened[chestId] = T + 1; LootingId = chestId; LootEnd = T + 2000; }
|
||||
LastErr = 0; Seq++;
|
||||
return true;
|
||||
}
|
||||
public long OpenedAt(int chestId) => Opened.TryGetValue(chestId, out long t) ? t : 0;
|
||||
public bool Looting(int chestId) => LootingId == chestId;
|
||||
public void Log(string text) => Logs.Add(text);
|
||||
|
||||
/// <summary>Moves the clock in 100 ms steps, ticking as the loot tick does (may start: no corpse waits).</summary>
|
||||
public void Run(long ms, Func<bool>? until = null)
|
||||
{
|
||||
long end = T + ms;
|
||||
while (T < end && (until == null || !until()))
|
||||
{
|
||||
T += 100;
|
||||
if (_pendingAppraisal != 0) { Stamps[_pendingAppraisal] = T; _pendingAppraisal = 0; }
|
||||
if (LootingId != 0 && T >= LootEnd) LootingId = 0; // the corpse looter finishes and closes it
|
||||
L.Tick(mayStart: true);
|
||||
}
|
||||
}
|
||||
|
||||
public int Count(string prefix) => Sent.Count(s => s.StartsWith(prefix, StringComparison.Ordinal));
|
||||
}
|
||||
|
||||
private static Env NewEnv()
|
||||
{
|
||||
var e = new Env();
|
||||
e.L = new NearbyChestLooter(e);
|
||||
return e;
|
||||
}
|
||||
|
||||
private static string Sent(Env e) => string.Join(" | ", e.Sent);
|
||||
|
||||
// ── State machine ───────────────────────────────────────────────────────
|
||||
|
||||
private static void UnlockedHappyPath()
|
||||
{
|
||||
var e = NewEnv();
|
||||
e.Run(5000, () => e.L.Looted == 1 && !e.L.Busy);
|
||||
Check.Eq(Sent(e), "id 1 | open 1", "one appraisal, one open, nothing else");
|
||||
Check.Eq(e.L.Looted, 1, "looted");
|
||||
Check.False(e.L.Busy, "done");
|
||||
Check.True(e.L.IsLeftAlone(1, e.T), "left alone after the loot");
|
||||
Check.True(e.Logs.Any(l => l.Contains("Nearby chests: done with chest") && l.Contains("left alone until it resets")), "the finish says why it is left: " + string.Join(" / ", e.Logs));
|
||||
|
||||
// Nothing more until the re-lock wait (125 s) passes, then it is looted again.
|
||||
e.Run(100_000);
|
||||
Check.Eq(e.Count("open"), 1, "no second open before the wait");
|
||||
e.Run(40_000, () => e.L.Looted == 2);
|
||||
Check.Eq(e.L.Looted, 2, "looted again after the re-lock wait (the chest regenerated)");
|
||||
Check.Eq(e.Count("id"), 2, "appraised again first");
|
||||
}
|
||||
|
||||
private static void CandidateSelection()
|
||||
{
|
||||
var e = NewEnv();
|
||||
e.Chests.Clear();
|
||||
e.Chests.Add(new NearbyChest(1, "Far Chest", 8));
|
||||
e.Chests.Add(new NearbyChest(2, "Near Chest", 3));
|
||||
Check.Eq(e.L.Candidate(), 2, "the nearest first");
|
||||
|
||||
e.Fighting = true;
|
||||
Check.Eq(e.L.Candidate(), 0, "nothing while fighting");
|
||||
e.Run(2000);
|
||||
Check.Eq(e.Sent.Count, 0, "nothing sent while fighting");
|
||||
|
||||
// The fight ends; the appraisal goes out, a fight starts before the next step: the chest is dropped.
|
||||
e.Fighting = false;
|
||||
e.AppraisalAnswers = false; // the answer is slow
|
||||
e.Run(150, () => e.Sent.Count > 0);
|
||||
Check.Eq(Sent(e), "id 2", "the near chest is appraised");
|
||||
e.Fighting = true;
|
||||
e.Run(AppraiseWait());
|
||||
Check.False(e.L.Busy, "a fight drops the chest once nothing is owed");
|
||||
Check.Eq(e.Count("open"), 0, "no open in the fight");
|
||||
Check.True(e.Logs.Any(l => l.Contains("for the fight")), "says it left the chest for the fight");
|
||||
Check.False(e.L.IsLeftAlone(2, e.T), "nothing marked: tried again after the fight");
|
||||
|
||||
// The hold: nothing starts while the client/arbiter holds the send.
|
||||
e.Fighting = false;
|
||||
e.AppraisalAnswers = true;
|
||||
e.Hold = "Looting doesn't have the tick";
|
||||
int before = e.Sent.Count;
|
||||
e.Run(2000);
|
||||
Check.Eq(e.Sent.Count, before, "nothing while held");
|
||||
e.Hold = null;
|
||||
e.Run(5000, () => e.L.Looted == 1);
|
||||
Check.Eq(e.L.Looted, 1, "looted once free");
|
||||
Check.Eq(e.L.Candidate(), 1, "then the far chest (the near one is left alone)");
|
||||
}
|
||||
|
||||
private static long AppraiseWait() => NearbyChestLooter.AppraiseMaxMs + 300;
|
||||
|
||||
private static Env LockedEnv(int resist = 100, int? pct = null)
|
||||
{
|
||||
var e = NewEnv();
|
||||
e.LockedMap[1] = true;
|
||||
e.Resist[1] = resist;
|
||||
if (pct != null) e.Pct[1] = pct.Value;
|
||||
return e;
|
||||
}
|
||||
|
||||
private static void LockedKeyFits()
|
||||
{
|
||||
var e = LockedEnv();
|
||||
e.KeyList.Add(new ChestTool(50, "Aged Key"));
|
||||
e.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
e.OnUseWith = t => t.Name == "Aged Key" ? (0u, "The Chest has been unlocked.\nYour key has 4 uses left.", true) : (NearbyChestLooter.ErrKeyDoesntFit, null, false);
|
||||
e.Run(10_000, () => e.L.Looted == 1 && !e.L.Busy);
|
||||
Check.Eq(Sent(e), "id 1 | use Aged Key | open 1", "the key, then the open; no lockpick");
|
||||
Check.Eq(e.L.Looted, 1, "looted");
|
||||
}
|
||||
|
||||
private static void LockedKeyDoesntFit()
|
||||
{
|
||||
var e = LockedEnv();
|
||||
e.KeyList.Add(new ChestTool(50, "Black Key"));
|
||||
e.KeyList.Add(new ChestTool(51, "Aged Key"));
|
||||
e.OnUseWith = t => t.Name == "Aged Key" ? (0u, "The Chest has been unlocked.", true) : (NearbyChestLooter.ErrKeyDoesntFit, null, false);
|
||||
e.Run(10_000, () => e.L.Looted == 1 && !e.L.Busy);
|
||||
Check.Eq(Sent(e), "id 1 | use Black Key | use Aged Key | open 1", "the wrong key, then the next, then the open");
|
||||
Check.True(e.Logs.Any(l => l.Contains("Black Key doesn't fit")), "says the key doesn't fit");
|
||||
|
||||
// None fits, no lockpick: skipped. A retry (10 min later) never tries the keys that didn't fit.
|
||||
var f = LockedEnv();
|
||||
f.KeyList.Add(new ChestTool(50, "Black Key"));
|
||||
f.OnUseWith = _ => (NearbyChestLooter.ErrKeyDoesntFit, null, false);
|
||||
f.Run(10_000, () => f.L.IsLeftAlone(1, f.T));
|
||||
Check.Eq(Sent(f), "id 1 | use Black Key", "one key tried, nothing else (no lockpick)");
|
||||
Check.True(f.L.IsLeftAlone(1, f.T), "skipped");
|
||||
f.Run(NearbyChestLooter.SkipMs + 2000, () => f.Count("id") == 2);
|
||||
f.Run(2000);
|
||||
Check.Eq(f.Count("use Black Key"), 1, "the key that didn't fit is not tried again on that chest");
|
||||
f.KeyList.Add(new ChestTool(52, "Gold Key"));
|
||||
f.Run(NearbyChestLooter.SkipMs + 5000, () => f.Count("use Gold Key") == 1);
|
||||
Check.Eq(f.Count("use Gold Key"), 1, "a new key is tried on the next attempt");
|
||||
}
|
||||
|
||||
private static void LockpickEnoughSkill()
|
||||
{
|
||||
// Resistance 250 against skill 300: ACE's chance 81% (as its appraisal truncates it). The first pick fails, the second works.
|
||||
var e = LockedEnv(resist: 250);
|
||||
e.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
int picks = 0;
|
||||
e.OnUseWith = t => ++picks == 1
|
||||
? (0u, "You have failed to pick the lock. It is still locked. Your lockpicks have 4 uses left.", false)
|
||||
: (0u, "You have successfully picked the lock! It is now unlocked.\n Your lockpicks have 3 uses left.", true);
|
||||
e.Run(15_000, () => e.L.Looted == 1 && !e.L.Busy);
|
||||
Check.Eq(Sent(e), "id 1 | use Plain Lockpick | use Plain Lockpick | open 1", "two picks (the first failed), then the open");
|
||||
Check.True(e.Logs.Any(l => l.Contains("picking chest") && l.Contains("81%")), "says the chance it picks at: " + string.Join(" / ", e.Logs));
|
||||
|
||||
// Every pick fails: three, then skipped.
|
||||
var f = LockedEnv(resist: 250);
|
||||
f.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
f.OnUseWith = _ => (0u, "You have failed to pick the lock. It is still locked.", false);
|
||||
f.Run(20_000, () => f.L.IsLeftAlone(1, f.T));
|
||||
Check.Eq(f.Count("use Plain Lockpick"), NearbyChestLooter.MaxPicks, "at most 3 picks");
|
||||
Check.True(f.L.IsLeftAlone(1, f.T), "then skipped");
|
||||
Check.True(f.Logs.Any(l => l.Contains("the lock held after 3 lockpick tries") && l.Contains("10 minutes")), "says why and when again");
|
||||
|
||||
// The server's own percent wins over the estimate.
|
||||
var g = LockedEnv(resist: 250, pct: 40);
|
||||
g.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
g.Run(10_000, () => g.L.IsLeftAlone(1, g.T));
|
||||
Check.Eq(g.Count("use"), 0, "the server says 40%: not picked");
|
||||
}
|
||||
|
||||
private static void LockpickNotEnoughSkill()
|
||||
{
|
||||
var e = LockedEnv(resist: 400); // skill 300: ~5%
|
||||
e.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
e.Run(10_000, () => e.L.IsLeftAlone(1, e.T));
|
||||
Check.Eq(Sent(e), "id 1", "appraised; no lockpick spent");
|
||||
Check.True(e.L.IsLeftAlone(1, e.T), "skipped");
|
||||
Check.True(e.Logs.Any(l => l.Contains("too low") && l.Contains("10 minutes")), "says the skill is too low: " + string.Join(" / ", e.Logs));
|
||||
|
||||
var u = LockedEnv(resist: 10);
|
||||
u.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
u.Trained = false;
|
||||
u.Run(10_000, () => u.L.IsLeftAlone(1, u.T));
|
||||
Check.Eq(u.Count("use"), 0, "untrained: never picks");
|
||||
Check.True(u.Logs.Any(l => l.Contains("isn't trained")), "says so");
|
||||
|
||||
var n = NewEnv();
|
||||
n.LockedMap[1] = true; // locked, appraised, and no resistance: ACE can't pick it
|
||||
n.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
n.Run(10_000, () => n.L.IsLeftAlone(1, n.T));
|
||||
Check.Eq(n.Count("use"), 0, "an unpickable lock: no pick");
|
||||
Check.True(n.Logs.Any(l => l.Contains("can't be picked")), "says so");
|
||||
}
|
||||
|
||||
private static void NoLockpickSkipThenRetry()
|
||||
{
|
||||
var e = LockedEnv(resist: 50);
|
||||
e.Run(10_000, () => e.L.IsLeftAlone(1, e.T));
|
||||
Check.Eq(Sent(e), "id 1", "appraised, nothing to use");
|
||||
Check.True(e.Logs.Any(l => l.Contains("carry no lockpick") && l.Contains("10 minutes")), "says why");
|
||||
e.Run(NearbyChestLooter.SkipMs - 15_000);
|
||||
Check.Eq(e.Count("id"), 1, "left alone for 10 minutes");
|
||||
e.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
e.OnUseWith = _ => (0u, "You have successfully picked the lock! It is now unlocked.", true);
|
||||
e.Run(30_000, () => e.L.Looted == 1);
|
||||
Check.Eq(e.L.Looted, 1, "tried again after 10 minutes (with a lockpick now) and looted");
|
||||
}
|
||||
|
||||
private static void RespawnTimer()
|
||||
{
|
||||
var e = LockedEnv(resist: 50);
|
||||
e.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
e.OnUseWith = _ => (0u, "You have successfully picked the lock!", true);
|
||||
e.Run(10_000, () => e.L.Looted == 1 && !e.L.Busy);
|
||||
Check.Eq(e.L.Looted, 1, "looted");
|
||||
Check.True(e.L.IsLeftAlone(1, e.T), "left alone");
|
||||
e.Run(20_000);
|
||||
e.LockedMap[1] = true; // ACE's Chest.Reset: locked again (and regenerated)
|
||||
Check.False(e.L.IsLeftAlone(1, e.T), "reads locked again: ready at once");
|
||||
e.Run(10_000, () => e.L.Looted == 2);
|
||||
Check.Eq(e.L.Looted, 2, "picked and looted again");
|
||||
|
||||
// Not re-locked when the wait is over: appraised, and another wait without a use.
|
||||
int uses = e.Count("use");
|
||||
e.Run(126_000, () => e.Count("id") == 3);
|
||||
e.Run(1000);
|
||||
Check.Eq(e.Count("use"), uses, "no use on a chest that hasn't reset");
|
||||
Check.Eq(e.Count("open"), 2, "no open either");
|
||||
Check.True(e.L.IsLeftAlone(1, e.T), "another wait");
|
||||
Check.True(e.Logs.Any(l => l.Contains("hasn't reset yet")), "says so");
|
||||
|
||||
// Gone from the world: forgotten (a new one comes in fresh).
|
||||
e.Gone.Add(1);
|
||||
e.Run(1000);
|
||||
Check.True(e.Logs.Any(l => l.Contains("left the world; forgotten")), "forgotten");
|
||||
e.Gone.Remove(1);
|
||||
Check.False(e.L.IsLeftAlone(1, e.T), "back: not left alone");
|
||||
}
|
||||
|
||||
private static void WontOpenTakenAsLocked()
|
||||
{
|
||||
var e = NewEnv();
|
||||
e.CanAppraise = false; // an engine without the ID: the lock is unknown
|
||||
e.Pick = new ChestTool(60, "Plain Lockpick");
|
||||
bool unlocked = false;
|
||||
e.OnOpen = _ => unlocked;
|
||||
e.OnUseWith = _ => (0u, "You have failed to pick the lock. It is still locked.", false);
|
||||
e.Run(30_000, () => e.L.IsLeftAlone(1, e.T));
|
||||
Check.Eq(Sent(e), "open 1 | use Plain Lockpick | use Plain Lockpick", "the open failed: taken as locked, two picks at an unknown resistance, then skipped");
|
||||
Check.True(e.Logs.Any(l => l.Contains("taking it as locked")), "says so");
|
||||
}
|
||||
|
||||
private static void OffNothing()
|
||||
{
|
||||
var e = NewEnv();
|
||||
e.Enabled = false;
|
||||
Check.Eq(e.L.Candidate(), 0, "no candidate");
|
||||
e.Run(5000);
|
||||
Check.Eq(e.Sent.Count, 0, "nothing sent");
|
||||
// Turned off mid-chest: dropped, nothing marked.
|
||||
e.Enabled = true;
|
||||
e.AppraisalAnswers = false;
|
||||
e.Run(200, () => e.Sent.Count > 0);
|
||||
e.L.StandDown("Loot Nearby Chests was turned off");
|
||||
Check.False(e.L.Busy, "dropped");
|
||||
Check.False(e.L.IsLeftAlone(1, e.T), "nothing marked");
|
||||
}
|
||||
|
||||
private static void PickRuleMath()
|
||||
{
|
||||
Check.True(Math.Abs(NearbyChestLooter.PickChance(300, 300) - 0.5) < 1e-9, "skill = resistance: 50%");
|
||||
Check.True(Math.Abs(NearbyChestLooter.PickChance(300, 250) - (1 - 1 / (1 + Math.Exp(1.5)))) < 1e-9, "ACE's logistic, factor 0.03");
|
||||
Check.Eq(NearbyChestLooter.PickTries(true, 300, true, true, true, 300, null, out _), NearbyChestLooter.MaxPicks, "50%: picks");
|
||||
Check.Eq(NearbyChestLooter.PickTries(true, 299, true, true, true, 300, null, out _), null, "just under 50%: no");
|
||||
Check.Eq(NearbyChestLooter.PickTries(true, 100, true, true, true, 300, 60, out _), NearbyChestLooter.MaxPicks, "the server's 60% wins over the estimate");
|
||||
Check.Eq(NearbyChestLooter.PickTries(true, 300, false, true, true, 10, null, out _), null, "untrained: no");
|
||||
Check.Eq(NearbyChestLooter.PickTries(true, 900, true, true, true, 9999, null, out _), null, "9999: unpickable");
|
||||
Check.Eq(NearbyChestLooter.PickTries(true, 300, true, true, true, null, null, out _), null, "locked with no resistance after an appraisal: unpickable");
|
||||
Check.Eq(NearbyChestLooter.PickTries(true, 300, true, false, null, null, null, out _), NearbyChestLooter.MaxPicksUnknown, "never appraised: a couple of tries");
|
||||
}
|
||||
|
||||
private static void ChestRule()
|
||||
{
|
||||
const uint stuck = NearbyChestLooter.BfStuck;
|
||||
Check.Eq(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, true, stuck, 0, "Chest", true, 0, 0), null, "a stuck container in the world: a chest");
|
||||
Check.Eq(NearbyChestLooter.ChestRefusal(AcObjectClass.Corpse, true, stuck, 0, "Corpse of X", true, 0, 0), "a corpse", "corpse class");
|
||||
Check.Eq(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, true, stuck | NearbyChestLooter.BfCorpse, 0, "x", true, 0, 0), "a corpse", "corpse bit");
|
||||
Check.Eq(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, true, stuck | NearbyChestLooter.BfVendor, 0, "x", true, 0, 0), "a vendor", "vendor");
|
||||
Check.Eq(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, true, stuck | NearbyChestLooter.BfPlayer, 0, "x", true, 0, 0), "a player", "player");
|
||||
Check.True(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, true, stuck, 0x50000001, "Chest", true, 0, 0)!.StartsWith("house storage"), "house owner");
|
||||
Check.True(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, true, stuck, 0, "Storage", true, 0, 0)!.StartsWith("house storage"), "named storage");
|
||||
Check.True(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, true, 0, 0, "Pack", true, 0, 0)!.Contains("picked up"), "a dropped pack (not stuck)");
|
||||
Check.Eq(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, true, stuck, 0, "Chest", true, 0x50000001, 0), "someone holds it", "held");
|
||||
Check.Eq(NearbyChestLooter.ChestRefusal(AcObjectClass.Door, true, stuck | NearbyChestLooter.BfDoor, 0, "Door", true, 0, 0), "not a container", "a door");
|
||||
Check.True(NearbyChestLooter.ChestRefusal(AcObjectClass.Container, false, 0, 0, "Chest", true, 0, 0) != null, "no bitfield read: not trusted");
|
||||
}
|
||||
|
||||
// ── Plugin glue ─────────────────────────────────────────────────────────
|
||||
|
||||
private const uint Player = 0x50000D01;
|
||||
private const uint Chest = 0x7A9B4011;
|
||||
private const uint Storage = 0x7A9B4012;
|
||||
private const uint VendorBox = 0x7A9B4013;
|
||||
private const uint DroppedPack = 0x80263400;
|
||||
private const uint FarChest = 0x7A9B4015;
|
||||
private const uint Gem = 0x80263401;
|
||||
private const uint ItemTypeContainer = 0x200, ItemTypeGem = 0x800;
|
||||
private const uint Stuck = 0x4;
|
||||
|
||||
private static (uint Cell, float X, float Y, float Z) Me0 => (0x1048002Au, 100f, 100f, 0f);
|
||||
|
||||
private static void Place(uint id, string name, float dx, uint bitfield, uint type = ItemTypeContainer)
|
||||
{
|
||||
FakeHost.Names[id] = name;
|
||||
FakeHost.ItemTypes[id] = type;
|
||||
FakeHost.Positions[id] = (Me0.Cell, Me0.X + dx, Me0.Y, Me0.Z);
|
||||
FakeHost.NotAttackable.Add(id);
|
||||
FakeHost.Containers[id] = 0;
|
||||
FakeHost.Bitfields[id] = bitfield;
|
||||
}
|
||||
|
||||
private static void World()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.SalvageCalls = true;
|
||||
FakeHost.WeaponCalls = true; // RequestId, HasAppraisalData, UseObject
|
||||
FakeHost.CloseContainerCalls = true;
|
||||
FakeHost.UseOnCalls = true;
|
||||
FakeHost.Names[Player] = "Dargoth Hera";
|
||||
FakeHost.Positions[Player] = Me0;
|
||||
FakeHost.PlayerPose = Me0;
|
||||
FakeHost.Bitfields[Player] = 0x8;
|
||||
Place(Storage, "Storage", 1.0f, Stuck);
|
||||
FakeHost.InstanceIds[(Storage, 32)] = 0x50000AAA; // HouseOwner
|
||||
Place(VendorBox, "Vendor Chest", 1.2f, Stuck | 0x200);
|
||||
Place(DroppedPack, "Pack", 1.6f, 0);
|
||||
Place(Chest, "Chest", 3.0f, Stuck);
|
||||
Place(FarChest, "Far Chest", 60.0f, Stuck);
|
||||
FakeHost.Names[Gem] = "Black Opal";
|
||||
FakeHost.ItemTypes[Gem] = ItemTypeGem;
|
||||
FakeHost.Containers[Gem] = Chest;
|
||||
FakeHost.Appraised.Add(Gem);
|
||||
}
|
||||
|
||||
private sealed class Bot
|
||||
{
|
||||
public readonly RynthAiPlugin P = new();
|
||||
public readonly LegacyUiSettings S = new()
|
||||
{
|
||||
IsMacroRunning = true,
|
||||
EnableLooting = true,
|
||||
EnableCombat = false,
|
||||
LootOwnership = 0,
|
||||
LootContentSettleMs = 0,
|
||||
LootEmptyCorpseMs = 0,
|
||||
StopLootingWhenPackFull = false,
|
||||
LootNearbyChests = true,
|
||||
};
|
||||
public readonly WorldObjectCache Cache;
|
||||
|
||||
public Bot(RynthCoreHost host)
|
||||
{
|
||||
typeof(RynthPluginBase).GetMethod("Attach", Any)!.Invoke(P, new object[] { FakeHost.LastApi });
|
||||
var dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
|
||||
typeof(LegacyDashboardRenderer).GetField("_profileLoaded", Any)!.SetValue(dash, true);
|
||||
typeof(LegacyDashboardRenderer).GetField("_settings", Any)!.SetValue(dash, S);
|
||||
Set("_dashboard", dash);
|
||||
Cache = new WorldObjectCache(host);
|
||||
Cache.SetPlayerId(Player);
|
||||
Set("_objectCache", Cache);
|
||||
Set("_playerId", Player);
|
||||
string profile = Path.Combine(Program.TempRoot, "loot-nearby-chest.json");
|
||||
var p = new LootProfile { Name = "chest" };
|
||||
var gems = new LootRule { Name = "Gems", Action = LootAction.Keep };
|
||||
gems.Conditions.Add(new ObjectClassCondition { ObjectClass = AcObjectClass.Gem });
|
||||
p.Rules.Add(gems);
|
||||
p.Save(profile);
|
||||
S.CurrentLootPath = profile;
|
||||
}
|
||||
|
||||
public void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(P, v);
|
||||
public T Get<T>(string f) => (T)typeof(RynthAiPlugin).GetField(f, Any)!.GetValue(P)!;
|
||||
public object? Call(string m, params object[] a) => typeof(RynthAiPlugin).GetMethod(m, Any)!.Invoke(P, a);
|
||||
public bool HasLootWork() => (bool)Call("HasLootWork", S, DateTimeOffset.UtcNow.ToUnixTimeMilliseconds())!;
|
||||
public void Tick(BotActivity act = BotActivity.Looting)
|
||||
{
|
||||
Set("_activity", act);
|
||||
Call("TickCorpseOpening");
|
||||
}
|
||||
public void Create(params uint[] ids)
|
||||
{
|
||||
foreach (uint id in ids) Cache.OnCreateObject(id);
|
||||
Cache.Tick();
|
||||
}
|
||||
public void TickUntil(Func<bool> done, int max = 300)
|
||||
{
|
||||
for (int i = 0; i < max && !done(); i++) { Tick(); Thread.Sleep(10); }
|
||||
}
|
||||
public void TickFor(int ms, BotActivity act = BotActivity.Looting)
|
||||
{
|
||||
long end = Environment.TickCount64 + ms;
|
||||
while (Environment.TickCount64 < end) { Tick(act); Thread.Sleep(10); }
|
||||
}
|
||||
}
|
||||
|
||||
private static Bot NewBot(bool on = true)
|
||||
{
|
||||
World();
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host);
|
||||
bot.S.LootNearbyChests = on;
|
||||
bot.Create(Storage, VendorBox, DroppedPack, Chest, FarChest, Gem);
|
||||
return bot;
|
||||
}
|
||||
|
||||
private static readonly uint[] NotChests = { Storage, VendorBox, DroppedPack, FarChest };
|
||||
|
||||
private static void PluginOffNothing()
|
||||
{
|
||||
Check.False(new LegacyUiSettings().LootNearbyChests, "off by default");
|
||||
var bot = NewBot(on: false);
|
||||
Check.False(bot.HasLootWork(), "off: a chest in range is no loot work");
|
||||
bot.TickFor(300);
|
||||
Check.Eq(FakeHost.IdRequests.Count, 0, "off: nothing appraised");
|
||||
Check.Eq(FakeHost.Uses.Count, 0, "off: nothing used");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 0, "off: no key or lockpick used");
|
||||
|
||||
// The macro off with the setting on: nothing either.
|
||||
var b2 = NewBot();
|
||||
b2.S.IsMacroRunning = false;
|
||||
Check.False(b2.HasLootWork(), "macro off: no loot work");
|
||||
b2.TickFor(200);
|
||||
Check.Eq(FakeHost.IdRequests.Count + FakeHost.Uses.Count, 0, "macro off: nothing sent");
|
||||
// Looting off: nothing.
|
||||
var b3 = NewBot();
|
||||
b3.S.EnableLooting = false;
|
||||
Check.False(b3.HasLootWork(), "Looting off: no loot work");
|
||||
b3.TickFor(200);
|
||||
Check.Eq(FakeHost.IdRequests.Count + FakeHost.Uses.Count, 0, "Looting off: nothing sent");
|
||||
}
|
||||
|
||||
private static void PluginCandidates()
|
||||
{
|
||||
var bot = NewBot();
|
||||
Check.True(bot.HasLootWork(), "a chest in loot range is loot work");
|
||||
bot.TickUntil(() => FakeHost.IdRequests.Count > 0, 50);
|
||||
Check.Eq(string.Join(",", FakeHost.IdRequests.Select(i => $"{i:X8}")), $"{Chest:X8}", "only the real chest is appraised (the nearer storage, vendor chest and dropped pack, and the far chest, are passed by; corpses: ChestRule)");
|
||||
bot.TickFor(300);
|
||||
foreach (uint id in NotChests)
|
||||
{
|
||||
Check.False(FakeHost.IdRequests.Contains(id) || FakeHost.Uses.Contains(id), $"0x{id:X8} '{FakeHost.Names[id]}' is never touched");
|
||||
}
|
||||
}
|
||||
|
||||
private static void PluginLootsChest()
|
||||
{
|
||||
var bot = NewBot();
|
||||
bot.TickUntil(() => FakeHost.IdRequests.Count > 0, 50);
|
||||
FakeHost.Appraised.Add(Chest); // the ID arrives: no Locked property, so it isn't locked
|
||||
bot.TickUntil(() => FakeHost.Uses.Contains(Chest), 100);
|
||||
Check.True(FakeHost.Uses.Contains(Chest), "the chest is used (the server walks there and opens it)");
|
||||
Check.Eq(FakeHost.AutoRunCalls.Count(on => on), 0, "no walking of our own");
|
||||
|
||||
// The server opens it: the chest looter takes it and loots the gem by the profile.
|
||||
FakeHost.GroundContainer = Chest;
|
||||
bot.P.OnViewObjectContents(Chest);
|
||||
bot.P.OnUpdateObjectInventory(Chest);
|
||||
bot.TickUntil(() => FakeHost.ExternalMoves.Any(m => m.Id == Gem));
|
||||
Check.True(FakeHost.ExternalMoves.Contains((Gem, Player, 0)), "the gem is picked up");
|
||||
FakeHost.Containers[Gem] = Player;
|
||||
int closes = FakeHost.Closes.Count;
|
||||
bot.TickUntil(() => FakeHost.Closes.Count > closes);
|
||||
if (FakeHost.GroundContainer == Chest) FakeHost.GroundContainer = 0;
|
||||
bot.P.OnStopViewingObjectContents(Chest);
|
||||
bot.TickFor(300);
|
||||
var looter = bot.Get<NearbyChestLooter>("_nearbyChests");
|
||||
Check.Eq(looter.Looted, 1, "counted as looted");
|
||||
Check.True(looter.IsLeftAlone(unchecked((int)Chest), RynthAiPlugin.CorpseClock()), "left alone until it resets");
|
||||
Check.False(bot.HasLootWork(), "no loot work left");
|
||||
int uses = FakeHost.Uses.Count(u => u == Chest);
|
||||
bot.TickFor(300);
|
||||
Check.Eq(FakeHost.Uses.Count(u => u == Chest), uses, "not opened again");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("Nearby chests: done with chest")), "the finish is logged");
|
||||
}
|
||||
|
||||
private const uint Monster = 0x80263501;
|
||||
|
||||
private static void PluginSkippedWhileFighting()
|
||||
{
|
||||
World();
|
||||
FakeHost.Names[Monster] = "Drudge Skulker";
|
||||
FakeHost.ItemTypes[Monster] = 0x10;
|
||||
FakeHost.Positions[Monster] = (Me0.Cell, Me0.X + 20f, Me0.Y + 0.5f, Me0.Z);
|
||||
var host = FakeHost.Create(Player);
|
||||
var bot = new Bot(host);
|
||||
bot.S.EnableCombat = true;
|
||||
bot.S.MonsterRange = 50;
|
||||
bot.Create(Storage, VendorBox, DroppedPack, Chest, FarChest, Gem);
|
||||
_ = bot.Cache[unchecked((int)Monster)];
|
||||
bot.Cache.OnUpdateHealth(Monster, 1f);
|
||||
bot.Cache.Tick();
|
||||
var combat = new CombatManager(host, bot.S, bot.Cache);
|
||||
combat.SetPlayerId(Player);
|
||||
typeof(CombatManager).GetField("_lastScanTime", Any)?.SetValue(combat, DateTime.MinValue);
|
||||
combat.ScanNearbyTargets();
|
||||
bot.Set("_combatManager", combat);
|
||||
Check.True(combat.HasTargets, "a monster in range");
|
||||
Check.False(bot.HasLootWork(), "fighting: the chest is no loot work");
|
||||
bot.TickFor(300);
|
||||
bot.TickFor(300, BotActivity.Combat);
|
||||
Check.Eq(FakeHost.IdRequests.Count + FakeHost.Uses.Count + FakeHost.UsesOn.Count, 0, "nothing sent to the chest while fighting");
|
||||
}
|
||||
|
||||
private static void PluginSettingPlumbing()
|
||||
{
|
||||
var s = new LegacyUiSettings { LootNearbyChests = true };
|
||||
var dash = (LegacyDashboardRenderer)RuntimeHelpers.GetUninitializedObject(typeof(LegacyDashboardRenderer));
|
||||
typeof(LegacyDashboardRenderer).GetField("_profileLoaded", Any)!.SetValue(dash, true);
|
||||
typeof(LegacyDashboardRenderer).GetField("_settings", Any)!.SetValue(dash, s);
|
||||
typeof(LegacyDashboardRenderer).GetField("_advancedSettingsUi", Any)!.SetValue(dash, new LegacyAdvancedSettingsUi(s));
|
||||
var sent = JsonSerializer.Deserialize(dash.BuildSettingsJson(), RynthAiJsonContext.Default.SettingsBridgePayload);
|
||||
Check.True(sent != null && sent.LootNearbyChests == true, "sent to the engine's Settings row");
|
||||
dash.ApplySettingsJson("{\"PatrolOnLogin\":false}");
|
||||
Check.True(s.LootNearbyChests, "an engine save without the field leaves it");
|
||||
dash.ApplySettingsJson("{\"LootNearbyChests\":false}");
|
||||
Check.False(s.LootNearbyChests, "an engine save with it sets it");
|
||||
|
||||
FakeHost.Reset();
|
||||
var host = FakeHost.Create();
|
||||
var ms = new LegacyUiSettings();
|
||||
var meta = new MetaManager(ms, host, new PlayerVitalsCache());
|
||||
meta.TryHandleVtCommand("/vt opt set lootnearbychests true");
|
||||
Check.True(ms.LootNearbyChests, "/vt opt set lootnearbychests turns it on");
|
||||
meta.TryHandleVtCommand("/vt opt set lootnearbychests false");
|
||||
Check.False(ms.LootNearbyChests, "and off");
|
||||
var e = ExpressionTests.Engine(settings: ms);
|
||||
Check.Eq(e.Evaluate("vtsetsetting[LootNearbyChests, 1]"), "1", "metas: vtsetsetting knows it");
|
||||
Check.True(ms.LootNearbyChests, "and turns it on");
|
||||
|
||||
// /ra chests always answers.
|
||||
var bot = NewBot(on: false);
|
||||
int before = FakeHost.Chat.Count;
|
||||
bot.Call("HandleNearbyChestsCommand");
|
||||
Check.True(FakeHost.Chat.Skip(before).Any(l => l.Contains("Loot Nearby Chests: off")), "/ra chests says it is off: " + string.Join(" / ", FakeHost.Chat.Skip(before)));
|
||||
bot.S.LootNearbyChests = true;
|
||||
before = FakeHost.Chat.Count;
|
||||
bot.Call("HandleNearbyChestsCommand");
|
||||
Check.True(FakeHost.Chat.Skip(before).Any(l => l.Contains("Loot Nearby Chests: on")), "/ra chests says it is on");
|
||||
}
|
||||
}
|
||||
|
|
@ -26,6 +26,8 @@ internal static class OutdoorHuntTests
|
|||
r.Add("hunt: the settings round-trip with the rest (saved, copied, engine payload)", Settings);
|
||||
r.Add("hunt (test 10-23): a monster 12 yd away but a 143 yd walk is too far round; the one being walked to is kept past Hunt Range", FarRound);
|
||||
r.Add("hunt (test 10-23): at a wall with the monster on its far side: no 1 yd walks every half second; left out after NoFightSec", WallBetween);
|
||||
r.Add("hunt (2026-11-16): a walk ending where it stands, its corners round it, is no walk: it stands, then the monster is left out", EndsHereNoWalk);
|
||||
r.Add("hunt (2026-11-16 17:11): the walk over, under a monster on the floor above: left out, not walked again every half second", FloorApartLeftOut);
|
||||
r.Add("hunt: a monster right beside it that combat doesn't take: stands, then leaves it out", RightHere);
|
||||
r.Add("hunt (test 10-23): in a building it walks back out the way it went in (the loops it made cut out)", WayBackOut);
|
||||
r.Add("hunt: in a building with no way in known, or the walks out ending still inside: it waits", IndoorsWaits);
|
||||
|
|
@ -287,6 +289,56 @@ internal static class OutdoorHuntTests
|
|||
Check.True(h.IsSkipped(1, T0.AddSeconds(h.NoFightSec + 1)), "combat never took it: left out");
|
||||
}
|
||||
|
||||
// 2026-11-16, a Thread: under a monster on the floor above, the walk to it was two corners a yard or
|
||||
// so either side of the character, planned again every half second: it turned in circles.
|
||||
private static void EndsHereNoWalk()
|
||||
{
|
||||
var me = V(1000, 1000);
|
||||
var h = new OutdoorHunt();
|
||||
h.Start(T0, me);
|
||||
var nav = new Nav();
|
||||
nav.Overrides[(1000.5, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1001.2, 1000.8), V(1000.6, 1000.1) }, 2.6, 0);
|
||||
var d = h.Tick(T0, me, true, Sorted(C(1, 1000.5, 1000, me)), nav.Path);
|
||||
Check.True(d.Act != OutdoorHunt.Act.Walk && d.TargetId == 1, $"a 2.6 yd walk ending where it stands: no walk, it stands ({d.Act} {d.TargetId})");
|
||||
h.Tick(T0.AddSeconds(h.NoFightSec + 0.6), me, true, Sorted(C(1, 1000.5, 1000, me)), nav.Path);
|
||||
Check.True(h.IsSkipped(1, T0.AddSeconds(h.NoFightSec + 1)), "combat never took it: left out, no circling");
|
||||
}
|
||||
|
||||
// 2026-11-16 17:11, a Thread: the walk "through its rooms" to a monster on the floor above (3 m up) ended
|
||||
// under it (nav's points count as reached by the flat distance), and the same walk was planned and walked
|
||||
// again every half second for 20 s.
|
||||
private static void FloorApartLeftOut()
|
||||
{
|
||||
var me = V(1000, 1000);
|
||||
var h = new OutdoorHunt();
|
||||
h.Start(T0, me);
|
||||
var nav = new Nav();
|
||||
var up = new OutdoorHunt.Vec(1006, 1000, 3.3);
|
||||
nav.Overrides[(1006, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1003, 1002), up }, 7.5, 0); // a doorway, then the monster
|
||||
var list = Sorted(new OutdoorHunt.Candidate(1, "Elite Olthoi Ravener", up, up.DistanceTo(me), 1));
|
||||
var d = h.Tick(T0, me, true, list, nav.Path);
|
||||
Check.Eq(d.Act, OutdoorHunt.Act.Walk, "walks to it");
|
||||
|
||||
// Walked: under where it was. It moved 2.5 yd up there, so the walk planned again would end 2 yd off.
|
||||
var under = V(1006.4, 1000.3);
|
||||
var moved = new OutdoorHunt.Vec(1008.5, 1000, 3.3);
|
||||
nav.Overrides[(1008.5, 1000)] = new(OutdoorHunt.PathStatus.Ok, new[] { V(1003, 1002), moved }, 9.5, 0);
|
||||
list = Sorted(new OutdoorHunt.Candidate(1, "Elite Olthoi Ravener", moved, moved.DistanceTo(under), 1));
|
||||
d = h.Tick(T0.AddSeconds(3), under, true, list, nav.Path);
|
||||
Check.True(d.Act != OutdoorHunt.Act.Walk, $"the walk over, under it: no walk again ({d.Act})");
|
||||
Check.True(h.IsSkipped(1, T0.AddSeconds(4)), "left out");
|
||||
var notes = string.Join(" | ", h.PendingNotes);
|
||||
Check.True(notes.Contains("the walk to it ended 3 yd below it"), "says so: " + notes);
|
||||
|
||||
// Up there with it (the walk took it up the stairs): not left out.
|
||||
var h2 = new OutdoorHunt();
|
||||
h2.Start(T0, me);
|
||||
h2.Tick(T0, me, true, list, nav.Path);
|
||||
var level = new OutdoorHunt.Vec(1006.4, 1000.3, 3.3);
|
||||
h2.Tick(T0.AddSeconds(3), level, true, Sorted(new OutdoorHunt.Candidate(1, "Elite Olthoi Ravener", up, up.DistanceTo(level), 1)), nav.Path);
|
||||
Check.False(h2.IsSkipped(1, T0.AddSeconds(4)), "level with it: combat's turn, not left out");
|
||||
}
|
||||
|
||||
private static void WayBackOut()
|
||||
{
|
||||
var h = new OutdoorHunt();
|
||||
|
|
|
|||
|
|
@ -39,6 +39,9 @@ internal static class PatrolPortalTests
|
|||
r.Add("patrol portals: a portal in a dead end (Tiny Hive's nook) is turned round before; it used to get a point on it", DeadEndTurnedRoundBefore);
|
||||
r.Add("patrol portals: without the map geometry (cell walk) the patrol keeps out too", CellWalkKeepsOut);
|
||||
r.Add("patrol portals: a start next to a portal walks straight away from it first, then round it", StartNextToPortalWalksAway);
|
||||
r.Add("patrol portals: a start ON a portal walks out towards the room's doorway, never to a spot in the wall (Thread 0x00B5)", StartOnPortalWalksToDoorway);
|
||||
r.Add("patrol portals: a start in a portal with no checked spot round it walks nowhere (no unchecked spot)", StartOnPortalNoSpot);
|
||||
r.Add("nav escapes: a stuck escape burst turns away from a portal it would run into; boxed in: none", EscapeBurstKeepsOutOfPortals);
|
||||
r.Add("patrol portals: a portal across the start's corridor leaves the patrol the side the character is on", PortalSplitsStartCorridor);
|
||||
r.Add("patrol portals: a portal on another level changes nothing", OtherLevelIgnored);
|
||||
r.Add("patrol portals: Tiny Hive 0x0289 on the real dats keeps out of the Surface Portal (if the dats are here)", TinyHiveRealDats);
|
||||
|
|
@ -331,6 +334,80 @@ internal static class PatrolPortalTests
|
|||
Check.True(DungeonPathfinder.PortalLeadIn(d.Graph, geo, portals, At(3, 3), At(3, 17), 1.0).Count == 0, "a clear walk needs no corners");
|
||||
}
|
||||
|
||||
private static void StartOnPortalWalksToDoorway()
|
||||
{
|
||||
// DreamWeave Thread 0x00B5 (2026-11-15): the character arrives ON the Thread Exit, in a one-cell
|
||||
// room whose one way out is a doorway north. Here: a room x 0..4, y 0..8, the portal at (2, 2),
|
||||
// a doorway north (y 8, x 0.5..3.5) into a corridor. The character stands 0.07 m from the
|
||||
// portal's centre, so "away from it" is a random heading (south-east here). The old search
|
||||
// (that heading +-90 degrees) found no spot and fell back to one off the floor, by the wall.
|
||||
var d = new Dungeon();
|
||||
uint room = d.Cell(0, 0, 4, 8);
|
||||
uint corr = d.Cell(0.5, 8, 3.5, 20);
|
||||
d.OpenY(room, corr, 8, 0.5, 3.5);
|
||||
var geo = d.Geo();
|
||||
var p = Portal(2, 2);
|
||||
var portals = new[] { p };
|
||||
double px = 2.05, py = 1.95;
|
||||
var report = new List<PortalAvoidance> { new() { Portal = p } };
|
||||
|
||||
var walk = DungeonPathfinder.PortalWalkOut(geo, portals, px, py, 0, 1.0, report, d.Graph, room);
|
||||
Check.NotNull(walk, "a spot to walk out to");
|
||||
double wx = X(walk!), wy = Y(walk);
|
||||
Check.True(geo.OnWalkableFloor(wx, wy, 0), $"on walkable floor: ({wx:F2}, {wy:F2})");
|
||||
Check.True(wy > p.Y + 3.0, $"north, the doorway's side: ({wx:F2}, {wy:F2})");
|
||||
Check.True(Math.Sqrt((wx - p.X) * (wx - p.X) + (wy - p.Y) * (wy - p.Y)) >= p.Radius, "outside the circle");
|
||||
Check.True(geo.LegClearance(px, py, 0, wx, wy, 0, 1.0, 0.3, out _, out _, out _) >= 0.1, "walked to in a straight line through no wall");
|
||||
Check.True(report[0].StartInside && !report[0].NoWalkOut, "the report: started inside, walked out");
|
||||
Check.True(report[0].Describe().Contains("walked out first"), report[0].Describe());
|
||||
|
||||
// The patrol from there starts on the doorway's side too.
|
||||
var route = DungeonPathfinder.BuildPatrolRoute(d.Graph, room, null, geo, null, portals, (wx, wy, 0));
|
||||
KeptOut(route, p, "start on a portal");
|
||||
}
|
||||
|
||||
private static void StartOnPortalNoSpot()
|
||||
{
|
||||
// A sealed 3 m room with the portal in its middle: no spot 3.9 m out is on any floor.
|
||||
var d = new Dungeon();
|
||||
uint room = d.Cell(0, 0, 3, 3);
|
||||
var geo = d.Geo();
|
||||
var p = Portal(1.5, 1.5);
|
||||
var report = new List<PortalAvoidance> { new() { Portal = p } };
|
||||
var walk = DungeonPathfinder.PortalWalkOut(geo, new[] { p }, 1.5, 1.6, 0, 1.0, report, d.Graph, room);
|
||||
Check.Null(walk, "no checked spot: nowhere to walk (it used to be a spot off the floor)");
|
||||
Check.True(report[0].StartInside && report[0].NoWalkOut, "the report says so");
|
||||
Check.True(report[0].Describe().Contains("no clear spot to walk out to"), report[0].Describe());
|
||||
}
|
||||
|
||||
private static void EscapeBurstKeepsOutOfPortals()
|
||||
{
|
||||
// Facing north at (0, 0); a portal 5 m east-north-east: the +75 degree side-step runs at it.
|
||||
double off = 75;
|
||||
var east = new[] { (5.0, 1.5, 0.0) };
|
||||
Check.True(NavigationEngine.EscapeOffsetClear(0, 0, 0, 0, east, ref off, out string? note), "a clear way is found");
|
||||
Check.Near(off, -75, 1e-9, "the other side-step instead");
|
||||
Check.True(note != null && note.Contains("instead"), "said: " + note);
|
||||
|
||||
// Nothing near, or only on another level: the rung's own heading, nothing said.
|
||||
off = 75;
|
||||
Check.True(NavigationEngine.EscapeOffsetClear(0, 0, 0, 0, Array.Empty<(double, double, double)>(), ref off, out note) && off == 75 && note == null, "no portal: as it was");
|
||||
off = 75;
|
||||
Check.True(NavigationEngine.EscapeOffsetClear(0, 0, 0, 0, new[] { (5.0, 1.5, 10.0) }, ref off, out note) && off == 75 && note == null, "a portal 10 m up: as it was");
|
||||
|
||||
// Standing 1 m west of a portal: anything eastwards gets nearer it; the burst goes the other way.
|
||||
off = 75;
|
||||
Check.True(NavigationEngine.EscapeOffsetClear(0, 0, 0, 0, new[] { (1.0, 0.0, 0.0) }, ref off, out note), "a way away from it");
|
||||
double h = off * Math.PI / 180.0;
|
||||
Check.True(Math.Sin(h) < 0, $"westwards ({off:+0;-0} degrees)");
|
||||
|
||||
// Boxed in by portals all round: no burst (the jump instead).
|
||||
var ring = Enumerable.Range(0, 12).Select(i => (4.0 * Math.Sin(i * Math.PI / 6), 4.0 * Math.Cos(i * Math.PI / 6), 0.0)).ToArray();
|
||||
off = 75;
|
||||
Check.False(NavigationEngine.EscapeOffsetClear(0, 0, 0, 0, ring, ref off, out note), "every heading runs at one");
|
||||
Check.True(note != null && note.Contains("portal"), "names the portal: " + note);
|
||||
}
|
||||
|
||||
private static void PortalSplitsStartCorridor()
|
||||
{
|
||||
// A corridor (x 0..5.3, y 0..20) between a room south (y -10..0) and a room north (y 20..30),
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ internal static class PetRefillTests
|
|||
r.Add("pets: 'not enough charges' after a confirmed refill ends the trust; refill again", TrustEndsOnEmptySummon);
|
||||
r.Add("pets: refilled twice in 2 min and still empty (no reply) -> parked 5 min", SilentRefillsParked);
|
||||
r.Add("pets: the server's 'full' trust expires after 30 min", TrustExpires);
|
||||
r.Add("pets: a landed summon whose pet is not in the cache yet holds a second essence back for the 10 s window", LandedSummonHoldsWindow);
|
||||
r.Add("pets: a landed summon whose pet is not in the cache yet holds a second essence back for the 10 s window, then the shared 45 s cooldown", LandedSummonHoldsWindow);
|
||||
r.Add("pets: failed summon (no charge drop) does not assume a pet; waits the 45 s essence cooldown", FailedSummonRespectsCooldown);
|
||||
r.Add("pets: Boost Nav Priority along a route (RynthAi only follows it): no summon with a monster near; route unloaded: it summons", BoostNavNoSummon);
|
||||
r.Add("pets: Boost Nav Priority with no route: it summons as with the flag off (R-20261103-000159-a65e)", BoostNavNoRouteSummons);
|
||||
|
|
@ -280,7 +280,12 @@ internal static class PetRefillTests
|
|||
FakeHost.Ints[(Essence2, StructureKey)] = 49; // whichever essence it was, its charge dropped
|
||||
rig.Run(8_000);
|
||||
Check.Eq(rig.AllSummons, 1, "inside the 10 s window the other essence is not used");
|
||||
// Window over and still no pet: the other essence used to be summoned now. Every ACE combat
|
||||
// essence shares one 45 s cooldown (SharedCooldown 213), so the server refused it; the next
|
||||
// summon waits for that cooldown (2026-11-13, R-20261113-130755-35ae).
|
||||
rig.Run(5_000);
|
||||
Check.Eq(rig.AllSummons, 2, "window over and still no pet: the other essence is used");
|
||||
Check.Eq(rig.AllSummons, 1, "window over and still no pet: the shared 45 s cooldown still runs, no other essence");
|
||||
rig.Run(32_000);
|
||||
Check.Eq(rig.AllSummons, 2, "the cooldown over: the next summon goes");
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,54 @@ internal static class PetSelectionTests
|
|||
r.Add("pet choice: an essence used before its appraisal that turns out passive is learned, and its pet holds nothing (before: held for good)", PassiveLearnedAfterSummon);
|
||||
r.Add("pet choice: the Pets tab shows a listed passive essence under Cosmetic, unticked, and the combat pick skips it", PetsTabShowsPassiveAsCosmetic);
|
||||
r.Add("pet choice: pack fill does not list an appraised passive essence as a Pet; a combat essence and an unappraised one still are", FillSkipsPassiveEssence);
|
||||
// R-20261113-130755-35ae (Conquest, 2026.11.12.1): "Cold chosen -> Frost ..." on every line, yet
|
||||
// when the pet died before 45 s the next listed essences (other elements) were used: refused
|
||||
// "used this item too recently" for most of the window, summoned for real at its edge.
|
||||
r.Add("pet choice: the pet dies inside the shared 45 s cooldown: the chosen element waits for it; no other essence is used (before: the next listed)", ChosenWaitsSharedCooldown);
|
||||
r.Add("pet choice: 'used this item too recently' does not park the chosen essence 45 s; it is tried again in 5 s, no other essence (before: the next listed)", TooRecentlyRetriesChosen);
|
||||
}
|
||||
|
||||
/// <summary>The report's fight: Cold chosen for the monster, a Fire essence listed after the Frost one.</summary>
|
||||
private static Rig ColdChosenRig()
|
||||
{
|
||||
var rig = new Rig(frostFirst: true);
|
||||
rig.Store.SetManualPet(MobWcid, "E:Cold");
|
||||
return rig;
|
||||
}
|
||||
|
||||
private static void ChosenWaitsSharedCooldown()
|
||||
{
|
||||
using var rig = ColdChosenRig();
|
||||
rig.Run(1_500);
|
||||
Check.Eq(Rig.UsesOf(Frost), 1, "Cold chosen: the Frost essence is summoned");
|
||||
Check.True(Logged("Cold chosen -> Frost Moar Essence"), "the choice line names it");
|
||||
FakeHost.Ints[(Frost, StructureKey)] = 49; // the summon landed: a charge spent
|
||||
rig.ShowPet(Ours, "Pet Tester's Frost Moar");
|
||||
rig.Run(18_000);
|
||||
Check.Eq(Rig.UsesOf(Frost) + Rig.UsesOf(Essence), 1, "the pet is out: no second summon");
|
||||
FakeHost.Names.Remove(Ours); // the pet dies about 20 s in
|
||||
FakeHost.Positions.Remove(Ours);
|
||||
rig.Run(20_000);
|
||||
Check.Eq(Rig.UsesOf(Essence), 0, "inside the 45 s cooldown every essence shares, the Fire essence is not used (before: it was, at once)");
|
||||
Check.True(Logged("every essence shares the 45s summon cooldown"), "the wait is logged");
|
||||
rig.Run(8_000);
|
||||
Check.Eq(Rig.UsesOf(Frost), 2, "the cooldown over: the chosen Frost essence is summoned again");
|
||||
Check.Eq(Rig.UsesOf(Essence), 0, "and never the Fire one");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("every essence shares the 45s")), 1, "the wait logged once");
|
||||
}
|
||||
|
||||
private static void TooRecentlyRetriesChosen()
|
||||
{
|
||||
using var rig = ColdChosenRig();
|
||||
rig.Run(1_500);
|
||||
Check.Eq(Rig.UsesOf(Frost), 1, "Cold chosen: the Frost essence is tried");
|
||||
rig.Pets.OnChatWindowText("You have used this item too recently"); // a pet summoned by hand started the cooldown
|
||||
Check.True(Logged("used too recently"), "the refusal is logged");
|
||||
rig.Run(3_000);
|
||||
Check.Eq(Rig.UsesOf(Frost) + Rig.UsesOf(Essence), 1, "no Use for a moment");
|
||||
rig.Run(3_000);
|
||||
Check.Eq(Rig.UsesOf(Frost), 2, "the chosen Frost essence is tried again (before: parked 45 s, so the Fire one went)");
|
||||
Check.Eq(Rig.UsesOf(Essence), 0, "never the Fire one");
|
||||
}
|
||||
|
||||
private const uint Golem = 0x80320030; // Common Golem Essence: a passive pet's essence
|
||||
|
|
|
|||
79
Tools/RynthCore.RynthAiHostTests/Tests/StackedStepTests.cs
Normal file
79
Tools/RynthCore.RynthAiHostTests/Tests/StackedStepTests.cs
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Steps nav can't walk (DungeonPathfinder.Explore.cs, 2026-11-16). DreamWeave Thread 0x0278: the explore crossed a
|
||||
// two-level room straight, from the doorway at its foot (z -42) to the opening on the level above (z -36), 1 m off
|
||||
// on the map; nav took the upper point as reached and ran from the lower floor into the wall under the next one.
|
||||
internal static class StackedStepTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("stacked steps: Thread 0x0278's walk from where that run started has no step 6 m up in 1 m (its doorway closed, the walk laid again, the rooms still walked); the stairs of 0x00B5 and 0x0185 are left as they are (if the dats are here)", RealDats);
|
||||
}
|
||||
|
||||
private static int Stacked(List<NavPoint> pts, Dictionary<uint, DungeonNavNode> graph, DungeonGeometry geo)
|
||||
{
|
||||
DungeonPathfinder.StackedStepOpenings(pts, graph, geo, out int steps);
|
||||
return steps;
|
||||
}
|
||||
|
||||
private static void RealDats()
|
||||
{
|
||||
string acDir = DunRouteTests.AcDir;
|
||||
if (!Directory.Exists(acDir)) { Console.WriteLine(" (no dats on this PC: skipped)"); return; }
|
||||
var loader = new GeometryLoader();
|
||||
if (!loader.Initialize(acDir)) { Console.WriteLine(" (geometry loader failed: " + loader.StatusMessage + ")"); return; }
|
||||
var before = DungeonPathfinder.StaticMeshSource;
|
||||
try
|
||||
{
|
||||
DungeonPathfinder.StaticMeshSource = lb => loader.GetDungeonStaticMeshes(lb);
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var graph = DungeonPathfinder.GetGraph(0x0278, loader.CellDat);
|
||||
var geo = DungeonPathfinder.GetGeometry(0x0278, loader.CellDat, loader.DungeonLOS)!;
|
||||
|
||||
DungeonPathfinder.CloseStackedSteps = false;
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
var old = DungeonPathfinder.BuildExploreRoute(graph, 0x02780369, null, geo, null, null, null, null, out var oldPlan);
|
||||
int oldStacked = Stacked(old.Points, graph, geo);
|
||||
DungeonPathfinder.CloseStackedSteps = true;
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
var route = DungeonPathfinder.BuildExploreRoute(graph, 0x02780369, null, geo, null, null, null, null, out var plan);
|
||||
string note = DungeonPathfinder.MainRouteNote ?? "";
|
||||
Console.WriteLine($" 0x0278: as laid {old.Points.Count} points, {oldStacked} stacked, {oldPlan.Order.Count} rooms; now {route.Points.Count} points, {plan.Order.Count} rooms; {note}");
|
||||
Check.True(oldStacked >= 1, "as laid, the walk has the step 6 m up in 1 m");
|
||||
Check.Eq(Stacked(route.Points, graph, geo), 0, "now it has none");
|
||||
Check.True(note.Contains("stacked steps:"), "and says so: " + note);
|
||||
Check.True(plan.Order.Count >= oldPlan.Order.Count * 0.9, $"the rooms still walked ({plan.Order.Count} of {oldPlan.Order.Count})");
|
||||
var keys = DungeonPathfinder.StackedStepOpenings(old.Points, graph, geo, out _);
|
||||
Check.True(keys.Contains(DungeonPathfinder.OpeningKey(0x0278012C, 0x02780155)) && keys.Contains(DungeonPathfinder.OpeningKey(0x0278012C, 0x02780156)),
|
||||
"the doorway closed is the one at its foot, both cell pairs (012C>0155, 012C>0156)");
|
||||
|
||||
foreach (uint lb in new uint[] { 0x00B5, 0x0185 })
|
||||
{
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var g = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
var gg = DungeonPathfinder.GetGeometry(lb, loader.CellDat, loader.DungeonLOS)!;
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
var r = DungeonPathfinder.BuildExploreRoute(g, g.Keys.Min(), null, gg, null, null, null, null, out _);
|
||||
string n = DungeonPathfinder.MainRouteNote ?? "";
|
||||
Check.False(n.Contains("stacked steps:"), $"0x{lb:X4}: its stairs (3 m up over 2 m) are walkable steps: " + n);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
DungeonPathfinder.CloseStackedSteps = true;
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
DungeonPathfinder.StaticMeshSource = before;
|
||||
loader.Dispose();
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
92
Tools/RynthCore.RynthAiHostTests/Tests/StraightenTests.cs
Normal file
92
Tools/RynthCore.RynthAiHostTests/Tests/StraightenTests.cs
Normal file
|
|
@ -0,0 +1,92 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// The explore's walk straightened (DungeonPathfinder.Straighten.cs, 2026-11-15). DreamWeave Thread
|
||||
// 0x00ED: its zig-zag corridors are cut into many 3-5 cell rooms, the walk had a point at every room
|
||||
// boundary (334 points, 182 of them at openings) and the character turned every 2.5-5 m. On the real
|
||||
// dats: far fewer points, every leg walkable, and every room the walk was laid into still crossed.
|
||||
internal static class StraightenTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("straighten: Thread 0x00ED's explore on the real dats has far fewer turns, every leg walkable, every room still crossed (if the dats are here)", Real00ED);
|
||||
}
|
||||
|
||||
private static void Real00ED()
|
||||
{
|
||||
string acDir = DunRouteTests.AcDir;
|
||||
if (!Directory.Exists(acDir)) { Console.WriteLine(" (no dats on this PC: skipped)"); return; }
|
||||
var loader = new GeometryLoader();
|
||||
if (!loader.Initialize(acDir)) { Console.WriteLine(" (geometry loader failed: " + loader.StatusMessage + ")"); return; }
|
||||
try
|
||||
{
|
||||
const uint lb = 0x00ED, start = 0x00ED0350;
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var graph = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
var geo = DungeonPathfinder.GetGeometry(lb, loader.CellDat, loader.DungeonLOS)!;
|
||||
Check.NotNull(geo, "geometry");
|
||||
// Where the character arrives (local 180, -330), and the Thread Exit beside it (as logged 2026-11-15).
|
||||
double sx = 180.0, sy = 0xED * 192.0 - 330.0;
|
||||
var exit = new PatrolPortal { Id = 0x700ED032, Name = "Thread Exit", Cell = 0x00ED0351, X = 180.0, Y = 45160.0, Z = -0.1 };
|
||||
// As laid, for comparison: the rooms that walk crosses.
|
||||
DungeonPathfinder.StraightenEnabled = false;
|
||||
var laid = DungeonPathfinder.BuildExploreRoute(graph, start, null, geo, null, new[] { exit }, (sx, sy, 0), null, out var laidPlan);
|
||||
DungeonPathfinder.StraightenEnabled = true;
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
var route = DungeonPathfinder.BuildExploreRoute(graph, start, null, geo, null, new[] { exit }, (sx, sy, 0), null, out var plan);
|
||||
var pts = route.Points;
|
||||
Console.WriteLine($" {pts.Count} points (laid in game before: 334), {plan.Order.Count} rooms in order; {DungeonPathfinder.MainRouteNote}");
|
||||
// Against the same walk laid unstraightened, waits left out. (2026-11-16: the explore walks into every dead
|
||||
// end and keeps those middles, so it has more points than the 334 of 2026-11-15.)
|
||||
int moves = pts.Count(p => p.Type == NavPointType.Point), laidMoves = laid.Points.Count(p => p.Type == NavPointType.Point);
|
||||
Console.WriteLine($" {moves} moving points straightened, {laidMoves} as laid");
|
||||
Check.True(moves > 50 && moves < laidMoves * 0.85, $"far fewer points ({moves}, {laidMoves} as laid)");
|
||||
|
||||
double X(NavPoint p) => DungeonGeometry.NavToWorld(p.EW);
|
||||
double Y(NavPoint p) => DungeonGeometry.NavToWorld(p.NS);
|
||||
int bad = 0;
|
||||
for (int i = 0; i + 1 < pts.Count; i++)
|
||||
if (geo.LegClearance(X(pts[i]), Y(pts[i]), pts[i].Z * 240.0, X(pts[i + 1]), Y(pts[i + 1]), pts[i + 1].Z * 240.0, 1.0, 0.5, out _, out _, out _) < 0.2) bad++;
|
||||
Check.Eq(bad, 0, "every leg on walkable floor, off the walls");
|
||||
|
||||
// Every room the walk was laid into is crossed by it (sampled every 0.5 m) - as the walk as laid did.
|
||||
HashSet<int> Crossed(List<NavPoint> pts)
|
||||
{
|
||||
var crossed = new HashSet<int>();
|
||||
for (int i = 0; i + 1 < pts.Count; i++)
|
||||
{
|
||||
double x0 = X(pts[i]), y0 = Y(pts[i]), z0 = pts[i].Z * 240.0, x1 = X(pts[i + 1]), y1 = Y(pts[i + 1]), z1 = pts[i + 1].Z * 240.0;
|
||||
int steps = Math.Max(1, (int)Math.Ceiling(Math.Sqrt((x1 - x0) * (x1 - x0) + (y1 - y0) * (y1 - y0)) / 0.5));
|
||||
double zf = z0;
|
||||
for (int s = 0; s <= steps; s++)
|
||||
{
|
||||
double t = (double)s / steps, x = x0 + (x1 - x0) * t, y = y0 + (y1 - y0) * t;
|
||||
if (geo.TryFloorHeight(x, y, zf, 0.6, out double h)) zf = h;
|
||||
foreach (var n in graph.Values)
|
||||
if (geo.OnCellFloor(n.CellId, x, y, zf)) { int r = plan.RoomOf(n.CellId); if (r >= 0) crossed.Add(r); break; }
|
||||
}
|
||||
}
|
||||
return crossed;
|
||||
}
|
||||
var before = Crossed(laid.Points);
|
||||
var after = Crossed(pts);
|
||||
var laidMissed = plan.Order.Where(r => !before.Contains(r)).ToList();
|
||||
var missed = plan.Order.Where(r => !after.Contains(r) && before.Contains(r)).ToList();
|
||||
Console.WriteLine($" as laid: {laid.Points.Count} points, rooms not crossed {laidMissed.Count} ({string.Join(",", laidMissed.Take(10))})");
|
||||
Check.Eq(missed.Count, 0, $"no room the laid walk crossed is left out ({missed.Count}: {string.Join(",", missed.Take(10))})");
|
||||
}
|
||||
finally
|
||||
{
|
||||
loader.Dispose();
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -24,6 +24,7 @@ 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("too busy (Conquest 10-25): a try held by another check (animating) is not spent; the next asker (combat) gets it", TryNotSpentWhenHeld);
|
||||
r.Add("too busy (R-20261115-172110-9e6a): a try let through but sent nothing with is not spent; combat, asking next, gets it", TrySpentOnlyBySend);
|
||||
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);
|
||||
|
|
@ -346,6 +347,38 @@ internal static class StuckCastTests
|
|||
// Conquest report R-20261025-183343 (Dargoth Hera): a corpse pickup and a cast went out together, the
|
||||
// cast was refused 'too busy', and the buff step took all three tries after it while the character was
|
||||
// still animating, so it sent nothing; combat never got a try and the fight stood for the latch's 15 s.
|
||||
// 2026-11-15, R-20261115-172110-9e6a: the buff step passed MayStart three times in a 15 s latch, found
|
||||
// nothing to cast and sent nothing; combat, asking after it, never got a try with eleven monsters in range.
|
||||
private static void TrySpentOnlyBySend()
|
||||
{
|
||||
var host = Setup();
|
||||
try
|
||||
{
|
||||
Check.True(MayAs(host, "Combat", HealNeed.None), "free");
|
||||
Cast(host, "Heart Rend");
|
||||
_t += 100;
|
||||
FakeHost.UseDone(ActionPacer.TooBusyErr);
|
||||
Check.False(MayAs(host, "Combat", HealNeed.None), "held right after the 0x1D");
|
||||
_t += ActionPacer.BusyProbeMs;
|
||||
Check.True(MayAs(host, "Buff", HealNeed.None), "the buff step is let through with the try");
|
||||
// ...and sends nothing (nothing to cast).
|
||||
Check.True(MayAs(host, "Combat", HealNeed.None), "unused, the try is still there for combat");
|
||||
Check.False(FakeHost.Logs.Any(l => l.Contains("one try (#")), "nothing spent it yet");
|
||||
Check.True(host.CastSpellFor(Monster, DrainHealthOtherI, "Combat", "Heart Rend"), "combat casts");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("Combat: one try (#1)")), "the send spent it, and it was combat's");
|
||||
FakeHost.UseDone(ActionPacer.TooBusyErr);
|
||||
Check.False(MayAs(host, "Buff", HealNeed.None), "spent: the next asker waits for the next try");
|
||||
|
||||
// Let through and never used: after TryOpenMs it counts as spent (no endless passes).
|
||||
_t += ActionPacer.BusyProbeMs * 2;
|
||||
Check.True(MayAs(host, "Buff", HealNeed.None), "the second try is let through");
|
||||
_t += ActionPacer.TryOpenMs;
|
||||
Check.False(MayAs(host, "Combat", HealNeed.None), "unused for TryOpenMs: spent, the next one waits");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("went unused for") && l.Contains("first let through for Buff")), "and said so");
|
||||
}
|
||||
finally { Done(); }
|
||||
}
|
||||
|
||||
private static void TryNotSpentWhenHeld()
|
||||
{
|
||||
var host = Setup();
|
||||
|
|
@ -361,9 +394,11 @@ internal static class StuckCastTests
|
|||
Check.False(MayAs(host, "Buff", HealNeed.None), "the buff step's try is held by the animation");
|
||||
FakeHost.CastBusy = 0;
|
||||
Check.True(MayAs(host, "Combat", HealNeed.None), "combat gets the try the buff step couldn't use");
|
||||
Check.True(host.CastSpellFor(Monster, DrainHealthOtherI, "Combat", "Heart Rend"), "and casts with it");
|
||||
Check.False(MayAs(host, "Buff", HealNeed.None), "and only one start has it");
|
||||
Check.Eq(FakeHost.Logs.Count(l => l.Contains("one try (#1)")), 1, "one try logged");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("Combat: one try (#1)")), "and it was combat's");
|
||||
FakeHost.UseDone(ActionPacer.TooBusyErr); // refused again: the latch goes on
|
||||
// The next try is counted from the one that went (doubling as before).
|
||||
_t += ActionPacer.BusyProbeMs * 2 - 1;
|
||||
Check.False(MayAs(host, "Combat", HealNeed.None), "the next try waits twice as long");
|
||||
|
|
@ -389,8 +424,8 @@ internal static class StuckCastTests
|
|||
Check.False(Start(host), "held until BusyProbeMs");
|
||||
_t += 1;
|
||||
Check.True(Start(host), "one probe at BusyProbeMs");
|
||||
Check.False(Start(host), "only one");
|
||||
Cast(host, "Heart Rend");
|
||||
Check.False(Start(host), "only one (the send spent it; 2026-11-15 a pass that sends nothing doesn't)");
|
||||
_t += 100;
|
||||
FakeHost.UseDone(ActionPacer.TooBusyErr); // refused again
|
||||
_t += ActionPacer.BusyProbeMs * 2 - 101;
|
||||
|
|
|
|||
78
Tools/RynthCore.RynthAiHostTests/Tests/StuckOpeningTests.cs
Normal file
78
Tools/RynthCore.RynthAiHostTests/Tests/StuckOpeningTests.cs
Normal file
|
|
@ -0,0 +1,78 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.Raycasting;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// Stuck for good in an opening the map says is open (DungeonPathfinder.OpeningPairs, 2026-11-16). DreamWeave
|
||||
// Thread 0x5456: cells 014F and 0150 have one centre at the big room's west edge, and both join 0148 through
|
||||
// the one doorway at (16133, 16492). The explore, stuck in it (something in the doorway no dat has), closed
|
||||
// 014F>0148, laid the walk again through 0150>0148, and was stuck in the same doorway again (three closings,
|
||||
// the last an opening inside the big room). The same at 0177 (0173>0177 and 0174>0177) and 0157 (0158>0157
|
||||
// and 0159>0157): each one doorway.
|
||||
internal static class StuckOpeningTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("stuck opening: Thread 0x5456 on the real dats - a doorway two stacked cells open into is closed whole; the walk laid again keeps out (if the dats are here)", Real5456);
|
||||
}
|
||||
|
||||
private const uint C014F = 0x5456014F, C0150 = 0x54560150, C0148 = 0x54560148, C0147 = 0x54560147,
|
||||
C0173 = 0x54560173, C0174 = 0x54560174, C0177 = 0x54560177;
|
||||
|
||||
private static void Real5456()
|
||||
{
|
||||
string acDir = DunRouteTests.AcDir;
|
||||
if (!Directory.Exists(acDir)) { Console.WriteLine(" (no dats on this PC: skipped)"); return; }
|
||||
var loader = new GeometryLoader();
|
||||
if (!loader.Initialize(acDir)) { Console.WriteLine(" (geometry loader failed: " + loader.StatusMessage + ")"); return; }
|
||||
try
|
||||
{
|
||||
const uint lb = 0x5456;
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
var graph = DungeonPathfinder.GetGraph(lb, loader.CellDat);
|
||||
var geo = DungeonPathfinder.GetGeometry(lb, loader.CellDat, loader.DungeonLOS)!;
|
||||
Check.NotNull(geo, "geometry");
|
||||
ulong K(uint a, uint b) => DungeonPathfinder.OpeningKey(a, b);
|
||||
|
||||
var west = DungeonPathfinder.OpeningPairs(graph, geo, C014F, C0148);
|
||||
Check.True(west.SetEquals(new[] { K(C014F, C0148), K(C0150, C0148) }),
|
||||
$"the west doorway is 014F>0148 and 0150>0148 ({west.Count} pair(s))");
|
||||
var south = DungeonPathfinder.OpeningPairs(graph, geo, C0173, C0177);
|
||||
Check.True(south.SetEquals(new[] { K(C0173, C0177), K(C0174, C0177) }),
|
||||
$"the doorway into 0177 is 0173>0177 and 0174>0177, 3 m over it ({south.Count} pair(s))");
|
||||
Check.Eq(DungeonPathfinder.OpeningPairs(graph, geo, C0148, C0147).Count, 1, "the next doorway (0148>0147, 2 m on) is one pair");
|
||||
var east = DungeonPathfinder.OpeningPairs(graph, geo, 0x54560158, 0x54560157);
|
||||
Check.True(east.SetEquals(new[] { K(0x54560158, 0x54560157), K(0x54560159, 0x54560157) }),
|
||||
$"the doorway into 0157 is 0158>0157 and 0159>0157 (the third doorway it was stuck in: {east.Count} pair(s))");
|
||||
|
||||
// A web where the character stood stuck (16148.0, 16506.4): that doorway, both pairs; the big room's middle: none.
|
||||
var web = DungeonPathfinder.DoorwayAt(graph, geo, 16148.0, 16506.6, -24.0, 1.5, out var webDoor);
|
||||
Check.True(web.SetEquals(east), $"a web at (16148, 16506.6) stands in the doorway into 0157 ({web.Count} pair(s), {webDoor?.CellA:X8}>{webDoor?.CellB:X8})");
|
||||
Check.Eq(DungeonPathfinder.DoorwayAt(graph, geo, 16150.0, 16470.0, -24.0, 1.5, out _).Count, 0, "one in the big room's middle stands in no doorway");
|
||||
|
||||
// Laid again from 014F as it was (014F>0148 closed) and as it is now (the doorway's pairs closed).
|
||||
var (x, y) = (16137.0, 16492.0);
|
||||
foreach (bool whole in new[] { false, true })
|
||||
{
|
||||
var closed = whole ? west : new HashSet<ulong> { K(C014F, C0148) };
|
||||
var g = DungeonPathfinder.WithoutOpenings(graph, closed, C014F);
|
||||
var route = DungeonPathfinder.BuildExploreRoute(g, C014F, null, geo, null, null, (x, y, -24.0), null, out _);
|
||||
int behind = route.Points.Count(p => DungeonPathfinder.CellAt(graph, geo, p) is C0148 or C0147);
|
||||
Console.WriteLine($" {(whole ? "whole doorway" : "014F>0148 only")} closed: {route.Points.Count} points, {behind} behind the doorway");
|
||||
DungeonPathfinder.MainRouteNote = null;
|
||||
if (whole) Check.Eq(behind, 0, "the doorway closed whole: the walk keeps out of the rooms behind it");
|
||||
else Check.True(behind > 0, $"as it was, the walk went back through the same doorway ({behind})");
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
loader.Dispose();
|
||||
DungeonPathfinder.InvalidateCache();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -239,6 +239,53 @@ internal static class TargetingTests
|
|||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Magic;
|
||||
Check.Eq(magic.Tick(), A, "magic: one on a balcony in sight is still a target");
|
||||
|
||||
// 2026-11-16, a Thread: in a building, an Armoredillo 5.5 m up and 8 m off in another of its cells
|
||||
// (h 8.1, dz +5.5: a gentle slope by the rule above). It was locked and chased round under it.
|
||||
Check.False(CombatManager.OutOfMeleeReachUpOrDown(9.8, 5.5), "by the slope alone it would be walked to");
|
||||
var balcony = new ScanPick(20);
|
||||
balcony.Place(A, "Mob A", north: 8, up: 5.5);
|
||||
FakeHost.Positions[Player] = (Lb | 0x0107, 96f, 96f, 0f);
|
||||
FakeHost.PlayerPose = (Lb | 0x0107, 96f, 96f, 0f);
|
||||
FakeHost.Positions[A] = (Lb | 0x0100, FakeHost.Positions[A].Item2, FakeHost.Positions[A].Item3, FakeHost.Positions[A].Item4);
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Melee;
|
||||
Check.Eq(balcony.Tick(), 0u, "melee, both inside, another cell 5.5 m up: not the target (the stairs first)");
|
||||
|
||||
// 2026-11-16 17:11, a Thread: the building's floor above 3.0 m up, the monsters in the next cell 2.5 m
|
||||
// off; "more than 3 m" let them through and they were swung at from the floor below.
|
||||
var floorAbove = new ScanPick(20);
|
||||
floorAbove.Place(A, "Mob A", north: 2.5, up: 3.0);
|
||||
FakeHost.Positions[Player] = (Lb | 0x0125, 96f, 96f, 0f);
|
||||
FakeHost.PlayerPose = (Lb | 0x0125, 96f, 96f, 0f);
|
||||
FakeHost.Positions[A] = (Lb | 0x0126, FakeHost.Positions[A].Item2, FakeHost.Positions[A].Item3, FakeHost.Positions[A].Item4);
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Melee;
|
||||
Check.Eq(floorAbove.Tick(), 0u, "melee, both inside, the next cell 3.0 m up: not the target");
|
||||
|
||||
var stair = new ScanPick(20);
|
||||
stair.Place(A, "Mob A", north: 2.5, up: 2.0);
|
||||
FakeHost.Positions[Player] = (Lb | 0x0125, 96f, 96f, 0f);
|
||||
FakeHost.PlayerPose = (Lb | 0x0125, 96f, 96f, 0f);
|
||||
FakeHost.Positions[A] = (Lb | 0x0126, FakeHost.Positions[A].Item2, FakeHost.Positions[A].Item3, FakeHost.Positions[A].Item4);
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Melee;
|
||||
Check.Eq(stair.Tick(), A, "the next cell 2.0 m up (a stair): still the target");
|
||||
|
||||
var hill = new ScanPick(20);
|
||||
hill.Place(A, "Mob A", north: 8, up: 5.5);
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Melee;
|
||||
Check.Eq(hill.Tick(), A, "outdoors, the same up a hillside: still the target");
|
||||
|
||||
var sameCell = new ScanPick(20);
|
||||
sameCell.Place(A, "Mob A", north: 8, up: 5.5);
|
||||
FakeHost.Positions[Player] = (Lb | 0x0107, 96f, 96f, 0f);
|
||||
FakeHost.PlayerPose = (Lb | 0x0107, 96f, 96f, 0f);
|
||||
FakeHost.Positions[A] = (Lb | 0x0107, FakeHost.Positions[A].Item2, FakeHost.Positions[A].Item3, FakeHost.Positions[A].Item4);
|
||||
FakeHost.WeaponCalls = true;
|
||||
FakeHost.CombatModeValue = CombatMode.Melee;
|
||||
Check.Eq(sameCell.Tick(), A, "inside, up a ramp in the same cell: still the target");
|
||||
}
|
||||
|
||||
public static void Register(Runner r)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
|
|
@ -25,6 +26,9 @@ internal static class VitalWandGateTests
|
|||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("heal before stamina: health falling to Emergency Heal At within a stamina kit's 3 s: the healing kit goes, no stamina kit", HealBeforeStaminaWhenFalling);
|
||||
r.Add("heal before stamina: health steady or falling slowly: the stamina kit goes as before", StaminaWhenHealthSteady);
|
||||
r.Add("heal before stamina: the projection (latest high, at least 1 s of rate, 4 s window)", HealthProjection);
|
||||
r.Add("vital wand gate: out of Magic with a healing kit carried, Heal Self starts no wand swap (not handled)", HealRefusedWithKit);
|
||||
r.Add("vital wand gate: the refused Heal Self falls through to the kit despite Kit Min Success", KitDespiteMinSuccessAfterRefusal);
|
||||
r.Add("vital wand gate: a caster already wielded in melee stance: the Magic stance change only, no weapon move", StanceOnlyWithCasterWielded);
|
||||
|
|
@ -32,20 +36,21 @@ internal static class VitalWandGateTests
|
|||
r.Add("vital wand gate: Revitalize with a stamina kit, Stamina to Mana in a fight, the script heal with a health potion: no swap", OtherVitalsRefused);
|
||||
r.Add("vital wand gate: a pure caster in Magic mode with a kit carried still casts Heal Self", PureCasterUnaffected);
|
||||
r.Add("vital wand gate: buffing still swaps to the wand with a kit carried", BuffsStillSwap);
|
||||
r.Add("vital wand gate: Revitalize refused, no stamina potion: the stamina kit is used despite Kit Min Success", StaminaKitDespiteMinSuccess);
|
||||
r.Add("vital wand gate: a stamina kit under Stamina Kit Min Success % is never used, with a weapon out too; Revitalize goes instead", StaminaKitDespiteMinSuccess);
|
||||
r.Add("vital wand gate: Stamina to Mana never swaps in a fight; out of one with no mana potion it may", ManaInFightNoSwap);
|
||||
r.Add("vital wand gate: in Magic stance with no wand in hand and a kit carried, Heal Self is not gated", MagicNoWandNotGated);
|
||||
r.Add("vital wand gate: a kit its line called used up, or gone from the client's pack, is no kit: Heal Self is handled and the swap is allowed", GoneKitAllowsSwap);
|
||||
r.Add("vital wand gate: a swap already under way finishes when a kit reappears (no abandoned swap, no kit mid-wield)", SwapInFlightFinishes);
|
||||
r.Add("vital wand gate: a kit the server refused 3 times within 10 s is no kit for the gate; a kit landing counts it again", RefusedKitAllowsSwap);
|
||||
r.Add("vital wand gate: the mana step's stamina refill also uses the stamina kit despite Kit Min Success", ManaRefillStaminaLastResort);
|
||||
r.Add("vital wand gate: the mana step's stamina refill respects Stamina Kit Min Success % too", ManaRefillStaminaLastResort);
|
||||
r.Add("vital wand gate: out of a fight Stamina to Mana may swap with a mana potion carried; in a fight it may not", ManaPotionOutOfFightSwaps);
|
||||
r.Add("vital wand gate: a refusal streak ages out: 11 s after the last refusal the kit counts again", RefusedStreakAgesOut);
|
||||
r.Add("vital wand gate: no wand found: Heal Self takes the bare-handed Magic stance, not gated", NoWandNotGated);
|
||||
r.Add("vital wand gate: one line when it starts refusing, one when the swap may go again or nothing asks for 5 s, one for a refused kit", GateLogLines);
|
||||
r.Add("vital wand gate: under Emergency Heal At the kit despite Kit Min Success still goes; the HP failsafe's recall still swaps to the wand", EmergencyFloorKept);
|
||||
r.Add("vital wand gate: the between-fights top-off (no Revitalize) uses a stamina kit under Stamina Kit Min Success as the last resort", TopOffStaminaLastResort);
|
||||
r.Add("vital wand gate: the between-fights top-off (no Revitalize) uses no stamina kit under Stamina Kit Min Success %", TopOffStaminaLastResort);
|
||||
r.Add("vital wand gate: at or under Emergency Heal At a health spell may swap to the wand with a kit carried (the surest heal goes)", EmergencySpellMaySwap);
|
||||
r.Add("emergency heal: under Stamina To Health At but over Emergency Heal At, a melee character casts Stamina to Health, no kit first", StamToHealthLineFirst);
|
||||
r.Add("buffs wait: under Heal At in a fight no buff is cast and the arbiter isn't asked for buffs; over it or out of a fight they go on", BuffsWaitWhileHurt);
|
||||
}
|
||||
|
||||
|
|
@ -65,6 +70,42 @@ internal static class VitalWandGateTests
|
|||
Check.True(Why(a).Contains("no wand swap for a vital spell", StringComparison.Ordinal), "with its reason: " + Why(a));
|
||||
}
|
||||
|
||||
// 2026-11-13: Stamina To Health At over Emergency Heal At = the spell is the emergency heal.
|
||||
private static void StamToHealthLineFirst()
|
||||
{
|
||||
var b = Rig(CombatMode.Melee, new[] { Kit }, kitMinSuccess: 0);
|
||||
S.HealAt = 0; S.TopOffHP = 0; S.EmergencyHealAt = 15; S.StaminaToHealthAt = 40;
|
||||
b.InCombatOverride = () => true;
|
||||
SetVitals(b, 35, 74, 100);
|
||||
Check.True(b.CheckVitals(), "35% under Stamina To Health At 40%: the vitals act: " + Why(b));
|
||||
Check.Eq(FakeHost.UsesOn.Count, 0, "no kit ahead of the spell");
|
||||
Check.True(SwapActive(b), "Stamina to Health's wand swap is under way");
|
||||
|
||||
// Under Emergency Heal At too: the kit-first order is unchanged.
|
||||
var k = Rig(CombatMode.Melee, new[] { Kit }, kitMinSuccess: 0);
|
||||
S.HealAt = 0; S.TopOffHP = 0; S.EmergencyHealAt = 15; S.StaminaToHealthAt = 40;
|
||||
k.InCombatOverride = () => true;
|
||||
SetVitals(k, 10, 74, 100);
|
||||
Check.True(k.CheckVitals(), "10%: the vitals act");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "under Emergency Heal At the kit goes first, as before");
|
||||
|
||||
// Stamina at or under the floor: no spell, the normal chain (the kit) heals.
|
||||
var f = Rig(CombatMode.Melee, new[] { Kit }, kitMinSuccess: 0);
|
||||
S.HealAt = 50; S.TopOffHP = 50; S.EmergencyHealAt = 15; S.StaminaToHealthAt = 40;
|
||||
f.InCombatOverride = () => true;
|
||||
SetVitals(f, 35, 10, 100);
|
||||
Check.True(f.CheckVitals(), "35%, stamina 10%: the vitals act");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "no Stamina to Health under its stamina floor: the kit under Heal At");
|
||||
|
||||
// Defaults (30 / 30): both lines together, kit first as before.
|
||||
var d = Rig(CombatMode.Melee, new[] { Kit }, kitMinSuccess: 0);
|
||||
S.HealAt = 0; S.TopOffHP = 0; S.EmergencyHealAt = 30; S.StaminaToHealthAt = 30;
|
||||
d.InCombatOverride = () => true;
|
||||
SetVitals(d, 25, 74, 100);
|
||||
Check.True(d.CheckVitals(), "25% on the 30 / 30 defaults: the vitals act");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "defaults unchanged: the kit first");
|
||||
}
|
||||
|
||||
// 2026-11-07: four weapon auras in a row with a golem hitting him under Heal At; the emergency heal waited for the last cast.
|
||||
private static void BuffsWaitWhileHurt()
|
||||
{
|
||||
|
|
@ -142,19 +183,25 @@ internal static class VitalWandGateTests
|
|||
Check.True(SwapActivity() > before, "the recall's wand swap starts with a kit and a potion carried");
|
||||
}
|
||||
|
||||
// b2e1ade4: between fights out of Magic no Revitalize is cast for Top Off Stamina; kits still top off,
|
||||
// and with this port a stamina kit under Stamina Kit Min Success % is that last resort.
|
||||
// b2e1ade4: between fights out of Magic no Revitalize is cast for Top Off Stamina; kits still top off.
|
||||
// 2026-11-13: a stamina kit under Stamina Kit Min Success % is not used (no last resort); the wand
|
||||
// comes out for Revitalize instead (Tom), between fights too.
|
||||
private static void TopOffStaminaLastResort()
|
||||
{
|
||||
var b = Rig(CombatMode.Melee, new[] { StamKit }, kitMinSuccess: 95);
|
||||
b.InCombatOverride = () => false;
|
||||
S.TopOffStam = 60; S.RestamAt = 10;
|
||||
SetVitals(b, 100, 40, 100);
|
||||
Check.True(b.CheckVitals(), "stamina 40% under Top Off Stamina 60%, no fight: acts");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "one kit use");
|
||||
Check.Eq(FakeHost.UsesOn[0].Source, StamKit, "the stamina kit");
|
||||
Check.Eq(FakeHost.Casts.Count, 0, "no Revitalize");
|
||||
Check.Eq(FakeHost.CombatModeRequests.Count(m => m == CombatMode.Magic), 0, "no Magic stance");
|
||||
Check.True(b.CheckVitals(), "stamina 40% under Top Off Stamina 60%, no fight, kit under its %: acts: " + Why(b));
|
||||
Check.Eq(FakeHost.UsesOn.Count, 0, "no kit use under Stamina Kit Min Success %");
|
||||
Check.True(SwapActive(b), "the wand swap for Revitalize is under way");
|
||||
|
||||
var ok = Rig(CombatMode.Melee, new[] { StamKit }, kitMinSuccess: 0);
|
||||
ok.InCombatOverride = () => false;
|
||||
S.TopOffStam = 60; S.RestamAt = 10;
|
||||
SetVitals(ok, 100, 40, 100);
|
||||
Check.True(ok.CheckVitals(), "control, min 0: the top-off acts");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "control: the kit tops off");
|
||||
}
|
||||
|
||||
// Out of a fight buffing is about to swap to the wand anyway, so a
|
||||
|
|
@ -183,10 +230,8 @@ internal static class VitalWandGateTests
|
|||
bool acted = (bool)typeof(BuffManager).GetMethod("AttemptManaRefill", Np)!.Invoke(b, args)!;
|
||||
Check.True(acted, "the mana step acts");
|
||||
Check.True((bool)args[1], "by refilling stamina");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "one kit use");
|
||||
Check.Eq(FakeHost.UsesOn[0].Source, StamKit, "the stamina kit Kit Min Success skipped");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("using the stamina kit despite Stamina Kit Min Success", StringComparison.Ordinal)), "logged");
|
||||
Check.Eq(SwapActivity(), 0, "no swap");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 0, "no kit under Stamina Kit Min Success %");
|
||||
Check.True(SwapActive(b), "Revitalize's wand swap goes instead (the kit under its % refuses nothing)");
|
||||
}
|
||||
|
||||
/// <summary>The kit sent and refused by the server (a UseDone with an error code).</summary>
|
||||
|
|
@ -329,6 +374,71 @@ internal static class VitalWandGateTests
|
|||
Check.Eq(FakeHost.Wields.Count, 0, "no wield");
|
||||
}
|
||||
|
||||
// 2026-11-11 16:24: Drakkon (Heal At 1, Emergency Heal At 30, Re-stam To 90) took three stamina kits in a
|
||||
// row while a monster hit him, each started over 30%, and died. 2026-11-17: the heal goes first.
|
||||
private static void HealBeforeStaminaWhenFalling()
|
||||
{
|
||||
var b = Rig(CombatMode.Melee, new[] { Kit, StamKit }, kitMinSuccess: 0);
|
||||
S.HealAt = 1; S.TopOffHP = 95; S.EmergencyHealAt = 30; S.RestamAt = 50; S.RestamTo = 90;
|
||||
DateTime now = new DateTime(2026, 1, 1, 18, 0, 0);
|
||||
b.Clock = () => now;
|
||||
SetVitals(b, 100, 100, 100);
|
||||
b.CheckVitals(); // a reading at full health
|
||||
Check.Eq(FakeHost.UsesOn.Count, 0, "full health, full stamina: nothing used");
|
||||
now = now.AddMilliseconds(1500);
|
||||
SetVitals(b, 70, 30, 100); // 30% lost in 1.5 s: 60% more in a kit's 3 s
|
||||
Check.True(b.CheckVitals(), "70% and falling 20%/s, stamina 30% under Re-stam At: the vitals act: " + Why(b));
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "one use");
|
||||
Check.Eq(FakeHost.UsesOn[0].Source, Kit, "the healing kit, not the stamina kit");
|
||||
Check.True(FakeHost.Logs.Any(l => l.Contains("a heal first, the stamina after it", StringComparison.Ordinal)), "the line says why");
|
||||
}
|
||||
|
||||
private static void StaminaWhenHealthSteady()
|
||||
{
|
||||
// Steady: the same health 1.5 s ago.
|
||||
var b = Rig(CombatMode.Melee, new[] { Kit, StamKit }, kitMinSuccess: 0);
|
||||
S.HealAt = 1; S.TopOffHP = 95; S.EmergencyHealAt = 30; S.RestamAt = 50; S.RestamTo = 90;
|
||||
DateTime now = new DateTime(2026, 1, 1, 18, 0, 0);
|
||||
b.Clock = () => now;
|
||||
SetVitals(b, 70, 100, 100);
|
||||
b.CheckVitals();
|
||||
now = now.AddMilliseconds(1500);
|
||||
SetVitals(b, 70, 30, 100);
|
||||
Check.True(b.CheckVitals(), "70% steady, stamina 30%: the vitals act");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "one use");
|
||||
Check.Eq(FakeHost.UsesOn[0].Source, StamKit, "the stamina kit, as before");
|
||||
|
||||
// Falling slowly: 100% to 90% over 3 s (10% more in a kit's 3 s, well over 30%).
|
||||
var s = Rig(CombatMode.Melee, new[] { Kit, StamKit }, kitMinSuccess: 0);
|
||||
S.HealAt = 1; S.TopOffHP = 95; S.EmergencyHealAt = 30; S.RestamAt = 50; S.RestamTo = 90;
|
||||
DateTime t = new DateTime(2026, 1, 1, 18, 0, 0);
|
||||
s.Clock = () => t;
|
||||
SetVitals(s, 100, 100, 100);
|
||||
s.CheckVitals();
|
||||
t = t.AddSeconds(3);
|
||||
SetVitals(s, 90, 30, 100);
|
||||
Check.True(s.CheckVitals(), "90% falling slowly, stamina 30%: the vitals act");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "one use");
|
||||
Check.Eq(FakeHost.UsesOn[0].Source, StamKit, "slow fall: the stamina kit");
|
||||
}
|
||||
|
||||
private static void HealthProjection()
|
||||
{
|
||||
DateTime t0 = new DateTime(2026, 1, 1, 18, 0, 0);
|
||||
var none = new List<(DateTime, int)>();
|
||||
Check.Eq(BuffManager.ProjectedHealthPct(none, t0, 60, 3000), 60, "no samples: health as it is");
|
||||
var fall = new List<(DateTime, int)> { (t0, 100), (t0.AddMilliseconds(500), 100), (t0.AddMilliseconds(1500), 80) };
|
||||
// Latest high at +0.5 s, 20% lost in 1 s: 60% more over 3 s.
|
||||
Check.Eq(BuffManager.ProjectedHealthPct(fall, t0.AddMilliseconds(1500), 80, 3000), 20, "20%/s from the latest high: 80 -> 20");
|
||||
var hit = new List<(DateTime, int)> { (t0, 100) };
|
||||
// One hit 0.2 s after the reading: the rate is taken over 1 s, not 0.2 s.
|
||||
Check.Eq(BuffManager.ProjectedHealthPct(hit, t0.AddMilliseconds(200), 90, 3000), 60, "one hit: over at least 1 s (10%/s -> 60)");
|
||||
var rising = new List<(DateTime, int)> { (t0, 40), (t0.AddMilliseconds(1000), 70) };
|
||||
Check.Eq(BuffManager.ProjectedHealthPct(rising, t0.AddMilliseconds(1000), 70, 3000), 70, "rising: health as it is");
|
||||
var stale = new List<(DateTime, int)> { (t0, 100) };
|
||||
Check.Eq(BuffManager.ProjectedHealthPct(stale, t0.AddMilliseconds(5000), 50, 3000), 50, "a high older than the 4 s window is no trend");
|
||||
}
|
||||
|
||||
private static void SetVitals(BuffManager b, uint health, uint stamina, uint mana)
|
||||
{
|
||||
var v = (PlayerVitalsCache)typeof(BuffManager).GetField("_vitals", Np)!.GetValue(b)!;
|
||||
|
|
@ -343,13 +453,18 @@ internal static class VitalWandGateTests
|
|||
S.RestamAt = 50;
|
||||
SetVitals(b, 100, 20, 100);
|
||||
Check.True(b.CheckVitals(), $"min {minSuccess}: stamina 20% under Re-stam At 50%: the chain acts");
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, $"min {minSuccess}: one kit use");
|
||||
Check.Eq(FakeHost.UsesOn[0].Source, StamKit, $"min {minSuccess}: the stamina kit");
|
||||
bool lastResort = FakeHost.Logs.Any(l => l.Contains("using the stamina kit despite Stamina Kit Min Success", StringComparison.Ordinal));
|
||||
if (minSuccess == 95) Check.True(lastResort, "under Kit Min Success: used as the last resort, logged");
|
||||
else Check.False(lastResort, "control, chance fine: the normal kit use, no last-resort line");
|
||||
Check.Eq(FakeHost.CombatModeRequests.Count(m => m == CombatMode.Magic), 0, $"min {minSuccess}: no Magic stance");
|
||||
Check.Eq(FakeHost.Casts.Count, 0, $"min {minSuccess}: no Revitalize");
|
||||
if (minSuccess == 95)
|
||||
{
|
||||
Check.Eq(FakeHost.UsesOn.Count, 0, "under Stamina Kit Min Success % (weapon out, no 30% bar): no kit");
|
||||
Check.True(SwapActive(b), "Revitalize's wand swap goes instead");
|
||||
}
|
||||
else
|
||||
{
|
||||
Check.Eq(FakeHost.UsesOn.Count, 1, "control, min 0: one kit use");
|
||||
Check.Eq(FakeHost.UsesOn[0].Source, StamKit, "control: the stamina kit");
|
||||
Check.Eq(FakeHost.CombatModeRequests.Count(m => m == CombatMode.Magic), 0, "control: no Magic stance");
|
||||
Check.Eq(FakeHost.Casts.Count, 0, "control: no Revitalize");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ internal static unsafe class FakeHost
|
|||
|
||||
public static RynthCoreApiNative Build()
|
||||
{
|
||||
var a = new RynthCoreApiNative { Version = 73 };
|
||||
var a = new RynthCoreApiNative { Version = 85 }; // 85: the server prompt answers (AnswerNextPrompt)
|
||||
a.LogFn = (IntPtr)(delegate* unmanaged[Cdecl]<IntPtr, void>)&LogImpl;
|
||||
a.WriteToChatFn = (IntPtr)(delegate* unmanaged[Cdecl]<IntPtr, int, int>)&WriteToChat;
|
||||
a.InvokeChatParserFn = (IntPtr)(delegate* unmanaged[Cdecl]<IntPtr, int>)&InvokeChatParser;
|
||||
|
|
@ -109,6 +109,8 @@ internal static unsafe class FakeHost
|
|||
a.TradeDeclineFn = (IntPtr)(delegate* unmanaged[Cdecl]<int>)&TradeDecline;
|
||||
a.TradeResetFn = (IntPtr)(delegate* unmanaged[Cdecl]<int>)&TradeReset;
|
||||
a.TradeCloseFn = (IntPtr)(delegate* unmanaged[Cdecl]<int>)&TradeClose;
|
||||
a.ArmConfirmationFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint, int, int, int>)&ArmConfirmation;
|
||||
a.GetLastConfirmationFn = (IntPtr)(delegate* unmanaged[Cdecl]<uint*, uint*, int*, int*, int*, int>)&GetLastConfirmation;
|
||||
return a;
|
||||
}
|
||||
|
||||
|
|
@ -127,6 +129,27 @@ internal static unsafe class FakeHost
|
|||
|
||||
// ── Identity ────────────────────────────────────────────────────────────
|
||||
|
||||
// ── The server's yes/no prompts (API v85) ──
|
||||
// The last arm a script made, and the last prompt the "server" sent (the harness sets it).
|
||||
public static uint ArmType;
|
||||
public static int ArmMinPercent, ArmTimeoutMs, ArmCalls;
|
||||
public static int PromptSeq, PromptPercent = -1, PromptOutcome, PromptAgeMs;
|
||||
public static uint PromptType, PromptContext;
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int ArmConfirmation(uint type, int minPercent, int timeoutMs)
|
||||
{
|
||||
ArmType = type; ArmMinPercent = minPercent; ArmTimeoutMs = timeoutMs; ArmCalls++;
|
||||
return 1;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static int GetLastConfirmation(uint* type, uint* context, int* percent, int* outcome, int* ageMs)
|
||||
{
|
||||
*type = PromptType; *context = PromptContext; *percent = PromptPercent; *outcome = PromptOutcome; *ageMs = PromptAgeMs;
|
||||
return PromptSeq;
|
||||
}
|
||||
|
||||
[UnmanagedCallersOnly(CallConvs = new[] { typeof(CallConvCdecl) })]
|
||||
private static uint GetPlayerId() => FakeWorld.Player;
|
||||
|
||||
|
|
|
|||
|
|
@ -84,6 +84,20 @@ internal static class Harness
|
|||
}
|
||||
|
||||
Fn("chat", a => { W.IncomingChat(Str(a, 0), (int)Num(a, 1, 0)); return DynValue.Nil; });
|
||||
// The server prompt answers: what the script armed, and the last prompt the "server" sent.
|
||||
Fn("promptArm", a =>
|
||||
{
|
||||
var t = new Table(s);
|
||||
t["Type"] = (double)FakeHost.ArmType; t["MinPercent"] = (double)FakeHost.ArmMinPercent;
|
||||
t["TimeoutMs"] = (double)FakeHost.ArmTimeoutMs; t["Calls"] = (double)FakeHost.ArmCalls;
|
||||
return DynValue.NewTable(t);
|
||||
});
|
||||
Fn("setLastPrompt", a =>
|
||||
{
|
||||
FakeHost.PromptSeq = (int)Num(a, 0); FakeHost.PromptType = (uint)Num(a, 1); FakeHost.PromptContext = (uint)Num(a, 2);
|
||||
FakeHost.PromptPercent = (int)Num(a, 3, -1); FakeHost.PromptOutcome = (int)Num(a, 4); FakeHost.PromptAgeMs = (int)Num(a, 5);
|
||||
return DynValue.Nil;
|
||||
});
|
||||
Fn("chatInput", a =>
|
||||
{
|
||||
int eat = 0;
|
||||
|
|
|
|||
|
|
@ -23,6 +23,34 @@ eq(Character.BurdenUnits, 1500, "BurdenUnits")
|
|||
eq(Character.MaxBurdenUnits, 200 * 150, "MaxBurdenUnits")
|
||||
eq(Character.IsBusy(), false, "IsBusy()")
|
||||
|
||||
-- the server's yes/no prompts (AnswerNextPrompt / LastPrompt)
|
||||
eq(Character.LastPrompt, nil, "LastPrompt: none this session")
|
||||
eq(Character.AnswerNextPrompt(), true, "AnswerNextPrompt() arms")
|
||||
local arm = harness.promptArm()
|
||||
eq(arm.Type, 7, "default type YESNO")
|
||||
eq(arm.TimeoutMs, 5000, "default 5 s")
|
||||
eq(arm.MinPercent, 0, "default: Yes whatever the percent")
|
||||
eq(Character.AnswerNextPrompt(ClientConfirmationType.CRAFT_INTERACTION, 90000, 70), true, "a craft prompt")
|
||||
arm = harness.promptArm()
|
||||
eq(arm.Type, 5, "CRAFT_INTERACTION")
|
||||
eq(arm.TimeoutMs, 30000, "the timeout is capped at 30 s")
|
||||
eq(arm.MinPercent, 70, "Yes from 70%")
|
||||
eq(Character.AnswerNextPrompt(9), false, "an unknown type is refused")
|
||||
eq(harness.promptArm().Calls, 2, "and not armed")
|
||||
eq(Character.AnswerNextPrompt(7, 0), true, "0 ms disarms")
|
||||
eq(harness.promptArm().TimeoutMs, 0, "disarm sent")
|
||||
harness.setLastPrompt(4, 7, 0x1234, -1, 2, 150)
|
||||
local lp = Character.LastPrompt
|
||||
check(lp ~= nil, "LastPrompt after one")
|
||||
eq(lp.Seq, 4, "LastPrompt.Seq")
|
||||
eq(lp.Type, 7, "LastPrompt.Type")
|
||||
eq(lp.ContextId, 0x1234, "LastPrompt.ContextId")
|
||||
eq(lp.Percent, -1, "LastPrompt.Percent: none in its text")
|
||||
eq(lp.Outcome, "Accepted", "LastPrompt.Outcome")
|
||||
eq(lp.AgeMs, 150, "LastPrompt.AgeMs")
|
||||
harness.setLastPrompt(5, 7, 0, -1, 1, 10)
|
||||
eq(Character.LastPrompt.Outcome, "Shown", "not armed: the client's dialog")
|
||||
|
||||
-- stats the UB way (on the weenie) and with the vital numbering UB uses
|
||||
local vitals = Character.Weenie.Vitals
|
||||
eq(vitals[VitalId.Health].Current, 300, "Health.Current")
|
||||
|
|
|
|||
15
Tools/RynthLua.CompatTests/Scripts/deathline.lua
Normal file
15
Tools/RynthLua.CompatTests/Scripts/deathline.lua
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
-- DreamWeave's death line ("... (Killing blow: N damage. You had H/M health.)") fires OnDeath
|
||||
-- (2026-11-15: a script missed one, the health read having skipped the 0 too).
|
||||
local death
|
||||
game.Character.OnDeath.Add(function(e) death = e end)
|
||||
sleep(700)
|
||||
|
||||
harness.chat("You are fatally punctured by Zefir Knotbinder! (Killing blow: 130 damage. You had 21/346 health.)", ChatMessageType.System)
|
||||
local t = 0
|
||||
while not death and t < 3000 do sleep(20); t = t + 20 end
|
||||
check(death ~= nil, "OnDeath on DreamWeave's killing-blow line")
|
||||
if death then
|
||||
check(death.Text:find("Killing blow", 1, true) ~= nil, "OnDeath.Text is the line")
|
||||
end
|
||||
|
||||
done()
|
||||
|
|
@ -66,6 +66,7 @@ namespace RynthOracle.Tests
|
|||
SkillsTabs();
|
||||
ServerMove();
|
||||
Replies();
|
||||
ReadyEarly();
|
||||
Console.WriteLine($"{_pass} passed, {_fail} failed");
|
||||
return _fail == 0 ? 0 : 1;
|
||||
}
|
||||
|
|
|
|||
77
Tools/RynthOracle.Tests/ReadyEarlyTests.cs
Normal file
77
Tools/RynthOracle.Tests/ReadyEarlyTests.cs
Normal file
|
|
@ -0,0 +1,77 @@
|
|||
using System;
|
||||
using RynthCore.Plugin.RynthOracle.Data;
|
||||
|
||||
namespace RynthOracle.Tests
|
||||
{
|
||||
// R-20261110-155059-e947 (2026-11-13): every daily quest showed "ready" hours early; the server
|
||||
// turned one down with "You may complete this quest again in 2h 50m 42s." /myquests had been read
|
||||
// once, at a login 34 hours before, so a quest done since kept its older stamp. The store now asks
|
||||
// for a fresh read when the server turns a quest down or the flags on screen are old.
|
||||
internal static partial class Program
|
||||
{
|
||||
private static void ReadyEarly()
|
||||
{
|
||||
DateTime now = DateTime.UtcNow; // the store stamps its reads with the real clock
|
||||
long ms = 1_000_000;
|
||||
long Unix(DateTime t) => new DateTimeOffset(t).ToUnixTimeSeconds();
|
||||
|
||||
// The login read: the daily (20 h timer) was last done 30 h before. Ready, rightly, then.
|
||||
var store = new QuestFlagStore();
|
||||
Check(!store.NeedsReread(now, timersInUse: true), "ready-early: no re-read before the first read (the login read does that)");
|
||||
store.OnChatLine($"dailyquesttimer - 5 solves ({Unix(now.AddHours(-30))})\"Daily\" -1 72000", ms);
|
||||
store.Tick(ms + 2_000);
|
||||
Check(store.TryGet("dailyquesttimer", out QuestFlag before) && before.Ready(now), "ready-early: the login read has the daily ready");
|
||||
Check(!store.NeedsReread(now.AddMinutes(5), timersInUse: true), "ready-early: fresh flags on screen aren't re-read");
|
||||
Check(!store.NeedsReread(now.AddHours(5), timersInUse: false), "ready-early: old flags nobody looks at aren't re-read");
|
||||
Check(store.NeedsReread(now.AddMinutes(11), timersInUse: true), "ready-early: flags over 10 min old on screen are re-read");
|
||||
|
||||
// Hours later the player turns it in and the server says no (they did it again after the
|
||||
// login read). The pasted lines, with the chat timestamp.
|
||||
DateTime said = now.AddMinutes(5);
|
||||
ms += 300_000;
|
||||
Check(store.OnChatLine("9:45:47 You have solved this quest too recently!", ms, said) == MyQuestsLine.TooRecent,
|
||||
"ready-early: 'solved this quest too recently' is recognised");
|
||||
Check(store.OnChatLine("9:45:47 You may complete this quest again in 2h 50m 42s.", ms + 1, said) == MyQuestsLine.TooRecent,
|
||||
"ready-early: 'again in' is recognised");
|
||||
TimeSpan wait = new(2, 50, 42);
|
||||
Check(store.LastServerWait is { } w && w.Left == wait && w.AtUtc == said, "ready-early: the server's wait is kept: " + store.LastServerWait);
|
||||
Check(store.RereadWanted && store.NeedsReread(said, timersInUse: false), "ready-early: the turn-down asks for a fresh read, on screen or not");
|
||||
Check(store.WaitingAbout(wait, said, TimeSpan.FromMinutes(2)).Count == 0, "ready-early: the stale flags have no quest that long from ready");
|
||||
|
||||
// The fresh read: completed 20 h - 2:50:42 before the server's line.
|
||||
int sent = 0;
|
||||
Check(store.Request(_ => { sent++; return true; }, ms + 10_000) && sent == 1, "ready-early: the re-read sends /myquests");
|
||||
DateTime redone = said - (TimeSpan.FromSeconds(72000) - wait);
|
||||
store.OnChatLine($"dailyquesttimer - 6 solves ({Unix(redone)})\"Daily\" -1 72000", ms + 10_200);
|
||||
store.Tick(ms + 12_000);
|
||||
Check(!store.RereadWanted && !store.NeedsReread(said, timersInUse: true), "ready-early: the reply ends the re-read");
|
||||
Check(store.TryGet("dailyquesttimer", out QuestFlag after) && !after.Ready(said)
|
||||
&& QuestTimer.State(after, true, said, out string text) == QuestTimerState.Waiting && text == "2h 50m",
|
||||
"ready-early: after the re-read the daily waits 2h 50m, as the server said");
|
||||
var near = store.WaitingAbout(wait, said, TimeSpan.FromMinutes(2));
|
||||
Check(near.Count == 1 && near[0].Flag.Key == "dailyquesttimer" && near[0].Off.Duration() < TimeSpan.FromSeconds(2),
|
||||
"ready-early: the server's wait points at the daily in the fresh read");
|
||||
|
||||
// The lines only count whole: quoted in a tell, they're chat.
|
||||
var s2 = new QuestFlagStore();
|
||||
Check(s2.OnChatLine("Someone tells you, \"You may complete this quest again in 1h 0m 0s.\"", 1) == MyQuestsLine.None
|
||||
&& s2.OnChatLine("Someone tells you, \"You have solved this quest too recently!\"", 2) == MyQuestsLine.None
|
||||
&& !s2.RereadWanted, "ready-early: a quoted turn-down is ordinary chat");
|
||||
Check(QuestFlagStore.TryParseAgainIn("You may complete this quest again in 1d 3h 0m 5s.", out TimeSpan d)
|
||||
&& d == new TimeSpan(1, 3, 0, 5), "ready-early: days in the wait");
|
||||
Check(QuestFlagStore.TryParseAgainIn("You may complete this quest again in 12m 4s.", out TimeSpan m) && m == new TimeSpan(0, 12, 4),
|
||||
"ready-early: a short wait");
|
||||
Check(!QuestFlagStore.TryParseAgainIn("You may complete this quest again in a while.", out _), "ready-early: no number, no wait");
|
||||
|
||||
// A server without /myquests is never re-read; a logout forgets the wish.
|
||||
var s3 = new QuestFlagStore();
|
||||
s3.OnChatLine("alpha - 1 solves (1719432000)\"A\" -1 72000", 10);
|
||||
s3.Tick(5_000);
|
||||
s3.OnChatLine(QuestFlagStore.DisabledText, 6_000);
|
||||
s3.WantReread();
|
||||
Check(!s3.NeedsReread(DateTime.UtcNow.AddHours(1), timersInUse: true), "ready-early: no re-read where /myquests is off");
|
||||
s3.Clear();
|
||||
Check(!s3.RereadWanted && s3.LastServerWait == null, "ready-early: Clear forgets the re-read");
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue