Esempio n. 1
0
        public int Attack(Hero hero, DiceService diceService)
        {
            var damageMaximum = DamageMaximum - hero.ArmorBonus;

            damageMaximum = (damageMaximum > 10 ? damageMaximum : 10);
            return(diceService.Roll(damageMaximum));
        }
Esempio n. 2
0
        public void WhenDiceRolled_Should_ReturnNumberBw1And6()
        {
            var sut    = new DiceService();
            var result = sut.RollDice();

            result.Should().BeInRange(1, 6);
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            IDiceService       diceService     = new DiceService();
            IRulesService      rulesService    = new RulesService(diceService);
            var                rules           = rulesService.GetRules(ERules.Percentage);
            IStrategyService   strategyService = new StrategyService(rules);
            IVillage           village         = new Village(diceService, strategyService, rules);
            IList <ICharacter> fighters        = new List <ICharacter>();

            for (int i = 0; i < 200; i++)
            {
                var character = village.GetFighter(EFighterClass.Warrior);
                fighters.Add(character);
            }

            for (int i = 0; i < 10; i++)
            {
                var character = village.GetFighter(EFighterClass.Ranger);
                fighters.Add(character);
            }

            IArena arena = new ClassicArena(fighters);

            arena.StartFight();
        }
Esempio n. 4
0
        public int CollectCredits(DiceService diceService, RobotDifficulty difficulty)
        {
            var maxCredits = 0;

            switch (difficulty)
            {
            case RobotDifficulty.Difficult:
            {
                maxCredits = DifficultRobotMaxCredits;
                break;
            }

            case RobotDifficulty.Moderate:
            {
                maxCredits = ModerateRobotMaxCredits;
                break;
            }

            case RobotDifficulty.Easy:
            {
                maxCredits = EasyRobotMaxCredits;
                break;
            }
            }
            var creditsEarned = diceService.Roll(maxCredits);

            Credits += creditsEarned;
            return(creditsEarned);
        }
        /// <summary>
        /// Creats an instance of <see cref="DiceRollViewModel"/>
        /// </summary>
        public DiceRollViewModel(DiceService diceService)
        {
            _diceService = diceService;

            _diceWorker         = new BackgroundWorker();
            _diceWorker.DoWork += _diceWorker_DoWork;

            _rollCommand = new RelayCommand(obj => true, obj => Roll());
        }
Esempio n. 6
0
        public void DiceWithSixOnceSuccessfully()
        {
            diceService = new DiceService();
            DiceThrowVM result;

            result = diceService.Roll(6, 1);

            Assert.True(result.Result[0] <= 6);
            Assert.True(result.Result[0] >= 0);
        }
Esempio n. 7
0
 public DiceRollModel(int die, int sides, int rollModifier, int totalModifier)
 {
     Die           = die;
     Sides         = sides;
     RollModifier  = rollModifier;
     TotalModifier = totalModifier;
     Rolls         = DiceService.Roll(die, sides, rollModifier);
     Total         = Accumulate(Rolls) + TotalModifier;
     Description   = ToString();
 }
Esempio n. 8
0
        public InitiativeViewModel(DiceService diceService)
        {
            _diceService = diceService;

            _rollCharacterInitiativeCommand   = new RelayCommand(obj => true, obj => RollCharacterInitiative((EncounterCreatureViewModel)obj));
            _rollAllMonstersInitiativeCommand = new RelayCommand(obj => true, obj => RollAllMonstersInitiative());
            _rollMonsterInitiativeCommand     = new RelayCommand(obj => true, obj => RollMonsterInitiative((EncounterCreatureViewModel)obj));
            _acceptCommand = new RelayCommand(obj => true, obj => Accept());
            _rejectCommand = new RelayCommand(obj => true, obj => Reject());
        }
        public void Should_roll_dice_multiple_times(int times, int sides, int expected)
        {
            var random = Mock.Create <IRandomHelper>();

            Mock.Arrange(() => random.Next()).Occurs(times);

            var roller = new DiceService(random);

            var totalRoll = roller.Roll(times, sides);

            Assert.AreEqual(expected, totalRoll);
        }
