forked from Shardstone/trail-into-darkness
Moar refactoring
This commit is contained in:
@@ -8,14 +8,16 @@ namespace Nox.Game {
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class CharacterTemplate {
|
||||
public Guid id = Guid.NewGuid();
|
||||
public string displayName = "New Character";
|
||||
public CharacterRace race = (CharacterRace)GetRandomInt(1, Enum.GetValues(typeof(CharacterRace)).Length-1);
|
||||
public CharacterClass @class = (CharacterClass)GetRandomInt(1, Enum.GetValues(typeof(CharacterClass)).Length-1);
|
||||
public EntityAttributes attributes = GetDefaultAttributes();
|
||||
public PerksData perksData = new();
|
||||
public ModifiersData modifiersData = new();
|
||||
public sealed class CharacterTemplate : IEntityDefinition {
|
||||
public Guid Id { get; set; } = Guid.NewGuid();
|
||||
public string Name { get; set; } = "New Character";
|
||||
public CharacterRace Race { get; set; } = (CharacterRace)GetRandomInt(1, Enum.GetValues(typeof(CharacterRace)).Length-1);
|
||||
public CharacterClass Class { get; set; } = (CharacterClass)GetRandomInt(1, Enum.GetValues(typeof(CharacterClass)).Length-1);
|
||||
public CharacterRole Role { get; set; } = CharacterRole.Companion;
|
||||
public EntityAttributes Attributes { get; set; } = GetDefaultAttributes();
|
||||
public EntityStats Stats { get; set; } = new();
|
||||
public PerksData Perks { get; set; } = new();
|
||||
public ModifiersData Modifiers { get; set; } = new();
|
||||
|
||||
private static int GetRandomInt(int start, int end) => new Random().Next(start, end);
|
||||
private static EntityAttributes GetDefaultAttributes() {
|
||||
@@ -33,29 +35,33 @@ namespace Nox.Game {
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class CustomCharacterCreationRequest {
|
||||
public Guid id = Guid.Empty;
|
||||
public string displayName;
|
||||
public CharacterRace race;
|
||||
public CharacterClass @class;
|
||||
public EntityStats stats;
|
||||
public EntityAttributes attributes;
|
||||
public PerksData perks = new();
|
||||
public ModifiersData modifiers = new();
|
||||
public sealed class CustomCharacterCreationRequest : IEntityDefinition {
|
||||
public Guid Id { get; set; }
|
||||
public string Name { get; set; }
|
||||
public CharacterRace Race { get; set; }
|
||||
public CharacterClass Class { get; set; }
|
||||
public CharacterRole Role { get; set; }
|
||||
public EntityAttributes Attributes { get; set; }
|
||||
public EntityStats Stats { get; set; }
|
||||
public PerksData Perks { get; set; }
|
||||
public ModifiersData Modifiers { get; set; }
|
||||
}
|
||||
|
||||
public sealed class CharacterFactory : ICharacterFactory {
|
||||
private readonly ICharacterAttributesFactory attributesFactory;
|
||||
private readonly ICharacterStatsFactory statsFactory;
|
||||
private readonly IPerkFactory perkFactory;
|
||||
private readonly IModifiersFactory modifiersFactory;
|
||||
|
||||
public CharacterFactory(
|
||||
ICharacterAttributesFactory attributesFactory,
|
||||
ICharacterStatsFactory statsFactory,
|
||||
IPerkFactory perkFactory) {
|
||||
IPerkFactory perkFactory,
|
||||
IModifiersFactory modifiersFactory) {
|
||||
this.attributesFactory = attributesFactory ?? throw new ArgumentNullException(nameof(attributesFactory));
|
||||
this.statsFactory = statsFactory ?? throw new ArgumentNullException(nameof(statsFactory));
|
||||
this.perkFactory = perkFactory ?? throw new ArgumentNullException(nameof(perkFactory));
|
||||
this.modifiersFactory = modifiersFactory ?? throw new ArgumentNullException(nameof(modifiersFactory));
|
||||
}
|
||||
|
||||
public CharacterDefinition CreateCustomProtagonist(CustomCharacterCreationRequest request) {
|
||||
@@ -63,22 +69,21 @@ namespace Nox.Game {
|
||||
throw new ArgumentNullException(nameof(request));
|
||||
}
|
||||
|
||||
var attributes = attributesFactory.Create(request.attributes);
|
||||
var stats = statsFactory.Create(request.attributes);
|
||||
var attributes = attributesFactory.Create(request.Attributes);
|
||||
var stats = statsFactory.Create(request);
|
||||
|
||||
var character = new CharacterDefinition {
|
||||
ID = request.id == Guid.Empty ? Guid.NewGuid() : request.id,
|
||||
Name = request.displayName,
|
||||
Race = request.race,
|
||||
Class = request.@class,
|
||||
Id = request.Id == Guid.Empty ? Guid.NewGuid() : request.Id,
|
||||
Name = request.Name,
|
||||
Race = request.Race,
|
||||
Class = request.Class,
|
||||
Role = CharacterRole.Protagonist,
|
||||
Attributes = attributes,
|
||||
Stats = stats,
|
||||
Perks = request.perks ?? new PerksData(),
|
||||
Modifiers = request.modifiers ?? new ModifiersData()
|
||||
Perks = request.Perks ?? new PerksData(),
|
||||
Modifiers = request.Modifiers ?? new ModifiersData()
|
||||
};
|
||||
|
||||
AddStartingPerks(character, request.perks);
|
||||
AddStartingPerks(character, request.Perks);
|
||||
return character;
|
||||
}
|
||||
|
||||
@@ -87,23 +92,23 @@ namespace Nox.Game {
|
||||
throw new ArgumentNullException(nameof(template));
|
||||
}
|
||||
|
||||
template.perksData ??= new PerksData();
|
||||
template.modifiersData ??= new ModifiersData();
|
||||
template.Perks ??= new PerksData();
|
||||
template.Modifiers ??= new ModifiersData();
|
||||
|
||||
var character = new CharacterDefinition {
|
||||
ID = template.id == Guid.Empty ? Guid.NewGuid() : template.id,
|
||||
Name = template.displayName,
|
||||
Race = template.race,
|
||||
Class = template.@class,
|
||||
Id = template.Id == Guid.Empty ? Guid.NewGuid() : template.Id,
|
||||
Name = template.Name,
|
||||
Race = template.Race,
|
||||
Class = template.Class,
|
||||
Role = role,
|
||||
Attributes = attributesFactory.Create(template.attributes),
|
||||
Stats = statsFactory.Create(template.attributes),
|
||||
Perks = template.perksData,
|
||||
Modifiers = template.modifiersData
|
||||
Attributes = attributesFactory.Create(template.Attributes),
|
||||
Stats = statsFactory.Create(template),
|
||||
Perks = template.Perks,
|
||||
Modifiers = template.Modifiers
|
||||
};
|
||||
|
||||
AddStartingPerks(character, template.perksData);
|
||||
AddStartingModifiers(character, template.modifiersData);
|
||||
AddStartingPerks(character, template.Perks);
|
||||
AddStartingModifiers(character, template.Modifiers);
|
||||
return character;
|
||||
}
|
||||
|
||||
@@ -123,7 +128,7 @@ namespace Nox.Game {
|
||||
}
|
||||
|
||||
foreach(var modifierId in modifiersData.modifiers.Distinct()) {
|
||||
perkFactory.TryAddPerk(character, modifierId.Id);
|
||||
modifiersFactory.TryAddModifier(character, modifierId.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user