コード例 #1
0
 public Die(GameObject _gameObject, Rigidbody _rigidbody, Vector3 _startingPosition)
 {
     gameobject  = _gameObject;
     rigidbody   = _rigidbody;
     startingPos = _startingPosition;
     lastResult  = CheckDieSide();
 }
コード例 #2
0
 public Initiative()
 {
     Modifiers      = new List <Modifier>();
     LastRollResult = new DieResult()
     {
         DieRolls = new List <int>(), modifier = 0, Total = -1
     };
 }
コード例 #3
0
        public static RemoteDieResult ToRemote(this DieResult result)
        {
            if (result == null)
            {
                return(null);
            }

            return(new RemoteDieResult()
            {
                Die = result.Die, Result = result.Result
            });
        }
コード例 #4
0
        public DieResult Run()
        {
            results = new DieResult();

            ProcessPreOutput();

            Dictionary <FaceMap, long> outcomePool = ProcessDicePool();

            ProcessMainOutput(outcomePool);

            //ProcessAnalysisOutput(outcomePool, dicePool);

            SummarizePool(outcomePool);

            return(results);
        }
コード例 #5
0
        public void Successfully_RoundtripDieResult_ForPersistence()
        {
            var stream = new MemoryStream();
            var die    = new DieResult()
            {
                DieType  = DieType.Fudge,
                NumSides = 3,
                Value    = -2,
                Flags    = DieFlags.Extra | DieFlags.Failure,
                Data     = "Some Data"
            };

            die.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var die2 = DieResult.Deserialize(stream);

            Assert.AreEqual(die, die2);
        }
コード例 #6
0
        public void Successfully_RoundtripDieResult()
        {
            var formatter = new BinaryFormatter();
            var stream    = new MemoryStream();
            var die       = new DieResult()
            {
                DieType  = DieType.Fudge,
                NumSides = 3,
                Value    = -2,
                Flags    = DieFlags.Extra | DieFlags.Failure,
                Data     = "Some Data"
            };

            formatter.Serialize(stream, die);
            stream.Seek(0, SeekOrigin.Begin);
            var die2 = (DieResult)formatter.Deserialize(stream);

            Assert.AreEqual(die, die2);
        }
コード例 #7
0
        public DieResult CheckDieSide()
        {
            float   minimumAngle = float.MaxValue;
            int     side         = 0;
            Vector3 dieUp        = gameobject.transform.InverseTransformDirection(Vector3.up);

            float[] angles = new float[6];
            for (int i = 1; i <= 6; i++)
            {
                Vector3 vector = SideVector3(i);
                float   angle  = Vector3.Angle(vector, dieUp);
                angles[i - 1] = angle;
                if (angle < minimumAngle)
                {
                    side         = i;
                    minimumAngle = angle;
                }
            }
            lastResult = new DieResult()
            {
                dieSide = side, angleFromSide = minimumAngle
            };
            return(lastResult);
        }
コード例 #8
0
ファイル: RerollNode.cs プロジェクト: garyray-k/DiceRoller
        private long MaybeReroll(RollData data, DiceAST root, int depth)
        {
            long rolls      = 0;
            int  rerolls    = 0;
            int  maxRerolls = MaxRerolls;

            if (MaxRerolls < 0)
            {
                if (MaxRerollsExpr.Value < 0 || Math.Floor(MaxRerollsExpr.Value) != MaxRerollsExpr.Value || MaxRerollsExpr.Value > Int32.MaxValue)
                {
                    throw new DiceException(DiceErrorCode.BadRerollCount);
                }

                maxRerolls = (int)MaxRerollsExpr.Value;
            }
            maxRerolls = maxRerolls == 0 ? data.Config.MaxRerolls : Math.Min(maxRerolls, data.Config.MaxRerolls);
            _values.Clear();

            void DoReroll(DieResult die, out DieResult reroll)
            {
                rerolls++;

                if (die.DieType == DieType.Group)
                {
                    var group = data.InternalContext.GetGroupExpression(die.Data);
                    rolls += group.Reroll(data, root, depth + 1);

                    reroll = new DieResult()
                    {
                        DieType  = DieType.Group,
                        NumSides = 0,
                        Value    = group.Value,
                        // maintain any crit/fumble flags from the underlying dice, combining them together
                        Flags = group.Values
                                .Where(d => d.DieType != DieType.Special && !d.Flags.HasFlag(DieFlags.Dropped))
                                .Select(d => d.Flags & (DieFlags.Critical | DieFlags.Fumble))
                                .Aggregate((d1, d2) => d1 | d2) | DieFlags.Extra,
                        Data = die.Data
                    };
                }
                else
                {
                    rolls++;
                    RollType rt = RollType.Normal;
                    switch (die.DieType)
                    {
                    case DieType.Normal:
                        rt = RollType.Normal;
                        break;

                    case DieType.Fudge:
                        rt = RollType.Fudge;
                        break;

                    default:
                        throw new InvalidOperationException("Unsupported die type in reroll");
                    }

                    reroll = RollNode.DoRoll(data, rt, die.NumSides, DieFlags.Extra);
                }
            }

            foreach (var die in Expression.Values)
            {
                if (die.DieType == DieType.Special || die.Flags.HasFlag(DieFlags.Dropped) || !Comparison.Compare(die.Value))
                {
                    _values.Add(die);
                    continue;
                }

                _values.Add(die.Drop());
                DoReroll(die, out DieResult rr);

                while (rerolls < maxRerolls && Comparison.Compare(rr.Value))
                {
                    _values.Add(new DieResult(SpecialDie.Add));
                    _values.Add(rr.Drop()); // mark the overall result as dropped
                    DoReroll(die, out rr);
                }

                _values.Add(new DieResult(SpecialDie.Add));
                _values.Add(rr);
            }

            var dice = _values.Where(d => d.DieType != DieType.Special && !d.Flags.HasFlag(DieFlags.Dropped));

            if (Expression.ValueType == ResultType.Total)
            {
                Value     = dice.Sum(d => d.Value);
                ValueType = ResultType.Total;
            }
            else
            {
                Value     = dice.Sum(d => d.SuccessCount);
                ValueType = ResultType.Successes;
            }

            return(rolls);
        }