예제 #1
0
파일: Race.cs 프로젝트: stjordanis/amaranth
        public Race(Content content, string name, int depth, object appearance, int speed, Roller health)
            : base(content)
        {
            mName       = name;
            mDepth      = depth;
            mAppearance = appearance;
            mSpeed      = speed;

            // if the health is fixed, then automatically create a range for it
            if (health.IsFixed)
            {
                int amount = health.Roll();
                int range  = (int)(amount * 0.2f);

                if (range > 0)
                {
                    mHealth = Roller.Triangle(amount, range);
                }
                else
                {
                    mHealth = Roller.Fixed(amount);
                }
            }
            else
            {
                mHealth = health;
            }

            mDescription = "A nondescript beast of the dungeon.";
        }
예제 #2
0
        /// <summary>
        /// Tries to create a new Roller by parsing the given string representation of it.
        /// Valid strings include "3", "2-5", "2d6", "6t3", and "2-5(1:4)".
        /// </summary>
        /// <param name="text">The string to parse.</param>
        /// <returns>The parsed Roller or <c>null</c> if unsuccessful.</returns>
        public static Roller Parse(string text)
        {
            // ignore whitespace
            text = text.Trim();

            // compile the regex if needed
            if (sParser == null)
            {
                string pattern = @"^((?<die>(?<dice>\d+)d(?<sides>\d+))|(?<tri>(?<center>\d+)t(?<range>\d+))|(?<range>(?<min>\d+)-(?<max>\d+))|(?<fixed>(?<value>-?\d+)))(?<taper>\((?<chance>\d+)\:(?<outof>\d+)\))?$";

                sParser = new Regex(pattern, RegexOptions.Compiled | RegexOptions.ExplicitCapture);
            }

            // parse it
            Match match = sParser.Match(text);

            if (!match.Success)
            {
                return(null);
            }

            Roller roller;

            if (match.Groups["die"].Success)
            {
                int dice  = Int32.Parse(match.Groups["dice"].Value);
                int sides = Int32.Parse(match.Groups["sides"].Value);
                roller = Roller.Dice(dice, sides);
            }
            else if (match.Groups["tri"].Success)
            {
                int center = Int32.Parse(match.Groups["center"].Value);
                int range  = Int32.Parse(match.Groups["range"].Value);
                roller = Roller.Triangle(center, range);
            }
            else if (match.Groups["range"].Success)
            {
                int min = Int32.Parse(match.Groups["min"].Value);
                int max = Int32.Parse(match.Groups["max"].Value);
                roller = Roller.Range(min, max);
            }
            else // fixed
            {
                int value = Int32.Parse(match.Groups["value"].Value);
                roller = Roller.Fixed(value);
            }

            // add the taper
            if (match.Groups["taper"].Success)
            {
                int chance = Int32.Parse(match.Groups["chance"].Value);
                int outOf  = Int32.Parse(match.Groups["outof"].Value);

                roller.mNextRoller = Taper(chance, outOf);
            }

            return(roller);
        }