forked from Shardstone/trail-into-darkness
End of refactor for the Entities
This commit is contained in:
@@ -6,10 +6,16 @@ using UnityEngine;
|
||||
|
||||
namespace Nox.Game {
|
||||
public interface IEntityDefinition {
|
||||
string ID { get; }
|
||||
string DisplayName { get; }
|
||||
Guid ID { get; }
|
||||
string Name { get; }
|
||||
CharacterRace Race { get; }
|
||||
CharacterClass Class { get; }
|
||||
CharacterRole Role { get; }
|
||||
EntityAttributes Attributes { get; }
|
||||
EntityStats Stats { get; }
|
||||
PerksData Perks { get; }
|
||||
ModifiersData Modifiers { get; }
|
||||
|
||||
}
|
||||
|
||||
public enum StatType {
|
||||
@@ -51,22 +57,21 @@ namespace Nox.Game {
|
||||
|
||||
[Serializable]
|
||||
public sealed class Stat {
|
||||
private readonly StatType health;
|
||||
public StatType type;
|
||||
public StatType stat;
|
||||
public int value;
|
||||
public Stat(StatType health, int value) {
|
||||
this.health = health;
|
||||
public Stat(StatType stat, int value) {
|
||||
this.stat = stat;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed record Attribute {
|
||||
private readonly int values;
|
||||
public AttributeType attribute;
|
||||
public int value;
|
||||
public Attribute(AttributeType attributeType, int values) {
|
||||
this.values = values;
|
||||
public Attribute(AttributeType attribute, int value) {
|
||||
this.attribute = attribute;
|
||||
this.value = value;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,55 +94,37 @@ namespace Nox.Game {
|
||||
public Stat[] stats;
|
||||
|
||||
public int GetValue(StatType statType) {
|
||||
return stats.First(stat => stat.type == statType).value;
|
||||
return stats.First(stat => stat.stat == statType).value;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class CharacterDefinition : IEntityDefinition {
|
||||
[SerializeField] private string id;
|
||||
[SerializeField] private string displayName;
|
||||
public CharacterRace race;
|
||||
public CharacterClass @class;
|
||||
public CharacterRole role;
|
||||
[SerializeField] private EntityAttributes attributes;
|
||||
[SerializeField] private EntityStats stats;
|
||||
public PerksData perksData = new();
|
||||
public ModifiersData activeModifiers = new();
|
||||
public class CharacterDefinition : IEntityDefinition {
|
||||
public Guid ID { get; set; }
|
||||
[field: SerializeField] public string Name { get; set; }
|
||||
[field: SerializeField] public CharacterRace Race { get; set; }
|
||||
[field: SerializeField] public CharacterClass Class { get; set; }
|
||||
[field: SerializeField] public CharacterRole Role { get; set; }
|
||||
[field: SerializeField] public EntityAttributes Attributes { get; set; }
|
||||
[field: SerializeField] public EntityStats Stats { get; set; }
|
||||
[field: SerializeField] public PerksData Perks { get; set; }
|
||||
[field: SerializeField] public ModifiersData Modifiers { get; set; }
|
||||
|
||||
public CharacterDefinition Clone() {
|
||||
return new CharacterDefinition {
|
||||
id = id,
|
||||
displayName = displayName,
|
||||
role = role,
|
||||
race = race,
|
||||
@class = @class,
|
||||
attributes = new EntityAttributes(),
|
||||
stats = new EntityStats(),
|
||||
perksData = new PerksData(),
|
||||
activeModifiers = new ModifiersData()
|
||||
ID = Guid.NewGuid(),
|
||||
Name = Name,
|
||||
Role = Role,
|
||||
Race = Race,
|
||||
Class = Class,
|
||||
Attributes = Attributes,
|
||||
Stats = Stats,
|
||||
Perks = Perks,
|
||||
Modifiers = Modifiers
|
||||
};
|
||||
}
|
||||
|
||||
public string ID {
|
||||
get => id;
|
||||
set => id = value;
|
||||
}
|
||||
|
||||
public string DisplayName {
|
||||
get => displayName;
|
||||
set => displayName = value;
|
||||
}
|
||||
|
||||
public EntityAttributes Attributes {
|
||||
get => attributes;
|
||||
set => attributes = value;
|
||||
}
|
||||
|
||||
public EntityStats Stats {
|
||||
get => stats;
|
||||
set => stats = value;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -146,9 +133,9 @@ namespace Nox.Game {
|
||||
public List<CharacterDefinition> members = new();
|
||||
|
||||
[JsonIgnore]
|
||||
public CharacterDefinition Protagonist => members.FirstOrDefault(m => m.role == CharacterRole.Protagonist);
|
||||
public CharacterDefinition Protagonist => members.FirstOrDefault(m => m.Role == CharacterRole.Protagonist);
|
||||
|
||||
[JsonIgnore]
|
||||
public IReadOnlyList<CharacterDefinition> Companions => members.Where(m => m.role == CharacterRole.Companion).ToList();
|
||||
public IReadOnlyList<CharacterDefinition> Companions => members.Where(m => m.Role == CharacterRole.Companion).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user