예제 #1
0
        public override Attack GetAttack(Entity defender)
        {
            // default to barehanded
            Roller          damage     = Roller.Dice(1, 3);
            Element         element    = Element.Anima;
            string          verb       = Verbs.Hit;
            EffectType      effectType = EffectType.Hit;
            IFlagCollection flags      = new FlagCollection();

            // find the equipped melee weapon
            Item weapon = Equipment.MeleeWeapon;

            if (weapon != null)
            {
                damage  = weapon.Attack.Damage;
                element = weapon.Attack.Element;
                verb    = weapon.Attack.Verb;
                flags   = weapon.Flags;

                //### bob: temp. need to get from weapon data
                effectType = EffectType.Stab;
            }

            var attack = new Attack(damage, MeleeStrikeBonus, MeleeDamageBonus, element, verb, effectType, flags);

            // give the class a chance to modify it
            mClass.BeforeAttack(defender, attack);

            return(attack);
        }
예제 #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);
        }