Example #1
0
        /// <summary>
        /// Calculates the final (modified) Xp result for the skill use.
        /// </summary>
        /// <param name="sourceRating"></param>
        /// <param name="targetRating"></param>
        /// <param name="testResult">Skill result</param>
        /// <param name="baseXpValue">Base Xp gain for the calculations</param>
        /// <returns>Integer value representing the final (modified) Xp gain</returns>
        /// <remarks>
        /// Skills grow through use and this is calculated by awarding "Skill XP" using
        /// the difference between the absolute value of the source and target ratings
        /// where a higher source rating results in lower % of XP applied and a higher
        /// target rating results in a higher % of XP applied.  In addition, the test
        /// result type also impacts the final XP value with CriticalSuccess results
        /// increasing the final result by 150% and CriticalFailures lowering that same
        /// result by 50%.
        ///</remarks>
        public static int CalculateXp(int sourceRating, int targetRating,
                                      Globals.SkillTestResultTypes testResult, int baseXpValue)
        {
            float modifiedXp;
            var   skillDiff = Math.Abs(sourceRating - targetRating);

            if (skillDiff == 0)
            {
                // no difference, so XP value is given straight up
                modifiedXp = testResult.CalculateXpResult(baseXpValue);
            }
            else
            {
                if (sourceRating >= targetRating)
                {
                    modifiedXp = baseXpValue * CalculateXpMultiplier(skillDiff);
                    if (modifiedXp <= 0)
                    {
                        modifiedXp = 1;
                    }
                    modifiedXp = testResult.CalculateXpResult(modifiedXp);
                }
                else
                {
                    modifiedXp = baseXpValue + baseXpValue * CalculateXpMultiplier(skillDiff);
                    modifiedXp = testResult.CalculateXpResult(modifiedXp);
                }
            }
            return((int)modifiedXp);
        }
        /// <summary>
        /// Calculates the XP result given the outcome of the skill use and the base XP
        /// </summary>
        /// <param name="result"></param>
        /// <param name="xp"></param>
        /// <returns></returns>
        public static float CalculateXpResult(this Globals.SkillTestResultTypes result, Single xp)
        {
            Validation.Validate <ArgumentOutOfRangeException>(xp >= 1 && xp <= Single.MaxValue);

            switch (result)
            {
            case Globals.SkillTestResultTypes.CriticalFailure:
                return(xp * 0.5f);

            case Globals.SkillTestResultTypes.CriticalSuccess:
                return(xp * 1.5f);

            default:
                return(xp);
            }
        }