コード例 #1
0
        /// <summary>
        /// Registers a spell.
        /// </summary>
        /// <returns>The registered spell.</returns>
        /// <param name="spell">The spell to register.</param>
        /// <param name="keyAbilityScore">The ability score which powers the spell.</param>
        /// <param name="baseCasterLevel">The spell's caster level.</param>
        /// <exception cref="System.ArgumentNullException"></exception>
        public ICastableSpell Register(ISpell spell, IAbilityScore keyAbilityScore, Func <byte> baseCasterLevel)
        {
            if (null == spell)
            {
                throw new ArgumentNullException(nameof(spell), "Argument cannot be null.");
            }
            if (null == keyAbilityScore)
            {
                throw new ArgumentNullException(nameof(keyAbilityScore), "Argument cannot be null.");
            }
            if (null == baseCasterLevel)
            {
                throw new ArgumentNullException(nameof(baseCasterLevel), "Argument cannot be null.");
            }
            ICastableSpell existingSpell = this.RegisteredSpells.Where(rs => rs.Spell == spell)
                                           .FirstOrDefault();

            if (null != existingSpell)
            {
                return(existingSpell);
            }
            ICastableSpell newSpell = new CastableSpell(spell, keyAbilityScore, baseCasterLevel);

            this.RegisteredSpells.Add(newSpell);
            this.OnRegistered?.Invoke(this, new SpellRegisteredEventArgs(newSpell));
            return(newSpell);
        }
コード例 #2
0
        public void IsClassSkill_OneRank_Aggregates()
        {
            // Arrange
            var mockAbilityScore = new Mock <IAbilityScore>();

            mockAbilityScore.Setup(a => a.GetModifier())
            .Returns(0);
            IAbilityScore abilityScore = mockAbilityScore.Object;

            var mockCharacter = new Mock <ICharacter>();

            mockCharacter.Setup(c => c.Level)
            .Returns(20);
            ICharacter character = mockCharacter.Object;

            string skillName = "my skill";

            Skill skill = new Skill(character, abilityScore, skillName)
            {
                IsClassSkill = true,
                Ranks        = 1
            };

            // Act
            var result = skill.GetTotal();

            // Assert
            Assert.IsTrue(result.HasValue);
            Assert.AreEqual(4, result.Value,
                            "An trained class skill with no bonuses and no ability score modifier should have a total of 4.");
        }
コード例 #3
0
        public void Register1_Returns_ConfiguredISpellLikeAbility()
        {
            // Arrange
            var mockSpell = new Mock <ISpell>();

            mockSpell.Setup(s => s.Level)
            .Returns(7);
            ISpell spell = mockSpell.Object;

            var mockAbilityScore = new Mock <IAbilityScore>();

            mockAbilityScore.Setup(ab => ab.GetBonus())
            .Returns(4);
            IAbilityScore abilityScore = mockAbilityScore.Object;

            var mockCharacter = new Mock <ICharacter>();

            mockCharacter.Setup(c => c.Level)
            .Returns(19);
            ICharacter character = mockCharacter.Object;

            SpellRegistrar spellReg = new SpellRegistrar(character);

            // Act
            ICastableSpell castable = spellReg.Register(spell, abilityScore);

            // Assert
            Assert.AreSame(spell, castable.Spell);
        }
コード例 #4
0
        public void CanBeUsedUntrained_FalseTrained_Aggregates()
        {
            // Arrange
            var mockAbilityScore = new Mock <IAbilityScore>();

            mockAbilityScore.Setup(a => a.GetModifier())
            .Returns(0);
            IAbilityScore abilityScore = mockAbilityScore.Object;

            var mockCharacter = new Mock <ICharacter>();

            mockCharacter.Setup(c => c.Level)
            .Returns(20);
            ICharacter character = mockCharacter.Object;

            string skillName = "my skill";

            Skill skill = new Skill(character, abilityScore, skillName)
            {
                Ranks = 1,
                CanBeUsedUntrained = false
            };

            // Act
            var result = skill.GetTotal();

            // Assert
            Assert.IsTrue(result.HasValue,
                          "A skill which has at least one rank and cannot be used untrained should have a total.");
            Assert.AreEqual(1, result.Value);
        }
コード例 #5
0
        public void Register1_Returns_ConfiguredISpellLikeAbility()
        {
            // Arrange
            byte usesPerDay = 3;

            var mockSpell = new Mock <ISpell>();

            mockSpell.Setup(s => s.Level)
            .Returns(7);
            ISpell spell = mockSpell.Object;

            var mockAbilityScore = new Mock <IAbilityScore>();

            mockAbilityScore.Setup(ab => ab.GetBonus())
            .Returns(4);
            IAbilityScore abilityScore = mockAbilityScore.Object;

            var mockCharacter = new Mock <ICharacter>();

            mockCharacter.Setup(c => c.Level)
            .Returns(19);
            ICharacter character = mockCharacter.Object;

            SpellLikeAbilityRegistrar slaReg = new SpellLikeAbilityRegistrar(character);

            // Act
            ISpellLikeAbility sla = slaReg.Register(usesPerDay, spell, abilityScore);

            // Assert
            Assert.IsNotNull(sla);
            Assert.AreEqual(usesPerDay, sla.UsesPerDay);
            Assert.AreSame(spell, sla.Spell);
        }
コード例 #6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Core.Domain.Characters.Spellcasting.CastableSpell"/> class.
 /// </summary>
 /// <param name="spell">The spell.</param>
 /// <param name="keyAbilityScore">The ability scored which is tied to the DC of this spell.</param>
 /// <param name="baseCasterLevel">The base caster level of this spell.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when an argument is null.</exception>
 internal CastableSpell(ISpell spell, IAbilityScore keyAbilityScore, Func <byte> baseCasterLevel)
 {
     if (null == baseCasterLevel)
     {
         throw new ArgumentNullException(nameof(baseCasterLevel), "Argument cannot be null.");
     }
     _spell           = spell ?? throw new ArgumentNullException($"{ nameof(spell) } argument cannot be null.");
     _keyAbilityScore = keyAbilityScore ?? throw new ArgumentNullException($"{ nameof(keyAbilityScore) } argument cannot be null.");
     _casterLevel     = new CasterLevel(baseCasterLevel);
 }
コード例 #7
0
        public void Constructor_NullIAbilityScore_Throws()
        {
            // Arrange
            IAbilityScore abilityScore = null;

            // Act
            TestDelegate constructor = () => new Initiative(abilityScore);

            // Assert
            Assert.Throws <ArgumentNullException>(constructor);
        }
コード例 #8
0
        public void Constructor_NullIAbilityScore_Throws()
        {
            // Arrange
            var           character    = Mock.Of <ICharacter>();
            IAbilityScore abilityScore = null;

            // Act
            TestDelegate constructor = () => new SavingThrow(character, abilityScore);

            // Assert
            Assert.Throws <ArgumentNullException>(constructor);
        }
コード例 #9
0
        public void Constructor_NullIAbilityScore_Throws()
        {
            // Arrange
            var           character    = Mock.Of <ICharacter>();
            IAbilityScore abilityScore = null;
            var           attackBonus  = Mock.Of <IUniversalAttackBonus>();

            // Act
            TestDelegate constructor = () => new WeaponAttackBonus(character, abilityScore, attackBonus);

            // Assert
            Assert.Throws <ArgumentNullException>(constructor);
        }
コード例 #10
0
        public void Constructor1_NullFunc_Throws()
        {
            // Arrange
            var           spell        = Mock.Of <ISpell>();
            IAbilityScore abilityScore = null;
            Func <byte>   casterLevel  = null;

            // Act
            TestDelegate constructor = () => new CastableSpell(spell, abilityScore, casterLevel);

            // Assert
            Assert.Throws <ArgumentNullException>(constructor,
                                                  "Null arguments should not be accepted.");
        }
コード例 #11
0
        public void Constructor1_NullIAbilityScore_Throws()
        {
            // Arrange
            byte          usesPerDay   = 1;
            var           spell        = Mock.Of <ISpell>();
            IAbilityScore abilityScore = null;
            Func <byte>   casterLevel  = () => 1;

            // Act
            TestDelegate constructor = () => new SpellLikeAbility(usesPerDay, spell, abilityScore, casterLevel);

            // Assert
            Assert.Throws <ArgumentNullException>(constructor,
                                                  "Null arguments should not be accepted.");
        }
コード例 #12
0
        public void KeyAbilityScore_PassThrough()
        {
            // Arrange
            var character    = Mock.Of <ICharacter>();
            var abilityScore = Mock.Of <IAbilityScore>();
            var attackBonus  = Mock.Of <IUniversalAttackBonus>();

            WeaponAttackBonus wab = new WeaponAttackBonus(character, abilityScore, attackBonus);

            // Act
            IAbilityScore keyAbilityScore = wab.KeyAbilityScore;

            // Assert
            Assert.AreSame(abilityScore, keyAbilityScore,
                           $"By default, the key ability score returned from the { nameof(WeaponAttackBonus.KeyAbilityScore) } property should be the same instance that was passed into the constructor.");
        }
