Exemplo n.º 1
0
        private void statusChanged(string pEvent, ARollable pSourceA = null, ARollable pSourceB = null)
        {
            //collect info about all the dice info (one level deep) and print it
            _stringBuilder.Length = 0;

            if (logEvents)
            {
                _stringBuilder.AppendLine(pEvent + (pSourceA == null ? "" : " / " + pSourceA.name) + (pSourceB == null ? "" : " / " + pSourceB.name));
            }

            for (int i = 0; i < _dieCollection.Count; i++)
            {
                ARollable   die    = _dieCollection.Get(i);
                IRollResult result = die.GetRollResult();

                string resultColor = (die.HasEndResult() && result.isExact) ? "green" : "blue";
                //only show values if we are NOT rolling OR updating every frame
                string resultValues = (!die.isRolling || updateEveryFrame) ? result.valuesAsString : "*";
                _stringBuilder.AppendFormat("<color={0}>{1}={2}</color> ", resultColor, die.name, resultValues);
            }

            _stringBuilder.AppendLine("\nAny dice still rolling? " + (_dieCollection.isRolling ? "Yes (" + _dieCollection.RollingCount + ")" : "No"));

            IRollResult collectionResult       = _dieCollection.GetRollResult();
            string      collectionResultValues = (!_dieCollection.isRolling || updateEveryFrame) ? collectionResult.valuesAsString : "*";

            _stringBuilder.AppendLine("Dice collection value totals:" + collectionResultValues);

            Debug.Log(_stringBuilder.ToString());
        }
Exemplo n.º 2
0
        public DieCollectionResult(DieCollection pDieCollection)
        {
            //to be exact we cannot be rolling
            isExact = !pDieCollection.isRolling;

            //go through all items in the collection, get the results and add them together
            int rollableCount = pDieCollection.Count;

            for (int i = 0; i < rollableCount; i++)
            {
                IRollResult result = pDieCollection.Get(i).GetRollResult();

                //the collection is only exact if every item is exact
                isExact &= result.isExact;

                //make sure the valueTotals list contains enough items and add the totals
                for (int j = 0; j < result.valueCount; j++)
                {
                    if (_valueTotals.Count < j + 1)
                    {
                        _valueTotals.Add(0);
                    }
                    _valueTotals[j] += result.Value(j);
                }
            }

            _valuesAsString = StringUtility.ToString(_valueTotals);
        }
Exemplo n.º 3
0
        private void statusChanged(string pEvent, ARollable pSourceA = null, ARollable pSourceB = null)
        {
            if (_dieCollection == null)
            {
                return;
            }

            if (logEvents && pEvent != null)
            {
                Debug.Log(pEvent + (pSourceA == null?"": "/" + pSourceA.name) + (pSourceB == null ? "" : "/" + pSourceB.name));
            }

            int diceTextsCount = Mathf.Min(_diceTexts.Count, _dieCollection.Count);

            for (int i = 0; i < diceTextsCount; i++)
            {
                ARollable   die    = _dieCollection.Get(i);
                IRollResult result = die.GetRollResult();

                string resultColor = (die.HasEndResult() && result.isExact)?"green":"blue";
                //only show values if we are NOT rolling OR updating every frame
                string resultValues =
                    (!die.isRolling || updateEveryFrame) ? result.valuesAsString : "*";

                _diceTexts[i].text = string.Format("<color={0}>{1}={2}</color>", resultColor, die.name, resultValues);
            }

            _dieCountText.text = "" + _dieCollection.Count;
            if (pEvent != null)
            {
                _lastEventText.text = pEvent;
            }
            _rollingInfoText.text = _dieCollection.isRolling ? ("Yes (" + _dieCollection.RollingCount + ")") : "No";

            IRollResult collectionResult       = _dieCollection.GetRollResult();
            string      collectionResultValues = (!_dieCollection.isRolling || updateEveryFrame) ? collectionResult.valuesAsString : "*";

            _dieTotalText.text = collectionResultValues;
        }