PF-1: Add basic classes #1

Merged
malmal200 merged 5 commits from PF-1-add-basics into master 2024-06-15 02:05:33 +02:00
15 changed files with 139 additions and 81 deletions
Showing only changes of commit 5eadaa67fa - Show all commits

View File

@ -1,9 +1,10 @@
using System.Collections.Generic; using System.Collections.Generic;
using NUnit.Framework; using NUnit.Framework;
using pflib_net.characters.internals.characters; using pflib_net.characters;
using pflib_net.characters.internals.characters.internals.proficiencies; 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] [TestFixture]
[TestOf(typeof(PlayerCharacter))] [TestOf(typeof(PlayerCharacter))]
@ -14,12 +15,12 @@ public class PlayerCharacterTest
public void DamageReducesHp() public void DamageReducesHp()
{ {
var stats = new Stats(0, 0, 0, 0, 0, 0); var stats = new Stats(0, 0, 0, 0, 0, 0);
var armorValues = new Dictionary<ProficiencyTypes, ProficiencyValues> var armorValues = new Dictionary<ProficiencyType, ProficiencyValue>
{ {
{ ProficiencyTypes.Unarmored, ProficiencyValues.Expert }, { ProficiencyType.Unarmored, ProficiencyValue.Expert },
{ ProficiencyTypes.LightArmor, ProficiencyValues.None }, { ProficiencyType.LightArmor, ProficiencyValue.None },
{ ProficiencyTypes.MediumArmor, ProficiencyValues.None }, { ProficiencyType.MediumArmor, ProficiencyValue.None },
{ ProficiencyTypes.HeavyArmor, ProficiencyValues.None } { ProficiencyType.HeavyArmor, ProficiencyValue.None }
}; };
var armorProficiency = new ArmorProficiency(armorValues); var armorProficiency = new ArmorProficiency(armorValues);
var creature = new PlayerCharacter(50, stats, 5, armorProficiency); var creature = new PlayerCharacter(50, stats, 5, armorProficiency);
@ -31,12 +32,12 @@ public class PlayerCharacterTest
public void AttackFailsOnMiss() public void AttackFailsOnMiss()
{ {
var stats = new Stats(0, 0, 0, 0, 0, 0); var stats = new Stats(0, 0, 0, 0, 0, 0);
var armorValues = new Dictionary<ProficiencyTypes, ProficiencyValues> var armorValues = new Dictionary<ProficiencyType, ProficiencyValue>
{ {
{ ProficiencyTypes.Unarmored, ProficiencyValues.Expert }, { ProficiencyType.Unarmored, ProficiencyValue.Expert },
{ ProficiencyTypes.LightArmor, ProficiencyValues.None }, { ProficiencyType.LightArmor, ProficiencyValue.None },
{ ProficiencyTypes.MediumArmor, ProficiencyValues.None }, { ProficiencyType.MediumArmor, ProficiencyValue.None },
{ ProficiencyTypes.HeavyArmor, ProficiencyValues.None } { ProficiencyType.HeavyArmor, ProficiencyValue.None }
}; };
var armorProficiency = new ArmorProficiency(armorValues); var armorProficiency = new ArmorProficiency(armorValues);
var creature = new PlayerCharacter(50, stats, 5, armorProficiency); var creature = new PlayerCharacter(50, stats, 5, armorProficiency);

View File

@ -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<StatType, int> _values = new Dictionary<StatType, int>()
{
{ 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]));
}
}

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks> <TargetFramework>net6.0</TargetFramework>
<RootNamespace>pflib_net.Tests</RootNamespace> <RootNamespace>pflib_net.Tests</RootNamespace>
<IsPackable>false</IsPackable> <IsPackable>false</IsPackable>

View File

@ -1,4 +1,4 @@
namespace pflib_net.characters.internals.characters; namespace pflib_net.characters;
public interface ICharacter public interface ICharacter
{ {

View File

@ -1,15 +1,25 @@
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) public class PlayerCharacter : ICharacter
: ICharacter
{ {
private int Hp { get; set; } = hp; private int Hp { get; set; }
private Stats Stats { get; set; } = stats; private Stats Stats { get; set; }
private int Level { get; set; } = level; private int Level { get; set; }
private ArmorProficiency ArmorProficiency { get; set; } = armorProficiency; private ArmorProficiency ArmorProficiency { get; set; }
private HashSet<ICondition> Conditions { get; set; } = []; private HashSet<ICondition> Conditions { get; set; } = new HashSet<ICondition>();
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) public void ResolveAttack(int roll, int damage)
{ {
@ -19,7 +29,7 @@ public class PlayerCharacter(int hp, Stats stats, int level, ArmorProficiency ar
private int GetAc() 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() public int GetHp()

View File

@ -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;
}
}

View File

@ -1,12 +1,19 @@
namespace pflib_net.characters.internals.characters.internals.proficiencies; using System.Collections.Generic;
public class ArmorProficiency(Dictionary<ProficiencyTypes, ProficiencyValues> values) : IProficiency namespace pflib_net.characters.internals.proficiencies;
{
private Dictionary<ProficiencyTypes, ProficiencyValues> Values { get; set; } = values;
public int GetValue(ProficiencyTypes type, int level) public class ArmorProficiency : IProficiency
{ {
if (Values[type].Equals(ProficiencyValues.None)) private Dictionary<ProficiencyType, ProficiencyValue> Values { get; set; }
public ArmorProficiency(Dictionary<ProficiencyType, ProficiencyValue> values)
{
Values = values;
}
public int GetValue(ProficiencyType type, int level)
{
if (Values[type].Equals(ProficiencyValue.None))
{ {
return 0; return 0;
} }

View File

@ -1,6 +1,6 @@
namespace pflib_net.characters.internals.characters.internals.proficiencies; namespace pflib_net.characters.internals.proficiencies;
public interface IProficiency public interface IProficiency
{ {
public int GetValue(ProficiencyTypes type, int level); public int GetValue(ProficiencyType type, int level);
} }

View File

@ -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, Unarmored,
LightArmor, LightArmor,

View File

@ -0,0 +1,10 @@
namespace pflib_net.characters.internals.proficiencies;
public enum ProficiencyValue: ushort
{
None = 0,
Trained = 2,
Expert = 4,
Master = 6,
Legendary = 8
}

View File

@ -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
}

View File

@ -0,0 +1,11 @@
namespace pflib_net.characters.internals.stats;
public enum StatType
{
Strength,
Dexterity,
Constitution,
Intelligence,
Wisdom,
Charisma
}

View File

@ -0,0 +1,23 @@
using System.Collections.Generic;
namespace pflib_net.characters.internals.stats;
public class Stats
{
private Dictionary<StatType, int> 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];
}
}

View File

@ -1,4 +1,4 @@
namespace pflib_net.characters.internals; namespace pflib_net.conditions;
public interface ICondition public interface ICondition
{ {

View File

@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk"> <Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup> <PropertyGroup>
<TargetFramework>net8.0</TargetFramework> <TargetFramework>net6.0</TargetFramework>
<RootNamespace>pflib_net</RootNamespace> <RootNamespace>pflib_net</RootNamespace>
<ImplicitUsings>enable</ImplicitUsings> <ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable> <Nullable>enable</Nullable>