Esempio n. 1
0
        /// <summary>
        /// Used to add an effect to a character.
        /// </summary>
        /// <param name="callerId">The user identifier of the caller.</param>
        /// <param name="effectName">The name of the effect to add to the character.</param>
        public async Task <IResult> AddEffectAsync(ulong callerId, string effectName)
        {
            var character = await _charProvider.GetActiveCharacterAsync(callerId);

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

            var effect = await _effectProvider.GetEffectAsync(effectName);

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

            if (character.Effects == null)
            {
                character.Effects = new List <Effect>();
            }

            if (character.Effects.Count(x => x.Id == effect.Id) > 0)
            {
                return(EffectResult.EffectAlreadyAdded());
            }

            character.Effects.Add(effect);
            await _charProvider.UpdateCharacterAsync(character);

            return(EffectResult.EffectAdded());
        }
Esempio n. 2
0
        public async Task <IResult> AddExperienceAsync(ulong callerId, int xp)
        {
            var character = await _charProvider.GetActiveCharacterAsync(callerId);

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

            await _strategy.AddExperience(character, xp);

            await _charProvider.UpdateCharacterAsync(character);

            return(CharacterResult.CharacterUpdatedSuccessfully());
        }
Esempio n. 3
0
        /// <summary>
        /// Gets the caller's specified character by name, sets it as active, and updates it.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="charName">The name of the character to set as active.</param>
        /// <returns>A new CharacterResult object.</returns>
        public async Task <IResult> ActivateCharacterAsync(ulong callerId, string charName)
        {
            var characters = await _provider.GetAllCharactersAsync(callerId);

            var match = characters.OrderBy(x => x.Id).FirstOrDefault(x => x.Name.ContainsIgnoreCase(charName));

            if (match == null)
            {
                return(CharacterResult.CharacterNotFound());
            }
            if (match.Active)
            {
                return(CharacterResult.CharacterAlreadyActive());
            }
            match.Active = true;

            await _provider.UpdateCharacterAsync(match);

            return(CharacterResult.CharacterActive(match.Name));
        }