Beispiel #1
0
        /// <summary>
        /// Generates a random roll result
        /// </summary>
        /// <returns></returns>
        public static RollResult NextResult()
        {
            int        result = rand.Next(0, PossibleResults.Length);
            RollResult rr     = new RollResult(PossibleResults[result]);

            return(rr);
        }
Beispiel #2
0
        public void TotalReturnsTheSumOfBothRolls()
        {
            var expectedTotal = 9;
            var rollResult    = new RollResult(5, 4);

            Assert.AreEqual(expectedTotal, rollResult.Total);
        }
Beispiel #3
0
        /// <summary>
        /// Performs a roll on a character's statistic and returns the result.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="statName">The statistic name.</param>
        /// <returns>The result of the roll.</returns>
        public async Task <IResult> RollStatisticAsync(ulong callerId, string statName, bool useEffects = false)
        {
            var character = await _provider.GetActiveCharacterAsync(callerId);

            if (character == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var stat = await _statProvider.GetStatisticAsync(statName);

            if (stat == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            string result = _strategy.GetRollMessage(stat, character, useEffects);

            if (!string.IsNullOrEmpty(result))
            {
                return(RollResult.Roll(result));
            }

            return(RollResult.RollFailed());
        }
Beispiel #4
0
        public void AddPoints(Category category)
        {
            if (_gameStatus[ActivePlayer][category] != null)
            {
                throw new ArgumentException($"Category {category} already taken! Choose other category.");
            }

            int[] rollResult = RollResult.Select(x => x.Result).ToArray();
            var   scorer     = ScorerFactory.GetScorer(_hasYahtzee[ActivePlayer]);

            _gameStatus[ActivePlayer][category] = scorer.CalculateCategoryScore(category, rollResult);

            CalculateScore();

            if (!_hasYahtzee[ActivePlayer] && _gameStatus[ActivePlayer][Category.Yahtzee] == 50)
            {
                _hasYahtzee[ActivePlayer] = true;
            }
            else if (_hasYahtzee[ActivePlayer] && new RegularScorer().CalculateCategoryScore(Category.Yahtzee, rollResult) == 50)
            {
                _gameStatus[ActivePlayer][Category.Yahtzee] += 100;
            }

            ActivePlayer++;
            RollsLeft = 3;

            if (ActivePlayer > Players.Length - 1)
            {
                ActivePlayer = 0;
            }
        }
Beispiel #5
0
        public IEnumerable <Bet> HandleBets(Models.Game game, RollResult roll, IEnumerable <Bet> bets)
        {
            IEnumerable <Bet> openBets = _gameRepository.GetBetsByStatus(BetStatus.Open);

            foreach (Bet bet in bets)
            {
                // handle winning bets
                if (game.LastGameEvents.Any(x => x == bet.GameEventId))
                {
                    bet.BetStatusId = BetStatus.Won;
                    bet.Payout      = CalculateBetPayout(bet);
                }
                else
                {
                    // check if last game event constitutes bet loss
                    if (DoesGameEventLoseBet(game, roll, bet))
                    {
                        bet.BetStatusId = BetStatus.Lost;
                        bet.Payout      = bet.Amount * -1;
                    }
                }
            }

            return(bets);
        }
Beispiel #6
0
        public static void RollTest(string roll, string regex, double min, double max)
        {
            RollResult result = dieRoller.RollDice(roll);

            Assert.IsTrue(min <= result.Result && result.Result <= max);
            Assert.IsTrue(Regex.IsMatch(result.RolledNotation, regex));
        }
Beispiel #7
0
    public static RollResult GetResultFromRoll(IAttacker attacker, IDefender defender, List <int> rolledFaceIndexAttack, List <int> rolledFaceIndexDefense)
    {
        var result = new RollResult();

        if (attacker != null)
        {
            var attackerDice = attacker.AttackDice;
            for (int i = 0; i < attackerDice.Count; ++i)
            {
                var face = attackerDice[i].GetFace(rolledFaceIndexAttack[i]);
                result.heart     += face.heart;
                result.surge     += face.surge;
                result.range     += face.range;
                result.pierce     = attacker.Pierce;
                result.bonusRange = attacker.RangeModifier;
                if (face.IsMiss)
                {
                    result.miss = true;
                }
            }
        }
        if (defender != null)
        {
            var defenderDice = defender.DefenseDice;
            for (int i = 0; i < defenderDice.Count; ++i)
            {
                result.defense += defenderDice[i].GetDefensePerFace(rolledFaceIndexDefense[i]);
            }
        }
        result.defense = Mathf.Max(0, result.defense);

        return(result);
    }
Beispiel #8
0
        /// <summary>
        /// Performs a duel between two characters rolling a statistic and returns the result.
        /// </summary>
        /// <param name="callerId">Discord ID of the caller.</param>
        /// <param name="targetId">Discord ID of the target.</param>
        /// <param name="statName">The statistic name.</param>
        /// <returns>The result of the roll.</returns>
        public async Task <IResult> RollStatisticAgainstAsync(ulong callerId, ulong targetId, string statName, bool useEffects = false)
        {
            var caller = await _provider.GetActiveCharacterAsync(callerId);

            if (caller == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var target = await _provider.GetActiveCharacterAsync(targetId);

            if (target == null)
            {
                return(CharacterResult.CharacterNotFound());
            }

            var stat = await _statProvider.GetStatisticAsync(statName);

            if (stat == null)
            {
                return(StatisticResult.StatisticNotFound());
            }

            double?callerRoll = _strategy.RollStatistic(stat, caller, useEffects);
            double?targetRoll = _strategy.RollStatistic(stat, target, useEffects);

            if (callerRoll.HasValue && targetRoll.HasValue)
            {
                return(RollResult.RollAgainst(caller.Name, target.Name, callerRoll.Value, targetRoll.Value));
            }

            return(RollResult.RollFailed());
        }
    public void Roll()
    {
        IsRolling = true;

        ResetResultsText();

        _lastRollResult = Roller.CombatRoll(_attacker, _defender, out _rolledFaceIndexAttack, out _rolledFaceIndexDefense);

        var attackDice  = _attacker != null ? _attacker.AttackDice : new List <AttackDieDef>();
        var defenseDice = _defender != null ? _defender.DefenseDice : new List <DefenseDieDef>();

        ShowCombatRoll(attackDice, defenseDice, _rolledFaceIndexAttack, _rolledFaceIndexDefense);
        UpdatePierce(_attacker);
        UpdateRangeModifier(_attacker);

        if (_coroutine != null)
        {
            StopCoroutine(_coroutine);
        }

        var listDice = new List <DieAnimator>(_attackDiceAnimator);

        listDice.AddRange(_defenseDiceAnimator);         // add all die animators
        _coroutine = StartCoroutine(WaitAndUpdateResult(_lastRollResult, listDice));
    }
    void UpdateResult(RollResult result, AttackType attackType)
    {
        _textHeart.text   = result.heart.ToString();
        _textDefense.text = result.defense.ToString();
        if (result.pierce > 0)
        {
            _textDefense.text += " (-" + result.pierce + ")";
        }
        _textSurge.text = result.surge.ToString();
        if (attackType == AttackType.Ranged)
        {
            _textRange.text = result.range.ToString();
            if (result.bonusRange > 0)
            {
                _textRange.text += " (+" + result.bonusRange + ")";
            }
        }
        else
        {
            _textRange.text = "--";
        }
        var defense = result.defense - result.pierce;

        defense          = Mathf.Max(0, defense);
        _textDamage.text = (result.heart - defense).ToString();
        _gobMissed.SetActive(result.miss);
    }
Beispiel #11
0
        override public void RenderResult(object sender, RollResult result)
        {
            base.RenderResult(sender, result);
            if (result.RootSlot == null)
            {
                return;
            }

            if (highlighted)
            {
                highlighted.Dehighlight();
                highlighted = null;
            }

            if (chained)
            {
                if (needsReset)
                {
                    CreateWheel(result.RootSlot.subslots);
                }

                needsReset = true;
            }

            if (hideUnchosen)
            {
                foreach (KeyValuePair <WheelBase, DiskSliceBase> slicePair in sliceDict)
                {
                    slicePair.Value.Toggle(state: true);
                }
            }

            animationCoroutine = StartCoroutine(RollAnimation(result));
        }
        public async Task SendDieRollWebhook(string url, RollResult rollResult)
        {
            DiscordWebHookModel dwhm = new DiscordWebHookModel();

            string Title       = $"Rolled for {rollResult.Reason}";
            string Description = "";

            if (rollResult.OriginalTargetNumber != 0)
            {
                Title       = rollResult.Success ? " SUCCESS!" : " FAILURE";
                Description = "**Difficulty:** {rollResult.ModifiedTargetNumber} TN({rollResult.ModifiedTargetNumber * 3})\n";
            }



            dwhm.username = rollResult.CharacterName;
            dwhm.embeds.Add(
                new DiscordWebHookEmbed()
            {
                title       = Title,
                description = Description + $"**Trained** {rollResult.Trained}\n**Other Modifiers** {rollResult.Modifiers}\n**Final Difficulty:** {rollResult.ModifiedTargetNumber}\n**Roll:** {rollResult.Result} Beats difficulty {(rollResult.Result / 3) + rollResult.Modifiers + rollResult.Trained} (TN: {((rollResult.Result / 3) + rollResult.Modifiers + rollResult.Trained) * 3})",
                author      = new DiscordWebHookEmbedAuthor {
                    author = $"{rollResult.Reason} - {rollResult.Type} - {rollResult.Stat}"
                },
                footer = new DiscordWebHookEmbedFooter {
                    text = rollResult.SpecialText
                }
            });

            await SendWebHook(url, dwhm);
        }
Beispiel #13
0
    public RollResult Roll(int pool, int limit, bool explode)
    {
        RollResult returnValue = new RollResult(0, 0);
        int        rollResult;

        while (pool > 0)
        {
            pool--;
            rollResult = Random.Range(1, 7);

            if (rollResult > 4)
            {
                returnValue.successes++;
            }
            else if (rollResult == 1)
            {
                returnValue.glitch++;
            }

            if (explode && rollResult == 6)
            {
                pool++;
            }
        }

        if (!explode)
        {
            returnValue.successes = Mathf.Clamp(returnValue.successes, 0, limit);
        }

        return(returnValue);
    }
        public void HandleRoll_SubsequentRoll_TwelveRolled_ReturnTrue()
        {
            // instantiate Game
            _game       = new Models.Game();
            _game.State = GameState.SubsequentRoll;
            _game.Point = 9;

            // override Game
            _game = _gameService.OverrideGame(_game);

            // instantiate roll result
            RollResult roll = ForceRollResult(6, 6);

            // call HandleRoll with a twelve
            _game = _gameService.HandleRoll(roll);

            // Make sure game isn't marked as completed and correct events are triggered
            Assert.True(_game.Completed == false);
            Assert.Contains(_game.LastGameEvents, x => x == GameEvent.Twelve);
            Assert.Contains(_game.LastGameEvents, x => x == GameEvent.Craps);
            Assert.Contains(_game.LastGameEvents, x => x == GameEvent.C);
            Assert.Contains(_game.LastGameEvents, x => x == GameEvent.Field);
            Assert.DoesNotContain(_game.LastGameEvents, x => x == GameEvent.Pass);
            Assert.DoesNotContain(_game.LastGameEvents, x => x == GameEvent.DontPass);
        }
Beispiel #15
0
            public AttackRollResult(Attack atk)
            {
                _Attack = atk;

                _Name = atk.Name;

                Rolls = new List <SingleAttackRoll>();

                if (atk.Weapon != null)
                {
                    _Name = atk.Weapon.Name;
                }

                int totalAttacks = atk.Count * atk.Bonus.Count;

                for (int atkcount = 0; atkcount < atk.Count; atkcount++)
                {
                    foreach (int mod in atk.Bonus)
                    {
                        SingleAttackRoll sr = new SingleAttackRoll();

                        DieRoll roll = new DieRoll(1, 20, mod);

                        sr.Result = roll.Roll();
                        sr.Damage = atk.Damage.Roll();

                        if (atk.Plus != null)
                        {
                            Regex plusRegex = new Regex("(?<die>[0-9]+d[0-9]+((\\+|-)[0-9]+)?) (?<type>[a-zA-Z]+)");
                            Match dm        = plusRegex.Match(atk.Plus);
                            if (dm.Success)
                            {
                                DieRoll     bonusRoll = DieRoll.FromString(dm.Groups["die"].Value);
                                BonusDamage bd        = new BonusDamage();
                                bd.Damage     = bonusRoll.Roll();
                                bd.DamageType = dm.Groups["type"].Value;
                                sr.BonusDamage.Add(bd);
                            }
                        }

                        if (sr.Result.Rolls[0].Result >= atk.CritRange)
                        {
                            sr.CritResult = roll.Roll();

                            sr.CritDamage = new RollResult();

                            for (int i = 1; i < atk.CritMultiplier; i++)
                            {
                                RollResult crit = atk.Damage.Roll();

                                sr.CritDamage = crit + sr.CritDamage;
                            }
                        }


                        Rolls.Add(sr);
                    }
                }
            }
Beispiel #16
0
        public void RollResultCorrectlyAssignesInputs()
        {
            RollResult rr = new RollResult(1, 2, 3);

            Assert.AreEqual(1, rr.Die1());
            Assert.AreEqual(2, rr.Die2());
            Assert.AreEqual(3, rr.Die3());
        }
Beispiel #17
0
        public void Dice_2Set_6Side_CanRoll_ReturnTrue()
        {
            RollResult result = TwoSixSidedDice.Roll();

            Assert.True(result.Dice[0].Value >= 1 && result.Dice[0].Value <= 6);
            Assert.True(result.Dice[1].Value >= 1 && result.Dice[1].Value <= 6);
            Assert.True(result.Total > 0);
        }
Beispiel #18
0
        public void DiceRollDoesNotKeepPreviousResultOfZero()
        {
            RollResult previousResult = new RollResult(4, 0, 4);

            RollResult currentResult = master.RollDice(true, false, true, previousResult);

            Assert.AreNotEqual(0, currentResult.Die2());
        }
Beispiel #19
0
        public void DiceRollKeepsPreviousDie2Result()
        {
            RollResult previousResult = new RollResult(4, 7, 4);

            RollResult currentResult = master.RollDice(true, false, true, previousResult);

            Assert.AreEqual(7, currentResult.Die2());
        }
Beispiel #20
0
        public void DiceRollWorksWithoutPreviousResult()
        {
            RollResult rr = master.RollDice(true, true, true, null);

            Assert.IsTrue(1 <= rr.Die1() && 6 >= rr.Die1());
            Assert.IsTrue(1 <= rr.Die2() && 6 >= rr.Die2());
            Assert.IsTrue(1 <= rr.Die3() && 6 >= rr.Die3());
        }
Beispiel #21
0
        public async Task <RollResult> GetSkillResult(string characterName, CharacterSkill skill, int targetLevel)
        {
            var result = random.Next(1, 21);

            var rollresult = RollResult.PerformSkillRoll(characterName, result, 0, 0, skill);

            return(rollresult);
        }
Beispiel #22
0
        private static string FormatRollResult(RollResult rollResult)
        {
            var dicesfmt = rollResult.Dices.Count > 1 ? $"{FormatDices(rollResult.Dices)} = " : "";
            var namefmt  = FormatName(rollResult.Name);
            var descrfmt = FormatDescription(rollResult.Description);

            return($"{namefmt}{descrfmt} -> {dicesfmt}{rollResult.Result}");
        }
Beispiel #23
0
        /// <summary>
        /// Formats a single roll into it's string representation.
        /// </summary>
        /// <param name="roll">The roll to format.</param>
        /// <returns>A string representation of the roll.</returns>
        private static string FormatRoll(RollResult roll)
        {
            string rollText = $"{roll.Result}";

            rollText = !roll.Valid ? $"~~{rollText}~~" : rollText;
            rollText = roll.IsCrit() ? $"**{rollText}**" : rollText;

            return(rollText);
        }
Beispiel #24
0
        public RollResult Roll(string dieRollString)
        {
            DieRoll    dr     = new DieRoll(dieRollString);
            RollResult result = new RollResult();

            result.DieRollString = dieRollString;
            result.RolledValue   = dr.Roll();
            return(result);
        }
Beispiel #25
0
        public RollResult ComputeTurnResult()
        {
            RollResult rollResult = RollResult.Lose;

            if (Dices.All(dice => dice.Face == Dices[0].Face))
            {
                rollResult = Dices[0].Face == Dices[0].Max ? RollResult.Jackpot : RollResult.Win;
            }
            return(rollResult);
        }
        public void Successfully_RoundtripRollResult_ForPersistence()
        {
            var stream = new MemoryStream();
            var result = Roller.Roll("1d20+4");

            result.Serialize(stream);
            stream.Seek(0, SeekOrigin.Begin);
            var result2 = RollResult.Deserialize(stream);

            Assert.AreEqual(result, result2);
        }
Beispiel #27
0
 /// <summary>
 /// Execute the command providing the player is computer
 /// </summary>
 private void ExecuteAutomatic()
 {
     do
     {
         RollResult rr = NextResult();
         Context.RollResults.Add(rr);
         Context.RollAgain = rr.IsRepeatable;
     } while (Context.RollAgain);
     Status = CommandStatus.Completed;
     GameApp.Instance.Turn.Update();
 }
    IEnumerator WaitAndUpdateResult(RollResult result, List <DieAnimator> listDice)
    {
        _gobMissed.SetActive(false);

        yield return(DieAnimator.WaitForUntilAllDiceFinishRolling(listDice));

        UpdateResult(result, _attacker != null ? _attacker.AttackType : AttackType.Melee);

        IsRolling  = false;
        _coroutine = null;
    }
        private RollResult ForceRollResult(int dice1Value, int dice2Value)
        {
            RollResult rollResult = new RollResult();

            rollResult.Dice = new List <Die>();
            rollResult.Dice.Add(new Die(6));
            rollResult.Dice.Add(new Die(6));
            rollResult.Dice[0].Value = dice1Value;
            rollResult.Dice[1].Value = dice2Value;
            rollResult.Total         = dice1Value + dice2Value;
            return(rollResult);
        }
Beispiel #30
0
        void AddRoll(DieRoll r)
        {
            if (r != null)
            {
                RollResult res = r.Roll();

                _Results.Insert(0, res);

                TrimList();
            }
            RenderResults();
        }
Beispiel #31
0
    public IEnumerator SendPlayerStatus()
    {
        string _uuid;
        if (PlayerPrefs.HasKey ("uuid")) {
            _uuid = PlayerPrefs.GetString ("uuid");
        } else {
            yield break;
        }

        var data = new RollResult();
        data.BaseStatus = baseStatus;
        data.Status = status;

         var jsonData = JsonUtility.ToJson(data,true);

        string url = ConfURL.HOST_NAME+ConfURL.PLAYER_GENERATE;
        WWWForm form = new WWWForm ();
        form.AddField ("UUID", _uuid);
        form.AddField ("data", jsonData);

        WWW www = new WWW(url, form);

        yield return www;

        if (www.error != null) {
            Debug.Log("Error");
        } else {
            Debug.Log("Success");
            SceneManager.LoadScene("SkillSet");
        }
    }