RynthSuite as of 2026-10-04 (internal c94715f): RynthOracle (based on Oracle of Dereth by Advis Eveldan) and RynthInventory, RynthAi patrol doorways and rooms, healing priority, strict monster priority, finish the wounded target, slayer weapons, arcs when clear, blasts like rings, learn unknown spells, looting fixes, release 2026.10.4.6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
c33e24a610
commit
12ca25f911
426 changed files with 108239 additions and 7521 deletions
14
Tools/RynthCore.RynthAiTests/Fakes/CreatureProfileStore.cs
Normal file
14
Tools/RynthCore.RynthAiTests/Fakes/CreatureProfileStore.cs
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace RynthCore.Plugin.RynthAi.CreatureData;
|
||||
|
||||
// Stand-in for the plugin's CreatureProfileStore, which is not linked (it is a disk-backed
|
||||
// JSON store). CreatureWeakness only reads CreatureProfileStore.Folder, to look for the
|
||||
// user's creature_types.txt override in C:\Games\RynthSuite\RynthAi\CreatureData. Pointing
|
||||
// it at a folder that never exists keeps the tests on the shipped data only, so results do
|
||||
// not depend on what is installed on the machine running them.
|
||||
internal sealed class CreatureProfileStore
|
||||
{
|
||||
internal static readonly string Folder = Path.Combine(AppContext.BaseDirectory, "no-user-creature-data");
|
||||
}
|
||||
43
Tools/RynthCore.RynthAiTests/Fixtures/nav/circular-hunt.nav
Normal file
43
Tools/RynthCore.RynthAiTests/Fixtures/nav/circular-hunt.nav
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
uTank2 NAV 1.2
|
||||
1
|
||||
7
|
||||
0
|
||||
33.6012
|
||||
42.4987
|
||||
0.05
|
||||
0
|
||||
0
|
||||
33.6158
|
||||
42.5143
|
||||
0.0512
|
||||
0
|
||||
8
|
||||
33.6304
|
||||
42.5049
|
||||
0.0525
|
||||
0
|
||||
3
|
||||
33.6304
|
||||
42.5049
|
||||
0.0525
|
||||
0
|
||||
3000
|
||||
4
|
||||
33.6304
|
||||
42.5049
|
||||
0.0525
|
||||
0
|
||||
/vt opt set EnableLooting true
|
||||
9
|
||||
33.6221
|
||||
42.4913
|
||||
0.06
|
||||
0
|
||||
135.5
|
||||
False
|
||||
420
|
||||
0
|
||||
33.6087
|
||||
42.4901
|
||||
0.055
|
||||
0
|
||||
0
Tools/RynthCore.RynthAiTests/Fixtures/nav/empty.nav
Normal file
0
Tools/RynthCore.RynthAiTests/Fixtures/nav/empty.nav
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
uTank2 NAV 1.2
|
||||
3
|
||||
Vessa Thornwood
|
||||
1342177301
|
||||
18
Tools/RynthCore.RynthAiTests/Fixtures/nav/linear-patrol.nav
Normal file
18
Tools/RynthCore.RynthAiTests/Fixtures/nav/linear-patrol.nav
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
uTank2 NAV 1.2
|
||||
2
|
||||
3
|
||||
0
|
||||
-12.25
|
||||
8.75
|
||||
0.2
|
||||
0
|
||||
0
|
||||
-12.3
|
||||
8.8
|
||||
0.21
|
||||
0
|
||||
0
|
||||
-12.35
|
||||
8.85
|
||||
0.215
|
||||
0
|
||||
49
Tools/RynthCore.RynthAiTests/Fixtures/nav/once-town-run.nav
Normal file
49
Tools/RynthCore.RynthAiTests/Fixtures/nav/once-town-run.nav
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
uTank2 NAV 1.2
|
||||
4
|
||||
6
|
||||
2
|
||||
33.6
|
||||
42.5
|
||||
0
|
||||
0
|
||||
1635
|
||||
0
|
||||
33.62
|
||||
42.53
|
||||
0.05
|
||||
0
|
||||
5
|
||||
33.625
|
||||
42.535
|
||||
0.05
|
||||
0
|
||||
2147484001
|
||||
Tinker Aldo
|
||||
6
|
||||
33.63
|
||||
42.54
|
||||
0.05
|
||||
0
|
||||
Town Network Portal
|
||||
14
|
||||
1
|
||||
33.631
|
||||
42.541
|
||||
0.052
|
||||
7
|
||||
-45.5
|
||||
90.2
|
||||
0.1
|
||||
0
|
||||
Guard Captain Ilsa
|
||||
37
|
||||
False
|
||||
-45.502
|
||||
90.203
|
||||
0.101
|
||||
2
|
||||
-45.5
|
||||
90.2
|
||||
0.1
|
||||
0
|
||||
48
|
||||
10
Tools/RynthCore.RynthAiTests/Fixtures/nav/truncated.nav
Normal file
10
Tools/RynthCore.RynthAiTests/Fixtures/nav/truncated.nav
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
uTank2 NAV 1.2
|
||||
1
|
||||
3
|
||||
0
|
||||
10.5
|
||||
-20.25
|
||||
0
|
||||
0
|
||||
2
|
||||
10.6
|
||||
68
Tools/RynthCore.RynthAiTests/Harness/Check.cs
Normal file
68
Tools/RynthCore.RynthAiTests/Harness/Check.cs
Normal file
|
|
@ -0,0 +1,68 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RynthCore.RynthAiTests.Harness;
|
||||
|
||||
// Tiny assertion helper, in the style of the other RynthSuite test tools: a failed check is
|
||||
// recorded against the running test and the test carries on, so one run prints every broken
|
||||
// expectation instead of stopping at the first. The runner reads Failures after each test.
|
||||
internal static class Check
|
||||
{
|
||||
[ThreadStatic] private static List<string>? _failures;
|
||||
[ThreadStatic] private static int _count;
|
||||
|
||||
/// <summary>Checks recorded by the current test so far.</summary>
|
||||
public static int Count => _count;
|
||||
public static IReadOnlyList<string> Failures => _failures ??= new List<string>();
|
||||
|
||||
internal static void Reset()
|
||||
{
|
||||
_failures = new List<string>();
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
private static void Fail(string msg) => (_failures ??= new List<string>()).Add(msg);
|
||||
|
||||
public static void True(bool cond, string msg)
|
||||
{
|
||||
_count++;
|
||||
if (!cond) Fail(msg);
|
||||
}
|
||||
|
||||
public static void False(bool cond, string msg) => True(!cond, msg);
|
||||
|
||||
public static void Eq<T>(T actual, T expected, string msg)
|
||||
{
|
||||
_count++;
|
||||
if (!EqualityComparer<T>.Default.Equals(actual, expected))
|
||||
Fail($"{msg}: expected <{expected}>, got <{actual}>");
|
||||
}
|
||||
|
||||
public static void Near(double actual, double expected, double tol, string msg)
|
||||
{
|
||||
_count++;
|
||||
if (double.IsNaN(actual) || Math.Abs(actual - expected) > tol)
|
||||
Fail($"{msg}: expected {expected:0.####} ±{tol}, got {actual:0.####}");
|
||||
}
|
||||
|
||||
public static void NotNull(object? value, string msg)
|
||||
{
|
||||
_count++;
|
||||
if (value is null) Fail($"{msg}: was null");
|
||||
}
|
||||
|
||||
public static void Null(object? value, string msg)
|
||||
{
|
||||
_count++;
|
||||
if (value is not null) Fail($"{msg}: expected null, got <{value}>");
|
||||
}
|
||||
|
||||
public static void Throws<TEx>(Action body, string msg) where TEx : Exception
|
||||
{
|
||||
_count++;
|
||||
try { body(); }
|
||||
catch (TEx) { return; }
|
||||
catch (Exception ex) { Fail($"{msg}: expected {typeof(TEx).Name}, got {ex.GetType().Name}: {ex.Message}"); return; }
|
||||
Fail($"{msg}: expected {typeof(TEx).Name}, nothing was thrown");
|
||||
}
|
||||
}
|
||||
76
Tools/RynthCore.RynthAiTests/Harness/Runner.cs
Normal file
76
Tools/RynthCore.RynthAiTests/Harness/Runner.cs
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RynthCore.RynthAiTests.Harness;
|
||||
|
||||
// Runs registered tests one by one and prints a PASS / FAIL line per test (with the failed
|
||||
// checks under it). A test fails when any Check fails, when it throws, or when it made no
|
||||
// checks at all (a test that asserts nothing proves nothing).
|
||||
//
|
||||
// Known failures: a test that exposes a real, unfixed bug is registered with KnownFailure and
|
||||
// a reason. It still runs; while it fails it prints KNOWN and does not fail the run. If it
|
||||
// starts passing it prints XPASS and DOES fail the run, so the marker gets removed with the fix.
|
||||
internal sealed class Runner
|
||||
{
|
||||
private readonly List<(string Name, Action Body, string? KnownReason)> _tests = new();
|
||||
|
||||
public void Add(string name, Action body) => _tests.Add((name, body, null));
|
||||
|
||||
public void KnownFailure(string name, string reason, Action body) => _tests.Add((name, body, reason));
|
||||
|
||||
/// <summary>Runs every test whose name contains <paramref name="filter"/> (all when empty). Returns the exit code.</summary>
|
||||
public int Run(string title, string? filter)
|
||||
{
|
||||
Console.WriteLine($"=== {title} ===");
|
||||
int ran = 0, passed = 0, failed = 0, known = 0, checks = 0;
|
||||
|
||||
foreach (var (name, body, knownReason) in _tests)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(filter) && name.IndexOf(filter, StringComparison.OrdinalIgnoreCase) < 0)
|
||||
continue;
|
||||
ran++;
|
||||
Check.Reset();
|
||||
string? crash = null;
|
||||
try { body(); }
|
||||
catch (Exception ex) { crash = $"threw {ex.GetType().Name}: {ex.Message}"; }
|
||||
|
||||
var fails = new List<string>(Check.Failures);
|
||||
if (crash != null) fails.Add(crash);
|
||||
if (crash == null && Check.Count == 0) fails.Add("made no checks");
|
||||
checks += Check.Count;
|
||||
bool ok = fails.Count == 0;
|
||||
|
||||
if (knownReason == null)
|
||||
{
|
||||
if (ok) { passed++; Console.WriteLine($"[PASS] {name}"); }
|
||||
else { failed++; Console.WriteLine($"[FAIL] {name}"); Print(fails); }
|
||||
}
|
||||
else if (!ok)
|
||||
{
|
||||
known++;
|
||||
Console.WriteLine($"[KNOWN] {name} - known failure: {knownReason}");
|
||||
Print(fails);
|
||||
}
|
||||
else
|
||||
{
|
||||
failed++;
|
||||
Console.WriteLine($"[XPASS] {name} - marked as a known failure but passed; remove the KnownFailure marker ({knownReason})");
|
||||
}
|
||||
}
|
||||
|
||||
Console.WriteLine();
|
||||
Console.WriteLine($"{ran} test(s), {checks} check(s): {passed} passed, {failed} failed, {known} known failure(s).");
|
||||
if (ran == 0)
|
||||
{
|
||||
Console.WriteLine(string.IsNullOrEmpty(filter) ? "ABORT: no tests registered." : $"ABORT: no test matches '{filter}'.");
|
||||
return 1;
|
||||
}
|
||||
Console.WriteLine(failed == 0 ? "ALL RYNTHAI TESTS PASSED." : $"{failed} FAILURE(S).");
|
||||
return failed == 0 ? 0 : 1;
|
||||
}
|
||||
|
||||
private static void Print(List<string> fails)
|
||||
{
|
||||
foreach (string f in fails) Console.WriteLine($" - {f}");
|
||||
}
|
||||
}
|
||||
24
Tools/RynthCore.RynthAiTests/Program.cs
Normal file
24
Tools/RynthCore.RynthAiTests/Program.cs
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
using RynthCore.RynthAiTests.Harness;
|
||||
using RynthCore.RynthAiTests.Tests;
|
||||
|
||||
namespace RynthCore.RynthAiTests;
|
||||
|
||||
// Test runner for RynthAi's pure logic: no game, no engine, no host. Each test prints
|
||||
// PASS / FAIL (or KNOWN for a registered known bug); the exit code is 1 on any failure.
|
||||
// README.md lists the seams for the areas that aren't reachable yet.
|
||||
//
|
||||
// Run: dotnet run -c Release (all tests)
|
||||
// dotnet run -c Release -- weakness (tests whose name contains "weakness")
|
||||
internal static class Program
|
||||
{
|
||||
private static int Main(string[] args)
|
||||
{
|
||||
var runner = new Runner();
|
||||
NavRouteParserTests.Register(runner);
|
||||
NavFormatTests.Register(runner);
|
||||
CombatStallWatchdogTests.Register(runner);
|
||||
CreatureWeaknessTests.Register(runner);
|
||||
MonsterDamageTierTests.Register(runner);
|
||||
return runner.Run("RynthAi tests", args.Length > 0 ? args[0] : null);
|
||||
}
|
||||
}
|
||||
171
Tools/RynthCore.RynthAiTests/README.md
Normal file
171
Tools/RynthCore.RynthAiTests/README.md
Normal file
|
|
@ -0,0 +1,171 @@
|
|||
# RynthCore.RynthAiTests
|
||||
|
||||
A console test runner for RynthAi's pure logic. It needs no game, no engine and no host.
|
||||
It follows the house style of the other test tools here (`RynthCore.LootSdkTests`,
|
||||
`RynthCore.AutoVendorTests`, `RynthCore.MissileArcTests`): a plain net10.0 exe, no test
|
||||
framework, and exit code 0 when everything passes.
|
||||
|
||||
```
|
||||
dotnet run -c Release # all tests
|
||||
dotnet run -c Release -- weakness # only tests whose name contains "weakness"
|
||||
```
|
||||
|
||||
Each test prints one line:
|
||||
|
||||
| Line | Meaning |
|
||||
|-----------|---------|
|
||||
| `[PASS]` | Every check passed. |
|
||||
| `[FAIL]` | At least one check failed, the test threw, or it made no checks. Each failed check is listed under the line. The run exits with code 1. |
|
||||
| `[KNOWN]` | The test was registered with `Runner.KnownFailure(name, reason, body)` because it exposes a real bug that is not fixed yet. It still fails, but the run does not. |
|
||||
| `[XPASS]` | A known-failure test now passes. The run fails so that the marker gets removed along with the fix. |
|
||||
|
||||
The run also exits with code 1 when no test runs (an empty registry or a filter that matches nothing).
|
||||
|
||||
Layout:
|
||||
|
||||
- `Harness/Check.cs`: the assertion helper (`True`, `False`, `Eq`, `Near`, `Null`, `NotNull`, `Throws`). A failed check is recorded and the test keeps going, so one run shows every broken expectation.
|
||||
- `Harness/Runner.cs`: registers tests, prints PASS/FAIL, handles known failures, sets the exit code.
|
||||
- `Tests/*.cs`: one static class per area. Each has a `Register(Runner)` method, which `Program.cs` calls.
|
||||
- `Fakes/`: stand-ins for plugin classes that a linked file mentions but that are not linked.
|
||||
|
||||
To add a test: write a `static void` method that calls `Check.*`, then register it in that
|
||||
area's `Register` method. For a new area, add a class and call its `Register` from
|
||||
`Program.cs`. When the code under test lives in a new source file, add a `<Compile Include
|
||||
... Link=...>` for it to the csproj.
|
||||
|
||||
Current smoke tests (13 tests, 142 checks, all passing on 2026-09-29):
|
||||
|
||||
- **nav** (`LegacyUi/NavRouteParser.cs`): the trailer of every waypoint type, the EW-before-NS order, a write/read round trip, the fix that converts a Z stored in metres, Follow routes, and stopping with a warning at an unknown type instead of desyncing.
|
||||
- **stall** (`Combat/CombatStallWatchdog.cs`): the whole 4-step ladder with its 6 s / 3 s / 30 s timings, recovery, the tick-gap reset, and the ineligible case.
|
||||
- **weakness** (`CreatureData/CreatureWeakness.cs`): element aliases, server-table ranking (with a check that the wcid and the name agree), creature-type keywords (whole words only), and a learned element going first. Assertions that depend on the data are computed from the embedded tables, so regenerating `creature_resists.tsv` / `creature_types.txt` does not break them.
|
||||
|
||||
**Second runner: `Tools/RynthCore.RynthAiHostTests`** (added 2026-09-30). Loot rule matching
|
||||
and metas are host-bound, so they are tested there, through the project-reference route
|
||||
described below (net10.0-windows, win-x86, InternalsVisibleTo). It links this runner's
|
||||
`Harness/` files, so both print the same PASS / FAIL / KNOWN / XPASS lines. Its
|
||||
`Fakes/FakeHost.cs` fills a `RynthCoreApiNative` with `[UnmanagedCallersOnly]` fakes, so a
|
||||
test can set skills, level, item spells, vitals, position, enchantments and so on. Its
|
||||
`Program.cs` points the pvar/gvar/ItemGiver paths at a scratch folder before any test runs
|
||||
(the seam is `ExpressionEngine.PvarsDir` / `GvarsPath` / `ItemGiverDir`); `MetaManager.Clock`
|
||||
and `ExpressionEngine.TickMs` make the timers testable without sleeping.
|
||||
|
||||
**Both runners in one go: `Tools\Run-RynthAiTests.ps1`** (added 2026-09-30, `-Filter text`
|
||||
optional). It builds and runs both and exits 1 only on FAIL or XPASS (or a build error).
|
||||
|
||||
Added 2026-09-30 (nav, buffs, combat numbers):
|
||||
|
||||
- here: `Tests/NavFormatTests.cs` reads the hand-written `.nav` files in `Fixtures/nav` (every route type and waypoint kind, malformed files).
|
||||
- host runner: `NavEngineTests` (route walking on a fake clock: advancing, pause/chat/jump/recall points, the closest-point start, the 160 yd off-track rule, the rejoin choice, the different-area hold and its decision), `BuffTests` (tier by buffed skill, the spell every buff resolves to at every tier checked against `SpellData.txt`, timer lengths, rebuff timing), `CombatMathTests` (damage text, element words, weapon choice by weakness, the target scan's range ring). Seams: `NavigationEngine.Clock`, `INavRecoveryPlanner`, `NavRecoveryPlanner.ClassifyArea`, and a few private helpers in `BuffManager` / `CombatManager` made internal.
|
||||
|
||||
## How the runner reaches RynthAi's code
|
||||
|
||||
**Decision: link individual source files (`<Compile Include ... Link=...>`), the same way
|
||||
the existing test tools do.** The alternative was checked and works, but only with
|
||||
conditions attached.
|
||||
|
||||
- **Project reference from a plain net10.0 exe: not possible.** The plugin targets `net10.0-windows`, so restore fails with `NU1201: Project RynthCore.Plugin.RynthAi is not compatible with net10.0`. RynthCore.PluginSdk and PluginCore are also `net10.0-windows`.
|
||||
- **Project reference from a `net10.0-windows` exe with `PlatformTarget=x86` and `RuntimeIdentifier=win-x86`: works.** This was tried in a scratch project on 2026-09-29. NativeAOT does not get in the way: `PublishAot` and `NativeLib` only apply when publishing, a normal build produces an ordinary IL dll, and the `[UnmanagedCallersOnly]` exports are just static methods nobody calls. The exe has to be x86, because the plugin dll is marked 32-bit and a 64-bit process would throw BadImageFormatException. That requires the x86 .NET runtime, which this PC has (10.0.7 under `C:\Program Files (x86)\dotnet`). The costs: the whole plugin compiles first (about 60 s and 100+ warnings); ImGui.NET comes along; and most classes are `internal`, so tests need `[assembly: InternalsVisibleTo("...")]` in the plugin, which is an allowed seam. `default(RynthCoreHost)` works as a null host: every `Has*` property is false and every call does nothing. With that host, the scratch probe (using reflection instead of InternalsVisibleTo) got these results:
|
||||
- `ExpressionEngine.Evaluate`: `1+2*3` gave 7, `setvar[x,5]` then `$x*2` gave 10, `listcount[listcreate[a,b,c]]` gave 3, and `iif[1>2,yes,no]` gave no.
|
||||
- `LootEvaluator.Classify`: matched a `StringValue(Name)` rule against a `WorldObject` whose `ItemPropertyOverlay` was set and which had no cache.
|
||||
- `MetaManager.Think()`: a `Default` state `Always` -> `SetMetaState Hunt` rule moved `CurrentState` to `Hunt`.
|
||||
|
||||
**Recommendation:** keep this runner link-based and fast. For any area below, first check
|
||||
whether a small seam (a pure helper moved into its own file with no dependencies) lets
|
||||
the code link. If many host-bound classes need testing, add a second runner (for example
|
||||
`RynthCore.RynthAiHostTests`: net10.0-windows, win-x86, a ProjectReference to the plugin,
|
||||
and InternalsVisibleTo) rather than turning this one into it.
|
||||
|
||||
**Safety note for any runner:** some RynthAi paths are hard-coded to the live install.
|
||||
`ExpressionEngine` has `PvarsDir`, `GvarsPath` and `ItemGiverDir` under
|
||||
`C:\Games\RynthSuite\RynthAi`, and `FlushVars` writes pvars and gvars there.
|
||||
`CreatureProfileStore.Folder` and the `MonsterDamageStore` files are also under `C:\Games`.
|
||||
Tests must not call `setpvar`, `setgvar` or `touchpvar`, save stores, or run meta rules that
|
||||
do, until those paths can be redirected. A redirect seam would be one internal settable
|
||||
root, defaulting to the current path. This runner's `Fakes/CreatureProfileStore.cs`
|
||||
points the creature override folder at a folder that does not exist, for exactly this
|
||||
reason.
|
||||
|
||||
## Seams, by area
|
||||
|
||||
"Linkable" means the file compiles into this plain net10.0 project as it is, with at most
|
||||
a LootSdk ProjectReference and `GlobalUsings.cs`. "Host runner" means it is reachable today
|
||||
only through the project-reference route above.
|
||||
|
||||
### 1. Loot rule matching
|
||||
|
||||
- **`Loot/LootEvaluator.cs`**: `Evaluate`, `Matches` and `Classify` are public static and pure. Their only input they don't own is `WorldObject` (`Combat/AcStubs.cs`). `WorldObject` can already be fed without a cache: set its internal `Overlay` to an `ItemPropertyOverlay` with `LiveFallback = false` and fill in `Ints`, `Strings` and `Doubles`.
|
||||
- **What blocks linking:** `AcStubs.cs` also contains `CharacterSkills`, which needs `RynthCoreHost` and therefore PluginSdk, which is net10.0-windows. It also contains `SpellTableStub`, which needs `SpellDatabase`. And `WorldObject.Cache` is typed `WorldObjectCache` (1843 lines, host-bound).
|
||||
- **Seam (moves only, behaviour-neutral):** put `WorldObject`, `ItemPropertyOverlay` and the `LongValueKey` / `StringValueKey` / `DoubleValueKey` enums in their own file. Have `WorldObject` read through a narrow interface that `WorldObjectCache` implements: `GetIntProperty`, `GetStringProperty`, `GetDoubleProperty`, `GetContainerId`, `GetWielderId` and `GetWieldedLocation`. Then `LootEvaluator.cs` and that file link on their own. `CharacterSkills` is only used by `CharacterSkillGECondition`, and `null` skills already mean "pass".
|
||||
- **Worth pinning:**
|
||||
- The first matching rule wins, and a disabled rule never matches.
|
||||
- `Classify` returns `(Sell, null)` when nothing matches, and callers look at the null rule, not the action.
|
||||
- Unknown condition types pass (`_ => true`).
|
||||
- A `StringValue(Name)` condition falls back to `WorldObject.Name` (the 2026-09-28 healing-kit fix).
|
||||
- `MinDamage` is computed as `max - variance * max`.
|
||||
- Total ratings are summed over keys 370-376 and 379.
|
||||
- **`Loot/VTankLootEvaluator.cs`**: `Match(rule, item, ctx: null)` is pure when `ctx` is null, because character and spell checks then pass. The file also contains `VTankLootContext`, which is host-bound. **Seam:** move `VTankLootContext` to its own file, and give the evaluator an interface for the five lookups it uses: skill, level, empty pack slots, spell ids and palettes. It also uses `Meta/RegexCache.cs`, which links.
|
||||
- `Vendor/AutoVendorRules.cs` and `AutoVendorPlanner.cs` are already covered by `RynthCore.AutoVendorTests`.
|
||||
|
||||
### 2. Meta: conditions, expressions, state transitions
|
||||
|
||||
- **.af parsing and writing: linkable now.** `Meta/AfFileParser.cs`, `AfFileWriter.cs`, `MetaSchema.cs`, `LoadedMeta.cs`, `RegexCache.cs`, `LegacyUi/LegacyUiSettings.cs` (which holds `MetaRule` and the condition/action enums), `LegacyUi/NavRouteParser.cs` and `GlobalUsings.cs`, plus a LootSdk reference, compile and run in a plain net10.0 exe. This was verified in a scratch project on 2026-09-29. **Next tests:**
|
||||
- Parse, write and parse again, and compare the results.
|
||||
- Check that every `MetaConditionType` and `MetaActionType` has exactly one keyword in `MetaSchema`, in both directions. This guards against the "SecsOnSpell _LE -> _GE" loss the schema comment mentions.
|
||||
- Check that embedded nav routes use `NavRouteParser.TrailerLineCount`.
|
||||
- `MetFileParser.cs` (.met) looks similar (it depends only on LegacyUi) but was not tried.
|
||||
- **Expression evaluation (`Meta/ExpressionEngine.cs`, about 3900 lines): host runner.** It needs `RynthCoreHost`, `WorldObjectCache`, `FellowshipTracker`, `QuestTracker`, `LegacyUiSettings` and the loot types. It works with a null host (see above), but mind the pvar/gvar paths. `ToBool` is already `internal static` and pure. **Seam for linking (larger):** the nested `Parser` (operator precedence, `||` down to unary), together with the private static list, dict and string helpers (`EvalListAdd`, `EvalListRemove`, `NewList`, `EvalCstrf`, `EvalIif`, `TryParseCoordObject` and the rest), could move into a dependency-free `ExpressionCore.cs` that calls back into the engine for function calls and variables. **Worth pinning:**
|
||||
- Operator precedence, including the single-character disambiguation of `&`, `|`, `<` and `>`.
|
||||
- Numeric versus string coercion per operator.
|
||||
- The recursion caps: `MaxEvalDepth` 64 and `MaxParenDepth` 256, which exist to prevent an uncatchable StackOverflow in acclient.
|
||||
- List handles.
|
||||
- Found by the probe, not investigated: `getregexmatch[abc123,[0-9]+]` returned an empty string. It may be argument splitting on the brackets, and deserves a test.
|
||||
- **State transitions (`Meta/MetaManager.cs`): host runner.** It can be built from `new LegacyUiSettings()`, `default(RynthCoreHost)` and `new PlayerVitalsCache()`, and `Think()` runs. **Seam:** it reads `DateTime.Now` directly (seconds in state, the watchdog, the 1 s chat window), so injecting a `Func<DateTime>` clock (internal, defaulting to `DateTime.Now`) would make timing rules testable without sleeping. `EvaluateCondition` is private. It becomes testable through `Think()` once the class can be constructed, or directly with InternalsVisibleTo if made internal. **Worth pinning:**
|
||||
- `HasFired` latches until `ForceStateReset`.
|
||||
- A state change stops the rest of that tick's rules.
|
||||
- The `CallMetaState` / `ReturnFromCall` stack.
|
||||
- Disabled rules are never indexed.
|
||||
- Composite conditions with no children: `All` gives true, `Any` gives **true**, `Not` gives false. The `Any` case is surprising and should be compared with VTank before anyone relies on it.
|
||||
- Vital conditions read the public `PlayerVitalsCache`.
|
||||
|
||||
### 3. Nav: route parsing, rejoin, closest point, 159 yd, different area
|
||||
|
||||
- **Parsing:** `LegacyUi/NavRouteParser.cs` is linked, and the tests above cover it.
|
||||
- **Rejoin, closest point, off track and area** all live inside `NavigationEngine` (about 2500 lines, instance state, `_host`, `_settings`, `_linearDir`). None of it links today. The pure parts are:
|
||||
- `PickRejoinIndex(route, idx, ns, ew, out skipped)`: the nearest of the target and up to 8 waypoints after it (`RejoinLookaheadPts`), never more than 20 yd of route ahead (`RejoinLookaheadYards`), stopping at any point that is not walkable, with 0.5 yd of hysteresis.
|
||||
- `DistanceToSegmentYd`, `PrevIndex` and `NextInOrder`: pure given the route type and `_linearDir`.
|
||||
- `NavYd` and `IsWalkTarget`: already private static.
|
||||
- The closest-point start in `ResumeFromNearestWaypoint`: an inline loop over plain waypoints. It starts from the current index on a Once route. Note that `MetaManager.StartIndexForRoute` / `FindNearestWaypoint` is a **second, different** rule: a Once route there always starts at 0. Pin both.
|
||||
- The closest-approach sweep: `_prevDist < ArrivalYards * SweepMult && dist > _prevDist + 0.3`, inline in the tick.
|
||||
- Off track, the "159 yd" rule: `OffTrackYards = max(160, NavOffTrackYards)` (the default is 170). `CheckOffTrack` arms when within the limit, is disarmed by every `Stop()` (combat, loot, buff, doors, metas), waits a 5 s grace and starts one recovery per excursion.
|
||||
- Area-grace overshoot: walks 4 yd on through the last waypoint when within 10 yd of it, for 6 s.
|
||||
- **Seam (a pure move):** a dependency-free `NavRouteMath` static class holding `NavYd`, `IsWalkTarget`, `PrevIndex` / `NextInOrder(routeType, count, cur, linearDir)`, `DistanceToSegmentYd`, `PickRejoinIndex` and `NearestPlainWaypoint(route, from, ns, ew)`. `NavigationEngine` would call it. A small `OffTrackGate` class in the style of `CombatStallWatchdog` (`Tick(nowMs, offYd)` returns whether to start recovery, plus `Disarm()`) would carry the arming and grace logic. **Next tests:**
|
||||
- 159 yd off never triggers.
|
||||
- 161 yd triggers once, after 5 s.
|
||||
- A pause disarms it, and coming back within the limit re-arms it.
|
||||
- A rejoin never goes backwards and never passes a Portal, Recall or Chat point.
|
||||
- A Linear route in reverse.
|
||||
- **Different area:** `NavRecoveryPlanner.CheckArea` needs dat geometry (`CellDat`), so it is not pure. The decision inputs are pure: the landblock is `cell >> 16`, "indoors" is `(cell & 0xFFFF) >= 0x0100`, and nav-to-landblock math is in `LegacyUi/NavCoordinateHelper.TryConvertPoseToCoords`, which is pure but sits in a file that imports PluginSdk. **Seam:** move `TryConvertPoseToCoords` into its own file. Pull the classification (same dungeon / other dungeon / dungeon versus landscape / unknown) out into a static function that takes `Func<uint,bool> isDungeonLandblock` and a cell-reach callback, and test it with fakes.
|
||||
|
||||
### 4. Buff and spell choice
|
||||
|
||||
- `SpellManager.ComputeTier` is private instance code over `_charSkills[skill].Buffed` (250 when there are no skills). **Seam:** `static int TierFor(int buffed, int t2..t8)`. Note that the `t1` threshold is never read, and anything below `t2` gives tier 1. Pin that.
|
||||
- `SpellManager.GetDynamicSelfBuffId` builds candidate names (Incantation of X Self, Aura of ..., the lore names in `LoreNames`, Roman numerals) and checks them against `SpellDictionary` and the known and unresolvable sets. The known-spell refresh needs the host. **Seam:** a static candidate-name generator, `IEnumerable<string> CandidateNames(baseName, tier)`, testable without a spellbook.
|
||||
- `BuffManager`: `SkillForBuff`, `IsItemEnchantment` and `GetSpellLevel(SpellInfo)` are private static and pure, but `BuffManager.cs` (2800+ lines) does not link. **Seam:** move them into a small `BuffNames.cs`. **Worth probing (not confirmed as bugs):**
|
||||
- `GetSpellLevel` tests `Contains(" V")` after `" VI"`, so a name with no numeral and a word starting with V (for example "... Vulnerability ...") would read as level 5.
|
||||
- `" I "` has a similar risk.
|
||||
- Impregnability must map to Creature Enchantment and Impenetrability to Item Enchantment, as the comment in `SkillForBuff` insists.
|
||||
- The `CharacterSkills` zero-artifact rule (`AcStubs.cs`): a success with buffed 0 for a trained skill, or for one that read a real value before, is ignored. **Seam:** `static bool IsZeroArtifact(buffed, training, hadGood, prevBuffed)`.
|
||||
- `Combat/CastGateWatchdog.cs` depends only on System and is **linkable now**.
|
||||
- `Combat/PetChoice.cs`: `Order`, `ElementFromName` and `NormalizeElement` are pure, but the file imports PluginSdk for `ElementOf(host, ...)`. With a null host, `ElementOf` falls back to the name. **Seam:** move `ElementOf` out, or use the host runner. **Worth probing:** `ElementFromName` matches substrings, so "Ice" hits any name containing "ice" (Justice, Price, Vice).
|
||||
|
||||
### 5. Other pure, valuable logic
|
||||
|
||||
- **Weapon weakness selection:** the data side, `CreatureData/CreatureWeakness.cs`, is linked and tested. The choice itself is inline in `CombatManager` (around lines 2930-2960). It tries, in order: the Monsters rule's element, then the weakness order filtered to weapons of the same `WeaponKind` as the first usable Items entry (so a bow character with a buff wand listed is not switched to magic), then the Damage tab's learned best weapon. **Seam:** `static int PickWeapon(items, ranking, Func<int,bool> usable, Func<int,int> kind, ...)` returning the id and the reason.
|
||||
- **Damage-line parsing:** `CombatManager.TryParseOutgoingDamage` and `WordAt` are private static, allocation-free and pure. They handle ACE lines ("for N points with <spell>") and retail lines ("points of X damage"), and reject incoming damage and vital drains. `ElementFromWord` and `ElementFromDamageType` are similar. This is an ideal table-test target. **Seam:** move them into a `CombatText.cs` (a pure move).
|
||||
- **Already covered elsewhere:** `Raycasting/MissileBallistics.cs` (MissileArcTests) and the AutoVendor rules and planner (AutoVendorTests).
|
||||
- **Linkable now, no tests yet:**
|
||||
- `Combat/CastGateWatchdog.cs`.
|
||||
- `Combat/AmmoRecipes.cs` + `AmmoRecipes.Data.cs`: System and LINQ only.
|
||||
- `Meta/RegexCache.cs` and `Meta/MetaSchema.cs`.
|
||||
- **Needs a clock seam:** `Combat/WeaponSwapGate.cs` reads `Environment.TickCount64` directly. An internal `Func<long>` clock would make the 3 s gate testable without sleeping.
|
||||
- **Host runner:** `Combat/MonsterMatchEvaluator.cs` (the vTank monster-match expressions `range>5 && species==drudge`). The parser is pure, but variables come from `WorldObjectCache`. Not tried.
|
||||
44
Tools/RynthCore.RynthAiTests/RynthCore.RynthAiTests.csproj
Normal file
44
Tools/RynthCore.RynthAiTests/RynthCore.RynthAiTests.csproj
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<!--
|
||||
Test runner for RynthAi's pure logic (no game, no engine, no host). The plugin itself is
|
||||
a NativeAOT x86 library on net10.0-windows, so a plain net10.0 exe cannot reference it
|
||||
(NU1201); instead the dependency-free source files are compiled in here directly, the
|
||||
same way RynthCore.MissileArcTests and RynthCore.AutoVendorTests do it. See README.md
|
||||
for how to reach code that is not dependency-free yet (seams, and the project-reference
|
||||
route, which works only as a net10.0-windows win-x86 exe).
|
||||
Run: dotnet run -c Release (exit 0 = pass, 1 = fail; a name filter can follow, see Program.cs)
|
||||
-->
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net10.0</TargetFramework>
|
||||
<Nullable>enable</Nullable>
|
||||
<RootNamespace>RynthCore.RynthAiTests</RootNamespace>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Nav: .nav route parsing / writing (LegacyUi/NavRouteParser.cs has no dependencies). -->
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthAi\LegacyUi\NavRouteParser.cs" Link="Linked\NavRouteParser.cs" />
|
||||
<!-- Combat: the melee/missile stall ladder (pure timing state, time passed in). -->
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthAi\Combat\CombatStallWatchdog.cs" Link="Linked\CombatStallWatchdog.cs" />
|
||||
<!-- Weapon weakness selection: element ranking per monster. Its only outside reference is
|
||||
CreatureProfileStore.Folder (the user override folder), faked in Fakes\. -->
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthAi\CreatureData\CreatureWeakness.cs" Link="Linked\CreatureWeakness.cs" />
|
||||
<!-- Learned per-monster damage (System only), for the Aelrynth difficulty-tier tests. -->
|
||||
<Compile Include="..\..\Plugins\RynthCore.Plugin.RynthAi\CreatureData\MonsterDamageStore.cs" Link="Linked\MonsterDamageStore.cs" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- CreatureWeakness reads these from the executing assembly under the plugin's resource
|
||||
names, so they are embedded here under the same logical names. -->
|
||||
<EmbeddedResource Include="..\..\Plugins\RynthCore.Plugin.RynthAi\CreatureData\creature_resists.tsv" Link="Linked\creature_resists.tsv" LogicalName="RynthCore.Plugin.RynthAi.CreatureData.creature_resists.tsv" />
|
||||
<EmbeddedResource Include="..\..\Plugins\RynthCore.Plugin.RynthAi\CreatureData\creature_types.txt" Link="Linked\creature_types.txt" LogicalName="RynthCore.Plugin.RynthAi.CreatureData.creature_types.txt" />
|
||||
<EmbeddedResource Include="..\..\Plugins\RynthCore.Plugin.RynthAi\Data\creature_weakness.json" Link="Linked\creature_weakness.json" LogicalName="RynthCore.Plugin.RynthAi.Data.creature_weakness.json" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<!-- Hand-written .nav files for NavFormatTests. -->
|
||||
<None Include="Fixtures\**\*" CopyToOutputDirectory="PreserveNewest" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
using Act = RynthCore.Plugin.RynthAi.CombatStallWatchdog.StallAction;
|
||||
|
||||
namespace RynthCore.RynthAiTests.Tests;
|
||||
|
||||
// Smoke tests for the melee/missile stall ladder: 6 s with no swing evidence starts it, one
|
||||
// step per 3 s (Reissue, Reselect, ToggleMode, Rewield), then GaveUp and a 30 s rest; a swing
|
||||
// after a step ends the episode (Recovered); a tick gap over 1.5 s starts the count over.
|
||||
// Time is passed in, so the whole ladder runs in microseconds.
|
||||
internal static class CombatStallWatchdogTests
|
||||
{
|
||||
private static readonly DateTime T0 = new(2026, 9, 29, 12, 0, 0, DateTimeKind.Utc);
|
||||
private static readonly DateTime NoEvidence = DateTime.MinValue;
|
||||
private const int TickMs = 500;
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("stall: full ladder, give up, then rest", FullLadder);
|
||||
r.Add("stall: a swing after a step is a recovery", Recovery);
|
||||
r.Add("stall: a tick gap starts the count over", TickGapResets);
|
||||
r.Add("stall: ineligible never acts", Ineligible);
|
||||
}
|
||||
|
||||
/// <summary>Ticks every 500 ms from <paramref name="fromMs"/> to <paramref name="toMs"/>
|
||||
/// inclusive; returns the first non-None action and when it happened (-1 = none).</summary>
|
||||
private static (Act Action, int AtMs) RunUntilAction(CombatStallWatchdog w, int fromMs, int toMs, DateTime evidence)
|
||||
{
|
||||
for (int t = fromMs; t <= toMs; t += TickMs)
|
||||
{
|
||||
var a = w.Tick(T0.AddMilliseconds(t), eligible: true, evidence, out _);
|
||||
if (a != Act.None) return (a, t);
|
||||
}
|
||||
return (Act.None, -1);
|
||||
}
|
||||
|
||||
private static void FullLadder()
|
||||
{
|
||||
var w = new CombatStallWatchdog();
|
||||
|
||||
Check.Eq(RunUntilAction(w, 0, 20_000, NoEvidence), (Act.Reissue, 6000), "step 1 after 6 s without swings");
|
||||
Check.Eq(w.Episodes, 1, "one episode");
|
||||
Check.Eq(w.CurrentStep, 1, "current step 1");
|
||||
Check.Eq(RunUntilAction(w, 6500, 20_000, NoEvidence), (Act.Reselect, 9000), "step 2 three seconds later");
|
||||
Check.Eq(RunUntilAction(w, 9500, 20_000, NoEvidence), (Act.ToggleMode, 12000), "step 3");
|
||||
Check.Eq(RunUntilAction(w, 12500, 20_000, NoEvidence), (Act.Rewield, 15000), "step 4");
|
||||
Check.Eq(RunUntilAction(w, 15500, 20_000, NoEvidence), (Act.GaveUp, 18000), "gave up after step 4");
|
||||
Check.Eq(w.CurrentStep, 0, "episode reset after giving up");
|
||||
|
||||
// Rest: nothing for 30 s, then the next episode starts at once (it has been stalled since 18 s).
|
||||
Check.Eq(RunUntilAction(w, 18500, 47_500, NoEvidence), (Act.None, -1), "resting for 30 s");
|
||||
Check.Eq(RunUntilAction(w, 48_000, 48_000, NoEvidence), (Act.Reissue, 48_000), "new episode after the rest");
|
||||
Check.Eq(w.Episodes, 2, "two episodes");
|
||||
Check.Eq(w.Recoveries, 0, "no recoveries");
|
||||
}
|
||||
|
||||
private static void Recovery()
|
||||
{
|
||||
var w = new CombatStallWatchdog();
|
||||
Check.Eq(RunUntilAction(w, 0, 10_000, NoEvidence), (Act.Reissue, 6000), "step 1");
|
||||
|
||||
DateTime swing = T0.AddMilliseconds(7000);
|
||||
var a = w.Tick(swing, eligible: true, swing, out double stalledMs);
|
||||
Check.Eq(a, Act.Recovered, "a hit after the step ends the episode");
|
||||
Check.Near(stalledMs, 7000, 0.001, "stalled time runs from the episode start to the swing");
|
||||
Check.Eq(w.Recoveries, 1, "one recovery");
|
||||
Check.Eq(w.CurrentStep, 0, "episode reset");
|
||||
|
||||
// Regular swings keep it quiet.
|
||||
int acted = 0;
|
||||
for (int t = 7500; t <= 30_000; t += TickMs)
|
||||
{
|
||||
DateTime now = T0.AddMilliseconds(t);
|
||||
if (w.Tick(now, true, now.AddMilliseconds(-1000), out _) != Act.None) acted++;
|
||||
}
|
||||
Check.Eq(acted, 0, "no steps while swinging every second");
|
||||
}
|
||||
|
||||
private static void TickGapResets()
|
||||
{
|
||||
var w = new CombatStallWatchdog();
|
||||
Check.Eq(RunUntilAction(w, 0, 5000, NoEvidence), (Act.None, -1), "5 s: not yet stalled");
|
||||
// 2 s without a tick (combat paused for looting): the count starts over at 7 s.
|
||||
Check.Eq(RunUntilAction(w, 7000, 12_500, NoEvidence), (Act.None, -1), "a gap restarts the 6 s count");
|
||||
Check.Eq(RunUntilAction(w, 13_000, 13_000, NoEvidence), (Act.Reissue, 13_000), "stalled 6 s after the gap");
|
||||
}
|
||||
|
||||
private static void Ineligible()
|
||||
{
|
||||
var w = new CombatStallWatchdog();
|
||||
int acted = 0;
|
||||
for (int t = 0; t <= 60_000; t += TickMs)
|
||||
if (w.Tick(T0.AddMilliseconds(t), eligible: false, NoEvidence, out _) != Act.None) acted++;
|
||||
Check.Eq(acted, 0, "no action in a minute of ineligible ticks");
|
||||
Check.Eq(w.Episodes, 0, "no episodes");
|
||||
}
|
||||
}
|
||||
133
Tools/RynthCore.RynthAiTests/Tests/CreatureWeaknessTests.cs
Normal file
133
Tools/RynthCore.RynthAiTests/Tests/CreatureWeaknessTests.cs
Normal file
|
|
@ -0,0 +1,133 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using RynthCore.Plugin.RynthAi.CreatureData;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiTests.Tests;
|
||||
|
||||
// Smoke tests for weapon weakness selection's data side (CreatureWeakness): which elements
|
||||
// hurt a monster most, from the shipped server table (wcid + name), what the Damage tab
|
||||
// learned, or the creature type / whole-word name keyword. Assertions are derived from the
|
||||
// embedded data where they depend on it, so regenerating the tables doesn't break them.
|
||||
internal static class CreatureWeaknessTests
|
||||
{
|
||||
// Names that are in no table and contain no type keyword.
|
||||
private const string Unknown = "Qzxv Blorpington";
|
||||
// "Olthoi" is a type keyword (type 1); this exact name is not in the server table.
|
||||
private const string OlthoiByKeyword = "Grand Qzxv Olthoi Tyrant";
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("weakness: element names normalise", Normalize);
|
||||
r.Add("weakness: server table ranks most damage first", ServerTable);
|
||||
r.Add("weakness: type keyword is a whole word", TypeKeyword);
|
||||
r.Add("weakness: learned element goes first, then the type order", LearnedFirst);
|
||||
}
|
||||
|
||||
private static void Normalize()
|
||||
{
|
||||
Check.Eq(CreatureWeakness.Normalize("Electric"), "Lightning", "Electric -> Lightning");
|
||||
Check.Eq(CreatureWeakness.Normalize("blade"), "Slash", "Blade -> Slash");
|
||||
Check.Eq(CreatureWeakness.Normalize(" fire "), "Fire", "case and spaces");
|
||||
Check.Eq(CreatureWeakness.Normalize("Holy"), "", "not an element");
|
||||
Check.Eq(CreatureWeakness.Normalize(null), "", "null");
|
||||
Check.Eq(CreatureWeakness.Elements.Length, 8, "eight elements");
|
||||
}
|
||||
|
||||
private static (uint Wcid, string Name, double[] Mult)? FirstServerRow()
|
||||
{
|
||||
using Stream? s = typeof(CreatureWeaknessTests).Assembly
|
||||
.GetManifestResourceStream("RynthCore.Plugin.RynthAi.CreatureData.creature_resists.tsv");
|
||||
if (s == null) return null;
|
||||
using var reader = new StreamReader(s);
|
||||
string? line;
|
||||
while ((line = reader.ReadLine()) != null)
|
||||
{
|
||||
if (line.Length == 0 || line[0] == '#') continue;
|
||||
string[] f = line.Split('\t');
|
||||
if (f.Length < 11 || !uint.TryParse(f[0], out uint wcid)) continue;
|
||||
var m = new double[8];
|
||||
for (int i = 0; i < 8; i++) m[i] = double.Parse(f[3 + i], CultureInfo.InvariantCulture);
|
||||
return (wcid, f[1], m);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static void ServerTable()
|
||||
{
|
||||
var row = FirstServerRow();
|
||||
Check.NotNull(row, "creature_resists.tsv is embedded and has a data row");
|
||||
if (row == null) return;
|
||||
var (wcid, name, mult) = row.Value;
|
||||
|
||||
var r = CreatureWeakness.Rank(wcid, name, 0, null);
|
||||
Check.NotNull(r, $"ranking for {name} ({wcid})");
|
||||
if (r == null) return;
|
||||
Check.Eq(r.Source, "server data", "source");
|
||||
Check.Eq(r.Order.Count, 8, "all eight elements ranked");
|
||||
for (int i = 1; i < r.Order.Count; i++)
|
||||
{
|
||||
var (pe, pm) = r.Order[i - 1];
|
||||
var (e, m) = r.Order[i];
|
||||
Check.True(pm >= m, $"most damage first: {pe} {pm} before {e} {m}");
|
||||
if (Math.Round(pm, 3) == Math.Round(m, 3))
|
||||
Check.True(Array.IndexOf(CreatureWeakness.Elements, pe) < Array.IndexOf(CreatureWeakness.Elements, e),
|
||||
$"ties keep element order: {pe} before {e}");
|
||||
}
|
||||
foreach (var (e, m) in r.Order)
|
||||
Check.Near(m, mult[Array.IndexOf(CreatureWeakness.Elements, e)], 1e-9, $"{e} multiplier from the table");
|
||||
|
||||
// By name alone (a meta asking by name): the same row.
|
||||
Check.Eq(CreatureWeakness.Rank(0, name, 0, null)?.Source, "server data", "found by name without a wcid");
|
||||
// The wcid with another name is not that creature (a custom monster reusing the wcid).
|
||||
Check.True(CreatureWeakness.Rank(wcid, Unknown, 0, null)?.Source != "server data", "wcid with a different name is not trusted");
|
||||
|
||||
Check.True(CreatureWeakness.TryGetMultiplier(wcid, name, 0, "Electric", out double lm), "multiplier by alias");
|
||||
Check.Near(lm, mult[6], 1e-9, "Lightning multiplier");
|
||||
}
|
||||
|
||||
private static void TypeKeyword()
|
||||
{
|
||||
var r = CreatureWeakness.Rank(0, OlthoiByKeyword, 0, null);
|
||||
Check.NotNull(r, "the Olthoi keyword finds a type");
|
||||
Check.Eq(r?.Source, "Olthoi type", "source names the type");
|
||||
Check.Eq(r?.Order.Count, 8, "the type lists all eight elements");
|
||||
if (r != null)
|
||||
for (int i = 1; i < r.Order.Count; i++)
|
||||
Check.True(r.Order[i - 1].Mult >= r.Order[i].Mult, $"type order is most damage first at {i}");
|
||||
|
||||
// Same type by id (creature type 1 = Olthoi), with a name that has no keyword.
|
||||
var byId = CreatureWeakness.Rank(0, Unknown, 1, null);
|
||||
Check.Eq(byId?.Source, "Olthoi type", "creature type id wins over the name");
|
||||
Check.Eq(byId?.Order[0].Element, r?.Order[0].Element, "same ranking by id and by keyword");
|
||||
|
||||
Check.Null(CreatureWeakness.Rank(0, Unknown, 0, null), "no data at all: null");
|
||||
Check.Null(CreatureWeakness.Rank(0, "Olthoiling Qzxv", 0, null), "keyword inside a longer word does not match");
|
||||
Check.False(CreatureWeakness.TryGetMultiplier(0, Unknown, 0, "Fire", out double m), "no multiplier when unknown");
|
||||
Check.Near(m, 1.0, 0, "unknown multiplier reads 1.0");
|
||||
}
|
||||
|
||||
private static void LearnedFirst()
|
||||
{
|
||||
var type = CreatureWeakness.Rank(0, OlthoiByKeyword, 0, null);
|
||||
var r = CreatureWeakness.Rank(0, OlthoiByKeyword, 0, "Electric");
|
||||
Check.NotNull(r, "ranking with a learned element");
|
||||
if (r == null || type == null) return;
|
||||
Check.Eq(r.Source, "learned, then Olthoi type", "source");
|
||||
Check.Eq(r.Order[0].Element, "Lightning", "learned element first (normalised)");
|
||||
Check.True(double.IsNaN(r.Order[0].Mult), "learned element has no multiplier");
|
||||
Check.Eq(r.Order.Count, 8, "learned element is not listed twice");
|
||||
var rest = new List<string>();
|
||||
foreach (var (e, _) in type.Order) if (e != "Lightning") rest.Add(e);
|
||||
for (int i = 0; i < rest.Count; i++)
|
||||
Check.Eq(r.Order[i + 1].Element, rest[i], $"then the type order at {i + 1}");
|
||||
|
||||
var alone = CreatureWeakness.Rank(0, Unknown, 0, "Fire");
|
||||
Check.Eq(alone?.Source, "learned", "learned with no type");
|
||||
Check.Eq(alone?.Order.Count, 1, "only the learned element");
|
||||
Check.Eq(alone?.Describe(), "Fire", "describe without a multiplier");
|
||||
}
|
||||
}
|
||||
173
Tools/RynthCore.RynthAiTests/Tests/MonsterDamageTierTests.cs
Normal file
173
Tools/RynthCore.RynthAiTests/Tests/MonsterDamageTierTests.cs
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using RynthCore.Plugin.RynthAi.CreatureData;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiTests.Tests;
|
||||
|
||||
// MonsterDamageStore and Aelrynth's difficulty tiers (2026-10-03). Awakened worlds and scaled
|
||||
// copies hold the same monsters (same wcids) with +5% health, skills and damage a tier, so the
|
||||
// store keeps the HP pool, casts-to-kill, accuracy, fight times and damage taken per (wcid,
|
||||
// tier). Tier 0 must stay today's data in today's rows: on every other server the tier is
|
||||
// always 0, and a file written there must be what the old code wrote.
|
||||
internal static class MonsterDamageTierTests
|
||||
{
|
||||
private const uint Drudge = 7; // any wcid
|
||||
private const uint Wand = 0x80001234;
|
||||
private const string Fire = "Fire";
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("damage tiers: tier 0 file round-trips unchanged", Tier0RoundTrip);
|
||||
r.Add("damage tiers: a tier's numbers are kept apart from real Dereth", TierKeptApart);
|
||||
r.Add("damage tiers: tier rows are extra lines; the tier-0 lines don't change", TierRowsAreExtra);
|
||||
r.Add("damage tiers: snapshot, known tiers, delete and reset", SnapshotAndHousekeeping);
|
||||
}
|
||||
|
||||
private static string NewFolder(string name)
|
||||
{
|
||||
string dir = Path.Combine(AppContext.BaseDirectory, "scratch-damage-tiers", name + "-" + Guid.NewGuid().ToString("N"));
|
||||
Directory.CreateDirectory(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
/// <summary>A store with some real-Dereth learning in it, saved.</summary>
|
||||
private static (MonsterDamageStore Store, string Folder, string File) Seeded(string name)
|
||||
{
|
||||
string dir = NewFolder(name);
|
||||
var s = new MonsterDamageStore();
|
||||
s.SetCharacter(dir);
|
||||
s.RecordHit(Wand, Drudge, "Drudge Skulker", Fire, 7, 300, crit: false);
|
||||
s.RecordHit(Wand, Drudge, "Drudge Skulker", Fire, 7, 600, crit: true);
|
||||
s.RecordKill(Wand, Drudge, "Drudge Skulker", Fire, 7, 2, 900);
|
||||
s.RecordMiss(Wand, Drudge, "Drudge Skulker");
|
||||
s.RecordFightTime(Wand, Drudge, "Drudge Skulker", 4.0, "none");
|
||||
s.RecordTaken(Drudge, "Drudge Skulker", "Slash", 40);
|
||||
s.SetManualWeapon(Drudge, Wand);
|
||||
s.SaveIfDirty();
|
||||
return (s, dir, Path.Combine(dir, "monster_damage.txt"));
|
||||
}
|
||||
|
||||
private static void Tier0RoundTrip()
|
||||
{
|
||||
var (_, dir, file) = Seeded("roundtrip");
|
||||
string before = File.ReadAllText(file);
|
||||
Check.False(before.Contains("\nA"), "no tier rows in a tier-0-only file");
|
||||
Check.False(before.Contains("Aelrynth difficulty"), "no tier header in a tier-0-only file");
|
||||
|
||||
var again = new MonsterDamageStore();
|
||||
again.SetCharacter(dir);
|
||||
again.SetManualWeapon(Drudge, Wand); // same value, but marks the store dirty
|
||||
again.SaveIfDirty();
|
||||
Check.Eq(File.ReadAllText(file), before, "load + save writes the same file");
|
||||
}
|
||||
|
||||
private static void TierKeptApart()
|
||||
{
|
||||
var (s, _, _) = Seeded("apart");
|
||||
double hp0 = s.GetLearnedHp(Drudge, 0);
|
||||
Check.Near(hp0, 900, 0.01, "real Dereth HP learned");
|
||||
|
||||
s.Difficulty = 10;
|
||||
s.RecordKill(Wand, Drudge, "Drudge Skulker", Fire, 7, 3, 1350);
|
||||
s.RecordHit(Wand, Drudge, "Drudge Skulker", Fire, 7, 450, crit: false);
|
||||
s.RecordMiss(Wand, Drudge, "Drudge Skulker");
|
||||
s.RecordMiss(Wand, Drudge, "Drudge Skulker");
|
||||
|
||||
Check.Near(s.GetLearnedHp(Drudge, 0), 900, 0.01, "tier 10 left real Dereth's HP alone");
|
||||
Check.Near(s.GetLearnedHp(Drudge, 10), 1350, 0.01, "tier 10 has its own HP");
|
||||
Check.Near(s.GetLearnedHp(Drudge), 1350, 0.01, "the tier-less reader answers for the current tier");
|
||||
|
||||
double c10 = s.GetAvgCastsToKill(Wand, Drudge, Fire, 7, out int k10);
|
||||
Check.Eq((k10, c10), (1, 3.0), "casts to kill at tier 10");
|
||||
s.Difficulty = 0;
|
||||
double c0 = s.GetAvgCastsToKill(Wand, Drudge, Fire, 7, out int k0);
|
||||
Check.Eq((k0, c0), (1, 2.0), "casts to kill at tier 0 unchanged");
|
||||
|
||||
// Damage per cast is shared: resistances and armour do not scale.
|
||||
double avg = s.GetAvgDamage(Wand, Drudge, Fire, 7, out int n);
|
||||
Check.Eq(n, 3, "the tier-10 hit counts toward the shared damage average");
|
||||
Check.True(avg > 300, "shared average moved");
|
||||
|
||||
var (_, hit0) = s.GetSummary(Drudge, 0);
|
||||
var (_, hit10) = s.GetSummary(Drudge, 10);
|
||||
Check.Near(hit0, 2.0 / 3.0, 0.001, "real Dereth hit rate (2 hits, 1 miss)");
|
||||
Check.Near(hit10, 1.0 / 3.0, 0.001, "tier 10 hit rate (1 hit, 2 misses)");
|
||||
|
||||
// A tier never fought: nothing, not real Dereth's numbers.
|
||||
Check.Eq(s.GetLearnedHp(Drudge, 15), 0.0, "an unfought tier has no HP");
|
||||
s.Difficulty = 15;
|
||||
s.GetAvgCastsToKill(Wand, Drudge, Fire, 7, out int k15);
|
||||
Check.Eq(k15, 0, "an unfought tier has no casts to kill (no one-shot guess)");
|
||||
|
||||
// Rules stay shared.
|
||||
Check.Eq(s.GetManualWeapon(Drudge), Wand, "the weapon rule is the same at every tier");
|
||||
}
|
||||
|
||||
private static void TierRowsAreExtra()
|
||||
{
|
||||
var (s, dir, file) = Seeded("extra");
|
||||
string[] tier0 = File.ReadAllLines(file);
|
||||
|
||||
// Only tier-scaled observations (no hits: those also feed the shared damage average).
|
||||
s.Difficulty = 10;
|
||||
s.RecordKill(Wand, Drudge, "Drudge Skulker", Fire, 7, 3, 1350);
|
||||
s.RecordMiss(Wand, Drudge, "Drudge Skulker");
|
||||
s.RecordFightTime(Wand, Drudge, "Drudge Skulker", 6.5, "Fire");
|
||||
s.RecordTaken(Drudge, "Drudge Skulker", "Slash", 60);
|
||||
s.SaveIfDirty();
|
||||
|
||||
string[] all = File.ReadAllLines(file);
|
||||
bool IsTierLine(string l) => l.StartsWith("A") || l.StartsWith("# A");
|
||||
Check.Eq(string.Join("\n", all.Where(l => !IsTierLine(l))), string.Join("\n", tier0), "tier-0 lines identical");
|
||||
Check.True(all.Any(l => l.StartsWith("AH|10|7|Drudge Skulker|1350|1")), "AH row written");
|
||||
Check.True(all.Any(l => l.StartsWith("AD|10|7|Drudge Skulker|" + Wand + "|Fire|7|3|1")), "AD row written");
|
||||
Check.True(all.Any(l => l.StartsWith("AU|10|7|")), "AU row written");
|
||||
Check.True(all.Any(l => l.StartsWith("APK|10|7|Drudge Skulker|Fire|1|6.5")), "APK row written");
|
||||
Check.True(all.Any(l => l.StartsWith("AT|10|7|Drudge Skulker|Slash|1|60|60")), "AT row written");
|
||||
|
||||
// Reload: tier numbers come back, tier 0 untouched.
|
||||
var again = new MonsterDamageStore();
|
||||
again.SetCharacter(dir);
|
||||
Check.Near(again.GetLearnedHp(Drudge, 10), 1350, 0.01, "tier HP reloaded");
|
||||
Check.Near(again.GetLearnedHp(Drudge, 0), 900, 0.01, "tier-0 HP reloaded");
|
||||
again.Difficulty = 10;
|
||||
Check.Eq(again.GetAvgCastsToKill(Wand, Drudge, Fire, 7, out int k), 3.0, "tier casts reloaded");
|
||||
Check.Eq(k, 1, "tier kill samples reloaded");
|
||||
var (w10, p10, t10) = again.GetDetail(Drudge, 10);
|
||||
Check.Eq((w10.Count, w10[0].Misses), (1, 1), "tier weapon use reloaded");
|
||||
Check.Eq((p10.Count, p10[0].Element, p10[0].Kills), (1, "Fire", 1), "tier summon kills reloaded");
|
||||
Check.Eq((t10.Count, t10[0].Max), (1, 60.0), "tier damage taken reloaded");
|
||||
var (_, p0, t0) = again.GetDetail(Drudge, 0);
|
||||
Check.Eq((p0.Count, p0[0].Element), (1, ""), "tier-0 summon row unchanged (no summon)");
|
||||
Check.Eq(t0[0].Max, 40.0, "tier-0 damage taken unchanged");
|
||||
}
|
||||
|
||||
private static void SnapshotAndHousekeeping()
|
||||
{
|
||||
var (s, _, _) = Seeded("snapshot");
|
||||
s.Difficulty = 10;
|
||||
s.RecordKill(Wand, Drudge, "Drudge Skulker", Fire, 7, 3, 1350);
|
||||
s.Difficulty = 5;
|
||||
s.RecordKill(Wand, Drudge, "Drudge Skulker", Fire, 7, 2, 1125);
|
||||
|
||||
Check.Eq(string.Join(",", s.KnownDifficulties()), "5,10", "known tiers");
|
||||
|
||||
var r0 = s.Snapshot(0).Single();
|
||||
var r10 = s.Snapshot(10).Single();
|
||||
var r20 = s.Snapshot(20).Single();
|
||||
Check.Eq((r0.HpPool, r0.AvgCastsToKill, r0.KillSamples), (900.0, 2.0, 1), "tier-0 row");
|
||||
Check.Eq((r10.HpPool, r10.AvgCastsToKill, r10.KillSamples), (1350.0, 3.0, 1), "tier-10 row");
|
||||
Check.Eq((r20.HpPool, r20.KillSamples), (0.0, 0), "an unfought tier lists the row with nothing learned");
|
||||
Check.Eq(r10.AvgDamage, r0.AvgDamage, "damage per cast is the same row at every tier");
|
||||
|
||||
s.ClearAllStats();
|
||||
Check.Eq(s.KnownDifficulties().Count, 0, "reset stats clears every tier");
|
||||
Check.Eq(s.GetManualWeapon(Drudge), Wand, "reset stats keeps the rules");
|
||||
|
||||
s.RecordKill(Wand, Drudge, "Drudge Skulker", Fire, 7, 3, 1125); // Difficulty is still 5
|
||||
Check.True(s.DeleteWcid(Drudge), "monster removed");
|
||||
Check.Eq(s.KnownDifficulties().Count, 0, "removing a monster removes its tiers");
|
||||
}
|
||||
}
|
||||
346
Tools/RynthCore.RynthAiTests/Tests/NavFormatTests.cs
Normal file
346
Tools/RynthCore.RynthAiTests/Tests/NavFormatTests.cs
Normal file
|
|
@ -0,0 +1,346 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiTests.Tests;
|
||||
|
||||
// .nav files as RynthAi reads them (NavRouteParser, VTank "uTank2 NAV 1.2"): one file per
|
||||
// supported route type (Circular, Linear, Once, Follow), every waypoint kind (point,
|
||||
// checkpoint, recall, pause, chat, vendor, portal, NPC, jump), and malformed files. The
|
||||
// fixtures in Fixtures\nav were written by hand for these tests.
|
||||
internal static class NavFormatTests
|
||||
{
|
||||
private static string Fixture(string name) => Path.Combine(AppContext.BaseDirectory, "Fixtures", "nav", name);
|
||||
|
||||
/// <summary>Scratch folder next to the exe for files these tests write. Emptied per test.</summary>
|
||||
private static string Scratch()
|
||||
{
|
||||
string dir = Path.Combine(AppContext.BaseDirectory, "scratch-nav");
|
||||
if (Directory.Exists(dir)) Directory.Delete(dir, recursive: true);
|
||||
Directory.CreateDirectory(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("nav format: Circular hunting route file (checkpoint, pause, chat, jump)", CircularFile);
|
||||
r.Add("nav format: Linear route file writes back line for line", LinearFile);
|
||||
r.Add("nav format: Once route file (recalls, vendor, portal, NPC)", OnceFile);
|
||||
r.Add("nav format: Follow file names the leader", FollowFile);
|
||||
r.Add("nav format: route type numbers 1-4 survive a save and load", RouteTypeNumbers);
|
||||
r.Add("nav format: CRLF file, spaces around numbers, Save then Load", CrlfAndSave);
|
||||
r.Add("nav format: Z repair only above 5 nav units", ZRepairBoundary);
|
||||
r.Add("nav format: tie and shift flags", Flags);
|
||||
r.Add("nav format: empty, missing, header-only and wrong-header files load empty", EmptyFiles);
|
||||
r.Add("nav format: malformed header warns", MalformedHeader);
|
||||
r.Add("nav format: truncated file keeps the points before the cut and warns", Truncated);
|
||||
r.Add("nav format: a bad number stops at that point and warns", BadNumber);
|
||||
r.Add("nav format: an unreadable file warns instead of throwing", UnreadableFile);
|
||||
r.Add("nav format: pinned oddities (short count, bad route type, comma decimals)", PinnedOddities);
|
||||
}
|
||||
|
||||
private static void CircularFile()
|
||||
{
|
||||
var warnings = new List<string>();
|
||||
var route = NavRouteParser.Load(Fixture("circular-hunt.nav"), warnings.Add);
|
||||
Check.Null(route.LoadWarning, "no warning");
|
||||
Check.Eq(warnings.Count, 0, "warn callback not called");
|
||||
Check.Eq(route.RouteType, NavRouteType.Circular, "route type 1 is Circular");
|
||||
Check.Eq(route.Points.Count, 7, "point count");
|
||||
if (route.Points.Count != 7) return;
|
||||
var p = route.Points;
|
||||
|
||||
var kinds = new[] { NavPointType.Point, NavPointType.Point, NavPointType.Checkpoint, NavPointType.Pause,
|
||||
NavPointType.Chat, NavPointType.Jump, NavPointType.Point };
|
||||
for (int i = 0; i < kinds.Length; i++) Check.Eq(p[i].Type, kinds[i], $"[{i}] type");
|
||||
|
||||
Check.Near(p[0].EW, 33.6012, 1e-9, "[0] EW (first coordinate line)");
|
||||
Check.Near(p[0].NS, 42.4987, 1e-9, "[0] NS (second coordinate line)");
|
||||
Check.Near(p[0].Z, 0.05, 1e-9, "[0] Z");
|
||||
Check.Eq(p[3].PauseTimeMs, 3000, "[3] pause 3 s");
|
||||
Check.Eq(p[4].ChatCommand, "/vt opt set EnableLooting true", "[4] chat text kept whole, spaces included");
|
||||
Check.Near(p[5].JumpHeading, 135.5, 1e-9, "[5] jump heading");
|
||||
Check.False(p[5].JumpShift, "[5] jump shift False");
|
||||
Check.Near(p[5].JumpMs, 420, 1e-9, "[5] jump hold ms");
|
||||
Check.True(NavRouteParser.IsPlainWaypoint(p[2].Type), "a checkpoint is walked like a point");
|
||||
Check.False(NavRouteParser.IsPlainWaypoint(p[5].Type), "a jump is not a plain waypoint");
|
||||
|
||||
// The writer reproduces this file exactly (every value here is in its written form).
|
||||
var fileLines = File.ReadAllLines(Fixture("circular-hunt.nav"));
|
||||
Check.Eq(string.Join("|", route.ToLines()), string.Join("|", fileLines), "written back line for line");
|
||||
}
|
||||
|
||||
private static void LinearFile()
|
||||
{
|
||||
var route = NavRouteParser.Load(Fixture("linear-patrol.nav"));
|
||||
Check.Null(route.LoadWarning, "no warning");
|
||||
Check.Eq(route.RouteType, NavRouteType.Linear, "route type 2 is Linear");
|
||||
Check.Eq(route.Points.Count, 3, "point count");
|
||||
if (route.Points.Count == 3)
|
||||
{
|
||||
Check.Near(route.Points[0].EW, -12.25, 1e-9, "west coordinates are negative EW");
|
||||
Check.Near(route.Points[2].NS, 8.85, 1e-9, "last point NS");
|
||||
}
|
||||
var fileLines = File.ReadAllLines(Fixture("linear-patrol.nav"));
|
||||
Check.Eq(string.Join("|", route.ToLines()), string.Join("|", fileLines), "written back line for line");
|
||||
}
|
||||
|
||||
private static void OnceFile()
|
||||
{
|
||||
var route = NavRouteParser.Load(Fixture("once-town-run.nav"));
|
||||
Check.Null(route.LoadWarning, "no warning");
|
||||
Check.Eq(route.RouteType, NavRouteType.Once, "route type 4 is Once");
|
||||
Check.Eq(route.Points.Count, 6, "point count");
|
||||
if (route.Points.Count != 6) return;
|
||||
var p = route.Points;
|
||||
|
||||
Check.Eq(p[0].Type, NavPointType.Recall, "[0] recall");
|
||||
Check.Eq(p[0].SpellId, 1635, "[0] Lifestone Recall's spell id");
|
||||
Check.Eq(p[2].Type, NavPointType.OpenVendor, "[2] vendor");
|
||||
Check.Eq(p[2].VendorId, 2147484001u, "[2] vendor id above int.MaxValue");
|
||||
Check.Eq(p[2].TargetName, "Tinker Aldo", "[2] vendor name");
|
||||
Check.Eq(p[3].Type, NavPointType.PortalNPC, "[3] portal");
|
||||
Check.Eq(p[3].TargetName, "Town Network Portal", "[3] portal name");
|
||||
Check.Eq(p[3].ObjectClass, 14, "[3] object class");
|
||||
Check.True(p[3].IsTie, "[3] a numeric tie flag 1 reads as true");
|
||||
Check.Near(p[3].PortalExitNS, 42.541, 1e-9, "[3] the portal object's NS");
|
||||
Check.Near(p[3].PortalExitZ, 0.052, 1e-9, "[3] the portal object's Z");
|
||||
Check.Eq(p[4].Type, NavPointType.Npc, "[4] NPC");
|
||||
Check.Eq(p[4].TargetName, "Guard Captain Ilsa", "[4] NPC name");
|
||||
Check.Eq(p[4].ObjectClass, 37, "[4] NPC object class");
|
||||
Check.False(p[4].IsTie, "[4] tie False");
|
||||
Check.Eq(p[5].Type, NavPointType.Recall, "[5] recall");
|
||||
Check.Eq(p[5].SpellId, 48, "[5] Primary Portal Recall's spell id");
|
||||
|
||||
// Written back, the numeric tie flag becomes "True"; everything else round-trips.
|
||||
var again = NavRouteParser.LoadFromLines(route.ToLines());
|
||||
Check.Eq(again.Points.Count, 6, "re-read point count");
|
||||
for (int i = 0; i < 6 && i < again.Points.Count; i++)
|
||||
Check.Eq(again.Points[i].ToString(), p[i].ToString(), $"[{i}] survives a write and read");
|
||||
Check.True(again.Points.Count == 6 && again.Points[3].IsTie, "tie survives as True");
|
||||
}
|
||||
|
||||
private static void FollowFile()
|
||||
{
|
||||
var route = NavRouteParser.Load(Fixture("follow-leader.nav"));
|
||||
Check.Null(route.LoadWarning, "no warning");
|
||||
Check.Eq(route.RouteType, NavRouteType.Follow, "route type 3 is Follow");
|
||||
Check.Eq(route.FollowTargetName, "Vessa Thornwood", "leader name with a space");
|
||||
Check.Eq(route.FollowTargetId, 1342177301u, "leader id");
|
||||
Check.Eq(route.Points.Count, 0, "no points");
|
||||
|
||||
var noId = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "3", "Vessa Thornwood" });
|
||||
Check.Eq(noId.FollowTargetName, "Vessa Thornwood", "no id line: name still read");
|
||||
Check.Eq(noId.FollowTargetId, 0u, "no id line: id 0");
|
||||
|
||||
var badId = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "3", "Vessa Thornwood", "not-an-id" });
|
||||
Check.Eq(badId.FollowTargetId, 0u, "a bad id reads as 0");
|
||||
Check.Null(badId.LoadWarning, "a bad id is not a warning");
|
||||
|
||||
// A Follow route with no leader name is written as an empty point list.
|
||||
var blank = new NavRouteParser { RouteType = NavRouteType.Follow };
|
||||
Check.Eq(string.Join("|", blank.ToLines()), "uTank2 NAV 1.2|3|0", "nameless Follow writes a zero point count");
|
||||
}
|
||||
|
||||
private static void RouteTypeNumbers()
|
||||
{
|
||||
foreach (var type in new[] { NavRouteType.Circular, NavRouteType.Linear, NavRouteType.Once })
|
||||
{
|
||||
var route = new NavRouteParser { RouteType = type };
|
||||
route.Points.Add(new NavPoint { Type = NavPointType.Point, EW = 1.5, NS = -2.5, Z = 0.1 });
|
||||
var lines = route.ToLines();
|
||||
Check.Eq(lines[1], ((int)type).ToString(), $"{type} is written as {(int)type}");
|
||||
var back = NavRouteParser.LoadFromLines(lines);
|
||||
Check.Eq(back.RouteType, type, $"{type} reads back");
|
||||
Check.Eq(back.Points.Count, 1, $"{type} keeps its point");
|
||||
}
|
||||
var follow = new NavRouteParser { RouteType = NavRouteType.Follow, FollowTargetName = "Leader Lin", FollowTargetId = 7 };
|
||||
var fb = NavRouteParser.LoadFromLines(follow.ToLines());
|
||||
Check.Eq(fb.RouteType, NavRouteType.Follow, "Follow reads back");
|
||||
Check.Eq(fb.FollowTargetName, "Leader Lin", "Follow leader reads back");
|
||||
}
|
||||
|
||||
private static void CrlfAndSave()
|
||||
{
|
||||
string dir = Scratch();
|
||||
// CRLF line endings and spaces around numbers, as a hand-edited or Windows-saved file has.
|
||||
string text = string.Join("\r\n", new[]
|
||||
{
|
||||
"uTank2 NAV 1.2", " 1 ", "2",
|
||||
"0", " 10.5", "-20.25 ", "0", "0",
|
||||
"4", "10.5", "-20.25", "0", "0", "/ra nav load next",
|
||||
}) + "\r\n";
|
||||
string path = Path.Combine(dir, "crlf.nav");
|
||||
File.WriteAllText(path, text);
|
||||
var route = NavRouteParser.Load(path);
|
||||
Check.Null(route.LoadWarning, "CRLF: no warning");
|
||||
Check.Eq(route.RouteType, NavRouteType.Circular, "CRLF: route type (with spaces)");
|
||||
Check.Eq(route.Points.Count, 2, "CRLF: point count");
|
||||
if (route.Points.Count == 2)
|
||||
{
|
||||
Check.Near(route.Points[0].EW, 10.5, 1e-9, "a leading space is allowed");
|
||||
Check.Near(route.Points[0].NS, -20.25, 1e-9, "a trailing space is allowed");
|
||||
Check.Eq(route.Points[1].ChatCommand, "/ra nav load next", "no carriage return left on the chat text");
|
||||
}
|
||||
|
||||
string saved = Path.Combine(dir, "sub", "saved.nav");
|
||||
route.Save(saved); // creates the folder
|
||||
Check.True(File.Exists(saved), "Save creates the folder and file");
|
||||
var back = NavRouteParser.Load(saved);
|
||||
Check.Eq(back.Points.Count, 2, "saved file reads back");
|
||||
Check.Eq(string.Join("|", back.ToLines()), string.Join("|", route.ToLines()), "Save and ToLines agree");
|
||||
}
|
||||
|
||||
private static void ZRepairBoundary()
|
||||
{
|
||||
var route = NavRouteParser.LoadFromLines(new[]
|
||||
{
|
||||
"uTank2 NAV 1.2", "4", "4",
|
||||
"0", "1", "2", "5", "0", // exactly 5 units: kept
|
||||
"0", "1", "2", "5.01", "0", // just above: treated as metres
|
||||
"0", "1", "2", "-120", "0", // negative metres too
|
||||
"6", "1", "2", "0", "0", "Portal", "14", "True", "1", "2", "300", // the portal object's Z is not repaired
|
||||
});
|
||||
Check.Eq(route.Points.Count, 4, "point count");
|
||||
if (route.Points.Count != 4) return;
|
||||
Check.Near(route.Points[0].Z, 5.0, 1e-9, "5.0 is kept");
|
||||
Check.Near(route.Points[1].Z, 5.01 / 240.0, 1e-9, "5.01 is divided by 240");
|
||||
Check.Near(route.Points[2].Z, -0.5, 1e-9, "-120 m becomes -0.5");
|
||||
Check.Near(route.Points[3].PortalExitZ, 300, 1e-9, "the portal object's Z is read as is");
|
||||
}
|
||||
|
||||
private static void Flags()
|
||||
{
|
||||
static NavPoint Portal(string tie) => NavRouteParser.LoadFromLines(new[]
|
||||
{ "uTank2 NAV 1.2", "4", "1", "6", "1", "2", "0", "0", "P", "14", tie, "1", "2", "0" }).Points[0];
|
||||
static NavPoint Jump(string shift) => NavRouteParser.LoadFromLines(new[]
|
||||
{ "uTank2 NAV 1.2", "4", "1", "9", "1", "2", "0", "0", "90", shift, "500" }).Points[0];
|
||||
|
||||
Check.True(Portal("True").IsTie, "tie True");
|
||||
Check.True(Portal("true").IsTie, "tie true (any case)");
|
||||
Check.True(Portal("1").IsTie, "tie 1");
|
||||
Check.True(Portal(" 1 ").IsTie, "tie 1 with spaces");
|
||||
Check.False(Portal("False").IsTie, "tie False");
|
||||
Check.False(Portal("0").IsTie, "tie 0");
|
||||
Check.False(Portal("yes").IsTie, "tie yes: not recognised, false");
|
||||
|
||||
Check.True(Jump("True").JumpShift, "shift True");
|
||||
Check.True(Jump(" TRUE ").JumpShift, "shift TRUE with spaces");
|
||||
Check.False(Jump("False").JumpShift, "shift False");
|
||||
// Pinned: unlike the tie flag, a numeric 1 is not read as true for the jump shift.
|
||||
Check.False(Jump("1").JumpShift, "shift 1 reads as false");
|
||||
}
|
||||
|
||||
private static void EmptyFiles()
|
||||
{
|
||||
foreach (var (what, route) in new[]
|
||||
{
|
||||
("empty file", NavRouteParser.Load(Fixture("empty.nav"))),
|
||||
("missing file", NavRouteParser.Load(Fixture("no-such-route.nav"))),
|
||||
("header only", NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2" })),
|
||||
("header and type only", NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "1" })),
|
||||
("other header", NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.1", "1", "0" })),
|
||||
("a JSON file", NavRouteParser.LoadFromLines(new[] { "{", " \"RouteType\": 1,", "}" })),
|
||||
})
|
||||
{
|
||||
Check.Eq(route.Points.Count, 0, $"{what}: no points");
|
||||
Check.Null(route.LoadWarning, $"{what}: no warning");
|
||||
}
|
||||
var lower = NavRouteParser.LoadFromLines(new[] { "utank2 nav 1.2", "1", "1", "0", "1", "2", "0", "0" });
|
||||
Check.Eq(lower.Points.Count, 1, "the header ignores case");
|
||||
var zero = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "1", "0" });
|
||||
Check.Eq(zero.Points.Count, 0, "zero points");
|
||||
Check.Null(zero.LoadWarning, "zero points is not a warning");
|
||||
}
|
||||
|
||||
private static void MalformedHeader()
|
||||
{
|
||||
var warnings = new List<string>();
|
||||
var badType = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "circular", "1", "0", "1", "2", "0", "0" }, warnings.Add);
|
||||
Check.Eq(badType.Points.Count, 0, "non-number route type: no points");
|
||||
Check.True(badType.LoadWarning?.Contains("malformed header") == true, "non-number route type: warning");
|
||||
var badCount = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "1", "many", "0", "1", "2", "0", "0" }, warnings.Add);
|
||||
Check.Eq(badCount.Points.Count, 0, "non-number point count: no points");
|
||||
Check.True(badCount.LoadWarning?.Contains("malformed header") == true, "non-number point count: warning");
|
||||
Check.Eq(warnings.Count, 2, "the warn callback heard both");
|
||||
}
|
||||
|
||||
private static void Truncated()
|
||||
{
|
||||
var warnings = new List<string>();
|
||||
var route = NavRouteParser.Load(Fixture("truncated.nav"), warnings.Add);
|
||||
Check.Eq(route.Points.Count, 1, "the whole first point is kept");
|
||||
Check.NotNull(route.LoadWarning, "warning set");
|
||||
Check.True(route.LoadWarning?.Contains("point 2") == true, "the warning names point 2");
|
||||
Check.Eq(warnings.Count, 1, "warned once");
|
||||
|
||||
// Cut inside a trailer (a portal missing its last three lines).
|
||||
var cut = NavRouteParser.LoadFromLines(new[]
|
||||
{ "uTank2 NAV 1.2", "4", "2", "0", "1", "2", "0", "0", "6", "1", "2", "0", "0", "Portal", "14", "True" });
|
||||
Check.Eq(cut.Points.Count, 1, "trailer cut: only the complete point is kept");
|
||||
Check.True(cut.LoadWarning?.Contains("point 2") == true, "trailer cut: warning names point 2");
|
||||
}
|
||||
|
||||
private static void BadNumber()
|
||||
{
|
||||
var route = NavRouteParser.LoadFromLines(new[]
|
||||
{
|
||||
"uTank2 NAV 1.2", "1", "3",
|
||||
"0", "1", "2", "0", "0",
|
||||
"0", "1", "north", "0", "0", // NS is not a number
|
||||
"0", "5", "6", "0", "0",
|
||||
});
|
||||
Check.Eq(route.Points.Count, 1, "stops at the bad point: the ones after it are not guessed");
|
||||
Check.True(route.LoadWarning?.Contains("parse error at point 2") == true, "warning names point 2");
|
||||
|
||||
var badRecall = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "4", "1", "2", "1", "2", "0", "0", "Lifestone Recall" });
|
||||
Check.Eq(badRecall.Points.Count, 0, "a recall with a spell name instead of an id is refused");
|
||||
Check.NotNull(badRecall.LoadWarning, "and warned");
|
||||
|
||||
var badType = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "4", "1", "point", "1", "2", "0", "0" });
|
||||
Check.Eq(badType.Points.Count, 0, "a non-number waypoint type is refused");
|
||||
Check.NotNull(badType.LoadWarning, "and warned");
|
||||
}
|
||||
|
||||
private static void UnreadableFile()
|
||||
{
|
||||
string dir = Scratch();
|
||||
string path = Path.Combine(dir, "locked.nav");
|
||||
File.WriteAllLines(path, new[] { "uTank2 NAV 1.2", "1", "0" });
|
||||
var warnings = new List<string>();
|
||||
NavRouteParser route;
|
||||
using (new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.None))
|
||||
route = NavRouteParser.Load(path, warnings.Add);
|
||||
Check.Eq(route.Points.Count, 0, "no points");
|
||||
Check.True(route.LoadWarning?.Contains("failed to read") == true, "warning says it could not be read");
|
||||
Check.Eq(warnings.Count, 1, "warned once");
|
||||
}
|
||||
|
||||
private static void PinnedOddities()
|
||||
{
|
||||
// The count says 5 but the file ends cleanly after 2 points: both load, no warning.
|
||||
var shortCount = NavRouteParser.LoadFromLines(new[]
|
||||
{ "uTank2 NAV 1.2", "1", "5", "0", "1", "2", "0", "0", "0", "3", "4", "0", "0" });
|
||||
Check.Eq(shortCount.Points.Count, 2, "short file: the points that are there load");
|
||||
Check.Null(shortCount.LoadWarning, "short file: no warning (pinned)");
|
||||
|
||||
// A negative count reads as an empty route, no warning.
|
||||
var negative = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "1", "-1", "0", "1", "2", "0", "0" });
|
||||
Check.Eq(negative.Points.Count, 0, "negative count: empty");
|
||||
Check.Null(negative.LoadWarning, "negative count: no warning (pinned)");
|
||||
|
||||
// Route types VTank never writes are kept as numbers, with no warning. The engine has
|
||||
// no case for them: it walks to the first point and stays there.
|
||||
var type5 = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "5", "1", "0", "1", "2", "0", "0" });
|
||||
Check.Eq((int)type5.RouteType, 5, "route type 5 kept as 5");
|
||||
Check.Null(type5.LoadWarning, "route type 5: no warning (pinned)");
|
||||
|
||||
// A comma decimal is read with the comma as a thousands separator: 33,6 becomes 336.
|
||||
var comma = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "1", "1", "0", "33,6", "42,5", "0", "0" });
|
||||
Check.Eq(comma.Points.Count, 1, "comma decimals: the point loads");
|
||||
if (comma.Points.Count == 1) Check.Near(comma.Points[0].EW, 336, 1e-9, "33,6 reads as 336 (pinned)");
|
||||
Check.Null(comma.LoadWarning, "comma decimals: no warning (pinned)");
|
||||
}
|
||||
}
|
||||
146
Tools/RynthCore.RynthAiTests/Tests/NavRouteParserTests.cs
Normal file
146
Tools/RynthCore.RynthAiTests/Tests/NavRouteParserTests.cs
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
using System.Collections.Generic;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiTests.Tests;
|
||||
|
||||
// Smoke tests for .nav route parsing (uTank2 NAV 1.2): each waypoint type's trailer lines,
|
||||
// EW-before-NS order, a write/read round trip, the metres-to-nav-units Z repair, Follow
|
||||
// routes, and stopping (not desyncing) on an unknown waypoint type.
|
||||
internal static class NavRouteParserTests
|
||||
{
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("nav: parses every waypoint type's trailer", ParsesEveryType);
|
||||
r.Add("nav: write then read gives the same route", RoundTrip);
|
||||
r.Add("nav: Z stored in metres is converted to nav units", MetresZRepair);
|
||||
r.Add("nav: Follow route names the leader, no points", FollowRoute);
|
||||
r.Add("nav: unknown waypoint type stops with a warning", UnknownTypeStops);
|
||||
}
|
||||
|
||||
// One point of each kind. Layout per point: type, EW, NS, Z, flag, then the trailer.
|
||||
private static List<string> SampleLines() => new()
|
||||
{
|
||||
"uTank2 NAV 1.2",
|
||||
"1", // Circular
|
||||
"8",
|
||||
// Point
|
||||
"0", "12.5", "-30.25", "0.1", "0",
|
||||
// Recall: spell id
|
||||
"2", "12.5", "-30.25", "0.1", "0", "48",
|
||||
// Pause: ms
|
||||
"3", "12.5", "-30.25", "0.1", "0", "2500",
|
||||
// Chat: command
|
||||
"4", "12.5", "-30.25", "0.1", "0", "/vt settings load hunt",
|
||||
// OpenVendor: id, name
|
||||
"5", "13", "-31", "0.1", "0", "2147483900", "Grocer Jon",
|
||||
// Portal: name, class, tie, EW, NS, Z of the portal object
|
||||
"6", "14", "-32", "0.2", "0", "Portal to Town Network", "14", "True", "14.01", "-32.02", "0.21",
|
||||
// Checkpoint: no trailer
|
||||
"8", "15", "-33", "0.3", "0",
|
||||
// Jump: heading, shift, ms
|
||||
"9", "16", "-34", "0.4", "0", "270", "True", "650",
|
||||
};
|
||||
|
||||
private static void ParsesEveryType()
|
||||
{
|
||||
var warnings = new List<string>();
|
||||
var route = NavRouteParser.LoadFromLines(SampleLines(), warnings.Add);
|
||||
|
||||
Check.Null(route.LoadWarning, "no load warning");
|
||||
Check.Eq(warnings.Count, 0, "warn callback not called");
|
||||
Check.Eq(route.RouteType, NavRouteType.Circular, "route type");
|
||||
Check.Eq(route.Points.Count, 8, "point count");
|
||||
if (route.Points.Count != 8) return;
|
||||
|
||||
var p = route.Points;
|
||||
Check.Eq(p[0].Type, NavPointType.Point, "[0] type");
|
||||
Check.Near(p[0].EW, 12.5, 1e-9, "[0] EW is the first coordinate line");
|
||||
Check.Near(p[0].NS, -30.25, 1e-9, "[0] NS is the second coordinate line");
|
||||
Check.Near(p[0].Z, 0.1, 1e-9, "[0] Z");
|
||||
|
||||
Check.Eq(p[1].Type, NavPointType.Recall, "[1] type");
|
||||
Check.Eq(p[1].SpellId, 48, "[1] recall spell id");
|
||||
Check.Eq(p[2].PauseTimeMs, 2500, "[2] pause ms");
|
||||
Check.Eq(p[3].ChatCommand, "/vt settings load hunt", "[3] chat command");
|
||||
Check.Eq(p[4].VendorId, 2147483900u, "[4] vendor id (above int.MaxValue)");
|
||||
Check.Eq(p[4].TargetName, "Grocer Jon", "[4] vendor name");
|
||||
|
||||
Check.Eq(p[5].Type, NavPointType.PortalNPC, "[5] type");
|
||||
Check.Eq(p[5].TargetName, "Portal to Town Network", "[5] portal name");
|
||||
Check.Eq(p[5].ObjectClass, 14, "[5] object class");
|
||||
Check.True(p[5].IsTie, "[5] tie flag");
|
||||
Check.Near(p[5].PortalExitEW, 14.01, 1e-9, "[5] portal object EW");
|
||||
Check.Near(p[5].PortalExitNS, -32.02, 1e-9, "[5] portal object NS");
|
||||
|
||||
Check.Eq(p[6].Type, NavPointType.Checkpoint, "[6] type");
|
||||
Check.True(NavRouteParser.IsPlainWaypoint(p[6].Type), "Checkpoint is walked like a Point");
|
||||
Check.False(NavRouteParser.IsPlainWaypoint(p[1].Type), "Recall is not a plain waypoint");
|
||||
|
||||
Check.Eq(p[7].Type, NavPointType.Jump, "[7] type");
|
||||
Check.Near(p[7].JumpHeading, 270, 1e-9, "[7] jump heading");
|
||||
Check.True(p[7].JumpShift, "[7] jump shift");
|
||||
Check.Near(p[7].JumpMs, 650, 1e-9, "[7] jump ms");
|
||||
}
|
||||
|
||||
private static void RoundTrip()
|
||||
{
|
||||
var first = NavRouteParser.LoadFromLines(SampleLines());
|
||||
var lines = first.ToLines();
|
||||
var second = NavRouteParser.LoadFromLines(lines);
|
||||
|
||||
Check.Null(second.LoadWarning, "re-read has no warning");
|
||||
Check.Eq(second.RouteType, first.RouteType, "route type survives");
|
||||
Check.Eq(second.Points.Count, first.Points.Count, "point count survives");
|
||||
for (int i = 0; i < first.Points.Count && i < second.Points.Count; i++)
|
||||
Check.Eq(second.Points[i].ToString(), first.Points[i].ToString(), $"point [{i}] survives");
|
||||
// The writer's output is stable: writing the re-read route gives the same lines.
|
||||
Check.Eq(string.Join("|", second.ToLines()), string.Join("|", lines), "second write matches the first");
|
||||
}
|
||||
|
||||
private static void MetresZRepair()
|
||||
{
|
||||
var route = NavRouteParser.LoadFromLines(new[]
|
||||
{
|
||||
"uTank2 NAV 1.2", "2", "2",
|
||||
"0", "1", "2", "120", "0", // 120 m: stored by the old UI in metres
|
||||
"0", "1", "2", "4.5", "0", // 4.5 nav units = 1080 m: kept as is
|
||||
});
|
||||
Check.Eq(route.RouteType, NavRouteType.Linear, "route type");
|
||||
Check.Eq(route.Points.Count, 2, "point count");
|
||||
if (route.Points.Count != 2) return;
|
||||
Check.Near(route.Points[0].Z, 0.5, 1e-9, "120 (metres) becomes 0.5 nav units");
|
||||
Check.Near(route.Points[1].Z, 4.5, 1e-9, "4.5 is already nav units");
|
||||
}
|
||||
|
||||
private static void FollowRoute()
|
||||
{
|
||||
var route = NavRouteParser.LoadFromLines(new[] { "uTank2 NAV 1.2", "3", "Some Leader", "1342177281" });
|
||||
Check.Eq(route.RouteType, NavRouteType.Follow, "route type");
|
||||
Check.Eq(route.FollowTargetName, "Some Leader", "leader name");
|
||||
Check.Eq(route.FollowTargetId, 1342177281u, "leader id");
|
||||
Check.Eq(route.Points.Count, 0, "no points");
|
||||
Check.Eq(string.Join("|", route.ToLines()), "uTank2 NAV 1.2|3|Some Leader|1342177281", "written back unchanged");
|
||||
}
|
||||
|
||||
private static void UnknownTypeStops()
|
||||
{
|
||||
var warnings = new List<string>();
|
||||
var route = NavRouteParser.LoadFromLines(new[]
|
||||
{
|
||||
"uTank2 NAV 1.2", "4", "3",
|
||||
"0", "1", "2", "0", "0",
|
||||
"1", "1", "2", "0", "0", // type 1: layout unknown, must not be guessed
|
||||
"0", "5", "6", "0", "0",
|
||||
}, warnings.Add);
|
||||
Check.Eq(route.RouteType, NavRouteType.Once, "route type");
|
||||
Check.Eq(route.Points.Count, 1, "only the point before the unknown one is kept");
|
||||
Check.NotNull(route.LoadWarning, "load warning set");
|
||||
Check.True(route.LoadWarning?.Contains("unknown waypoint type 1") == true, "warning names the type");
|
||||
Check.Eq(warnings.Count, 1, "warn callback called once");
|
||||
|
||||
var bad = NavRouteParser.LoadFromLines(new[] { "not a nav file", "1", "0" });
|
||||
Check.Eq(bad.Points.Count, 0, "wrong header: empty route");
|
||||
Check.Null(bad.LoadWarning, "wrong header: silently empty (no warning)");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue