From 0c9ab54048cfcc16cf5850c7935676d30de6e1b6 Mon Sep 17 00:00:00 2001 From: soul Date: Fri, 20 Nov 2026 01:14:15 +0100 Subject: [PATCH] Fix Soul s1: boss presets refused, refusal restores the item stream, anchor must be the player ship, drop the dead stocking-order claim Nothing at admission or activation reads cargo (ammunition is read at fire time), so the comment's ordering rule is removed. Co-Authored-By: Claude Sonnet 5.5 --- Assets/Scripts/ServerShared/ScenarioStage.cs | 37 +++++++++--- tests/Aetheria.Shared.Tests/ScenarioTests.cs | 62 ++++++++++++++++++++ 2 files changed, 91 insertions(+), 8 deletions(-) diff --git a/Assets/Scripts/ServerShared/ScenarioStage.cs b/Assets/Scripts/ServerShared/ScenarioStage.cs index 46996d482..ed13ae27b 100644 --- a/Assets/Scripts/ServerShared/ScenarioStage.cs +++ b/Assets/Scripts/ServerShared/ScenarioStage.cs @@ -108,9 +108,18 @@ public class ZoneStage public ScenarioFit Preset(string name) { var preset = _items.ItemData.GetAll().FirstOrDefault(loadout => loadout.Name == name); - if (preset != null) return new ScenarioFit(preset); - _failures.Add($"preset {name}: no such preset"); - return null; + if (preset == null) + { + _failures.Add($"preset {name}: no such preset"); + return null; + } + // A faction's boss is the zone generator's to place (boss-hulls-exclusive): Loadouts.BossOf owns which loadout it is. + if (_items.ItemData.GetAll().Any(faction => Loadouts.BossOf(_items.ItemData, faction, out _)?.Name == preset.Name)) + { + _failures.Add($"preset {name}: a faction's boss loadout is placed only by the zone generator"); + return null; + } + return new ScenarioFit(preset); } // Anything else in the arena. A stance holds both ways between it and the player. A piloted ship gets the zone's @@ -192,19 +201,30 @@ public class ZoneStage // Places ships into a running zone through the admission a run start uses: the script places with the stage's verbs, // and the entities join with their stance toward the player, a pilot when piloted and the knowledge the script stated. - // Returns the placed entities in order, or null with every failure listed and the zone unchanged. It draws from the - // live item stream and does not reseed (a reseed would give every summon the same fits). + // Returns the placed entities in order, or null with every failure listed and the zone and the item stream unchanged. + // It draws from the live item stream and does not reseed (a reseed would give every summon the same fits). The anchor + // is the player's ship: the stance is written against it. public static IReadOnlyList Summon(ItemManager items, Zone zone, Ship player, Action script, List failures) { + if (player == null || !player.IsPlayerShip) + { + failures.Add("summon: the anchor is not the player's ship"); + return null; + } if (!zone.Entities.Contains(player)) { failures.Add("summon: the player is not in this zone"); return null; } + var stream = items.Random; var stage = new ZoneStage(items, zone); script(stage); failures.AddRange(stage._failures); - if (stage._failures.Count > 0) return null; + if (stage._failures.Count > 0) + { + items.Random = stream; // a refusal draws nothing: the fits it built are discarded with it + return null; + } stage.StockUnauthoredAmmunition(); stage.AdmitPlaced(player); return stage._placed.Select(placed => placed.Entity).ToList(); @@ -284,8 +304,9 @@ public sealed class ScenarioStage : ZoneStage return null; } - // Run start's admission, in this order: stock unauthored ammunition (Activate reads cargo-driven behaviours, so it - // comes before admission), the player, then everything placed. + // Run start's admission: stock unauthored ammunition, the player, then everything placed. Nothing at admission or + // activation reads cargo (ammunition is read when a weapon fires), so stocking is not ordered by admission; it keeps + // the run start's order. internal void Admit() { StockUnauthoredAmmunition(); diff --git a/tests/Aetheria.Shared.Tests/ScenarioTests.cs b/tests/Aetheria.Shared.Tests/ScenarioTests.cs index 69135d879..74df3f8eb 100644 --- a/tests/Aetheria.Shared.Tests/ScenarioTests.cs +++ b/tests/Aetheria.Shared.Tests/ScenarioTests.cs @@ -469,6 +469,68 @@ public sealed partial class RunStartTests SafeAssert.Unchanged(zone, entities, agents); } + // A refused summon leaves the item stream where it was, so a refusal is not a draw: the next fit is the one it would have been. + // Kills: a summon that keeps the draws of the fits it built before refusing. + [Fact] + public void ARefusedSummonLeavesTheItemStream() + { + var zone = Arena(true); + var player = Stage(zone, new Scripted(true, stage => stage.Player(stage.Bare("Djinni"), float2(0, 0)))).Player; + var before = _items.Random; + var failures = new List(); + + Assert.Null(ZoneStage.Summon(_items, zone, player, stage => + { + stage.Place(stage.Generated("Longinus"), float2(400, 0)); + stage.Place(stage.Bare("No Such Hull"), float2(-400, 0)); + }, failures)); + + var after = _items.Random; + Assert.Equal(before.NextUInt(), after.NextUInt()); + } + + // The anchor of a summon is the player's ship, not any ship in the zone. Kills: a summon that takes any zone member as the player. + [Fact] + public void ASummonNeedsThePlayersShipAsItsAnchor() + { + var zone = Arena(true); + var player = Stage(zone, new Scripted(true, stage => stage.Player(stage.Bare("Djinni"), float2(0, 0)))).Player; + var other = zone.Entities.OfType().First(ship => !ship.IsPlayerShip); + var entities = zone.Entities.ToList(); + var agents = zone.Agents.ToList(); + var failures = new List(); + + Assert.Null(ZoneStage.Summon(_items, zone, other, stage => stage.Place(stage.Bare("Longinus"), float2(400, 0), stance: ScenarioStance.Hostile), failures)); + + Assert.Equal(new[] { "summon: the anchor is not the player's ship" }, failures); + SafeAssert.Unchanged(zone, entities, agents); + } + + // A faction's boss is the zone generator's to place (boss-hulls-exclusive): a preset naming the loadout Loadouts.BossOf + // returns is refused, through a summon as through a run start. Kills: a Preset that places any catalog loadout. + [Fact] + public void APresetCannotPlaceAFactionsBoss() + { + var zone = Arena(true); + var player = Stage(zone, new Scripted(true, stage => stage.Player(stage.Bare("Djinni"), float2(0, 0)))).Player; + var boss = _cache.GetAll().Select(faction => Loadouts.BossOf(_cache, faction, out _)).First(loadout => loadout != null); + var entities = zone.Entities.ToList(); + var agents = zone.Agents.ToList(); + var failures = new List(); + + Assert.Null(ZoneStage.Summon(_items, zone, player, stage => + stage.Place(stage.Preset(boss.Name), float2(400, 0), stance: ScenarioStance.Hostile, piloted: true), failures)); + + Assert.Contains(failures, failure => failure.Contains(boss.Name) && failure.Contains("boss")); + SafeAssert.Unchanged(zone, entities, agents); + var started = Refused(Arena(true), new Scripted(true, stage => + { + stage.Player(stage.Bare("Djinni"), float2(0, 0)); + stage.Place(stage.Preset(boss.Name), float2(400, 0)); + })); + Assert.Contains(started, failure => failure.Contains("boss")); + } + // A stance lasts the sitting: the player docking and undocking leaves it standing both ways. It goes with an entity // gone for good: once an entity is destroyed, the player holds no stance toward it. [Fact]