Add project files.
This commit is contained in:
32
RPGLibrary.Implementation/AttackCommand.cs
Normal file
32
RPGLibrary.Implementation/AttackCommand.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using RPGLibrary.Abstraction.Character;
|
||||
using RPGLibrary.Abstraction.Services;
|
||||
using RPGLibrary.Command;
|
||||
|
||||
namespace RPGLibrary.Implementation.Command
|
||||
{
|
||||
public class AttackCommand : ICommand
|
||||
{
|
||||
private readonly Character[] _target;
|
||||
private readonly StrengthAttackData _attackData;
|
||||
private readonly IDamageCalculator<StrengthAttackData> _damageCalculator;
|
||||
|
||||
public AttackCommand(Character[] target, StrengthAttackData attackData, IDamageCalculator<StrengthAttackData> damageCalculator)
|
||||
{
|
||||
_target = target;
|
||||
_attackData = attackData;
|
||||
_damageCalculator = damageCalculator;
|
||||
}
|
||||
|
||||
|
||||
public async IAsyncEnumerable<ICharacter> Execute()
|
||||
{
|
||||
foreach (var character in _target)
|
||||
{
|
||||
var damage = _damageCalculator.Calculate(character, (dynamic)_attackData);
|
||||
var newCurrentHP = new HP(character.HP.Value - damage, character.HP.Maximum);
|
||||
yield return character.With(newCurrentHP);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
20
RPGLibrary.Implementation/Attribute/DefenseAttribute.cs
Normal file
20
RPGLibrary.Implementation/Attribute/DefenseAttribute.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using RPGLibrary.Abstraction.Attribute;
|
||||
|
||||
namespace RPGLibrary.Implementation
|
||||
{
|
||||
public class DefenseAttribute : IAttribute
|
||||
{
|
||||
public DefenseAttribute(double value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public double Value { get; }
|
||||
|
||||
public override string? ToString()
|
||||
{
|
||||
return $"Defense: {Value}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
18
RPGLibrary.Implementation/Attribute/HP.cs
Normal file
18
RPGLibrary.Implementation/Attribute/HP.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using RPGLibrary.Attribute;
|
||||
|
||||
namespace RPGLibrary.Implementation
|
||||
{
|
||||
public class HP : PoolAttribute
|
||||
{
|
||||
public HP(double current, double maximum)
|
||||
: base(current, maximum)
|
||||
{
|
||||
}
|
||||
|
||||
public override string? ToString()
|
||||
{
|
||||
return $"HP: ({Value}/{Maximum})";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
13
RPGLibrary.Implementation/Attribute/Speed.cs
Normal file
13
RPGLibrary.Implementation/Attribute/Speed.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace RPGLibrary.Implementation
|
||||
{
|
||||
public class Speed
|
||||
{
|
||||
public Speed(double value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public double Value { get; }
|
||||
}
|
||||
|
||||
}
|
||||
20
RPGLibrary.Implementation/Attribute/StrengthAttribute.cs
Normal file
20
RPGLibrary.Implementation/Attribute/StrengthAttribute.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
using RPGLibrary.Abstraction.Attribute;
|
||||
|
||||
namespace RPGLibrary.Implementation
|
||||
{
|
||||
public class StrengthAttribute : IAttribute
|
||||
{
|
||||
public StrengthAttribute(double value)
|
||||
{
|
||||
Value = value;
|
||||
}
|
||||
|
||||
public double Value { get; }
|
||||
|
||||
public override string? ToString()
|
||||
{
|
||||
return $"Strength: {Value}";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
31
RPGLibrary.Implementation/Character.cs
Normal file
31
RPGLibrary.Implementation/Character.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using RPGLibrary.Abstraction.Character;
|
||||
|
||||
namespace RPGLibrary.Implementation
|
||||
{
|
||||
public class Character : ICharacter
|
||||
{
|
||||
public Character(string name, HP hp, StrengthAttribute strength, DefenseAttribute defense)
|
||||
{
|
||||
Name = name;
|
||||
HP = hp;
|
||||
Strength = strength;
|
||||
Defense = defense;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public HP HP { get; private set; }
|
||||
|
||||
public StrengthAttribute Strength { get; }
|
||||
|
||||
public DefenseAttribute Defense { get; }
|
||||
|
||||
public override string? ToString()
|
||||
{
|
||||
return $"{HP}, {Strength}, {Defense}";
|
||||
}
|
||||
|
||||
public ICharacter With(HP hp) => new Character(Name, hp, Strength, Defense);
|
||||
}
|
||||
|
||||
}
|
||||
13
RPGLibrary.Implementation/RPGLibrary.Implementation.csproj
Normal file
13
RPGLibrary.Implementation/RPGLibrary.Implementation.csproj
Normal file
@@ -0,0 +1,13 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\RPGLibrary\RPGLibrary.Abstraction.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
8
RPGLibrary.Implementation/StrengthAttackData.cs
Normal file
8
RPGLibrary.Implementation/StrengthAttackData.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using RPGLibrary.Abstraction.Character;
|
||||
|
||||
namespace RPGLibrary.Implementation
|
||||
{
|
||||
public record StrengthAttackData(ICharacter Source, StrengthAttribute Strength)
|
||||
: AttackData(Source, Strength);
|
||||
|
||||
}
|
||||
16
RPGLibrary.Implementation/StrengthBasedDamageCalculator.cs
Normal file
16
RPGLibrary.Implementation/StrengthBasedDamageCalculator.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using RPGLibrary.Abstraction.Character;
|
||||
using RPGLibrary.Abstraction.Services;
|
||||
|
||||
namespace RPGLibrary.Implementation
|
||||
{
|
||||
public class StrengthBasedDamageCalculator : IDamageCalculator<StrengthAttackData>
|
||||
{
|
||||
public double Calculate(ICharacter target, StrengthAttackData attackData)
|
||||
=> CalculateInternal((dynamic)target, attackData);
|
||||
|
||||
private double CalculateInternal(Character target, StrengthAttackData attackData)
|
||||
=> Math.Clamp(attackData.Strength.Value - target.Defense.Value, RPGConstants.MinDamage, RPGConstants.MaxDamage);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user