254 lines
13 KiB
C#
254 lines
13 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Reflection;
|
|
using System.Runtime.CompilerServices;
|
|
using RynthCore.Plugin.RynthAi;
|
|
using RynthCore.Plugin.RynthAi.LegacyUi;
|
|
using RynthCore.Plugin.RynthAi.Meta;
|
|
using RynthCore.PluginCore;
|
|
using RynthCore.PluginSdk;
|
|
using RynthCore.RynthAiHostTests.Fakes;
|
|
using RynthCore.RynthAiTests.Harness;
|
|
using C = RynthCore.Plugin.RynthAi.LegacyUi.MetaConditionType;
|
|
using A = RynthCore.Plugin.RynthAi.LegacyUi.MetaActionType;
|
|
|
|
namespace RynthCore.RynthAiHostTests.Tests;
|
|
|
|
// The 2026-12-01 command audit, wave 2: /vt verbs and VTank options that were accepted but did
|
|
// nothing, or the wrong thing. Each line runs as a meta's chat command.
|
|
internal static class MetaCommandAuditTests
|
|
{
|
|
private const uint Player = 0x50000A71;
|
|
|
|
public static void Register(Runner r)
|
|
{
|
|
r.Add("meta action (12-01 audit 2): /vt settings load|save, /vt meta save, /vt loot save go to RynthAi's profile verbs", ProfileVerbs);
|
|
r.Add("meta action (12-01 audit 2): VTank options with a RynthAi setting set it (LootOnlyRareCorpses, TargetSelectMethod, ...)", VtOptions);
|
|
r.Add("ub opt / mt opt (12-01 audit 2): UtilityBelt and Mag-Tools option names with a RynthAi setting set it", UbMtOptions);
|
|
r.Add("mt attack_melee (12-01 audit 2): melee mode first, then one attack on the selected or closest monster", MtAttackMelee);
|
|
}
|
|
|
|
private sealed class Rig
|
|
{
|
|
public readonly LegacyUiSettings S = new() { IsMacroRunning = true, EnableMeta = true, CurrentState = "Default" };
|
|
public readonly MetaManager M;
|
|
public readonly List<string> Ra = new();
|
|
|
|
public Rig()
|
|
{
|
|
FakeHost.Reset();
|
|
M = new MetaManager(S, FakeHost.Create(), new PlayerVitalsCache());
|
|
M.SetPlayerId(Player);
|
|
M.SetRaCommandHandler(Ra.Add);
|
|
}
|
|
|
|
/// <summary>Runs <paramref name="line"/> as a meta's chat command (one rule, one tick).</summary>
|
|
public void Run(string line)
|
|
{
|
|
S.MetaRules = new List<MetaRule> { new() { State = S.CurrentState, Condition = C.Always, Action = A.ChatCommand, ActionData = line } };
|
|
S.ForceStateReset = true;
|
|
M.Think();
|
|
}
|
|
}
|
|
|
|
private static void ProfileVerbs()
|
|
{
|
|
var rig = new Rig();
|
|
// VTank's shared settings profiles are RynthAi's character profiles (it has no other kind).
|
|
rig.Run("/vt settings load Hunting");
|
|
Check.True(rig.Ra.Contains("/ra settings loadchar Hunting"), "/vt settings load -> /ra settings loadchar");
|
|
rig.Run("/vt settings save After Buffs");
|
|
Check.True(rig.Ra.Contains("/ra settings savechar After Buffs"), "/vt settings save -> /ra settings savechar, spaces kept");
|
|
rig.Run("/vt settings loadchar Banes");
|
|
Check.True(rig.Ra.Contains("/ra settings loadchar Banes"), "loadchar as before");
|
|
int before = rig.Ra.Count;
|
|
rig.Run("/vt settings banana Hunting");
|
|
Check.Eq(rig.Ra.Count, before, "another settings verb is still ignored");
|
|
|
|
rig.Run("/vt meta save My Meta");
|
|
Check.True(rig.Ra.Contains("/ra meta saveas My Meta"), "/vt meta save -> /ra meta saveas");
|
|
|
|
rig.S.CurrentLootPath = @"X:\RynthAi\LootProfiles\Main Loot.utl";
|
|
rig.Run("/vt loot save Copy Of Loot");
|
|
Check.True(rig.Ra.Contains("/ra loot saveas Copy Of Loot"), "/vt loot save -> /ra loot saveas (a copy, then looted with)");
|
|
before = rig.Ra.Count;
|
|
rig.Run("/vt loot save main loot");
|
|
Check.Eq(rig.Ra.Count, before, "the loot profile in use's own name: nothing to copy");
|
|
Check.True(FakeHost.Logs.Any(l => l.Contains("Main Loot.utl is the loot profile in use")), "said (in the log, a meta's line)");
|
|
rig.Run("/vt loot save Main Loot.utl");
|
|
Check.Eq(rig.Ra.Count, before, "with the extension too");
|
|
|
|
Check.True(MetaManager.VtUsageFor("/vt meta").Contains("load|save"), "the usage names save");
|
|
}
|
|
|
|
private static void VtOptions()
|
|
{
|
|
var rig = new Rig();
|
|
var s = rig.S;
|
|
s.MineOnly = false;
|
|
rig.Run("/vt opt set LootOnlyRareCorpses true");
|
|
Check.True(s.LootOnlyRareCorpses, "LootOnlyRareCorpses is RynthAi's Loot Only Rare Corpses");
|
|
Check.False(s.MineOnly, "not MineOnly, which nothing reads");
|
|
rig.Run("/vt opt set lootonlyrarecorpses false");
|
|
Check.False(s.LootOnlyRareCorpses, "and off");
|
|
|
|
rig.Run("/vt opt set CorpeApproachRange-Min 0.0125");
|
|
Check.Near(s.CorpseApproachRangeMin, 3, 1e-3, "VTank's misspelt CorpeApproachRange-Min: landblock units to 3 yd");
|
|
rig.Run("/vt opt set BlacklistMonsterAttemptCount 6");
|
|
Check.Eq(s.BlacklistAttempts, 6, "BlacklistMonsterAttemptCount -> BlacklistAttempts");
|
|
s.ManaTapMacroOff = true;
|
|
rig.Run("/vt opt set ManaChargesWhenOff false");
|
|
Check.False(s.ManaTapMacroOff, "ManaChargesWhenOff -> mana tapping with the macro off");
|
|
rig.Run("/vt opt set ManaTankMinimumMana 4000");
|
|
Check.Eq(s.ManaTapMinMana, 4000, "ManaTankMinimumMana -> ManaTapMinMana");
|
|
rig.Run("/vt opt set Recharge-Helper-Stam 35");
|
|
Check.Eq(s.RestamOthersAt, 35, "Recharge-Helper-Stam -> Re-stam Others");
|
|
rig.Run("/vt opt set Recharge-Helper-Mana 25");
|
|
Check.Eq(s.InfuseOthersAt, 25, "Recharge-Helper-Mana -> Infuse Others");
|
|
rig.Run("/vt opt set Recharge-Helper-HitP 45");
|
|
Check.Eq(s.HealOthersAt, 45, "Recharge-Helper-HitP -> Heal Others");
|
|
|
|
// TargetSelectMethod: 1 range = Closest, 2 angle = Least turning, 3 both: no RynthAi mode, kept.
|
|
s.TargetSelection = 0;
|
|
rig.Run("/vt opt set TargetSelectMethod 1");
|
|
Check.Eq(s.TargetSelection, 1, "1 (range) -> Closest");
|
|
rig.Run("/vt opt set TargetSelectMethod 2");
|
|
Check.Eq(s.TargetSelection, 3, "2 (angle) -> Least turning");
|
|
rig.Run("/vt opt set TargetSelectMethod 3");
|
|
Check.Eq(s.TargetSelection, 3, "3 (both) leaves Targeting as it is");
|
|
s.TargetSelection = 0;
|
|
FakeHost.Chat.Clear();
|
|
rig.M.TryHandleVtCommand("/vt opt get TargetSelectMethod");
|
|
Check.True(FakeHost.Chat.Any(c => c.Contains("TargetSelectMethod = 3")), "with no VTank mode in use it reads back as set");
|
|
|
|
// DebuffEachFirst: 3 All = debuff every monster first, 1 One = off, 2 Priority: kept.
|
|
rig.Run("/vt opt set DebuffEachFirst 3");
|
|
Check.True(s.DebuffAllBeforeAttacking, "3 (all) -> Debuff every monster in range before attacking");
|
|
rig.Run("/vt opt set DebuffEachFirst 1");
|
|
Check.False(s.DebuffAllBeforeAttacking, "1 (one) -> off");
|
|
rig.Run("/vt opt set DebuffEachFirst 2");
|
|
Check.False(s.DebuffAllBeforeAttacking, "2 (priority) leaves it as it is");
|
|
|
|
// One that stays only stored: NavFarStopRange (VTank stops nav; RynthAi detours back instead).
|
|
float offTrack = s.NavOffTrackYards;
|
|
rig.Run("/vt opt set NavFarStopRange 0.5");
|
|
Check.Eq(s.NavOffTrackYards, offTrack, "NavFarStopRange doesn't touch the off-track detour distance");
|
|
}
|
|
|
|
private const BindingFlags Any = BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public;
|
|
|
|
private static void UbMtOptions()
|
|
{
|
|
FakeHost.Reset();
|
|
var p = new RynthAiPlugin();
|
|
var s = new LegacyUiSettings();
|
|
var host = FakeHost.Create(playerId: Player);
|
|
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);
|
|
void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(p, v);
|
|
Set("_dashboard", dash);
|
|
var m = new MetaManager(s, host, new PlayerVitalsCache());
|
|
Set("_metaManager", m);
|
|
Set("_playerId", Player);
|
|
Set("_initialized", true);
|
|
Set("_loginComplete", true);
|
|
bool Ub(string line) => (bool)typeof(RynthAiPlugin).GetMethod("HandleUbCommand", Any)!.Invoke(p, new object[] { line })!;
|
|
bool Mt(string line) => (bool)typeof(RynthAiPlugin).GetMethod("HandleMtCommand", Any)!.Invoke(p, new object[] { line })!;
|
|
|
|
s.EnableAutocram = false;
|
|
Check.True(Ub("/ub opt set InventoryManager.AutoCram true"), "/ub opt set InventoryManager.AutoCram");
|
|
Check.True(s.EnableAutocram, "-> RynthAi's autocram");
|
|
s.EnableAutostack = true;
|
|
Ub("/ub opt toggle InventoryManager.AutoStack");
|
|
Check.False(s.EnableAutostack, "/ub opt toggle takes UtilityBelt's name too");
|
|
|
|
s.AutoVendorEnabled = false;
|
|
Mt("/mt opt set AutoBuySell.Enabled true");
|
|
Check.True(s.AutoVendorEnabled, "Mag-Tools AutoBuySell.Enabled -> AutoVendor");
|
|
s.LootChestsMacroOff = true;
|
|
Mt("/mt opt set Looting.AutoLootChests false");
|
|
Check.False(s.LootChestsMacroOff, "Looting.AutoLootChests -> Pickup with macro off");
|
|
s.LootOwnCorpse = true;
|
|
Mt("/mt opt set Looting.AutoLootMyCorpse false");
|
|
Check.False(s.LootOwnCorpse, "Looting.AutoLootMyCorpse -> Loot own corpse");
|
|
Mt("/mt opt set InventoryManagement.AetheriaRevealer true");
|
|
Check.True(s.UnboxAetheriaWhenIdle, "AetheriaRevealer -> Unbox Aetheria When Idle");
|
|
s.AutoConfirmCraft = false;
|
|
s.AutoConfirmCraftPercent = 80;
|
|
Mt("/mt opt set Tinkering.AutoClickYes true");
|
|
Check.True(s.AutoConfirmCraft && s.AutoConfirmCraftPercent == 100, "Tinkering.AutoClickYes -> Auto-confirm crafting at 100%");
|
|
FakeHost.Chat.Clear();
|
|
Mt("/mt opt get Tinkering.AutoClickYes");
|
|
Check.True(FakeHost.Chat.Any(c => c.Contains("Tinkering.AutoClickYes = 1")), "reads back");
|
|
Mt("/mt opt set Tinkering.AutoClickYes false");
|
|
Check.False(s.AutoConfirmCraft, "and off");
|
|
|
|
// Store-only names are still kept for metas, and say so.
|
|
FakeHost.Chat.Clear();
|
|
Mt("/mt opt set InventoryManagement.KeyRinger true");
|
|
Check.True(FakeHost.Chat.Any(c => c.Contains("kept only for metas to read")), "KeyRinger: no RynthAi setting, kept");
|
|
}
|
|
|
|
private const uint Lb = 0xA9B40000, NearMob = 0x80000771, FarMob = 0x80000772;
|
|
|
|
private static void MtAttackMelee()
|
|
{
|
|
FakeHost.Reset();
|
|
FakeHost.WeaponCalls = FakeHost.CombatModeCalls = FakeHost.AttackSendCalls = true;
|
|
FakeHost.Names[Player] = "Attacker";
|
|
FakeHost.PlayerIdValue = Player;
|
|
FakeHost.PlayerPose = (Lb | 0x1C, 96f, 96f, 0f);
|
|
FakeHost.Positions[Player] = (Lb | 0x1C, 96f, 96f, 0f);
|
|
foreach (var (id, name, y) in new[] { (NearMob, "Drudge Skulker", 98f), (FarMob, "Drudge Ravener", 110f) })
|
|
{
|
|
FakeHost.Names[id] = name;
|
|
FakeHost.Positions[id] = (Lb | 0x1C, 96f, y, 0f);
|
|
FakeHost.ItemTypes[id] = 0x10;
|
|
}
|
|
var p = new RynthAiPlugin();
|
|
var s = new LegacyUiSettings { MeleeAttackHeight = 2, MeleeAttackPower = 60 };
|
|
var host = FakeHost.Create(playerId: Player);
|
|
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);
|
|
void Set(string f, object? v) => typeof(RynthAiPlugin).GetField(f, Any)!.SetValue(p, v);
|
|
Set("_dashboard", dash);
|
|
var cache = new WorldObjectCache(host);
|
|
cache.SetPlayerId(Player);
|
|
cache.Tick();
|
|
foreach (uint id in new[] { NearMob, FarMob }) _ = cache[unchecked((int)id)];
|
|
Set("_objectCache", cache);
|
|
Set("_playerId", Player);
|
|
Set("_initialized", true);
|
|
Set("_loginComplete", true);
|
|
bool Mt(string line) => (bool)typeof(RynthAiPlugin).GetMethod("HandleMtCommand", Any)!.Invoke(p, new object[] { line })!;
|
|
|
|
// Peace mode: the first call goes to melee mode and attacks nothing.
|
|
FakeHost.CombatModeValue = 1;
|
|
Check.True(Mt("/mt attack_melee"), "/mt attack_melee is handled (it was unknown)");
|
|
Check.True(FakeHost.CombatModeRequests.Contains(2), "out of melee mode: melee mode first");
|
|
Check.Eq(FakeHost.AttackCalls.Count, 0, "no attack yet");
|
|
|
|
// Melee mode, nothing selected: the closest monster, once, at the settings' height and power.
|
|
FakeHost.CombatModeValue = 2;
|
|
Mt("/mt attack_melee");
|
|
Check.Eq(FakeHost.AttackCalls.Count, 1, "one attack");
|
|
Check.Eq(FakeHost.AttackCalls[0].Target, NearMob, "on the closest monster");
|
|
Check.Eq(FakeHost.AttackCalls[0].Height, 1, "High (RynthAi 2) is AC's height 1");
|
|
Check.Near(FakeHost.AttackCalls[0].Power, 0.6, 1e-3, "at the melee attack power");
|
|
|
|
// A selected monster is attacked, unless "closest" is given.
|
|
FakeHost.SelectedItem = FarMob;
|
|
Mt("/mt attack_melee");
|
|
Check.Eq(FakeHost.AttackCalls[^1].Target, FarMob, "the selected monster");
|
|
Mt("/mt attack_melee closest");
|
|
Check.Eq(FakeHost.AttackCalls[^1].Target, NearMob, "closest: the closest one, whatever is selected");
|
|
|
|
Check.True(Mt("/mt attack_melee banana"), "a wrong word is handled");
|
|
Check.True(FakeHost.Chat.Any(c => c.Contains("Usage: /mt attack_melee")), "with the usage");
|
|
}
|
|
}
|