Esempio n. 1
0
        private void cmdRollDice_Click(object sender, EventArgs e)
        {
            List <int> lstRandom    = new List <int>(nudDice.ValueAsInt);
            int        intGlitchMin = 1;

            // If Rushed Job is checked, the minimum die result for a Glitch becomes 2.
            if (chkRushJob.Checked)
            {
                intGlitchMin = 2;
            }

            int intTarget = 5;

            // If Cinematic Gameplay is turned on, Hits occur on 4, 5, or 6 instead.
            if (chkCinematicGameplay.Checked)
            {
                intTarget = 4;
            }
            switch (cboMethod.SelectedValue.ToString())
            {
            case "Large":
            {
                intTarget = 3;
                break;
            }

            case "ReallyLarge":
            {
                intTarget    = 1;
                intGlitchMin = 7;
                break;
            }
            }

            for (int intCounter = 1; intCounter <= nudDice.Value; intCounter++)
            {
                if (chkRuleOf6.Checked)
                {
                    int intResult;
                    do
                    {
                        intResult = GlobalSettings.RandomGenerator.NextD6ModuloBiasRemoved();
                        lstRandom.Add(intResult);
                    } while (intResult == 6);
                }
                else
                {
                    int intResult = GlobalSettings.RandomGenerator.NextD6ModuloBiasRemoved();
                    lstRandom.Add(intResult);
                }
            }

            _lstResults.Clear();
            foreach (int intResult in lstRandom)
            {
                DiceRollerListViewItem lviCur = new DiceRollerListViewItem(intResult, intTarget, intGlitchMin);
                _lstResults.Add(lviCur);
            }

            int intHitCount    = cboMethod.SelectedValue?.ToString() == "ReallyLarge" ? _lstResults.Sum(x => x.Result) : _lstResults.Count(x => x.IsHit);
            int intGlitchCount = _lstResults.Count(x => x.IsGlitch);

            int intGlitchThreshold = chkVariableGlitch.Checked
                ? intHitCount + 1
                : ((nudDice.Value + 1) / 2).StandardRound();

            // Deduct the Gremlins Rating from the Glitch Threshold.
            intGlitchThreshold -= nudGremlins.ValueAsInt;
            if (intGlitchThreshold < 1)
            {
                intGlitchThreshold = 1;
            }

            string strSpace = LanguageManager.GetString("String_Space");

            if (chkBubbleDie.Checked &&
                (chkVariableGlitch.Checked ||
                 (intGlitchCount == intGlitchThreshold - 1 &&
                  (nudDice.ValueAsInt & 1) == 0)))
            {
                int intBubbleDieResult        = GlobalSettings.RandomGenerator.NextD6ModuloBiasRemoved();
                DiceRollerListViewItem lviCur = new DiceRollerListViewItem(intBubbleDieResult, intTarget, intGlitchMin, true);
                if (lviCur.IsGlitch)
                {
                    ++intGlitchCount;
                }
                _lstResults.Add(lviCur);
            }

            lblResultsLabel.Visible = true;
            using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                           out StringBuilder sbdResults))
            {
                if (intGlitchCount >= intGlitchThreshold)
                {
                    if (intHitCount > 0)
                    {
                        if (nudThreshold.Value > 0)
                        {
                            sbdResults.Append(LanguageManager.GetString(
                                                  intHitCount >= nudThreshold.Value
                                                      ? "String_DiceRoller_Success"
                                                      : "String_DiceRoller_Failure")).Append(strSpace).Append('(');
                        }

                        sbdResults.AppendFormat(GlobalSettings.CultureInfo,
                                                LanguageManager.GetString("String_DiceRoller_Glitch"), intHitCount);
                        if (nudThreshold.Value > 0)
                        {
                            sbdResults.Append(')');
                        }
                    }
                    else
                    {
                        sbdResults.Append(LanguageManager.GetString("String_DiceRoller_CriticalGlitch"));
                    }
                }
                else if (nudThreshold.Value > 0)
                {
                    sbdResults
                    .Append(LanguageManager.GetString(intHitCount >= nudThreshold.Value
                                                              ? "String_DiceRoller_Success"
                                                              : "String_DiceRoller_Failure")).Append(strSpace)
                    .Append('(')
                    .AppendFormat(GlobalSettings.CultureInfo, LanguageManager.GetString("String_DiceRoller_Hits"),
                                  intHitCount + ')');
                }
                else
                {
                    sbdResults.AppendFormat(GlobalSettings.CultureInfo,
                                            LanguageManager.GetString("String_DiceRoller_Hits"), intHitCount);
                }

                sbdResults.AppendLine().AppendLine().Append(LanguageManager.GetString("Label_DiceRoller_Sum"))
                .Append(strSpace).Append(_lstResults.Sum(x => x.Result).ToString(GlobalSettings.CultureInfo));
                lblResults.Text = sbdResults.ToString();
            }

            lstResults.BeginUpdate();
            lstResults.Items.Clear();
            foreach (DiceRollerListViewItem objItem in _lstResults)
            {
                lstResults.Items.Add(objItem);
            }
            lstResults.EndUpdate();
        }
