Exemplo n.º 1
0
 public void Verify(GameDef gameDef, WorldStateImmutable worldStateImmutable)
 {
     foreach (var player in worldStateImmutable.Players.Values)
     {
         VerifyPlayer(gameDef, player);
     }
 }
Exemplo n.º 2
0
 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()
     });
 }
Exemplo n.º 3
0
 public async Task StoreWorldSate(WorldStateImmutable worldStateImmutable)
 {
     await storage.Store("latest", serializer.Serialize(worldStateImmutable));
 }
Exemplo n.º 4
0
 public byte[] Serialize(WorldStateImmutable worldStateImmutable)
 {
     return(JsonSerializer.SerializeToUtf8Bytes <WorldStateImmutable>(worldStateImmutable, GetOptions()));
 }
Exemplo n.º 5
0
        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());
            }
        }
Exemplo n.º 6
0
        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
        }