Ejemplo n.º 1
0
        public SkillLevelData ServerAddSkillExperience(IProtoSkill skill, double experience)
        {
            Api.ValidateIsServer();

            if (double.IsNaN(experience) ||
                double.IsInfinity(experience))
            {
                throw new Exception($"Incorrect experience value provided for {skill}: {experience}");
            }

            if (experience > 0)
            {
                experience *= TechConstants.SkillExperienceGainMultiplier;
            }
            else
            {
                Api.Logger.Error($"Skill experience to add should be larger than zero (exp for skill {skill.ShortId})");
                experience = 0;
            }

            if (!this.Skills.TryGetValue(skill, out var skillLevelData))
            {
                skillLevelData = this.ServerSetSkillExperience(skill, experience);
                return(skillLevelData);
            }

            if (experience <= 0)
            {
                return(skillLevelData);
            }

            var oldLevel = skillLevelData.Level;

            var newExp = experience + skillLevelData.Experience;

            skillLevelData.Experience = newExp;

            if (newExp >= skillLevelData.ExperienceForNextLevel)
            {
                var previousLevel = skillLevelData.Level;

                skill.ServerUpdateSkillData(skillLevelData);

                if (previousLevel != skillLevelData.Level)
                {
                    Api.SafeInvoke(
                        () => ServerCharacterSkillLevelChanged?.Invoke(this.Character, skill, skillLevelData));
                }
            }

            if (skill.HasStatEffects &&
                oldLevel != skillLevelData.Level)
            {
                this.ServerSetCharacterFullStatsCacheDirty();
            }

            skill.ServerOnSkillExperienceAdded(this.Character, experience, skillLevelData.Level);
            return(skillLevelData);
        }
Ejemplo n.º 2
0
        public SkillLevelData ServerAddSkillExperience(IProtoSkill skill, double experience)
        {
            Api.ValidateIsServer();
            if (experience <= 0)
            {
                throw new ArgumentException("Experience to add should be larger than zero.", nameof(experience));
            }

            experience *= TechConstants.SkillExperienceMultiplier;

            if (!this.Skills.TryGetValue(skill, out var skillLevelData))
            {
                skillLevelData = this.ServerSetSkillExperience(skill, experience);
                return(skillLevelData);
            }

            var oldLevel = skillLevelData.Level;

            var newExp = experience + skillLevelData.Experience;

            skillLevelData.Experience = newExp;

            if (newExp >= skillLevelData.ExperienceForNextLevel)
            {
                var previousLevel = skillLevelData.Level;

                skill.ServerUpdateSkillData(skillLevelData);

                if (previousLevel != skillLevelData.Level)
                {
                    Api.SafeInvoke(
                        () => CharacterSkillLevelChanged?.Invoke(this.Character, skill, skillLevelData));
                }
            }

            if (skill.HasStatEffects &&
                oldLevel != skillLevelData.Level)
            {
                this.ServerSetCharacterFullStatsCacheDirty();
            }

            skill.ServerOnSkillExperienceAdded(this.Character, experience, skillLevelData.Level);
            return(skillLevelData);
        }