Exemplo n.º 1
0
        public async Task SetStatisticAsync_LevelTooHighButAttributesUnset_ReturnSuccess()
        {
            // Arrange
            var charProvider = new MockCharacterProvider();
            var character    = await charProvider.CreateCharacterAsync(100, "TooHigh");

            // the important bit
            character.Experience = 50000;

            var statProvider = new MockStatisticProvider();
            var statOptions  = new StatisticOptions
            {
                InitialAttributeMin    = 1,
                InitialAttributeMax    = 10,
                InitialAttributePoints = 10,
                InitialSetupMaxLevel   = 1
            };

            var controller = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, statOptions));

            // Act
            var result = await controller.SetStatisticAsync(100, "strength", 3);

            // Assert
            Assert.Equal(StatisticResult.StatisticSetSucessfully(), result);
        }
Exemplo n.º 2
0
        public async Task SetProficiencyAsync_SetFalse_ReturnSuccess()
        {
            // Arrange
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();

            var statOptions = new StatisticOptions
            {
                InitialAttributeMin         = 1,
                InitialAttributeMax         = 10,
                InitialAttributePoints      = 40,
                InitialAttributesAtMax      = 7,
                InitialAttributesProficient = 0
            };

            var controller = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, statOptions));
            var character  = await charProvider.GetActiveCharacterAsync(1);

            await controller.SetStatisticAsync(1, "strength", 10);

            // Act
            var result = await controller.SetProficiencyAsync(1, "strength", false);

            // Assert
            Assert.Equal(StatisticResult.StatisticSetSucessfully(), result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Used to set a character's attributes up.
        /// </summary>
        /// <param name="callerId">The user identifier of the caller.</param>
        /// <param name="values">What to set the initial attributes to.</param>
        public async Task <IResult> SetStatisticAsync(ulong callerId, string statName, int?newValue = null, bool force = false)
        {
            var character = await _charProvider.GetActiveCharacterAsync(callerId);

            if (character == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var statistic = await _statProvider.GetStatisticAsync(statName);

            if (statistic == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            try
            {
                if (force)
                {
                    var statValue = character.GetStatistic(statistic);

                    if (newValue.HasValue)
                    {
                        statValue.Value = newValue.Value;
                    }
                }
                else
                {
                    await _strategy.SetStatistic(character, statistic, newValue);
                }

                await _charProvider.UpdateCharacterAsync(character);

                return(StatisticResult.StatisticSetSucessfully());
            }
            catch (System.Exception e)
            {
                if (!(e is ProgressionException))
                {
                    System.Console.WriteLine(e);
                }

                return(GenericResult.Failure(e.Message));

                throw e;
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Used to set a character's proficiencies up.
        /// </summary>
        /// <param name="callerId">The user identifier of the caller.</param>
        /// <param name="values">What to set the initial attributes to.</param>
        public async Task <IResult> SetProficiencyAsync(ulong callerId, string statName, bool isProficient, bool force = false)
        {
            var character = await _charProvider.GetActiveCharacterAsync(callerId);

            if (character == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var statistic = await _statProvider.GetStatisticAsync(statName);

            if (statistic == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            try
            {
                if (force)
                {
                    var statVal = character.GetStatistic(statistic);
                    statVal.IsProficient = isProficient;
                }
                else
                {
                    await _strategy.SetProficiency(character, statistic, isProficient);
                }

                await _charProvider.UpdateCharacterAsync(character);

                return(StatisticResult.StatisticSetSucessfully());
            }
            catch (System.Exception e)
            {
                return(GenericResult.Failure(e.Message));

                throw e;
            }
        }