Ejemplo n.º 1
0
        public async Task <LoginResponseData> Login(LoginData data, string connectionId)
        {
            if (serverManager.GetServerStatus() != GameServerStatus.Started)
            {
                return(new LoginResponseData()
                {
                    ResponseType = LoginResponseType.ServerNotStarted
                });
            }

            if (!await accountService.UsernameExists(data.Username))
            {
                logService.Log($"{data.Username} was not found!");
                return(new LoginResponseData()
                {
                    ResponseType = LoginResponseType.UsernameNotFound
                });
            }

            if (!await accountService.CheckLoginCredentials(data.Username, data.Password))
            {
                logService.Log($"Incorrect password!");
                return(new LoginResponseData()
                {
                    ResponseType = LoginResponseType.PasswordIncorrect
                });
            }


            var playerName = await accountService.GetPlayerName(data.Username);

            var playerData = await databaseService.GetPlayerData(playerName);

            playerData.ConnectionId = connectionId;


            // Add that object to the game
            gameStateService.AddPlayerToGame(playerData);
            var characters = await databaseService.GetAllCharactersFromPlayer(playerData.PlayerName);

            foreach (var character in characters)
            {
                gameStateService.AddCharacterToGame(character);
            }
            characterPlacementService.PlaceAllPlayerCharactersIntoTheGame(playerData.PlayerName);

            // Add character to areas


            logService.Log($"Account was found and player data was added to the game");

            return(new LoginResponseData()
            {
                UniverseSyncData = gameStateService.GetUniverseSyncData(),
                PlayerData = playerData,
                ResponseType = LoginResponseType.Success
            });
        }
Ejemplo n.º 2
0
        public async Task <CharacterData> NewCharacter(string playerName, string worldId, CharacterType characterType)
        {
            logService.Log($"Creating new character for: {playerName} on world: {worldId}");

            // Create
            var characterDescription = storage[characterType];
            var characterData        = new CharacterData(playerName, characterDescription);

            // General
            characterData.WorldId             = worldId;
            characterData.CombatData.Level    = 1;
            characterData.CombatData.UnitName = playerName;
            characterData.Id = Guid.NewGuid().ToString();

            // Skills
            characterData.Skills = new List <SkillId>();

            // Resources
            characterData.Resources = new WorldResourcesData();

            // Talents
            characterData.TalentBundle = talentFactory.CreateNewBundle(characterDescription);

            // Equipments
            characterData.Equipments = new EquipmentBundle();

            // Refresh
            RefreshCharacter(characterData);

            // Add to game
            gameStateService.AddCharacterToGame(characterData);
            characterPlacementService.PlaceCharacterOnCity(characterData.Id);


            // Save to DB
            await databaseService.InsertCharacter(characterData);

            logService.Log("Finished creating character");

            return(characterData);
        }