diff --git a/pflib-net.Tests/characters/PlayerCharacterTest.cs b/pflib-net.Tests/characters/PlayerCharacterTest.cs index 8727e0a..0809a84 100644 --- a/pflib-net.Tests/characters/PlayerCharacterTest.cs +++ b/pflib-net.Tests/characters/PlayerCharacterTest.cs @@ -1,9 +1,10 @@ using System.Collections.Generic; using NUnit.Framework; -using pflib_net.characters.internals.characters; -using pflib_net.characters.internals.characters.internals.proficiencies; +using pflib_net.characters; +using pflib_net.characters.internals.proficiencies; +using pflib_net.characters.internals.stats; -namespace pflib_net.characters.internals.Tests.characters; +namespace pflib_net.Tests.characters; [TestFixture] [TestOf(typeof(PlayerCharacter))] @@ -14,12 +15,12 @@ public class PlayerCharacterTest public void DamageReducesHp() { var stats = new Stats(0, 0, 0, 0, 0, 0); - var armorValues = new Dictionary + var armorValues = new Dictionary { - { ProficiencyTypes.Unarmored, ProficiencyValues.Expert }, - { ProficiencyTypes.LightArmor, ProficiencyValues.None }, - { ProficiencyTypes.MediumArmor, ProficiencyValues.None }, - { ProficiencyTypes.HeavyArmor, ProficiencyValues.None } + { ProficiencyType.Unarmored, ProficiencyValue.Expert }, + { ProficiencyType.LightArmor, ProficiencyValue.None }, + { ProficiencyType.MediumArmor, ProficiencyValue.None }, + { ProficiencyType.HeavyArmor, ProficiencyValue.None } }; var armorProficiency = new ArmorProficiency(armorValues); var creature = new PlayerCharacter(50, stats, 5, armorProficiency); @@ -31,12 +32,12 @@ public class PlayerCharacterTest public void AttackFailsOnMiss() { var stats = new Stats(0, 0, 0, 0, 0, 0); - var armorValues = new Dictionary + var armorValues = new Dictionary { - { ProficiencyTypes.Unarmored, ProficiencyValues.Expert }, - { ProficiencyTypes.LightArmor, ProficiencyValues.None }, - { ProficiencyTypes.MediumArmor, ProficiencyValues.None }, - { ProficiencyTypes.HeavyArmor, ProficiencyValues.None } + { ProficiencyType.Unarmored, ProficiencyValue.Expert }, + { ProficiencyType.LightArmor, ProficiencyValue.None }, + { ProficiencyType.MediumArmor, ProficiencyValue.None }, + { ProficiencyType.HeavyArmor, ProficiencyValue.None } }; var armorProficiency = new ArmorProficiency(armorValues); var creature = new PlayerCharacter(50, stats, 5, armorProficiency); diff --git a/pflib-net.Tests/characters/internals/stats/StatsTest.cs b/pflib-net.Tests/characters/internals/stats/StatsTest.cs new file mode 100644 index 0000000..9563d92 --- /dev/null +++ b/pflib-net.Tests/characters/internals/stats/StatsTest.cs @@ -0,0 +1,40 @@ +using System.Collections.Generic; +using NUnit.Framework; +using pflib_net.characters.internals.stats; + +namespace pflib_net.Tests.characters.internals.stats; + +[TestFixture] +[TestOf(typeof(Stats))] +public class StatsTest +{ + private readonly Dictionary _values = new Dictionary() + { + { StatType.Strength, 1 }, + { StatType.Dexterity, 2 }, + { StatType.Constitution, 3 }, + { StatType.Intelligence, 4 }, + { StatType.Wisdom, 5 }, + { StatType.Charisma, 6 } + }; + + [Test] + [TestCase(StatType.Strength)] + [TestCase(StatType.Dexterity)] + [TestCase(StatType.Constitution)] + [TestCase(StatType.Intelligence)] + [TestCase(StatType.Wisdom)] + [TestCase(StatType.Charisma)] + public void GetStatsGivesCorrectValues(StatType type) + { + var stats = new Stats( + _values[StatType.Strength], + _values[StatType.Dexterity], + _values[StatType.Constitution], + _values[StatType.Intelligence], + _values[StatType.Wisdom], + _values[StatType.Charisma] + ); + Assert.That(stats.GetStat(type), Is.EqualTo(_values[type])); + } +} \ No newline at end of file diff --git a/pflib-net.Tests/pflib-net.Tests.csproj b/pflib-net.Tests/pflib-net.Tests.csproj index 652b646..c23782f 100644 --- a/pflib-net.Tests/pflib-net.Tests.csproj +++ b/pflib-net.Tests/pflib-net.Tests.csproj @@ -1,7 +1,7 @@ - net8.0 + net6.0 pflib_net.Tests false diff --git a/pflib-net/characters/ICharacter.cs b/pflib-net/characters/ICharacter.cs index a77f63b..a8fbaf0 100644 --- a/pflib-net/characters/ICharacter.cs +++ b/pflib-net/characters/ICharacter.cs @@ -1,4 +1,4 @@ -namespace pflib_net.characters.internals.characters; +namespace pflib_net.characters; public interface ICharacter { diff --git a/pflib-net/characters/PlayerCharacter.cs b/pflib-net/characters/PlayerCharacter.cs index 736e5e4..16c17a3 100644 --- a/pflib-net/characters/PlayerCharacter.cs +++ b/pflib-net/characters/PlayerCharacter.cs @@ -1,16 +1,26 @@ -using pflib_net.characters.internals.characters.internals.proficiencies; +using System.Collections.Generic; +using pflib_net.characters.internals.proficiencies; +using pflib_net.characters.internals.stats; +using pflib_net.conditions; -namespace pflib_net.characters.internals.characters; +namespace pflib_net.characters; -public class PlayerCharacter(int hp, Stats stats, int level, ArmorProficiency armorProficiency) - : ICharacter +public class PlayerCharacter : ICharacter { - private int Hp { get; set; } = hp; - private Stats Stats { get; set; } = stats; - private int Level { get; set; } = level; - private ArmorProficiency ArmorProficiency { get; set; } = armorProficiency; - private HashSet Conditions { get; set; } = []; - + private int Hp { get; set; } + private Stats Stats { get; set; } + private int Level { get; set; } + private ArmorProficiency ArmorProficiency { get; set; } + private HashSet Conditions { get; set; } = new HashSet(); + + public PlayerCharacter(int hp, Stats stats, int level, ArmorProficiency armorProficiency) + { + Hp = hp; + Stats = stats; + Level = level; + ArmorProficiency = armorProficiency; + } + public void ResolveAttack(int roll, int damage) { if (roll < GetAc()) return; @@ -19,7 +29,7 @@ public class PlayerCharacter(int hp, Stats stats, int level, ArmorProficiency ar private int GetAc() { - return 10 + Stats.GetDexterity() + ArmorProficiency.GetValue(ProficiencyTypes.Unarmored, Level); + return 10 + Stats.GetStat(StatType.Dexterity) + ArmorProficiency.GetValue(ProficiencyType.Unarmored, Level); } public int GetHp() diff --git a/pflib-net/characters/internals/Stats.cs b/pflib-net/characters/internals/Stats.cs deleted file mode 100644 index 5074a72..0000000 --- a/pflib-net/characters/internals/Stats.cs +++ /dev/null @@ -1,34 +0,0 @@ -namespace pflib_net.characters.internals; - -public class Stats -{ - private int Strength { get; set; } - - private int Dexterity { get; set; } - - private int Constitution { get; set; } - - private int Intelligence { get; set; } - private int Wisdom { get; set; } - private int Charisma { get; set; } - - public Stats(int strength, int dexterity, int constitution, int intelligence, int wisdom, int charisma) - { - Strength = strength; - Dexterity = dexterity; - Constitution = constitution; - Intelligence = intelligence; - Wisdom = wisdom; - Charisma = charisma; - } - - public int GetStrength() - { - return Strength; - } - - public int GetDexterity() - { - return Dexterity; - } -} \ No newline at end of file diff --git a/pflib-net/characters/internals/proficiencies/ArmorProficiency.cs b/pflib-net/characters/internals/proficiencies/ArmorProficiency.cs index d255c29..93cf5a2 100644 --- a/pflib-net/characters/internals/proficiencies/ArmorProficiency.cs +++ b/pflib-net/characters/internals/proficiencies/ArmorProficiency.cs @@ -1,12 +1,19 @@ -namespace pflib_net.characters.internals.characters.internals.proficiencies; +using System.Collections.Generic; -public class ArmorProficiency(Dictionary values) : IProficiency +namespace pflib_net.characters.internals.proficiencies; + +public class ArmorProficiency : IProficiency { - private Dictionary Values { get; set; } = values; + private Dictionary Values { get; set; } - public int GetValue(ProficiencyTypes type, int level) + public ArmorProficiency(Dictionary values) { - if (Values[type].Equals(ProficiencyValues.None)) + Values = values; + } + + public int GetValue(ProficiencyType type, int level) + { + if (Values[type].Equals(ProficiencyValue.None)) { return 0; } diff --git a/pflib-net/characters/internals/proficiencies/IProficiency.cs b/pflib-net/characters/internals/proficiencies/IProficiency.cs index 1439c98..f6966e9 100644 --- a/pflib-net/characters/internals/proficiencies/IProficiency.cs +++ b/pflib-net/characters/internals/proficiencies/IProficiency.cs @@ -1,6 +1,6 @@ -namespace pflib_net.characters.internals.characters.internals.proficiencies; +namespace pflib_net.characters.internals.proficiencies; public interface IProficiency { - public int GetValue(ProficiencyTypes type, int level); + public int GetValue(ProficiencyType type, int level); } \ No newline at end of file diff --git a/pflib-net/characters/internals/proficiencies/ProficiencyTypes.cs b/pflib-net/characters/internals/proficiencies/ProficiencyType.cs similarity index 82% rename from pflib-net/characters/internals/proficiencies/ProficiencyTypes.cs rename to pflib-net/characters/internals/proficiencies/ProficiencyType.cs index ef4703a..3de10e6 100644 --- a/pflib-net/characters/internals/proficiencies/ProficiencyTypes.cs +++ b/pflib-net/characters/internals/proficiencies/ProficiencyType.cs @@ -1,6 +1,6 @@ -namespace pflib_net.characters.internals.characters.internals.proficiencies; +namespace pflib_net.characters.internals.proficiencies; -public enum ProficiencyTypes +public enum ProficiencyType { Unarmored, LightArmor, diff --git a/pflib-net/characters/internals/proficiencies/ProficiencyValue.cs b/pflib-net/characters/internals/proficiencies/ProficiencyValue.cs new file mode 100644 index 0000000..dba91d4 --- /dev/null +++ b/pflib-net/characters/internals/proficiencies/ProficiencyValue.cs @@ -0,0 +1,10 @@ +namespace pflib_net.characters.internals.proficiencies; + +public enum ProficiencyValue: ushort +{ + None = 0, + Trained = 2, + Expert = 4, + Master = 6, + Legendary = 8 +} \ No newline at end of file diff --git a/pflib-net/characters/internals/proficiencies/ProficiencyValues.cs b/pflib-net/characters/internals/proficiencies/ProficiencyValues.cs deleted file mode 100644 index bd2c3fa..0000000 --- a/pflib-net/characters/internals/proficiencies/ProficiencyValues.cs +++ /dev/null @@ -1,10 +0,0 @@ -namespace pflib_net.characters.internals.characters.internals.proficiencies; - -public enum ProficiencyValues: ushort -{ - None = 0, - Trainer = 2, - Expert = 4, - Master = 6, - Legendary = 8 -} \ No newline at end of file diff --git a/pflib-net/characters/internals/stats/StatType.cs b/pflib-net/characters/internals/stats/StatType.cs new file mode 100644 index 0000000..82dbb64 --- /dev/null +++ b/pflib-net/characters/internals/stats/StatType.cs @@ -0,0 +1,11 @@ +namespace pflib_net.characters.internals.stats; + +public enum StatType +{ + Strength, + Dexterity, + Constitution, + Intelligence, + Wisdom, + Charisma +} \ No newline at end of file diff --git a/pflib-net/characters/internals/stats/Stats.cs b/pflib-net/characters/internals/stats/Stats.cs new file mode 100644 index 0000000..11ef3c6 --- /dev/null +++ b/pflib-net/characters/internals/stats/Stats.cs @@ -0,0 +1,23 @@ +using System.Collections.Generic; + +namespace pflib_net.characters.internals.stats; + +public class Stats +{ + private Dictionary StatDict { get; set; } = new(); + + public Stats(int strength, int dexterity, int constitution, int intelligence, int wisdom, int charisma) + { + StatDict[StatType.Strength] = strength; + StatDict[StatType.Dexterity] = dexterity; + StatDict[StatType.Constitution] = constitution; + StatDict[StatType.Intelligence] = intelligence; + StatDict[StatType.Wisdom] = wisdom; + StatDict[StatType.Charisma] = charisma; + } + + public int GetStat(StatType type) + { + return StatDict[type]; + } +} \ No newline at end of file diff --git a/pflib-net/conditions/ICondition.cs b/pflib-net/conditions/ICondition.cs index e3d7cad..d340ba5 100644 --- a/pflib-net/conditions/ICondition.cs +++ b/pflib-net/conditions/ICondition.cs @@ -1,4 +1,4 @@ -namespace pflib_net.characters.internals; +namespace pflib_net.conditions; public interface ICondition { diff --git a/pflib-net/pflib-net.csproj b/pflib-net/pflib-net.csproj index ef04a4d..43e5b13 100644 --- a/pflib-net/pflib-net.csproj +++ b/pflib-net/pflib-net.csproj @@ -1,7 +1,7 @@  - net8.0 + net6.0 pflib_net enable enable