コード例 #13
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Core.Domain.Characters.AttackBonuses.SpecificAttackBonus"/> class.
 /// </summary>
 /// <param name="character">The character to whom this attack bonus belongs.</param>
 /// <param name="keyAbilityScore">The ability score associated with this attack bonus.</param>
 /// <param name="sharedAttackBonus">The generic attack bonus which contains universal bonuses which apply to this attack bonus.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when an argument is null.</exception>
 internal WeaponAttackBonus(ICharacter character, IAbilityScore keyAbilityScore, IUniversalAttackBonus sharedAttackBonus)
     : base()
 {
     this.Character         = character ?? throw new ArgumentNullException(nameof(character), "Argument cannot be null.");
     this.KeyAbilityScore   = keyAbilityScore ?? throw new ArgumentNullException(nameof(keyAbilityScore), "Argument cannot be null");
     this.SharedAttackBonus = sharedAttackBonus ?? throw new ArgumentNullException(nameof(sharedAttackBonus), "Argument cannot be null");
     this.EnhancementBonuses.Add(
         () => this.SharedAttackBonus.EnhancementBonuses?.GetTotal() ?? 0
         );
     this.UntypedBonuses.Add(
         () => this.SharedAttackBonus.UntypedBonuses?.GetTotal() ?? 0
         );
     this.Penalties.Add(
         () => this.SharedAttackBonus.Penalties?.GetTotal() ?? 0
         );
 }
コード例 #14
0
        public void Register1_NullIAbilityScore_Throws()
        {
            // Arrange
            var           spell        = Mock.Of <ISpell>();
            IAbilityScore abilityScore = null;

            var            character = Mock.Of <ICharacter>();
            SpellRegistrar spellReg  = new SpellRegistrar(character);

            // Act
            TestDelegate registerMethod = () => spellReg.Register(spell, abilityScore);

            // Assert
            Assert.Throws <ArgumentNullException>(registerMethod,
                                                  "Null arguments are not allowed.");
        }
コード例 #15
0
        /// <summary>
        /// Initializes a new instance of the <see cref="T:Core.Domain.Characters.Skills.Skill"/> class.
        /// </summary>
        /// <param name="character">The character to whom this skill belongs.</param>
        /// <param name="keyAbilityScore">The ability score associated with this skill.</param>
        /// <param name="name">The name of the skill.</param>
        /// <exception cref="System.ArgumentNullException">Thrown when an argument is null.</exception>
        internal Skill(ICharacter character, IAbilityScore keyAbilityScore, string name)
        {
            _character       = character ?? throw new ArgumentNullException(nameof(character), "Argument cannot be null.");
            _keyAbilityScore = keyAbilityScore ?? throw new ArgumentNullException(nameof(keyAbilityScore), "Argument cannot be null.");
            _name            = name ?? throw new ArgumentNullException(nameof(name), "Argument cannot be null.");

            // Gives a +3 untyped bonus if this is a class skill and is trained.
            _getTrainedBonus = () =>              // Couldn't be assigned directly to the property because of "this" references
            {
                if (this.IsClassSkill && this.Ranks > 0)
                {
                    return(3);
                }
                return(0);
            };
            this.UntypedBonuses.Add(GetTrainedBonus);
        }
コード例 #16
0
        public void Register2_NullIAbilityScore_Throws()
        {
            // Arrange
            byte          usesPerDay   = 3;
            var           spell        = Mock.Of <ISpell>();
            IAbilityScore abilityScore = null;
            Func <byte>   casterLevel  = () => 10;

            var character = Mock.Of <ICharacter>();
            SpellLikeAbilityRegistrar slaReg = new SpellLikeAbilityRegistrar(character);

            // Act
            TestDelegate registerMethod = () => slaReg.Register(usesPerDay, spell, abilityScore, casterLevel);

            // Assert
            Assert.Throws <ArgumentNullException>(registerMethod,
                                                  "Null arguments are not allowed.");
        }
コード例 #17
0
        public void Constructor_NullStrength_Throws()
        {
            // Arrange
            IAbilityScore strength = null;

            var mockAbilityScores = new Mock <IAbilityScoreSection>();

            mockAbilityScores.Setup(abs => abs.Strength)
            .Returns(strength);

            var mockCharacter = new Mock <ICharacter>();

            mockCharacter.Setup(c => c.AbilityScores)
            .Returns(mockAbilityScores.Object);

            // Act
            TestDelegate constructor = () => new CombatManeuverBonus(mockCharacter.Object);

            // Assert
            Assert.Throws <ArgumentException>(constructor);
        }
