/// <summary> /// Initialize new game state for authenticated user. /// </summary> /// <param name="userDto">authenticated user</param> /// <param name="characterDto">associated character</param> private void InitializeNewGame(UserDTO userDto, CharacterDTO characterDto) { if (userDto == null) { throw new ArgumentNullException("userDto"); } if (characterDto == null) { throw new ArgumentNullException("characterDto"); } // Create game safe point var created = DateTime.UtcNow; var gameState = new GameStateModel( Guid.NewGuid().ToString(), userDto.Login, GeneralName.InitialGameSceneId, string.Format("Autosave for {0} at {1}", userDto.Login, created.ToLocalTime()), created); var gameStateDto = gameState.ConvertToDTO <GameStateDTO>(); // Create main character safe point state var gameStateCharacterDto = new CharacterStateDTO(gameStateDto.GameStateId, characterDto); // todo: save all objects to Database in transaction _connection.Insert(gameStateDto); _connection.Insert(gameStateCharacterDto); }
/// <summary> /// Save game state. /// </summary> /// <param name="login">authenticated user login</param> /// <param name="sceneId">active scene identifier</param> /// <param name="player">player state</param> /// <param name="extGameState">game state</param> /// <returns></returns> public void SaveGame(string login, string sceneId, CharacterModel player, ExtendedGameState extGameState) { // Create game safe point var created = DateTime.UtcNow; var gameState = new GameStateModel( Guid.NewGuid().ToString(), login, sceneId, string.Format("Save for {0} at {1}", login, created.ToLocalTime()), created); var gameStateDto = gameState.ConvertToDTO <GameStateDTO>(); // Create main character safe point state var gameStateCharacterDto = player.ConvertToDTO <CharacterStateDTO>(gameStateDto.GameStateId); // todo: save all objects to Database in transaction _connection.Insert(gameStateDto); _connection.Insert(gameStateCharacterDto); // todo: process extGameState saving }