Esempio n. 10
0
        public void GetDieAverage_shouldWork()
        {
            var diceService = new DiceService();

            diceService.GetDieAverage(6).Should().Be(4);
            diceService.GetDieAverage(8).Should().Be(5);
            diceService.GetDieAverage(10).Should().Be(6);
            diceService.GetDieAverage(12).Should().Be(7);

            // maybe you're playing with some bizarre house rules
            diceService.GetDieAverage(7).Should().Be(4);
        }
Esempio n. 11
0
        public int AwardBonusMoves(DiceService diceService, RobotDifficulty difficulty)
        {
            if (difficulty != RobotDifficulty.Difficult)
            {
                return(0);
            }

            var bonusMoves = diceService.Roll(3);

            MovesRemaining = MovesRemaining + bonusMoves;
            return(bonusMoves);
        }
Esempio n. 12
0
        public async Task RollInitiative()
        {
            try
            {
                var caller = Context.Guild.GetUser(Context.Message.Author.Id);

                List<ulong> players = caller.VoiceChannel.Users.Where(u => !u.IsBot).Select(u => u.Id).ToList();

                players.Remove(caller.Id);

                SortedDictionary<ulong, int> playerScores = new SortedDictionary<ulong, int>();

                List<string> failedInitiative = new List<string>();

                foreach (var player in players)
                {
                    var attributeResponse = CharacterService.GetAttribute(player, "Init");

                    if (!attributeResponse.Success)
                    {
                        await ReplyAsync($"`could not retrieve {Context.Guild.GetUser(player).Username} initiative. Error: {attributeResponse.Error}");
                        continue;
                    }

                    if (!int.TryParse(attributeResponse.Value, out int init))
                    {
                        failedInitiative.Add(Context.Guild.GetUser(player).Mention);
                    }
                    playerScores.Add(player, DiceService.RollExactDice("1d20").Sum() + init);
                }

                if (failedInitiative.Any())
                {
                    await ReplyAsync($"Players not registered: {string.Join(',', failedInitiative)}");
                }

                string response = string.Empty;
                foreach (var player in playerScores.OrderByDescending(x => x.Value))
                {
                    response += $"`[{Context.Guild.GetUser(player.Key).Username}]` : {player.Value}\r\n";
                }


                await ReplyAsync(response);
            }
            catch(Exception e)
            {
                string s = e.Message;
            }

            await Task.CompletedTask;
        }
        /// <summary>
        /// Creats an instance of <see cref="CalculatorViewModel"/>
        /// </summary>
        public CalculatorViewModel(DiceService diceService, DialogService dialogService)
        {
            _diceService   = diceService;
            _dialogService = dialogService;

            _rollWorker                     = new BackgroundWorker();
            _rollWorker.DoWork             += _rollWorker_DoWork;
            _rollWorker.RunWorkerCompleted += _rollWorker_RunWorkerCompleted;

            _addTextCommand   = new RelayCommand(obj => true, obj => AddText(obj as string));
            _calculateCommand = new RelayCommand(obj => true, obj => Calculate());
            _rollCommand      = new RelayCommand(obj => true, obj => Roll());
            _deleteCommand    = new RelayCommand(obj => true, obj => Delete());
            _clearCommand     = new RelayCommand(obj => true, obj => Clear());
        }
