不知道如何在 DnD 卡塔中添加强度修改器

本文关键字:添加 修改器 卡塔 DnD 不知道 | 更新日期: 2023-09-27 18:30:57

我开始在Everquest TDD Kata(Github Link)上编码,我正在参与其中

功能:角色能力修饰符修改属性

作为一个角色,我想使用我的能力修改器来提高我在战斗中的能力,这样我就可以以极端的偏见战胜我的敌人

将强度修正添加到:

  • 攻击滚动和伤害
  • 暴击时的双倍力量修正

但我无法弄清楚我的数学在我的测试中是否正确。使用 NUnit 的 TestCaseSource,我有以下测试

[TestFixture]
public class CharacterAbilityTests
{
    [TestCaseSource("StrengthAbilityTestCases", Category = "Character Strength Tests")]
    public int StrengthAbiltyAddsModifierToAttackRollAndDamage(Character hero, int hitroll)
    {
        var enemy = new Character();
        Assert.That(hero.Attack(enemy, hitroll), Is.True);
        return enemy.HitPoints;
    }
    private static IEnumerable<TestCaseData> StrengthAbilityTestCases
    {
        get
        {
            yield return My.Hero.WithStrength(12).RollsHitOf(9).LeavesEnemyWithHitPoints(3);
            yield return My.Hero.WithStrength(14).RollsHitOf(8).LeavesEnemyWithHitPoints(2);
            yield return My.Hero.WithStrength(16).RollsHitOf(7).LeavesEnemyWithHitPoints(1);
            yield return My.Hero.WithStrength(19).RollsHitOf(6).LeavesEnemyWithHitPoints(0);
            yield return My.Hero.WithStrength(20).RollsHitOf(5).LeavesEnemyWithHitPoints(-1);
            yield return My.Hero.WithStrength(12).RollsHitOf(20).LeavesEnemyWithHitPoints(2);
            yield return My.Hero.WithStrength(14).RollsHitOf(20).LeavesEnemyWithHitPoints(0);
            yield return My.Hero.WithStrength(16).RollsHitOf(20).LeavesEnemyWithHitPoints(-2);
            yield return My.Hero.WithStrength(19).RollsHitOf(20).LeavesEnemyWithHitPoints(-4);
            yield return My.Hero.WithStrength(20).RollsHitOf(20).LeavesEnemyWithHitPoints(-6);
        }
    }
    private class My
    {
        private Character hero;
        private int hitRoll;
        public static My Hero { get { return new My(); } }
        private My() { hero = new Character(); }
        public My WithStrength(int strength){hero.Strength = strength;return this;}
        public My RollsHitOf(int hitRoll) { this.hitRoll = hitRoll; return this; }
        public TestCaseData LeavesEnemyWithHitPoints(int expectedHitPoints)
        {
            var testCaseData = new TestCaseData(hero, hitRoll)
            {
                HasExpectedResult = true,
                ExpectedResult = expectedHitPoints,
                TestName = $"Hero with Stength of {hero.Strength} rolling a {hitRoll} Should leave enemy with {expectedHitPoints} Hit points"
            };
            return testCaseData;
        }
    }
}

我所有处理暴击的测试都失败了(最后 5 次测试)问题是我不确定我的数学是否正确。这是我的攻击方法:(请注意,我之前的所有测试目前都通过了)

public class Character
{
    public string Name { get; set; }
    public Alignment Alignment { get; set; }
    public int ArmorClass { get; private set; }
    public int HitPoints { get; private set; }
    public bool IsDead { get { return HitPoints <= 0; } }
    public Ability Strength { get; set; }
    public Ability Dexterity { get; set; }
    public Ability Constitution { get; set; }
    public Ability Wisdom { get; set; }
    public Ability Intelligence { get; set; }
    public Ability Charisma { get; set; }
    public Character()
    {
        ArmorClass = 10;
        HitPoints = 5;
        Strength = 10;
        Dexterity = 10;
        Constitution = 10;
        Wisdom = 10;
        Intelligence = 10;
        Charisma = 10;
    }
    public bool Attack(Character enemy, int hitRoll)
    {
        var damage = 0;
        var modifier = IsCritHit(hitRoll) ? Strength.Modifier * 2 : Strength.Modifier;
        var isEnemyHit = IsCritHit(hitRoll) || (enemy.ArmorClass <= (hitRoll + modifier));
        if (!isEnemyHit) return false;
        damage = 1 + modifier;
        if (IsCritHit(hitRoll)) damage *= 2;
        enemy.TakeDamage(damage);
        return true;
    }
    private static bool IsCritHit(int hitRoll)
    {
        return hitRoll == 20;
    }
    public void TakeDamage(int damage)
    {
        HitPoints-= damage;
    }
}
public class Ability
{
    public int Score { get; private set; }
    public int Modifier { get; private set; }
    private Ability(int score)
    {
        Score = score;
        Modifier = (int)(Math.Floor((Score - 10) / 2.0));
    }
    public override string ToString()
    {
        return $"{Score} [{Modifier}]";
    }
    public static implicit operator int(Ability ability)
    {
        return ability.Score;
    }
    public static implicit operator Ability(int score)
    {
        return new Ability(score);
    }
}

编辑

我忘了AC和HP的幻数分别是10和5。它们来自卡塔的规格。

编辑 2.0

这是我的 5 个失败测试中第一个的输出

Test Name:  Hero with Stength of 12 [1] rolling a 20 Should leave enemy with 2 Hit points
Test FullName:  EmptyProject.Tests.CharacterAbilityTests.Hero with Stength of 12 [1] rolling a 20 Should leave enemy with 2 Hit points
Test Source:    D:'Users'Robert'Source'Repos'EverCraft-Kata'dotNet'src'EmptyProject.Tests'CharacterAbilityTests.cs : line 14
Test Outcome:   Failed
Test Duration:  0:00:00.012
Result StackTrace:  
at NUnit.Framework.Internal.Commands.TestMethodCommand.Execute(TestExecutionContext context)
at NUnit.Framework.Internal.Commands.TestActionCommand.Execute(TestExecutionContext context)
Result Message: 
Expected: 2
  But was:  -1

编辑希望最终

我想我的意思是问它应该是 ( baseDamage + strengthModifier ) * 2,还是 ( baseDamage *2) + strengthModifier

不知道如何在 DnD 卡塔中添加强度修改器

你的.LeavesEnemyWithHitPoints(2)错了。它应该是 -1。

这部分代码:

var damage = 0;
var modifier = IsCritHit(hitRoll) ? Strength.Modifier * 2 : Strength.Modifier;
var isEnemyHit = IsCritHit(hitRoll) || (enemy.ArmorClass <= (hitRoll + modifier));
if (!isEnemyHit) return false;
damage = 1 + modifier;
if (IsCritHit(hitRoll)) damage *= 2;
    enemy.TakeDamage(damage);

Strength.Modifier为 1 时,modifier计算在暴击时产生 2。这意味着damage = 1 + modifier为 3。因为你已经掷出了暴击,所以伤害会翻倍,使你的总damage = 6。如果敌人的总生命值是5,而你打他6,他应该有-1点HP。

我不知道这是否是正确的 DnD 计算(不记得了)

这是(baseDamage+strengthModifier) * 2

但是,当非临界时,如果强度小于 10,并且修饰符为负数,那么您实际造成的伤害为负数或零,这听起来不合理。我的意思是,如果你有力量6并击中某人,你实际上给了那个玩家1点生命值?如果它很关键,你会给 2 个生命值?:P 本部分问题描述不明确