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); }
public void ServerUpdateSkillData(SkillLevelData data) { var level = this.ClampLevel(data.Level); var expForCurrentLevel = this.GetExperienceForLevel(level); var exp = data.Experience; if (exp >= expForCurrentLevel && exp < data.ExperienceForNextLevel) { // current level matches its range return; } // recalculate level and experience required for next level data.Level = this.CalculateLevelForExperience(exp); var nextLevel = data.Level + 1; data.ExperienceForNextLevel = nextLevel <= this.MaxLevel ? this.GetExperienceForLevel((byte)nextLevel) : double.MaxValue; }