AutoVendor: find a vendor by the server's vendor bitfield
The world cache never assigns AcObjectClass.Vendor, so a vendor was never found by name or id. Recognise a vendor by the server's BF_VENDOR bit (PublicWeenieDesc bitfield 0x200), or the cache class if one is ever set, and open the nearest match. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
parent
7166d256ce
commit
c999ff76d9
3 changed files with 119 additions and 2 deletions
|
|
@ -132,6 +132,7 @@ internal static class Program
|
|||
ServerPluginForwardTests.Register(runner);
|
||||
IgnoreMonsterTests.Register(runner);
|
||||
WorldCacheTypedTests.Register(runner);
|
||||
VendorFlagTests.Register(runner);
|
||||
NavOverlayTests.Register(runner);
|
||||
ActionPacingTests.Register(runner);
|
||||
HazardEscapeTests.Register(runner);
|
||||
|
|
|
|||
98
Tools/RynthCore.RynthAiHostTests/Tests/VendorFlagTests.cs
Normal file
98
Tools/RynthCore.RynthAiHostTests/Tests/VendorFlagTests.cs
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
using System;
|
||||
using System.Linq;
|
||||
using RynthCore.Loot;
|
||||
using RynthCore.Plugin.RynthAi;
|
||||
using RynthCore.Plugin.RynthAi.LegacyUi;
|
||||
using RynthCore.Plugin.RynthAi.Vendor;
|
||||
using RynthCore.RynthAiHostTests.Fakes;
|
||||
using RynthCore.RynthAiTests.Harness;
|
||||
|
||||
namespace RynthCore.RynthAiHostTests.Tests;
|
||||
|
||||
// /ub vendor open finds an object the server flags as a vendor (PublicWeenieDesc BF_VENDOR 0x200)
|
||||
// even when the world cache filed it as something else (a server-summoned vault NPC with 0/0 rates
|
||||
// reaches the cache as a typed item). Without the flag it is still not a vendor.
|
||||
internal static class VendorFlagTests
|
||||
{
|
||||
private const uint Player = 0x50000E01;
|
||||
private const uint Here = 0xA9B4001C;
|
||||
private const uint Flagged = 0x80310001;
|
||||
private const uint Plain = 0x80310002;
|
||||
private const uint BfVendor = 0x200;
|
||||
private const uint TGem = 0x800;
|
||||
private const string Attempt = "AutoVendor: attempting to open vendor";
|
||||
|
||||
public static void Register(Runner r)
|
||||
{
|
||||
r.Add("vendor open: a cache non-Vendor with the vendor bitfield is found by name", FoundByName);
|
||||
r.Add("vendor open: a cache non-Vendor with the vendor bitfield is found by id", FoundById);
|
||||
r.Add("vendor open: a cache non-Vendor without the vendor bitfield is not found", NotFlagged);
|
||||
r.Add("vendor open: a partial name finds the flagged object", FoundByPartial);
|
||||
}
|
||||
|
||||
private static AutoVendorManager Rig()
|
||||
{
|
||||
FakeHost.Reset();
|
||||
FakeHost.Names[Player] = "Vendor Tester";
|
||||
FakeHost.Positions[Player] = (Here, 96f, 96f, 0f);
|
||||
FakeHost.PlayerPose = (Here, 96f, 96f, 0f);
|
||||
FakeHost.Containers[Player] = 0;
|
||||
foreach (var (id, name) in new[] { (Flagged, "Vault Keeper"), (Plain, "Plain Gem") })
|
||||
{
|
||||
FakeHost.Names[id] = name;
|
||||
FakeHost.Positions[id] = (Here, 97f, 97f, 0f);
|
||||
FakeHost.ItemTypes[id] = TGem;
|
||||
FakeHost.Containers[id] = 0;
|
||||
FakeHost.NotAttackable.Add(id);
|
||||
}
|
||||
FakeHost.Bitfields[Flagged] = BfVendor;
|
||||
|
||||
var host = FakeHost.Create(Player);
|
||||
var cache = new WorldObjectCache(host);
|
||||
cache.SetPlayerId(Player);
|
||||
cache.OnCreateObject(Flagged);
|
||||
cache.OnCreateObject(Plain);
|
||||
for (int i = 0; i < 12; i++) cache.Tick();
|
||||
// Precondition: the cache really does file both as a non-Vendor.
|
||||
foreach (uint id in new[] { Flagged, Plain })
|
||||
Check.True(cache.AllKnownObjects().Any(w => w.Id == unchecked((int)id) && w.ObjectClass != AcObjectClass.Vendor),
|
||||
"precondition: cached as a non-Vendor");
|
||||
return new AutoVendorManager(host, new LegacyUiSettings(), cache, Player, () => string.Empty);
|
||||
}
|
||||
|
||||
private static bool Attempted() => FakeHost.Logs.Any(l => l.Contains(Attempt, StringComparison.Ordinal));
|
||||
|
||||
// The open attempt names the chosen object: "...attempting to open vendor <name>".
|
||||
private static bool Opened(string name) => FakeHost.Logs.Any(l => l.EndsWith(Attempt + " " + name, StringComparison.Ordinal));
|
||||
|
||||
private static void FoundByName()
|
||||
{
|
||||
var m = Rig();
|
||||
m.CommandOpen("Vault Keeper", false);
|
||||
Check.True(Opened("Vault Keeper"), "the flagged object is the one opened by name");
|
||||
}
|
||||
|
||||
private static void FoundById()
|
||||
{
|
||||
var m = Rig();
|
||||
m.CommandOpen("0x" + Flagged.ToString("X8"), false);
|
||||
Check.True(Opened("Vault Keeper"), "the flagged object is the one opened by hex id");
|
||||
}
|
||||
|
||||
private static void NotFlagged()
|
||||
{
|
||||
var m = Rig();
|
||||
m.CommandOpen("Plain Gem", false);
|
||||
Check.False(Attempted(), "an unflagged object is not opened by name");
|
||||
m.CommandOpen("0x" + Plain.ToString("X8"), false);
|
||||
Check.False(Attempted(), "an unflagged object is not opened by id");
|
||||
}
|
||||
|
||||
private static void FoundByPartial()
|
||||
{
|
||||
var m = Rig();
|
||||
m.CommandOpen("keeper", true);
|
||||
Check.True(Opened("Vault Keeper"), "a partial name opens the flagged object");
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in a new issue