Beispiel #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(
                () => CharacterSkillLevelChanged?.Invoke(this.Character, skill, skillLevelData));

            return(skillLevelData);
        }
Beispiel #2
0
        public void ServerReset()
        {
            Api.ValidateIsServer();

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

                this.Skills.Clear();
            }

            this.ServerSetCharacterFullStatsCacheDirty();
        }
Beispiel #3
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);
        }