Esempio n. 14
0
        /// <summary>Executes the command.</summary>
        /// <param name="actionInput">The full input specified for executing the command.</param>
        public override void Execute(ActionInput actionInput)
        {
            // Send the attack event.
            IController     sender          = actionInput.Controller;
            UnbalanceEffect unbalanceEffect = new UnbalanceEffect()
            {
                Duration = new TimeSpan(0, 0, 0, 0, 5000),
            };

            sender.Thing.Behaviors.Add(unbalanceEffect);

            // Set up the dice for attack and defense rolls.
            // Currently does not consider equipment, skills or stats.
            DiceService dice       = DiceService.Instance;
            Die         attackDie  = dice.GetDie(20);
            Die         defenseDie = dice.GetDie(20);

            // Roll the dice to determine if the attacker hits.
            int attackRoll  = attackDie.Roll();
            int defenseRoll = defenseDie.Roll();

            // Determine amount of damage, if any. Cannot exceed the target's current health.
            int targetHealth = this.target.Stats["HP"].Value;
            int damage       = Math.Max(attackRoll - defenseRoll, 0);

            damage = Math.Min(damage, targetHealth);

            // Choose sensory messaging based on whether or not the hit landed.
            SensoryMessage message = this.CreateResultMessage(sender.Thing, this.target, attackRoll, defenseRoll, damage);

            var attackEvent = new AttackEvent(this.target, message, sender.Thing);

            // Broadcast combat requests/events to the room they're happening in.
            sender.Thing.Eventing.OnCombatRequest(attackEvent, EventScope.ParentsDown);
            if (!attackEvent.IsCancelled)
            {
                this.target.Stats["HP"].Decrease(damage, sender.Thing);
                sender.Thing.Eventing.OnCombatEvent(attackEvent, EventScope.ParentsDown);
            }
        }
