Various additions and changes

This commit is contained in:
Malachy Byrne 2024-06-14 23:22:19 +01:00
parent cde67d45e0
commit 5eadaa67fa
Signed by: malmal200
GPG Key ID: EC21443030A655D9
15 changed files with 139 additions and 81 deletions

View File

@ -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<ProficiencyTypes, ProficiencyValues>
var armorValues = new Dictionary<ProficiencyType, ProficiencyValue>
{
{ 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<ProficiencyTypes, ProficiencyValues>
var armorValues = new Dictionary<ProficiencyType, ProficiencyValue>
{
{ 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);

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">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<TargetFramework>net6.0</TargetFramework>
<RootNamespace>pflib_net.Tests</RootNamespace>
<IsPackable>false</IsPackable>

View File

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

View File

@ -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<ICondition> 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<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)
{
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()

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;
public class ArmorProficiency : IProficiency
{
private Dictionary<ProficiencyTypes, ProficiencyValues> Values { get; set; } = values;
private Dictionary<ProficiencyType, ProficiencyValue> Values { get; set; }
public int GetValue(ProficiencyTypes type, int level)
public ArmorProficiency(Dictionary<ProficiencyType, ProficiencyValue> values)
{
if (Values[type].Equals(ProficiencyValues.None))
Values = values;
}
public int GetValue(ProficiencyType type, int level)
{
if (Values[type].Equals(ProficiencyValue.None))
{
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 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,
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
{

View File

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