Ejemplo n.º 1
0
        private SkillLevelData ServerSetSkillExperience(IProtoSkill skill, double newExperience)
        {
            var needToAdd = false;

            if (!this.Skills.TryGetValue(skill, out var skillLevelData))
            {
                needToAdd      = true;
                skillLevelData = new SkillLevelData();
            }

            skillLevelData.Experience = newExperience;
            skill.ServerUpdateSkillData(skillLevelData);

            if (needToAdd)
            {
                this.Skills[skill] = skillLevelData;
            }

            if (skill.HasStatEffects)
            {
                this.ServerSetCharacterFullStatsCacheDirty();
            }

            Api.SafeInvoke(
                () => ServerCharacterSkillLevelChanged?.Invoke(this.Character, skill, skillLevelData));

            return(skillLevelData);
        }
Ejemplo n.º 2
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.º 3
0
        public void ServerReset()
        {
            Api.ValidateIsServer();

            if (this.Skills.Count > 0)
            {
                foreach (var pair in this.Skills)
                {
                    Api.SafeInvoke(
                        () => ServerCharacterSkillLevelChanged?.Invoke(this.Character, pair.Key, pair.Value));
                }

                this.Skills.Clear();
            }

            this.ServerSetCharacterFullStatsCacheDirty();
        }