Esempio n. 2
0
        private async void cmdReroll_Click(object sender, EventArgs e)
        {
            //Remove the BubbleDie (it is always at the end)
            _lstResults.RemoveAll(x => x.BubbleDie);

            // If Rushed Job is checked, the minimum die result for a Glitch becomes 2.
            int intGlitchMin = 1;

            if (await chkRushJob.DoThreadSafeFuncAsync(x => x.Checked))
            {
                intGlitchMin = 2;
            }

            int intTarget = 5;

            // If Cinematic Gameplay is turned on, Hits occur on 4, 5, or 6 instead.
            if (await chkCinematicGameplay.DoThreadSafeFuncAsync(x => x.Checked))
            {
                intTarget = 4;
            }
            switch (await cboMethod.DoThreadSafeFuncAsync(x => x.SelectedValue.ToString()))
            {
            case "Large":
            {
                intTarget = 3;
                break;
            }

            case "ReallyLarge":
            {
                intTarget    = 1;
                intGlitchMin = 7;
                break;
            }
            }

            foreach (DiceRollerListViewItem objItem in _lstResults)
            {
                objItem.Target    = intTarget;
                objItem.GlitchMin = intGlitchMin;
            }

            // Remove everything that is not a hit
            int intNewDicePool = _lstResults.Count(x => !x.IsHit);

            _lstResults.RemoveAll(x => !x.IsHit);

            if (intNewDicePool == 0)
            {
                MessageBox.Show(await LanguageManager.GetStringAsync("String_NoDiceLeft_Text"), await LanguageManager.GetStringAsync("String_NoDiceLeft_Title"));
                return;
            }

            int intHitCount = await cboMethod.DoThreadSafeFuncAsync(x => x.SelectedValue?.ToString()) == "ReallyLarge" ? _lstResults.Sum(x => x.Result) : _lstResults.Count(x => x.IsHit);

            int        intGlitchCount = _lstResults.Count(x => x.IsGlitch);
            List <int> lstRandom      = new List <int>(intNewDicePool);

            for (int intCounter = 1; intCounter <= intNewDicePool; intCounter++)
            {
                if (await chkRuleOf6.DoThreadSafeFuncAsync(x => x.Checked))
                {
                    int intLoopResult;
                    do
                    {
                        intLoopResult = await GlobalSettings.RandomGenerator.NextD6ModuloBiasRemovedAsync();

                        lstRandom.Add(intLoopResult);
                    } while (intLoopResult == 6);
                }
                else
                {
                    int intLoopResult = await GlobalSettings.RandomGenerator.NextD6ModuloBiasRemovedAsync();

                    lstRandom.Add(intLoopResult);
                }
            }

            foreach (int intResult in lstRandom)
            {
                DiceRollerListViewItem lviCur = new DiceRollerListViewItem(intResult, intTarget, intGlitchMin);
                _lstResults.Add(lviCur);
            }

            int intGlitchThreshold = await chkVariableGlitch.DoThreadSafeFuncAsync(x => x.Checked)
                ? intHitCount + 1
                : (_lstResults.Count + 1) / 2;

            // Deduct the Gremlins Rating from the Glitch Threshold.
            intGlitchThreshold -= await nudGremlins.DoThreadSafeFuncAsync(x => x.ValueAsInt);

            if (intGlitchThreshold < 1)
            {
                intGlitchThreshold = 1;
            }

            string strSpace = await LanguageManager.GetStringAsync("String_Space");

            if (await chkBubbleDie.DoThreadSafeFuncAsync(x => x.Checked) &&
                (await chkVariableGlitch.DoThreadSafeFuncAsync(x => x.Checked) ||
                 (intGlitchCount == intGlitchThreshold - 1 &&
                  (_lstResults.Count & 1) == 0)))
            {
                int intBubbleDieResult = await GlobalSettings.RandomGenerator.NextD6ModuloBiasRemovedAsync();

                DiceRollerListViewItem lviCur = new DiceRollerListViewItem(intBubbleDieResult, intTarget, intGlitchMin, true);
                if (lviCur.IsGlitch)
                {
                    ++intGlitchCount;
                }
                _lstResults.Add(lviCur);
            }

            await lblResultsLabel.DoThreadSafeAsync(x => x.Visible = true);

            using (new FetchSafelyFromPool <StringBuilder>(Utils.StringBuilderPool,
                                                           out StringBuilder sbdResults))
            {
                if (intGlitchCount >= intGlitchThreshold)
                {
                    if (intHitCount > 0)
                    {
                        int intThreshold = await nudThreshold.DoThreadSafeFuncAsync(x => x.ValueAsInt);

                        if (intThreshold > 0)
                        {
                            sbdResults.Append(await LanguageManager.GetStringAsync(
                                                  intHitCount >= intThreshold
                                    ? "String_DiceRoller_Success"
                                    : "String_DiceRoller_Failure")).Append(strSpace).Append('(');
                        }

                        sbdResults.AppendFormat(GlobalSettings.CultureInfo,
                                                await LanguageManager.GetStringAsync("String_DiceRoller_Glitch"), intHitCount);
                        if (intThreshold > 0)
                        {
                            sbdResults.Append(')');
                        }
                    }
                    else
                    {
                        sbdResults.Append(await LanguageManager.GetStringAsync("String_DiceRoller_CriticalGlitch"));
                    }
                }
                else
                {
                    int intThreshold = await nudThreshold.DoThreadSafeFuncAsync(x => x.ValueAsInt);

                    if (intThreshold > 0)
                    {
                        sbdResults
                        .Append(await LanguageManager.GetStringAsync(intHitCount >= intThreshold
                                                                             ? "String_DiceRoller_Success"
                                                                             : "String_DiceRoller_Failure")).Append(strSpace)
                        .Append('(')
                        .AppendFormat(GlobalSettings.CultureInfo, await LanguageManager.GetStringAsync("String_DiceRoller_Hits"),
                                      intHitCount).Append(')');
                    }
                    else
                    {
                        sbdResults.AppendFormat(GlobalSettings.CultureInfo,
                                                await LanguageManager.GetStringAsync("String_DiceRoller_Hits"), intHitCount);
                    }
                }

                sbdResults.AppendLine().AppendLine().Append(await LanguageManager.GetStringAsync("Label_DiceRoller_Sum"))
                .Append(strSpace).Append(_lstResults.Sum(x => x.Result).ToString(GlobalSettings.CultureInfo));
                await lblResults.DoThreadSafeAsync(x => x.Text = sbdResults.ToString());
            }

            await lstResults.DoThreadSafeAsync(x =>
            {
                x.BeginUpdate();
                try
                {
                    x.Items.Clear();
                    foreach (DiceRollerListViewItem objItem in _lstResults)
                    {
                        x.Items.Add(objItem);
                    }
                }
                finally
                {
                    x.EndUpdate();
                }
            });
        }