forked from Shardstone/trail-into-darkness
End of refactor for the Entities
This commit is contained in:
@@ -9,25 +9,39 @@ namespace Nox.Game {
|
||||
|
||||
[Serializable]
|
||||
public sealed class CharacterTemplate {
|
||||
public string id;
|
||||
public string displayName;
|
||||
public EntityAttributes attributes;
|
||||
public CharacterRace characterRace;
|
||||
public CharacterClass characterClass;
|
||||
public EntityStats stats;
|
||||
public PerksData perksData = new ();
|
||||
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();
|
||||
|
||||
private static int GetRandomInt(int start, int end) => new Random().Next(start, end);
|
||||
private static EntityAttributes GetDefaultAttributes() {
|
||||
var attributes = new EntityAttributes {
|
||||
attributes = new Attribute[] {
|
||||
new (AttributeType.Might, 1),
|
||||
new (AttributeType.Knowledge, 1),
|
||||
new (AttributeType.Perception, 1),
|
||||
new (AttributeType.Reflex, 1)
|
||||
}
|
||||
};
|
||||
|
||||
return attributes;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class CustomCharacterCreationRequest {
|
||||
public string id;
|
||||
public Guid id = Guid.Empty;
|
||||
public string displayName;
|
||||
public CharacterRace characterRace;
|
||||
public CharacterClass characterClass;
|
||||
public CharacterRace race;
|
||||
public CharacterClass @class;
|
||||
public EntityStats stats;
|
||||
public EntityAttributes attributes;
|
||||
public PerksData perksData = new();
|
||||
public ModifiersData modifiersData = new();
|
||||
public PerksData perks = new();
|
||||
public ModifiersData modifiers = new();
|
||||
}
|
||||
|
||||
public sealed class CharacterFactory : ICharacterFactory {
|
||||
@@ -53,18 +67,18 @@ namespace Nox.Game {
|
||||
var stats = statsFactory.Create(request.attributes);
|
||||
|
||||
var character = new CharacterDefinition {
|
||||
ID = string.IsNullOrWhiteSpace(request.id) ? Guid.NewGuid().ToString("N") : request.id,
|
||||
DisplayName = request.displayName,
|
||||
race = request.characterRace,
|
||||
@class = request.characterClass,
|
||||
role = CharacterRole.Protagonist,
|
||||
ID = request.id == Guid.Empty ? Guid.NewGuid() : request.id,
|
||||
Name = request.displayName,
|
||||
Race = request.race,
|
||||
Class = request.@class,
|
||||
Role = CharacterRole.Protagonist,
|
||||
Attributes = attributes,
|
||||
Stats = stats,
|
||||
perksData = request.perksData ?? new PerksData(),
|
||||
activeModifiers = request.modifiersData ?? new ModifiersData()
|
||||
Perks = request.perks ?? new PerksData(),
|
||||
Modifiers = request.modifiers ?? new ModifiersData()
|
||||
};
|
||||
|
||||
AddStartingPerks(character, request.perksData);
|
||||
AddStartingPerks(character, request.perks);
|
||||
return character;
|
||||
}
|
||||
|
||||
@@ -73,21 +87,23 @@ namespace Nox.Game {
|
||||
throw new ArgumentNullException(nameof(template));
|
||||
}
|
||||
|
||||
var attributes = attributesFactory.Create(template.attributes);
|
||||
template.perksData ??= new PerksData();
|
||||
template.modifiersData ??= new ModifiersData();
|
||||
|
||||
var character = new CharacterDefinition {
|
||||
ID = string.IsNullOrWhiteSpace(template.id) ? Guid.NewGuid().ToString("N") : template.id,
|
||||
DisplayName = template.displayName,
|
||||
race = template.characterRace,
|
||||
@class = template.characterClass,
|
||||
role = role,
|
||||
Attributes = attributes,
|
||||
Stats = statsFactory.Create(attributes),
|
||||
perksData = new PerksData(),
|
||||
activeModifiers = new ModifiersData()
|
||||
ID = template.id == Guid.Empty ? Guid.NewGuid() : template.id,
|
||||
Name = template.displayName,
|
||||
Race = template.race,
|
||||
Class = template.@class,
|
||||
Role = role,
|
||||
Attributes = attributesFactory.Create(template.attributes),
|
||||
Stats = statsFactory.Create(template.attributes),
|
||||
Perks = template.perksData,
|
||||
Modifiers = template.modifiersData
|
||||
};
|
||||
|
||||
AddStartingPerks(character, template.perksData);
|
||||
AddStartingModifiers(character, template.modifiersData);
|
||||
return character;
|
||||
}
|
||||
|
||||
@@ -97,7 +113,17 @@ namespace Nox.Game {
|
||||
}
|
||||
|
||||
foreach(var perkId in perkData.perks.Distinct()) {
|
||||
perkFactory.TryAddPerk(character, perkId.id);
|
||||
perkFactory.TryAddPerk(character, perkId.Id);
|
||||
}
|
||||
}
|
||||
|
||||
private void AddStartingModifiers(CharacterDefinition character, ModifiersData modifiersData) {
|
||||
if(modifiersData?.modifiers == null || modifiersData.modifiers.Count == 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach(var modifierId in modifiersData.modifiers.Distinct()) {
|
||||
perkFactory.TryAddPerk(character, modifierId.Id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user