コード例 #1
0
        private AttackSummary HandleShoot(IEnemy enemy,
                                          int hitRoll,
                                          IModifier hitMod,
                                          IModifier dmgMod,
                                          int critValue)
        {
            int  attackResult = hitRoll + hitMod.Get();
            bool crit         = Crit(critValue, hitRoll);

            int  damageDone = 0;
            bool hit        = false;

            if (crit)
            {
                enemy.CritHit();
                damageDone = GetCritDamage(dmgMod);
                enemy.TakeDamage(damageDone);
                hit = true;
            }
            else
            {
                if (enemy.TryHit(attackResult))
                {
                    damageDone = GetDamage(dmgMod);
                    enemy.TakeDamage(damageDone);
                    hit = true;
                }
            }

            return(new AttackSummary(attackResult, damageDone, hit, crit));
        }
コード例 #2
0
        private void Test_Add_ChainAdd()
        {
            var a = new Modifier();                   //0, 0
            var b = new Modifier(2);                  //2, 2
            var c = new Modifier(always1, rolld4, 1); //2, 3
            var d = new Modifier(always1, new List <RollType>()
            {
                RollType.d12, RollType.d12
            }, 3);                                                                                 //5, 7
            var e = new Modifier(always1, new List <RollType>()
            {
                RollType.d20, RollType.d20, RollType.d20
            }, 2);                                                                                               //5, 8

            IModifier res = null;

            Assert.DoesNotThrow(() => res = a.Add(b));
            Assert.DoesNotThrow(() => res = res.Add(c));
            Assert.DoesNotThrow(() => res = res.Add(d));
            Assert.DoesNotThrow(() => res = res.Add(e));

            Assert.IsNotNull(res);
            Assert.AreEqual(14, res.Get());     //0+2+2+5+5 = 14
            Assert.AreEqual(20, res.GetCrit()); //0+2+3+7+8 = 20
        }
コード例 #3
0
        private int GetDamage(IModifier mod)
        {
            int dmgDieResult = DamageDice.Select(x => Rng.Roll(x))
                               .Sum();
            int x = mod.Get();

            return(dmgDieResult + x);
        }
コード例 #4
0
        private void Test_Add_SingleAddHasRollAndMod()
        {
            var testMod = new Modifier(always10, rolld12, 2);
            var mod13   = new Modifier(always10, rolld20, 3);

            IModifier res = null;

            Assert.DoesNotThrow(() => res = testMod.Add(mod13));

            Assert.IsNotNull(res);
            Assert.AreEqual(25, res.Get());
            Assert.AreEqual(45, res.GetCrit());
        }
コード例 #5
0
        private void Test_Add_SingleAddNoRollHasMod()
        {
            var testMod = new Modifier(4);
            var mod3    = new Modifier(3);

            IModifier res = null;

            Assert.DoesNotThrow(() => res = testMod.Add(mod3));

            Assert.IsNotNull(res);
            Assert.AreEqual(7, res.Get());
            Assert.AreEqual(7, res.GetCrit());
        }
コード例 #6
0
        private void Test_Add_SingleAddMultlDice()
        {
            var testMod = new Modifier(always10, new List <RollType>()
            {
                RollType.d20, RollType.d20, RollType.d20
            }, 1);
            var mod42 = new Modifier(always10, new List <RollType>()
            {
                RollType.d12, RollType.d12, RollType.d12, RollType.d12
            }, 2);

            IModifier res = null;

            Assert.DoesNotThrow(() => res = testMod.Add(mod42));

            Assert.IsNotNull(res);
            var y = res.GetCrit();

            Assert.AreEqual(73, res.Get());
            Assert.AreEqual(143, res.GetCrit());
        }