/// <summary> /// This will manually recalculate all stats. /// This should be used sparingly because it can be a heavy call. /// This method will not persist the changes so be sure your call DB.Set after calling this. /// </summary> public static void RecalculateAllStats(uint player, Player dbPlayer) { // Reset all adjusted stat values. foreach (var adjustedStat in dbPlayer.AdjustedStats) { dbPlayer.AdjustedStats[adjustedStat.Key] = 0.0f; } // Apply adjusted stat increases based on the player's skill ranks. // We use a pre-filtered list of skills for this to cut down on the number of iterations. var skills = Skill.GetAllSkillsWhichIncreaseStats(); foreach (var(type, value) in skills) { var primaryIncrease = dbPlayer.Skills[type].Rank * Skill.PrimaryStatIncrease; var secondaryIncrease = dbPlayer.Skills[type].Rank * Skill.SecondaryStatIncrease; if (value.PrimaryStat == AbilityType.Strength) { dbPlayer.AdjustedStats[AbilityType.Strength] += primaryIncrease; } if (value.PrimaryStat == AbilityType.Dexterity) { dbPlayer.AdjustedStats[AbilityType.Dexterity] += primaryIncrease; } if (value.PrimaryStat == AbilityType.Constitution) { dbPlayer.AdjustedStats[AbilityType.Constitution] += primaryIncrease; } if (value.PrimaryStat == AbilityType.Wisdom) { dbPlayer.AdjustedStats[AbilityType.Wisdom] += primaryIncrease; } if (value.PrimaryStat == AbilityType.Intelligence) { dbPlayer.AdjustedStats[AbilityType.Intelligence] += primaryIncrease; } if (value.PrimaryStat == AbilityType.Charisma) { dbPlayer.AdjustedStats[AbilityType.Charisma] += primaryIncrease; } if (value.SecondaryStat == AbilityType.Strength) { dbPlayer.AdjustedStats[AbilityType.Strength] += secondaryIncrease; } if (value.SecondaryStat == AbilityType.Dexterity) { dbPlayer.AdjustedStats[AbilityType.Dexterity] += secondaryIncrease; } if (value.SecondaryStat == AbilityType.Constitution) { dbPlayer.AdjustedStats[AbilityType.Constitution] += secondaryIncrease; } if (value.SecondaryStat == AbilityType.Wisdom) { dbPlayer.AdjustedStats[AbilityType.Wisdom] += secondaryIncrease; } if (value.SecondaryStat == AbilityType.Intelligence) { dbPlayer.AdjustedStats[AbilityType.Intelligence] += secondaryIncrease; } if (value.SecondaryStat == AbilityType.Charisma) { dbPlayer.AdjustedStats[AbilityType.Charisma] += secondaryIncrease; } } // We now have all of the correct values. Apply them to the player object. foreach (var(ability, amount) in dbPlayer.AdjustedStats) { var totalStat = (int)(dbPlayer.BaseStats[ability] + amount); Creature.SetRawAbilityScore(player, ability, totalStat); } }