コード例 #18
0
        public void GetTotal_Aggregates()
        {
            // Arrange
            var mockAbilityScore = new Mock <IAbilityScore>();

            mockAbilityScore.Setup(a => a.GetModifier())
            .Returns(5);
            IAbilityScore abilityScore = mockAbilityScore.Object;

            var mockCharacter = new Mock <ICharacter>();

            mockCharacter.Setup(c => c.Level)
            .Returns(1);
            ICharacter character = mockCharacter.Object;

            string skillName = "my skill";

            Skill skill = new Skill(character, abilityScore, skillName)
            {
                IsClassSkill = true,
                Ranks        = 1
            };

            skill.CompetenceBonuses.Add(() => 2);
            skill.LuckBonuses.Add(() => 4);
            skill.RacialBonuses.Add(() => 6);
            skill.SizeBonuses.Add(() => 7);
            skill.UntypedBonuses.Add(() => 8);
            skill.Penalties.Add(() => 9);

            // Act
            var result = skill.GetTotal();

            // Assert
            Assert.IsTrue(result.HasValue);
            Assert.AreEqual(27, result.Value,
                            "27 = (1 rank) + (2 competence) + (3 trained) + (4 luck) + (5 ability) + (6 racial) + (7 size) + (8 untyped) - (9 penalties)");
        }
コード例 #19
0
        public void CanBeUsedUntrained_Default_Aggregates()
        {
            // Arrange
            var mockAbilityScore = new Mock <IAbilityScore>();

            mockAbilityScore.Setup(a => a.GetModifier())
            .Returns(0);
            IAbilityScore abilityScore = mockAbilityScore.Object;

            var character = Mock.Of <ICharacter>();

            string skillName = "my skill";

            Skill skill = new Skill(character, abilityScore, skillName);

            // Act
            var result = skill.GetTotal();

            // Assert
            Assert.IsTrue(result.HasValue);
            Assert.AreEqual(0, result.Value,
                            "An untrained skill with no bonuses and no ability score modifier should have a total of zero.");
        }
コード例 #20
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Core.Domain.Characters.Initiatives.Initiative"/> class.
 /// </summary>
 /// <param name="keyAbilityScore">The ability score associated with initiative.</param>
 internal Initiative(IAbilityScore keyAbilityScore)
 {
     _keyAbilityScore = keyAbilityScore ?? throw new ArgumentNullException(nameof(keyAbilityScore), "Argument cannot be null.");
 }
コード例 #21
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Core.Domain.Characters.SavingThrows.SavingThrow"/> class.
 /// </summary>
 /// <param name="character">The character to whom this saving throw belongs.</param>
 /// <param name="keyAbilityScore">The ability score which is associated with this saving throw.</param>
 /// <exception cref="System.ArgumentNullException">Throw when an argument is null.</exception>
 internal SavingThrow(ICharacter character, IAbilityScore keyAbilityScore)
 {
     _character       = character ?? throw new ArgumentNullException(nameof(character), "Argument cannot be null.");
     _keyAbilityScore = keyAbilityScore ?? throw new ArgumentNullException(nameof(keyAbilityScore), "Argument cannot be null.");
 }
コード例 #22
0
 /// <summary>
 /// Registers a spell.  The spell's caster level is assumed to be the character's level.
 /// </summary>
 /// <returns>The registered spell.</returns>
 /// <param name="spell">The spell to register.</param>
 /// <param name="keyAbilityScore">The ability score which powers the spell.</param>
 /// <exception cref="System.ArgumentNullException"></exception>
 public ICastableSpell Register(ISpell spell, IAbilityScore keyAbilityScore)
 {
     return(this.Register(spell, keyAbilityScore, () => this.Character.Level));
 }
コード例 #23
0
 /// <summary>
 /// Initializes a new instance of the <see cref="T:Core.Domain.Characters.SpellRegistries.SpellLikeAbility"/> class.
 /// </summary>
 /// <param name="usesPerDay">The number of times per day this spell-like ability can be used.</param>
 /// <param name="spell">The spell this spell-like ability imitates.</param>
 /// <param name="keyAbilityScore">The ability score associated with casting this spell-like ability.</param>
 /// <param name="baseCasterLevel">The caster level of this spell-like ability.</param>
 public SpellLikeAbility(byte usesPerDay, ISpell spell, IAbilityScore keyAbilityScore, Func <byte> baseCasterLevel)
     : base(spell, keyAbilityScore, baseCasterLevel)
 {
     _usesPerDay = usesPerDay;
 }
コード例 #24
0
 /// <summary>
 /// Registers a spell-like ability.  The caster level is assumed to be equal to the character's level.
 /// </summary>
 /// <param name="usesPerDay">The number of times per day the spell-like ability can be used.</param>
 /// <param name="spell">The spell this spell-like ability imitates.</param>
 /// <param name="keyAbilityScore">The ability score associated with the spell-like ability.</param>
 /// <exception cref="System.ArgumentNullException">Thrown when an argument is null.</exception>
 public ISpellLikeAbility Register(byte usesPerDay, ISpell spell, IAbilityScore keyAbilityScore)
 {
     return(this.Register(usesPerDay, spell, keyAbilityScore, () => this.Character.Level));
 }