private void Calculate()
        {
            (double, string)mainDiceResult = _diceService.EvaluateExpression(_expressionString);
            _result = (int)mainDiceResult.Item1;

            if (_closeOnCalculate)
            {
                _accepted = true;
                Close?.Invoke(this, EventArgs.Empty);
            }
        }
        private void _diceWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            int rolls = 0;

            while (rolls++ < 10)
            {
                (double, string)mainDiceResult = _diceService.EvaluateExpression(_rollString);
                _rollResult           = mainDiceResult.Item1.ToString();
                _rollResultExpression = mainDiceResult.Item2;

                if (_advantageDisadvantageVisible)
                {
                    (double, string)secondDiceResult = _diceService.EvaluateExpression(_rollString);

                    if (secondDiceResult.Item1 > mainDiceResult.Item1)
                    {
                        _rollAdvantageResult              = secondDiceResult.Item1.ToString();
                        _rollAdvantageResultExpression    = secondDiceResult.Item2;
                        _rollDisadvantageResult           = mainDiceResult.Item1.ToString();
                        _rollDisadvantageResultExpression = mainDiceResult.Item2;
                    }
                    else
                    {
                        _rollAdvantageResult              = mainDiceResult.Item1.ToString();
                        _rollAdvantageResultExpression    = mainDiceResult.Item2;
                        _rollDisadvantageResult           = secondDiceResult.Item1.ToString();
                        _rollDisadvantageResultExpression = secondDiceResult.Item2;
                    }

                    OnPropertyChanged(nameof(RollAdvantageResult));
                    OnPropertyChanged(nameof(RollAdvantageResultExpression));
                    OnPropertyChanged(nameof(RollDisadvantageResult));
                    OnPropertyChanged(nameof(RollDisadvantageResultExpression));
                }

                OnPropertyChanged(nameof(RollResult));
                OnPropertyChanged(nameof(RollResultExpression));

                Thread.Sleep(100);
            }
        }
Esempio n. 3
0
 private void RollCompanionHP()
 {
     if (_companionModel.MonsterModel != null)
     {
         string hpString = _companionModel.MonsterModel.HP;
         if (!String.IsNullOrWhiteSpace(hpString))
         {
             string[] hpStrings = hpString.Split(new string[] { " " }, StringSplitOptions.RemoveEmptyEntries);
             if (hpStrings.Length > 1)
             {
                 (double, string)rollResult = _diceService.EvaluateExpression(hpStrings[1]);
                 if (rollResult.Item1 != 0)
                 {
                     _companionModel.MaxHP = (int)rollResult.Item1;
                     OnPropertyChanged(nameof(MaxHP));
                 }
             }
         }
     }
 }
Esempio n. 4
0
 private void RollCharacterInitiative(EncounterCreatureViewModel character)
 {
     character.Initiative = (int)_diceService.EvaluateExpression($"1d20+{character.InitiativeBonus}").Item1;
 }