Esempio n. 15
0
        public void RollWhiteDice(Random rnd, Dice dice, DB db, DbContextTransaction transaction)
        {
            try
            {
                DiceService _diceService = new DiceService(db);

                while (true && !_rollWhiteDiceThreadAborted && !_rollWhiteDiceThreadStopped)
                {
                    RollResult _rollResult = _diceService.RollDice(rnd, dice);
                    if (Mut.WaitOne())
                    {
                        try
                        {
                            if (!_transactionDisposed)
                            {
                                db.RollResults.Add(_rollResult);
                                db.SaveChanges();
                                if (_rollResult.RollValue == 1)
                                {
                                    _whiteAcesCounter++;
                                }
                                _whiteThrowsCounter++;
                                if (!lbl_white_dice_ace_counter.IsDisposed)
                                {
                                    lbl_white_dice_ace_counter.BeginInvoke((MethodInvoker)(() =>
                                    {
                                        lbl_white_dice_ace_counter.Text = _whiteAcesCounter.ToString();
                                    }));
                                }
                                if (!lbl_white_dice_throws_counter.IsDisposed)
                                {
                                    lbl_white_dice_throws_counter.BeginInvoke((MethodInvoker)(() =>
                                    {
                                        lbl_white_dice_throws_counter.Text = _whiteThrowsCounter.ToString();
                                    }));
                                }
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            Mut.ReleaseMutex();
                        }
                    }
                    Debug.WriteLine(_rollResult.ToString());
                }
                if (_rollWhiteDiceThreadStopped)
                {
                    if (Mut.WaitOne())
                    {
                        try
                        {
                            if (!_transactionDisposed)
                            {
                                transaction.Commit();
                                transaction.Dispose();
                                _transactionDisposed = true;
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            Mut.ReleaseMutex();
                        }
                    }
                }
                if (_rollWhiteDiceThreadAborted)
                {
                    if (Mut.WaitOne())
                    {
                        try
                        {
                            if (!_transactionDisposed)
                            {
                                transaction.Rollback();
                                transaction.Dispose();
                                _transactionDisposed = true;
                                ResetCounters(db);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                        finally
                        {
                            Mut.ReleaseMutex();
                        }
                    }
                }
            }
            catch (Exception ex)
            {
            }
        }
Esempio n. 16
0
        private async Task RollDice(string diceString)
        {
            if (Context.Message.Author.Id != lastMessageSender)
            {
                await ReplyAsync("_ _");
            }

            lastMessageSender = Context.Message.Author.Id;

            var character      = CharacterService.GetCharacter(Context.Message.Author.Id);
            var editionService = EditionService[character != null ? character.Edition : "Default"];

            diceString = diceString.ToLower().Replace(" ", "");

            var displayEquationString = diceString;
            var equationString        = diceString;

            Match match = WordRegex.Match(equationString);

            while (match.Success)
            {
                var attributeResponse = CharacterService.GetAttribute(Context.Message.Author.Id, match.Value);

                if (!attributeResponse.Success)
                {
                    await ReplyAsync($"Error: {match.Value} - {attributeResponse.Error}");
                }

                var regex = new Regex(Regex.Escape(match.Value));
                displayEquationString = regex.Replace(displayEquationString, $"[{match.Value} = {attributeResponse.Value}]", 1);
                equationString        = regex.Replace(equationString, attributeResponse.Value, 1);

                match = WordRegex.Match(equationString);
            }

            // if no diceroll, add 1d20
            if (!DiceRegex.Match(equationString).Success)
            {
                equationString        = editionService.DefaultRoll(equationString);
                displayEquationString = editionService.DefaultRoll(displayEquationString);
            }

            match = DiceRegex.Match(equationString);
            while (match.Success)
            {
                var rolls = DiceService.RollExactDice(match.Value);

                var regex = new Regex(Regex.Escape(match.Value));
                displayEquationString = regex.Replace(displayEquationString, $"[{match.Value} = {string.Join(", ", rolls.Select(n => n.ToString()).ToArray())}]", 1);

                equationString = regex.Replace(equationString, editionService.ParseRoll(rolls, match.Value), 1);

                match = DiceRegex.Match(equationString);
            }

            var username = Context.Message.Author.Mention;

            var result = editionService.CompleteRoll(equationString);

            await ReplyAsync($"{username} **{CleanUp(diceString)}** roll: \r\n`{displayEquationString}` results in... **{result}**");
        }
Esempio n. 17
0
 public DiceService_Tests()
 {
     _diceService = new DiceService();
 }
Esempio n. 18
0
 public ActionsController(GdrDbContext context, DiceService diceService)
 {
     _context     = context;
     _diceService = diceService;
 }
        private Talent DrawTalent(Race race)
        {
            var i = DiceService.Roll100();

            switch (race)
            {
            case Race.Human:
                if (i >= 1 && i <= 4)
                {
                    return(TalentsCollection.GetTalentById(2));
                }
                if (i >= 5 && i <= 9)
                {
                    return(TalentsCollection.GetTalentById(2));
                }
                if (i >= 10 && i <= 13)
                {
                    return(TalentsCollection.GetTalentById(3));
                }
                if (i >= 14 && i <= 18)
                {
                    return(TalentsCollection.GetTalentById(4));
                }
                if (i >= 19 && i <= 22)
                {
                    return(TalentsCollection.GetTalentById(5));
                }
                if (i >= 23 && i <= 27)
                {
                    return(TalentsCollection.GetTalentById(6));
                }
                if (i >= 28 && i <= 31)
                {
                    return(TalentsCollection.GetTalentById(7));
                }
                if (i >= 32 && i <= 35)
                {
                    return(TalentsCollection.GetTalentById(8));
                }
                if (i >= 36 && i <= 40)
                {
                    return(TalentsCollection.GetTalentById(9));
                }
                if (i >= 41 && i <= 44)
                {
                    return(TalentsCollection.GetTalentById(10));
                }
                if (i >= 45 && i <= 49)
                {
                    return(TalentsCollection.GetTalentById(11));
                }
                if (i >= 50 && i <= 53)
                {
                    return(TalentsCollection.GetTalentById(12));
                }
                if (i >= 54 && i <= 57)
                {
                    return(TalentsCollection.GetTalentById(13));
                }
                if (i >= 58 && i <= 61)
                {
                    return(TalentsCollection.GetTalentById(14));
                }
                if (i >= 62 && i <= 66)
                {
                    return(TalentsCollection.GetTalentById(15));
                }
                if (i >= 67 && i <= 71)
                {
                    return(TalentsCollection.GetTalentById(16));
                }
                if (i >= 72 && i <= 75)
                {
                    return(TalentsCollection.GetTalentById(17));
                }
                if (i >= 76 && i <= 79)
                {
                    return(TalentsCollection.GetTalentById(18));
                }
                if (i >= 80 && i <= 83)
                {
                    return(TalentsCollection.GetTalentById(19));
                }
                if (i >= 84 && i <= 87)
                {
                    return(TalentsCollection.GetTalentById(20));
                }
                if (i >= 88 && i <= 91)
                {
                    return(TalentsCollection.GetTalentById(21));
                }
                if (i >= 92 && i <= 95)
                {
                    return(TalentsCollection.GetTalentById(22));
                }
                if (i >= 96 && i <= 100)
                {
                    return(TalentsCollection.GetTalentById(23));
                }
                break;

            case Race.Halfling:
                if (i >= 1 && i <= 4)
                {
                    return(TalentsCollection.GetTalentById(1));
                }
                if (i >= 5 && i <= 9)
                {
                    return(TalentsCollection.GetTalentById(2));
                }
                if (i >= 10 && i <= 13)
                {
                    return(TalentsCollection.GetTalentById(3));
                }
                if (i >= 14 && i <= 18)
                {
                    return(TalentsCollection.GetTalentById(4));
                }
                if (i >= 19 && i <= 23)
                {
                    return(TalentsCollection.GetTalentById(5));
                }
                if (i >= 24 && i <= 28)
                {
                    return(TalentsCollection.GetTalentById(6));
                }
                if (i >= 29 && i <= 34)
                {
                    return(TalentsCollection.GetTalentById(7));
                }
                if (i >= 35 && i <= 39)
                {
                    return(TalentsCollection.GetTalentById(8));
                }
                if (i >= 40 && i <= 44)
                {
                    return(TalentsCollection.GetTalentById(9));
                }
                if (i >= 45 && i <= 49)
                {
                    return(TalentsCollection.GetTalentById(10));
                }
                if (i >= 50 && i <= 53)
                {
                    return(TalentsCollection.GetTalentById(11));
                }
                if (i >= 54 && i <= 58)
                {
                    return(TalentsCollection.GetTalentById(12));
                }
                if (i >= 59 && i <= 62)
                {
                    return(TalentsCollection.GetTalentById(13));
                }
                if (i >= 63 && i <= 64)
                {
                    return(TalentsCollection.GetTalentById(14));
                }
                if (i >= 65 && i <= 68)
                {
                    return(TalentsCollection.GetTalentById(15));
                }
                if (i >= 69 && i <= 73)
                {
                    return(TalentsCollection.GetTalentById(16));
                }
                if (i >= 74 && i <= 78)
                {
                    return(TalentsCollection.GetTalentById(17));
                }
                if (i >= 79 && i <= 82)
                {
                    return(TalentsCollection.GetTalentById(18));
                }
                if (i >= 83 && i <= 87)
                {
                    return(TalentsCollection.GetTalentById(19));
                }
                if (i >= 88 && i <= 92)
                {
                    return(TalentsCollection.GetTalentById(20));
                }
                if (i >= 93 && i <= 96)
                {
                    return(TalentsCollection.GetTalentById(21));
                }
                if (i >= 97 && i <= 100)
                {
                    return(TalentsCollection.GetTalentById(22));
                }
                break;
            }
            return(null);
        }
Esempio n. 20
0
 public int Attack(DiceService diceService)
 {
     return(diceService.Roll(DamageMaximum));
 }
Esempio n. 21
0
 public DiceService_Should()
 {
     _diceService = new DiceService();
 }