Exemplo n.º 1
0
        /// <summary>
        /// Gives experience to a character.
        /// </summary>
        public async Task <bool> GiveExperienceAsync(Character character, int experience = DEFAULT_EXP_GAIN)
        {
            if (character == null)
            {
                return(false);
            }

            var initialLevel = character.Level;

            character.Experience += experience;
            if (!UseOldProgression)
            {
                character.ExperiencePoints += experience;
            }

            await _charService.SaveCharacterAsync(character);

            var levelUp    = false;
            var difference = character.Level - initialLevel;

            if (difference >= 1)
            {
                await OnLevelUpAsync(character, difference);

                levelUp = true;
            }

            return(levelUp);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gives experience to a character.
        /// </summary>
        public async Task <bool> GiveExperienceAsync(Character character, int experience = DEFAULT_EXP_GAIN)
        {
            if (character == null)
            {
                return(false);
            }
            if (cooldownTimers.ContainsKey(character.DiscordId))
            {
                return(false);
            }

            var levelUp = false;

            if (WillLevelUp(character, experience))
            {
                await OnLevelUpAsync(character);

                levelUp = true;
            }

            character.Experience += experience;
            await _charService.SaveCharacterAsync(character);

            AddToCooldown(character.DiscordId);
            return(levelUp);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Set character's tag skills.
        /// </summary>
        public async Task SetTagSkills(Character character, string tag1, string tag2, string tag3)
        {
            if (character == null)
            {
                throw new ArgumentNullException("character");
            }

            if (!_specService.IsSpecialSet(character))
            {
                throw new Exception(Exceptions.CHAR_SPECIAL_NOT_FOUND);
            }

            if (!IsValidSkillName(tag1) || !IsValidSkillName(tag2) || !IsValidSkillName(tag3))
            {
                throw new ArgumentException(Exceptions.CHAR_INVALID_TAG_NAMES);
            }

            if (!AreUniqueTags(tag1, tag2, tag3))
            {
                throw new ArgumentException(Exceptions.CHAR_TAGS_NOT_UNIQUE);
            }

            InitializeSkills(character);

            SetTagSkill(character, tag1);
            SetTagSkill(character, tag2);
            SetTagSkill(character, tag3);

            await _charService.SaveCharacterAsync(character);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Set character's special.
        /// </summary>
        public async Task SetInitialSpecialAsync(Character character, int[] special)
        {
            if (character == null)
            {
                throw new ArgumentNullException("character");
            }

            if (!IsSpecialInRange(special))
            {
                throw new ArgumentException(Exceptions.CHAR_SPECIAL_NOT_IN_RANGE);
            }

            if (special.Sum() != DEFAULT_SPECIAL_POINTS)
            {
                throw new ArgumentException(Exceptions.CHAR_SPECIAL_DOESNT_ADD_UP);
            }

            InitializeSpecial(character, special);

            await _charService.SaveCharacterAsync(character);
        }