Пример #1
0
        /// <summary>
        /// Gives the amount of boost of a given stat with the given points
        /// </summary>
        /// <param name="stat"></param>
        /// <param name="pointsToSpend"></param>
        /// <returns></returns>
        public int GetBoostAmountWithPoints(BoostableStat stat, int pointsToSpend)
        {
            var currentPoints = GetBoostableStatPoints(stat);
            var threshold     = Breed.GetThreshold(currentPoints, stat);
            var nextThreshold = Breed.GetNextThreshold(currentPoints, stat);

            if (pointsToSpend < threshold.PointsPerBoost)
            {
                return(0);
            }

            int totalBoost = 0;

            while (pointsToSpend >= threshold.PointsPerBoost)
            {
                int boost = 0;
                if (nextThreshold != null && currentPoints >= nextThreshold.PointsThreshold)
                {
                    threshold     = Breed.GetThreshold(currentPoints, stat);
                    nextThreshold = Breed.GetNextThreshold(currentPoints, stat);
                }

                if (pointsToSpend - threshold.PointsPerBoost < 0)
                {
                    break;
                }

                if (nextThreshold != null && (pointsToSpend / (double)threshold.PointsPerBoost) > (nextThreshold.PointsThreshold - currentPoints))
                {
                    boost          = (short)(threshold.PointsThreshold - pointsToSpend);
                    pointsToSpend -= (short)(boost * threshold.PointsPerBoost);

                    boost = (short)(boost * threshold.BoostPerPoints);
                }
                else
                {
                    boost          = (short)Math.Floor(pointsToSpend / (double)threshold.PointsPerBoost);
                    pointsToSpend -= (short)(boost * threshold.PointsPerBoost);

                    boost = (short)(boost * threshold.BoostPerPoints);
                }

                currentPoints += boost;
                totalBoost    += boost;
            }

            return(totalBoost);
        }
Пример #2
0
        public short GetPointsForBoostAmount(BoostableStat stat, short amount)
        {
            var   currentPoints = GetBoostableStatPoints(stat);
            var   threshold     = Breed.GetThreshold(currentPoints, stat);
            var   nextThreshold = Breed.GetNextThreshold(currentPoints, stat);
            short pointsToSpend = 0;
            int   totalBoost    = 0;

            while (totalBoost < amount)
            {
                short boost = 0;
                if (nextThreshold != null && currentPoints >= nextThreshold.PointsThreshold)
                {
                    threshold     = Breed.GetThreshold(currentPoints, stat);
                    nextThreshold = Breed.GetNextThreshold(currentPoints, stat);
                }

                // must fill the current threshold first
                if (nextThreshold != null && amount > (nextThreshold.PointsThreshold - currentPoints))
                {
                    boost          = (short)(nextThreshold.PointsThreshold - pointsToSpend);
                    pointsToSpend += (short)(boost * threshold.PointsPerBoost);

                    boost = (short)(boost * threshold.BoostPerPoints);
                }
                else
                {
                    pointsToSpend += (short)(amount * threshold.PointsPerBoost);

                    boost = (short)(amount * threshold.BoostPerPoints);
                }

                amount        -= boost;
                currentPoints += boost;
                totalBoost    += boost;
            }

            return(pointsToSpend);
        }