Ejemplo n.º 1
0
        /// <summary>
        /// Gets the character associated with the id and checks
        /// if their specified statistic is higher than the given value.
        /// </summary>
        /// <param name="id">The id of the character to get.</param>
        /// <param name="statName">The name of the statistic to get.</param>
        /// <param name="minimum">Checks if the character's StatisticValue is greater than or equal to this value.</param>
        /// <returns>
        /// A result detailing if the operation was successful or why it failed.
        /// </returns>
        public async Task <IResult> CheckStatisticAsync(ulong id, string statName)
        {
            var character = await _charProvider.GetActiveCharacterAsync(id);

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

            var stat = await _statProvider.GetStatisticAsync(statName);

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

            var statValue = character.GetStatistic(stat);

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

            return(StatisticResult.StatisticCheck(character.Name, stat.Name, statValue.Value));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Performs a duel between two characters rolling a statistic and returns the result.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="targetId">Discord ID of the target.</param>
        /// <param name="statName">The statistic name.</param>
        /// <returns>The result of the roll.</returns>
        public async Task <IResult> RollStatisticAgainstAsync(ulong callerId, ulong targetId, string statName, bool useEffects = false)
        {
            var caller = await _provider.GetActiveCharacterAsync(callerId);

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

            var target = await _provider.GetActiveCharacterAsync(targetId);

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

            var stat = await _statProvider.GetStatisticAsync(statName);

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

            double?callerRoll = _strategy.RollStatistic(stat, caller, useEffects);
            double?targetRoll = _strategy.RollStatistic(stat, target, useEffects);

            if (callerRoll.HasValue && targetRoll.HasValue)
            {
                return(RollResult.RollAgainst(caller.Name, target.Name, callerRoll.Value, targetRoll.Value));
            }

            return(RollResult.RollFailed());
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Performs a roll on a character's statistic and returns the result.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="statName">The statistic name.</param>
        /// <returns>The result of the roll.</returns>
        public async Task <IResult> RollStatisticAsync(ulong callerId, string statName, bool useEffects = false)
        {
            var character = await _provider.GetActiveCharacterAsync(callerId);

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

            var stat = await _statProvider.GetStatisticAsync(statName);

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

            string result = _strategy.GetRollMessage(stat, character, useEffects);

            if (!string.IsNullOrEmpty(result))
            {
                return(RollResult.Roll(result));
            }

            return(RollResult.RollFailed());
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Sets the statistic effects of the specified effect.
        /// </summary>
        /// <param name="effectName">The name of the effect to set the value to.</param>
        /// <param name="statName">The name of the statistic to associate the value with.</param>
        /// <param name="value">The value to add (or subtract) to the statistic.</param>
        /// <returns>
        /// A result detailing if the operation was successful or why it failed.
        /// </returns>
        public async Task <IResult> SetStatisticEffectAsync(string effectName, string statName, int value)
        {
            var effect = await _effectProvider.GetEffectAsync(effectName);

            if (effect == null)
            {
                return(EffectResult.EffectNotFound());
            }

            var stat = await _statProvider.GetStatisticAsync(statName);

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

            var match = effect.StatisticEffects.FirstOrDefault(x => x.Statistic.Equals(stat));

            if (match == null)
            {
                effect.StatisticEffects.Add(new StatisticMapping(stat, new StatisticValue(value)));
            }
            else
            {
                match.StatisticValue.Value = value;
            }

            await _effectProvider.UpdateEffectAsync(effect);

            return(EffectResult.EffectUpdatedSucessfully());
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes a statistic in the database.
        /// </summary>
        /// <param name="statName">The name for the new skill.</param>
        /// A result detailing if the operation was successful or why it failed.
        /// </returns>
        public async Task <IResult> DeleteStatisticAsync(string statName)
        {
            var statistic = await _statProvider.GetStatisticAsync(statName);

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

            await _statProvider.DeleteStatisticAsync(statistic);

            return(StatisticResult.StatisticDeletedSuccessfully());
        }
Ejemplo n.º 6
0
        public async Task Roll_InvalidStat_ReturnStatNotFound()
        {
            // Arrange
            var provider     = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new RollController(provider, statProvider, new MockRollStrategy());

            // Act
            var result = await controller.RollStatisticAsync(1, "invalid");

            // Assert
            Assert.True(StatisticResult.StatisticNotFound().Equals(result));
        }
Ejemplo n.º 7
0
        public async Task DeleteStatistic_InvalidStatName_ReturnNotFound()
        {
            // Arrange
            var charProvider = new MockCharacterProvider();
            var statProvider = new MockStatisticProvider();
            var controller   = new StatisticController(charProvider, statProvider, new GenericProgressionStrategy(statProvider, new StatisticOptions()));

            // Act
            var result = await controller.DeleteStatisticAsync("bacon");

            // Assert
            Assert.Equal(result, StatisticResult.StatisticNotFound());
        }
Ejemplo n.º 8
0
        /// <summary>
        /// Clears the aliases of an already existing statistic.
        /// </summary>
        /// <param name="statName">The name of the statistic to add an alias to.</param>
        /// <returns>A result detailing if the operation was successful or why it failed.</returns>
        public async Task <IResult> ClearAliasesAsync(string statName)
        {
            var stat = await _statProvider.GetStatisticAsync(statName);

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

            stat.Aliases = stat.Name + "/";
            await _statProvider.UpdateStatisticAsync(stat);

            return(StatisticResult.StatisticUpdatedSucessfully());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Sets the order of an already existing statistic.
        /// </summary>
        /// <param name="statName">The name of the statistic to set the order of.</param>
        /// <param name="order">The order to sort the statistic in a descending manner.</param>
        /// <returns>A result detailing if the operation was successful or why it failed.</returns>
        public async Task <IResult> SetOrderAsync(string statName, int order)
        {
            var stat = await _statProvider.GetStatisticAsync(statName);

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

            stat.Order = order;
            await _statProvider.UpdateStatisticAsync(stat);

            return(StatisticResult.StatisticUpdatedSucessfully());
        }
Ejemplo n.º 10
0
        public async Task SetStatisticAsync_InvalidStatisticName_ReturnStatisticNotFound()
        {
            // Arrange
            var charProvider             = new MockCharacterProvider();
            var statProvider             = new MockStatisticProvider();
            StatisticOptions statOptions = new StatisticOptions();

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

            // Act
            var result = await controller.SetStatisticAsync(1, "invalid", 5);

            // Assert
            Assert.Equal(StatisticResult.StatisticNotFound(), result);
        }
Ejemplo n.º 11
0
        public async Task SetStatisticEffectAsync_InvalidStatisticName_ReturnStatisticNotFound()
        {
            // Arrange
            var charProvider   = new MockCharacterProvider();
            var effectProvider = new MockEffectProvider();
            var statProvider   = new MockStatisticProvider();

            var controller = new EffectController(charProvider, effectProvider, statProvider, null);

            await effectProvider.CreateEffectAsync(1, "ValidInput");

            var result = await controller.SetStatisticEffectAsync("ValidInput", "DoesNotExist", 1);

            Assert.Equal(StatisticResult.StatisticNotFound(), result);
        }
Ejemplo n.º 12
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;
            }
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Gets the caller's active character and returns the result.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <returns>A new CharacterResult object.</returns>
        public async Task <IResult> ShowStatisticsAsync(ulong callerId)
        {
            var character = await _charProvider.GetActiveCharacterAsync(callerId);

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

            if (character.Statistics == null || character.Statistics.Count <= 0)
            {
                return(StatisticResult.StatisticNotFound());
            }

            return(StatisticResult.ShowCharacter(character, await _strategy.GetCharacterStatisticsInfo(character)));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Adds an alias to an already existing statistic.
        /// </summary>
        /// <param name="statName">The name of the statistic to add an alias to.</param>
        /// <param name="alias">The new alias to add.</param>
        /// <returns>A result detailing if the operation was successful or why it failed.</returns>
        public async Task <IResult> AddAliasAsync(string statName, string alias)
        {
            var stat = await _statProvider.GetStatisticAsync(statName);

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

            if (await _statProvider.GetStatisticAsync(alias) != null)
            {
                return(StatisticResult.NameAlreadyExists());
            }

            stat.Aliases += alias + "/";
            await _statProvider.UpdateStatisticAsync(stat);

            return(StatisticResult.StatisticUpdatedSucessfully());
        }
Ejemplo n.º 15
0
        /// <summary>
        /// Renames an already existing statistic.
        /// </summary>
        /// <param name="statName">The name of the statistic to rename.</param>
        /// <param name="newName">The new name of the statistic.</param>
        /// <returns>A result detailing if the operation was successful or why it failed.</returns>
        /// <remarks>This method will also clear its aliases.</remarks>
        public async Task <IResult> RenameStatisticAsync(string statName, string newName)
        {
            var stat = await _statProvider.GetStatisticAsync(statName);

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

            if (await _statProvider.GetStatisticAsync(newName) != null)
            {
                return(StatisticResult.NameAlreadyExists());
            }

            stat.Name    = newName;
            stat.Aliases = newName + "/";
            await _statProvider.UpdateStatisticAsync(stat);

            return(StatisticResult.StatisticUpdatedSucessfully());
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Performs a roll on a character's statistic assuming it is set to the value given and returns the result.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="statName">The statistic name.</param>
        /// <param name="value">The new, temporary value of the character's statistic.</param>
        /// <returns>The result of the roll.</returns>
        public async Task <IResult> RollStatisticWithValueAsync(ulong callerId, string statName, int value, string displayName = null)
        {
            var stat = await _statProvider.GetStatisticAsync(statName);

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

            var character = await _provider.GetActiveCharacterAsync(callerId);

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

            if (displayName != null)
            {
                character.Name = displayName;
            }

            var current = character.GetStatistic(stat);

            if (current == null)
            {
                character.SetStatistic(stat, new StatisticValue(value));
            }
            else
            {
                current.Value = value;
            }

            string msg = _strategy.GetRollMessage(stat, character);

            if (!string.IsNullOrEmpty(msg))
            {
                return(RollResult.Roll(msg));
            }

            return(RollResult.RollFailed());
        }
Ejemplo n.º 17
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;
            }
        }