public void Verify(GameDef gameDef, WorldStateImmutable worldStateImmutable) { foreach (var player in worldStateImmutable.Players.Values) { VerifyPlayer(gameDef, player); } }
public static WorldState ToMutable(this WorldStateImmutable worldStateImmutable) { return(new WorldState { Players = worldStateImmutable.Players.ToDictionary(x => x.Key, y => y.Value.ToMutable()), GameTickState = worldStateImmutable.GameTickState.ToMutable(), GameActionQueue = worldStateImmutable.GameActionQueue.Select(x => x.ToMutable()).ToList() }); }
public async Task StoreWorldSate(WorldStateImmutable worldStateImmutable) { await storage.Store("latest", serializer.Serialize(worldStateImmutable)); }
public byte[] Serialize(WorldStateImmutable worldStateImmutable) { return(JsonSerializer.SerializeToUtf8Bytes <WorldStateImmutable>(worldStateImmutable, GetOptions())); }
private static async Task InitPersistenceAndGameState(IServiceCollection services, IBlobStorage storage, WorldStateImmutable defaultWorldState) { var serializer = new GameStateJsonSerializer(); var persistenceService = new PersistenceService(storage, serializer); services.AddSingleton <IBlobStorage>(storage); services.AddSingleton <GameStateJsonSerializer>(serializer); services.AddSingleton <PersistenceService>(persistenceService); if (persistenceService.WorldStateExists()) { // state exists. use it. ignore default state. var worldStateImmutable = await persistenceService.LoadWorldState(); services.AddSingleton <WorldState>(worldStateImmutable.ToMutable()); } else { // no state stored yet. use default state. services.AddSingleton <WorldState>(defaultWorldState.ToMutable()); } }
public static async Task AddGameServer(this IServiceCollection services, IBlobStorage storage, WorldStateImmutable defaultWorldState) { await InitPersistenceAndGameState(services, storage, defaultWorldState); services.AddSingleton <PlayerRepository>(); services.AddSingleton <PlayerRepositoryWrite>(); services.AddSingleton <ResourceRepository>(); services.AddSingleton <ResourceRepositoryWrite>(); services.AddSingleton <ScoreRepository>(); services.AddSingleton <AssetRepository>(); services.AddSingleton <AssetRepositoryWrite>(); services.AddSingleton <UnitRepository>(); services.AddSingleton <UnitRepositoryWrite>(); services.AddSingleton <ActionQueueRepository>(); services.AddSingleton <IGameTickModule, ActionQueueExecutor>(); services.AddSingleton <IGameTickModule, UnitReturn>(); services.AddSingleton <IGameTickModule, ResourceGrowthSco>(); services.AddSingleton <GameTickModuleRegistry>(); // Modules need to be registered before this services.AddSingleton <GameTickEngine>(); services.AddSingleton <IBattleBehavior, BattleBehaviorScoOriginal>(); // TODO: make this configurable through GameDef }