public virtual StartConditions CreateStartConditions(SuperMetroidModel model, ItemContainer itemContainer) { if (!model.Rooms.TryGetValue(itemContainer.StartingRoomName, out Room startingRoom)) { throw new Exception($"Starting room '{itemContainer.StartingRoomName}' not found."); } if (!startingRoom.Nodes.TryGetValue(itemContainer.StartingNodeId, out RoomNode startingNode)) { throw new Exception($"Starting node ID {itemContainer.StartingNodeId} not found in room '{startingRoom.Name}'."); } List <GameFlag> startingFlags = new List <GameFlag>(); foreach (string flagName in itemContainer.StartingGameFlagNames) { if (!model.GameFlags.TryGetValue(flagName, out GameFlag flag)) { throw new Exception($"Starting game flag {flagName} not found."); } startingFlags.Add(flag); } List <NodeLock> startingLocks = new List <NodeLock>(); foreach (string lockName in itemContainer.StartingNodeLockNames) { if (!model.Locks.TryGetValue(lockName, out NodeLock nodeLock)) { throw new Exception($"Starting node lock {lockName} not found."); } startingLocks.Add(nodeLock); } ResourceCount startingResources = new ResourceCount(); foreach (ResourceCapacity capacity in itemContainer.StartingResources) { startingResources.ApplyAmount(capacity.Resource, capacity.MaxAmount); } ItemInventory startingInventory = new ItemInventory(startingResources); foreach (string itemName in itemContainer.StartingItemNames) { if (!model.Items.TryGetValue(itemName, out Item item)) { throw new Exception($"Starting item {itemName} not found."); } startingInventory.ApplyAddItem(item); } StartConditions startConditions = new StartConditions { StartingNode = startingNode, StartingGameFlags = startingFlags, StartingOpenLocks = startingLocks, BaseResourceMaximums = startingResources, // Default starting resource counts to the starting maximum StartingResources = startingResources.Clone(), StartingInventory = startingInventory }; return(startConditions); }