feat(battle-engine M13): M3 spell emits PlayActions headless via OperateMgr -> NetworkBattleSender (O1 read = GO)
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
62
SVSim.BattleEngine.Tests/EmitPathReadOracleTests.cs
Normal file
62
SVSim.BattleEngine.Tests/EmitPathReadOracleTests.cs
Normal file
@@ -0,0 +1,62 @@
|
||||
using NUnit.Framework;
|
||||
using Wizard;
|
||||
using Wizard.Battle;
|
||||
|
||||
namespace SVSim.BattleEngine.Tests
|
||||
{
|
||||
// M13 (hub O1, deterministic): the first headless observation of the EMIT path. Drive the proven M3
|
||||
// fixed-damage spell (900124030) through mgr.OperateMgr.PlayCard on a NetworkBattleManagerBase-derived
|
||||
// mgr and confirm the engine reaches its emission path (RealTimeNetworkAgent.OnEmit fires PlayActions)
|
||||
// without crashing, while the committed state still matches the M3 direct-ActionProcessor oracle.
|
||||
// Liveness only (E4); structural frame decoding + the RNG rand-list (M14) are deferred.
|
||||
[TestFixture]
|
||||
public class EmitPathReadOracleTests
|
||||
{
|
||||
// Reset the process globals this fixture mutates so no later fixture inherits them:
|
||||
// - ToolboxGame.RealTimeNetworkAgent: the injected agent (the solo oracles don't read it, but
|
||||
// clearing it is defensive, mirroring RandomDrawOracleTests.ResetRandomDrawGate).
|
||||
// - BattleManagerBase.IsForecast: the network emit harness sets this FALSE (the emit path needs it);
|
||||
// every solo oracle and EnsureInitialized assume it TRUE. EnsureInitialized only sets it once
|
||||
// (guarded), so without restoring it here a solo fixture running after this one would see
|
||||
// IsForecast=false and un-suppressed VFX. Restore the EnsureInitialized default.
|
||||
[TearDown]
|
||||
public void ResetGlobals()
|
||||
{
|
||||
Wizard.ToolboxGame.SetRealTimeNetworkBattle(null);
|
||||
BattleManagerBase.IsForecast = true;
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void M3_spell_driven_via_OperateMgr_reaches_emit_without_crashing()
|
||||
{
|
||||
var (mgr, emitted) = HeadlessEngineEnv.NewNetworkEmitBattle();
|
||||
var player = mgr.BattlePlayer;
|
||||
var enemy = mgr.BattleEnemy;
|
||||
|
||||
int leaderLifeBefore = enemy.Class.Life;
|
||||
|
||||
var spell = HeadlessEngineEnv.CreateHeadlessHandCard(
|
||||
HeadlessEngineEnv.SpellId, index: 1, isPlayer: true, mgr);
|
||||
player.HandCardList.Add(spell);
|
||||
int cost = spell.Cost;
|
||||
player.Pp = 10;
|
||||
|
||||
Assert.DoesNotThrow(
|
||||
() => mgr.OperateMgr.PlayCard(spell, isPlayer: true, selectCards: null),
|
||||
"OperateMgr.PlayCard threw driving the M3 spell through the emit path");
|
||||
|
||||
Assert.Multiple(() =>
|
||||
{
|
||||
// Emit reached: OnEmit fired with PlayActions (the O1 liveness signal).
|
||||
Assert.That(emitted, Does.Contain(NetworkBattleDefine.NetworkBattleURI.PlayActions),
|
||||
"the engine did not reach a PlayActions emit");
|
||||
// State intact vs the M3 direct-path oracle.
|
||||
Assert.That(enemy.Class.Life, Is.EqualTo(leaderLifeBefore - 3), "enemy leader should take 3");
|
||||
Assert.That(player.Pp, Is.EqualTo(10 - cost), "PP should be paid");
|
||||
Assert.That(player.HandCardList, Does.Not.Contain(spell), "spell should leave the hand");
|
||||
Assert.That(player.CemeteryList, Does.Contain(spell), "spell should land in the cemetery");
|
||||
Assert.That(player.ClassAndInPlayCardList, Does.Not.Contain(spell), "a spell does not occupy the board");
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -216,6 +216,16 @@ namespace SVSim.BattleEngine.Tests
|
||||
new System.Collections.Generic.Dictionary<string, object> { ["fieldId"] = 1 },
|
||||
isWatchReplayRecovery: false);
|
||||
GameMgr.GetIns().SetNetworkUserInfoData(netUser);
|
||||
|
||||
// The network emit path's payload builder (RealTimeNetworkAgent.CreateEmitData) reads
|
||||
// Cute.Certification.Udid (RealTimeNetworkAgent.cs:1407). The Udid getter lazily decodes from
|
||||
// Toolbox.SavedataManager (Certification.cs:35), which is null headless. Seed the private static
|
||||
// backing field with a non-empty placeholder so the getter short-circuits before touching the
|
||||
// savedata manager. The value is opaque to the engine (it's just echoed into the emit dict).
|
||||
typeof(Cute.Certification)
|
||||
.GetField("udid", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.NonPublic)
|
||||
.SetValue(null, "headless-udid");
|
||||
|
||||
_done = true;
|
||||
}
|
||||
|
||||
@@ -353,8 +363,24 @@ namespace SVSim.BattleEngine.Tests
|
||||
{
|
||||
EnsureInitialized(); // sets IsForecast = true among other globals
|
||||
var mgr = new HeadlessNetworkBattleMgr(new HeadlessContentsCreator(), rng);
|
||||
mgr.IsRecovery = true; // collapse wait delays to 0 (F1)
|
||||
// NOTE: IsRecovery is left FALSE here (unlike the solo NewAuthoritativeBattle). The network
|
||||
// emit path is gated on !IsRecovery in BOTH places: NetworkStandardBattleMgr.SendPlayCard
|
||||
// (NetworkStandardBattleMgr.cs:155) and the OnSetCardComplete->SendPlayCard subscription in
|
||||
// SetUpNetworkOperateEvent (NetworkBattleManagerBase.cs:927, which early-returns under
|
||||
// IsRecovery). With IsRecovery=true the play would resolve state but never emit. (The solo
|
||||
// NewAuthoritativeBattle uses IsRecovery=true only to collapse VFX wait delays; here the no-op
|
||||
// view shims absorb the real view layer instead — see the IsForecast=false block below.)
|
||||
|
||||
// IsForecast MUST be false on the network emit path. BattleManagerBase.IsVirtualBattle is
|
||||
// `=> IsForecast` (BattleManagerBase.cs:657), and NetworkStandardBattleMgr.SendPlayCard is gated
|
||||
// on `!IsVirtualBattle` (NetworkStandardBattleMgr.cs:155) — under IsForecast=true the play
|
||||
// resolves state but the emit is suppressed. EnsureInitialized leaves IsForecast=true (correct
|
||||
// for the direct-ActionProcessor solo oracles, where it suppresses VFX); clear it here so the
|
||||
// genuine emit fires. The cost is that VFX registration is no longer short-circuited, so the
|
||||
// play exercises the real view layer — those view touches are satisfied by the no-op view shims
|
||||
// (InitCardTemplates, the HandView/DetailPanel fills below). M3's damage is literal, immune to
|
||||
// any play-count bump the OperateMgr path adds vs the direct path.
|
||||
BattleManagerBase.IsForecast = false;
|
||||
var player = mgr.BattlePlayer;
|
||||
var enemy = mgr.BattleEnemy;
|
||||
SetField(player, "_opponentBattlePlayer", enemy);
|
||||
@@ -364,6 +390,12 @@ namespace SVSim.BattleEngine.Tests
|
||||
|
||||
InitLeaderLife(mgr); // a 0-life leader reads as game-over and blocks plays
|
||||
InitCardTemplates(mgr); // play/draw VFX touches the card view layer
|
||||
// The OperateMgr emit path runs SetupActionProcessorEvent (skipped by the direct-ActionProcessor
|
||||
// solo oracles), which subscribes BattleMgr.DetailMgr.DetailPanelControl.UpdateCardDescriptionOnEvent
|
||||
// to OnPlayComplete (BattlePlayerBase.cs:1431). DetailMgr is created in CreateManager but its
|
||||
// DetailPanelControl (a UI control) is null headless. Seed the engine's own NullDetailPanelControl
|
||||
// no-op so the play-complete event resolves without touching the UI.
|
||||
mgr.DetailMgr.DetailPanelControl = new NullDetailPanelControl();
|
||||
|
||||
// Inject a headless RealTimeNetworkAgent so NetworkBattleSender's ToolboxGame.RealTimeNetworkAgent
|
||||
// .* calls resolve, and subscribe OnEmit. GetUninitializedObject skips the MonoBehaviour Awake.
|
||||
@@ -376,6 +408,25 @@ namespace SVSim.BattleEngine.Tests
|
||||
// public setter runs cleanly headless. Prepared (50) is the real enum member (RealTimeNetworkAgent.cs:35).
|
||||
agent.SetCurrentMatchingStatus(RealTimeNetworkAgent.MatchingStatus.Prepared);
|
||||
|
||||
// EmitMsgPack -> AddActionSequence (RealTimeNetworkAgent.cs:1773, fired for the PlayActions URI)
|
||||
// does `_gungnir._actionSequenceNum++` and `NetworkLogger.LogInfo(...)`. On the
|
||||
// GetUninitializedObject agent both are null (the real ctor builds them at :289/:301). Seed an
|
||||
// uninitialized Gungnir (its ctor news a ConnectionReporter + Ticks — unneeded; AddActionSequence
|
||||
// only touches the int counter) and the engine's own NetworkNullLogger no-op so the action-seq
|
||||
// bookkeeping runs without crashing. Neither drives game state.
|
||||
SetField(agent, "_gungnir",
|
||||
System.Runtime.Serialization.FormatterServices.GetUninitializedObject(typeof(Gungnir)));
|
||||
SetProperty(agent, "NetworkLogger", new NetworkNullLogger());
|
||||
|
||||
// Suppress the actual socket transmission. After OnEmit fires (RealTimeNetworkAgent.cs:1270, the
|
||||
// O1 liveness signal), EmitMsgPack -> EmitMsgUriPack reaches the stockEmitMessageMgr / _manager.Socket
|
||||
// network I/O (RealTimeNetworkAgent.cs:1444+/1487) — none of which exists headless. The engine's
|
||||
// OWN _notEmit flag (set in recovery/replay) short-circuits EmitMsgUriPack at :1438 BEFORE any of
|
||||
// that, so the emit stays genuine (OnEmit already fired through the real send path) while the
|
||||
// byte-push is skipped. This is the only honest way to terminate the path headless: we are NOT
|
||||
// faking OnEmit, only declining to open a socket we cannot open.
|
||||
SetField(agent, "_notEmit", true);
|
||||
|
||||
var emitted = new System.Collections.Generic.List<NetworkBattleDefine.NetworkBattleURI>();
|
||||
agent.OnEmit += uri => emitted.Add(uri);
|
||||
Wizard.ToolboxGame.SetRealTimeNetworkBattle(agent);
|
||||
@@ -393,6 +444,25 @@ namespace SVSim.BattleEngine.Tests
|
||||
$"{obj.GetType().Name} has no field '{name}'");
|
||||
f.SetValue(obj, value);
|
||||
}
|
||||
|
||||
// Set a property whose setter is non-public (e.g. RealTimeNetworkAgent.NetworkLogger has a
|
||||
// protected setter). Walks the type hierarchy because the declaring type may be a base class.
|
||||
private static void SetProperty(object obj, string name, object value)
|
||||
{
|
||||
var t = obj.GetType();
|
||||
System.Reflection.PropertyInfo p = null;
|
||||
while (t != null && p == null)
|
||||
{
|
||||
p = t.GetProperty(name,
|
||||
System.Reflection.BindingFlags.Instance |
|
||||
System.Reflection.BindingFlags.NonPublic |
|
||||
System.Reflection.BindingFlags.Public);
|
||||
t = t.BaseType;
|
||||
}
|
||||
if (p == null) throw new System.InvalidOperationException(
|
||||
$"{obj.GetType().Name} has no property '{name}'");
|
||||
p.SetValue(obj, value);
|
||||
}
|
||||
}
|
||||
|
||||
// Test-side replica of the engine's own StandardBattleMgrContentsCreator (the practice/solo
|
||||
|
||||
Reference in New Issue
Block a user