protected EthicsScale GetProbableEthics(Morality theMorality, EthicsScale theTrust, Random rng)
        {
            EthicsScale theEthics;
            bool        coinflip = rng.Next(0, 2) == 0;

            if (theMorality == Morality.Forgive)
            {
                theEthics = coinflip ? theTrust.HigherLevel() : theTrust;
            }
            else if (theMorality == Morality.Exploit)
            {
                theEthics = coinflip ? theTrust.LowerLevel() : theTrust;
            }
            else //Reciprocate
            {
                theEthics = theTrust;
            }

            return(theEthics);
        }
Пример #2
0
        protected string DescribeDurability(EthicsScale trustOrEthics, int durability)
        {
            if (durability == 0)
            {
                return(string.Empty);
            }

            int?threshold = durability > 0 ? GapToNextLevel(trustOrEthics, true) : GapToNextLevel(trustOrEthics, false);

            if (threshold == null)
            {
                return(string.Empty);
            }

            var percentDurability = System.Math.Abs((100 * durability) / threshold.Value);
            var nextLevel         = durability > 0 ? trustOrEthics.HigherLevel() : trustOrEthics.LowerLevel();


            var summary = string.Format("{0}% of the way to [{1}]", percentDurability, nextLevel.ToString());

            return(summary);
        }
Пример #3
0
        //#TODO - change private methods to be protected, and add Mock class to be unit tested

        private void UpdateLevelFromDurability(ref EthicsScale level, ref int durability)
        {
            bool movingUpwards = durability > 0;
            int? threshold     = GapToNextLevel(level, movingUpwards);

            if (threshold == null) //already at max/min level
            {
                return;
            }

            if (movingUpwards && durability >= threshold)
            {
                level       = level.HigherLevel();
                durability -= threshold.Value;
                UpdateLevelFromDurability(ref level, ref durability);
            }
            else if (!movingUpwards && durability <= threshold)
            {
                level       = level.LowerLevel();
                durability -= threshold.Value;
                UpdateLevelFromDurability(ref level, ref durability);
            }
        }
Пример #4
0
        private int?GapToNextLevel(EthicsScale currentLevel, bool movingUpwards)
        {
            int next = 0;

            if (movingUpwards)
            {
                next = (int)currentLevel.HigherLevel();
            }
            else
            {
                next = (int)currentLevel.LowerLevel();
            }

            int current = (int)currentLevel;

            if (next == current) //already at max/min level
            {
                return(null);
            }

            int gap = (next - current) * SCALE_FOR_GAPS_BETWEEN_TRUST_LEVELS;

            return(gap);
        }