a bit more work on the system to create a default character set and testable environment for that

This commit is contained in:
Sebastian Bularca
2026-03-22 18:11:58 +01:00
parent da74abb039
commit 47d30c0c49
16 changed files with 241 additions and 59 deletions

View File

@@ -7,17 +7,11 @@ namespace Nox.Game {
PartyDefinition Create(CharacterDefinition protagonist, IEnumerable<CharacterDefinition> companions = null);
}
public sealed class PartyFactoryOptions {
public int minPartySize = 1;
public int maxPartySize = 4;
public bool enforceUniqueCharacterIds = true;
}
public sealed class PartyFactory : IPartyFactory {
private readonly PartyFactoryOptions options;
private readonly CharacterBaseSettings characterBaseSettings;
public PartyFactory(PartyFactoryOptions options = null) {
this.options = options ?? new PartyFactoryOptions();
public PartyFactory(CharacterBaseSettings characterBaseSettings) {
this.characterBaseSettings = characterBaseSettings;
}
public PartyDefinition Create(CharacterDefinition protagonist, IEnumerable<CharacterDefinition> companions = null) {
@@ -25,17 +19,17 @@ namespace Nox.Game {
throw new ArgumentNullException(nameof(protagonist));
}
PartyDefinition party = new PartyDefinition {
maxPartySize = options.maxPartySize <= 0 ? int.MaxValue : options.maxPartySize
var party = new PartyDefinition {
maxPartySize = characterBaseSettings.maxPartySize <= 0 ? int.MaxValue : characterBaseSettings.maxPartySize
};
CharacterDefinition protagonistClone = protagonist.Clone();
var protagonistClone = protagonist.Clone();
protagonistClone.role = CharacterRole.Protagonist;
party.members.Add(protagonistClone);
if(companions != null) {
foreach(CharacterDefinition companion in companions.Where(c => c != null)) {
CharacterDefinition companionClone = companion.Clone();
foreach(var companion in companions.Where(c => c != null)) {
var companionClone = companion.Clone();
companionClone.role = CharacterRole.Companion;
party.members.Add(companionClone);
}
@@ -46,10 +40,6 @@ namespace Nox.Game {
}
private void ValidateParty(PartyDefinition party) {
if(party.members.Count < options.minPartySize) {
throw new ArgumentException($"Party size {party.members.Count} is below minimum {options.minPartySize}.");
}
if(party.members.Count > party.maxPartySize) {
throw new ArgumentException($"Party size {party.members.Count} exceeds max {party.maxPartySize}.");
}
@@ -59,15 +49,13 @@ namespace Nox.Game {
throw new ArgumentException($"Party must contain exactly one protagonist, found {protagonistCount}.");
}
if(options.enforceUniqueCharacterIds) {
int uniqueIds = party.members
.Where(m => !string.IsNullOrWhiteSpace(m.ID))
.Select(m => m.ID)
.Distinct()
.Count();
if(uniqueIds != party.members.Count) {
throw new ArgumentException("Party contains duplicate or missing character ids.");
}
int uniqueIds = party.members
.Where(m => !string.IsNullOrWhiteSpace(m.ID))
.Select(m => m.ID)
.Distinct()
.Count();
if(uniqueIds != party.members.Count) {
throw new ArgumentException("Party contains duplicate or missing character ids.");
}
}
}