Ejemplo n.º 1
0
    /// <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);
    }
Ejemplo n.º 2
0
    public override T ConvertToDTO <T>(params object[] data)
    {
        T result = null;

        // create initail character for user
        var characterDto = new CharacterDTO()
        {
            SceneId            = SceneId,
            CharacterId        = Id,
            Name               = Name,
            Age                = Age,
            Gender             = Gender,
            CharacterType      = CharacterType,
            CommandHint        = CommandHint,
            InventoryId        = Inventory.Id,
            ArmorLevel         = Statistics.ArmorLevel,
            DamageLevel        = Statistics.DamageLevel,
            HealthLevel        = Statistics.HealthLevel,
            StaminaLevel       = Statistics.StaminaLevel,
            CarriedWeightLevel = Statistics.CarriedWeightLevel,
            XpLevel            = Statistics.XpLevel,
            Health             = Statistics.CurrentHealth,
            Stamina            = Statistics.CurrentStamina,
            XpPoints           = Statistics.XpPoints,
            TimeStamp          = TimeStamp.ToString(),
        };

        result = characterDto as T;
        if (data.Length > 0)
        {
            // request current position of player
            ViewModel.Notify(NotificationName.RequestCharacterPosition, this);

            characterDto.LocationX = Position.X;
            characterDto.LocationY = Position.Y;

            result = new CharacterStateDTO(data[0].ToString(), characterDto) as T;
        }

        return(result);
    }