Added resolver

This commit is contained in:
Sebastian Bularca
2026-03-30 01:17:25 +02:00
parent e7d5acac7c
commit cfac76ed25
9 changed files with 147 additions and 45 deletions

View File

@@ -3,22 +3,31 @@ using System.Linq;
namespace Nox.Game {
public interface ICharacterAttributesFactory {
EntityAttributes Create(EntityAttributes entityAttributes);
EntityAttributes Create(IEntityDefinition entityDefinition);
}
public sealed class CharacterAttributesFactory : ICharacterAttributesFactory {
private readonly CharacterRegistry characterRegistry;
private readonly IModifierResolver modifierResolver;
public CharacterAttributesFactory(CharacterRegistry characterRegistry) {
this.characterRegistry = characterRegistry;
public CharacterAttributesFactory(IModifierResolver modifierResolver) {
this.modifierResolver = modifierResolver ?? throw new ArgumentNullException(nameof(modifierResolver));
}
public EntityAttributes Create(EntityAttributes entityAttributes) {
if(entityAttributes.attributes.Any(a => a.value <= 0)) {
public EntityAttributes Create(IEntityDefinition entityDefinition) {
var attributes = entityDefinition.Attributes;
if(attributes.attributes.Any(a => a.value <= 0)) {
throw new ArgumentOutOfRangeException( "attributes cannot be zero or negative.", new ArgumentException() );
}
//TODO: Handle attributes modifiers and perks
return entityAttributes;
return new EntityAttributes {
attributes = attributes.attributes
.Select(a => {
var modifiers = modifierResolver.CollectModifiers(entityDefinition, a.attribute);
return new Attribute(a.attribute, modifierResolver.Resolve(a.value, modifiers));
})
.ToArray()
};
}
}
}