Materialize purchased ships in daemon state
This commit is contained in:
parent
8660d5062d
commit
c063ff63f4
3 changed files with 123 additions and 0 deletions
|
|
@ -8889,6 +8889,27 @@ static void RequireTradePurchaseRequestAuthority(string root)
|
|||
string.Join(", ", unityTradeAcceptanceHits));
|
||||
}
|
||||
|
||||
var daemonOperationsPath = Path.Combine(root, "Packages", "org.gamecult.aetheria.state", "Runtime", "AetheriaRuntimeDaemonOperations.cs");
|
||||
var daemonOperations = File.Exists(daemonOperationsPath)
|
||||
? File.ReadAllText(daemonOperationsPath)
|
||||
: throw new InvalidOperationException("Cannot verify trade purchase authority; daemon operations are missing.");
|
||||
var requiredDaemonShipPurchaseSymbols = new[]
|
||||
{
|
||||
"ApplyCreateDockedShipPurchase(",
|
||||
"purchase.CreatesDockedShip",
|
||||
"run.CurrentEntityKey = purchasedShipKey",
|
||||
"HullItemKey = itemKey"
|
||||
};
|
||||
var missingDaemonShipPurchaseSymbols = requiredDaemonShipPurchaseSymbols
|
||||
.Where(symbol => !daemonOperations.Contains(symbol, StringComparison.Ordinal))
|
||||
.ToArray();
|
||||
if (missingDaemonShipPurchaseSymbols.Length > 0)
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"Daemon trade purchase no longer materializes purchased docked ships as typed run state: " +
|
||||
string.Join(", ", missingDaemonShipPurchaseSymbols));
|
||||
}
|
||||
|
||||
var tradeMenuPath = Path.Combine(root, "Assets", "Scripts", "UI", "Menu", "TradeMenu.cs");
|
||||
var tradeMenu = File.Exists(tradeMenuPath)
|
||||
? File.ReadAllText(tradeMenuPath)
|
||||
|
|
|
|||
|
|
@ -1927,6 +1927,40 @@ public class DaemonRuntimeDocumentTests
|
|||
Assert.AreEqual(5, targetCargo[0].Item.Quantity);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsCreatesPurchasedDockedShipInDaemonState()
|
||||
{
|
||||
var run = RunWithTwoEntities();
|
||||
var command = AetheriaRuntimeDaemonCommandDocument.Create(
|
||||
AetheriaRuntimeDaemonCommandKinds.TradePurchase,
|
||||
"codex",
|
||||
"session-trade",
|
||||
31,
|
||||
"zone.0.entity.0");
|
||||
command.TargetEntityKey = "zone.0.entity.1";
|
||||
command.TextValue = "starter-hull";
|
||||
command.ScalarValue = 300;
|
||||
command.TradePurchase.PurchaseKind = "docked_ship";
|
||||
command.TradePurchase.ItemKey = "starter-hull";
|
||||
command.TradePurchase.Quantity = 1;
|
||||
command.TradePurchase.UnitPrice = 300;
|
||||
command.TradePurchase.TotalPrice = 300;
|
||||
command.TradePurchase.TargetEntityKey = "zone.0.entity.1";
|
||||
command.TradePurchase.CreatesDockedShip = true;
|
||||
|
||||
var result = AetheriaRuntimeDaemonOperations.Execute(run, new[] { command });
|
||||
|
||||
var zone = run.Zones[0];
|
||||
Assert.AreEqual(1, result.AppliedCommandIds.Count);
|
||||
Assert.AreEqual(700, run.Credits);
|
||||
Assert.AreEqual(3, zone.Entities.Count);
|
||||
Assert.AreEqual("ship", zone.Entities[2].Kind);
|
||||
Assert.AreEqual("starter-hull", zone.Entities[2].HullItemKey);
|
||||
CollectionAssert.Contains(zone.Entities[1].ChildEntityIndices, 2);
|
||||
CollectionAssert.Contains(zone.Entities[1].DockingBayAssignments, 2);
|
||||
Assert.AreEqual("global:aetheria.run_state.daemon-command-apply-run.zone.0.entity.2.v1", run.CurrentEntityKey);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void DaemonOperationsRestoresLoadoutIntoDaemonState()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -809,6 +809,10 @@ namespace GameCult.Aetheria.State.Verse
|
|||
|
||||
if (purchase.CreatesDockedShip)
|
||||
{
|
||||
if (!ApplyCreateDockedShipPurchase(run, purchase, out var purchasedShipKey))
|
||||
return false;
|
||||
|
||||
run.CurrentEntityKey = purchasedShipKey;
|
||||
run.Credits -= totalPrice;
|
||||
return true;
|
||||
}
|
||||
|
|
@ -852,6 +856,70 @@ namespace GameCult.Aetheria.State.Verse
|
|||
return true;
|
||||
}
|
||||
|
||||
private static bool ApplyCreateDockedShipPurchase(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeTradePurchaseCommand purchase,
|
||||
out string purchasedShipKey)
|
||||
{
|
||||
purchasedShipKey = "";
|
||||
var itemKey = purchase.ItemKey ?? "";
|
||||
if (string.IsNullOrWhiteSpace(itemKey) ||
|
||||
!TryResolveEntity(run, purchase.TargetEntityKey, out var zoneIndex, out var parentIndex, out var parent))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var zones = (run.Zones ?? Array.Empty<AetheriaRuntimeZoneSnapshotCommit>()).ToArray();
|
||||
var zone = zones.FirstOrDefault(candidate => candidate != null && candidate.ZoneIndex == zoneIndex);
|
||||
if (zone == null)
|
||||
return false;
|
||||
|
||||
var entities = (zone.Entities ?? Array.Empty<AetheriaRuntimeEntitySnapshotCommit>()).ToList();
|
||||
var entityIndex = entities.Count;
|
||||
var ship = new AetheriaRuntimeEntitySnapshotCommit
|
||||
{
|
||||
EntityIndex = entityIndex,
|
||||
Name = string.IsNullOrWhiteSpace(itemKey) ? "Purchased Ship" : itemKey,
|
||||
Kind = "ship",
|
||||
HullItemKey = itemKey,
|
||||
DirectionX = parent.DirectionX,
|
||||
DirectionY = parent.DirectionY,
|
||||
PositionX = parent.PositionX,
|
||||
PositionY = parent.PositionY,
|
||||
PositionZ = parent.PositionZ,
|
||||
IsActive = true,
|
||||
TargetEntityIndex = -1,
|
||||
ShutdownPerformance = 0.25
|
||||
};
|
||||
entities.Add(ship);
|
||||
zone.Entities = entities.ToArray();
|
||||
run.Zones = zones;
|
||||
|
||||
var childIndices = (parent.ChildEntityIndices ?? Array.Empty<int>()).ToList();
|
||||
if (!childIndices.Contains(entityIndex))
|
||||
childIndices.Add(entityIndex);
|
||||
parent.ChildEntityIndices = childIndices.ToArray();
|
||||
|
||||
var assignments = (parent.DockingBayAssignments ?? Array.Empty<int>()).ToList();
|
||||
var assigned = false;
|
||||
for (var index = 0; index < assignments.Count; index++)
|
||||
{
|
||||
if (assignments[index] >= 0)
|
||||
continue;
|
||||
|
||||
assignments[index] = entityIndex;
|
||||
assigned = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if (!assigned)
|
||||
assignments.Add(entityIndex);
|
||||
parent.DockingBayAssignments = assignments.ToArray();
|
||||
|
||||
purchasedShipKey = BuildEntityKey(run.RunId, zoneIndex, entityIndex);
|
||||
return true;
|
||||
}
|
||||
|
||||
private static bool ApplyRestoreLoadout(
|
||||
AetheriaRuntimeRunCheckpointCommit run,
|
||||
AetheriaRuntimeDaemonCommandDocument command,
|
||||
|
|
|
|||
Loading…
Reference in a new issue