Files
trail-into-darkness/Assets/Code/GameState/Entities/CharacterStatsFactory.cs
Sebastian Bularca e7d5acac7c Moar refactoring
2026-03-30 01:06:02 +02:00

41 lines
1.5 KiB
C#

using System;
using System.Collections.Generic;
using System.Linq;
namespace Nox.Game {
public interface ICharacterStatsFactory {
EntityStats Create(IEntityDefinition entityDefinition);
}
public sealed class CharacterStatsFactory : ICharacterStatsFactory {
private readonly CharacterRegistry characterRegistry;
public CharacterStatsFactory(CharacterRegistry characterRegistry) {
this.characterRegistry = characterRegistry;
}
public EntityStats Create(IEntityDefinition entityDefinition) {
var attributes = entityDefinition.Attributes;
var stats = entityDefinition.Stats;
var perks = entityDefinition.Perks;
var modifiers = entityDefinition.Modifiers;
if(attributes.attributes.Any(a => a.value <= 0)) {
throw new ArgumentOutOfRangeException( "attributes cannot be zero or negative.", new ArgumentException() );
}
var healthModifiers = modifiers.modifiers.Where(m => m.StatType == StatType.Health);
var health = stats.GetValue(StatType.Health) + attributes.GetValue(AttributeType.Might) * ResolveModifiersValue(healthModifiers, attributes);
return new EntityStats {
stats = new[] {
new Stat(StatType.Health, health)
}
};
}
private int ResolveModifiersValue(IEnumerable<ModifierDefinition> healthModifiers, EntityAttributes attributes) {
throw new NotImplementedException();
}
}
}