Esempio n. 1
0
        /// <summary>
        /// Resolves the ItemRoll to a GameObject by performing a die roll
        /// </summary>
        /// <returns></returns>
        public IResolver Resolve()
        {
            string name = String.Empty;

            if (Item is GameObject)
            {
                name = ((GameObject)Item).Name;
            }
            else if (Item is GameObjectInstance)
            {
                name = ((GameObjectInstance)Item).Item.Name;
            }
            Logger.Write("Resolve ItemRoll: " + Item.ToString() + ", " + Dice.ToString() + " " + " x" + Multiplier + " (" + Percent + "%)");

            DieRoll percentRoll = new DieRoll(1, 100, 0);
            int     percent     = percentRoll.Roll();

            Logger.Write("... rolled " + percentRoll.ToString() + ": " + percent.ToString() + "%" + ((percent <= Percent) ? "" : " NO ROLL"));

            if (percent <= Percent)
            {
                return(Roll());
            }
            else
            {
                return(null);
            }
        }
Esempio n. 2
0
        /// <summary>
        /// Perform a die roll from die roll stats
        /// </summary>
        /// <param name="dice"></param>
        /// <param name="sides"></param>
        /// <param name="modifier"></param>
        /// <param name="keep"></param>
        /// <returns></returns>
        public static int Roll(int dice, int sides, int modifier, int keep)
        {
            DieRoll dr = new DieRoll(dice, sides, modifier);

            dr.Keep = keep;
            return(dr.Roll());
        }
Esempio n. 3
0
        /// <summary>
        /// Performs a die roll to generate one or more IResolvers from Item
        /// </summary>
        /// <returns></returns>
        public IResolver Roll()
        {
            //GameObjectInstance result = new GameObjectInstance(Item, Dice.Roll() * Multiplier);
            if (Item is GameObject)
            {
                GameObjectInstance item = new GameObjectInstance((GameObject)Item, Dice.Roll() * Multiplier);
                Logger.Write("... rolled " + item.ToString());
                return(item);
            }
            else if (Item is TableRoll && IsGrouped)
            {
                // Number of dice in Dice determines number of TableRolls performed.
                // Dice rolled with a single die determines number of occurrences of each TableRoll results.
                // e.g. if Dice = 4d10+2, 4 TableRolls are performed, and d10+2 is rolled to determine number of occurrences of each result.

                TableRoll t = (TableRoll)Item;
                Logger.Write("... performing " + Dice.Dice.ToString() + " rolls on " + t.Table.TableName);

                ItemList list       = new ItemList();
                DieRoll  singleRoll = new DieRoll(1, Dice.Sides, Dice.Modifier);
                for (int i = 0; i < Dice.Dice; i++)
                {
                    IResolver item = Item.Resolve();
                    if (item != null)
                    {
                        int count = singleRoll.Roll();
                        Logger.Write("... occurring " + count + " times");
                        for (int j = 0; j < count; j++)
                        {
                            list.Add(item);
                        }
                    }
                }
                return(list);
            }
            else
            {
                ItemList list  = new ItemList();
                int      count = Dice.Roll() * Multiplier;

                Logger.Write("... rolled " + Dice.ToString() + ": " + count.ToString());

                for (int i = 0; i < count; i++)
                {
                    list.Add(Item.Resolve());
                }
                return(list);
            }
        }
Esempio n. 4
0
        public IResolver Roll(int ignoreBelow, int ignoreAbove)
        {
            DieRoll dice     = new DieRoll(1, this.Count, 0);
            int     roll     = -1;
            int     attempts = 0;

            while (attempts <= Constants.MaxRollAttempts && (roll < ignoreBelow || roll > ignoreAbove))
            {
                roll = dice.Roll();
                attempts++;
            }

            IResolver result = this[roll];

            return(result.Resolve());
        }
Esempio n. 5
0
        /// <summary>
        /// Return a resolved, randomly selected item from the list
        /// </summary>
        /// <param name="ignoreBelow"></param>
        /// <param name="ignoreAbove"></param>
        /// <returns></returns>
        public IResolver Roll(int ignoreBelow, int ignoreAbove)
        {
            DieRoll dice     = new DieRoll(1, _list.Count, 0);
            int     roll     = -1;
            int     attempts = 0;

            while (attempts <= Constants.MaxRollAttempts && (roll < ignoreBelow || roll > ignoreAbove))
            {
                roll = dice.Roll();
                attempts++;
            }

            Dictionary <string, IResolver> .Enumerator en = _list.GetEnumerator();
            for (int i = 0; i < roll; i++)
            {
                en.MoveNext();
            }
            string key = en.Current.Key;

            return(this.Resolve(key));
        }
Esempio n. 6
0
        /// <summary>
        /// Perform a die roll from a string such as "3d8+1"
        /// </summary>
        /// <param name="dieRollString"></param>
        /// <returns></returns>
        public static int Roll(string dieRollString)
        {
            DieRoll dieRoll = DieRoll.FromString(dieRollString);

            return(dieRoll.Roll());
        }