forked from Shardstone/trail-into-darkness
Moar refactoring
This commit is contained in:
@@ -6,7 +6,7 @@ using UnityEngine;
|
||||
|
||||
namespace Nox.Game {
|
||||
public interface IEntityDefinition {
|
||||
Guid ID { get; }
|
||||
Guid Id { get; }
|
||||
string Name { get; }
|
||||
CharacterRace Race { get; }
|
||||
CharacterClass Class { get; }
|
||||
@@ -56,7 +56,7 @@ namespace Nox.Game {
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public sealed class Stat {
|
||||
public sealed record Stat {
|
||||
public StatType stat;
|
||||
public int value;
|
||||
public Stat(StatType stat, int value) {
|
||||
@@ -82,11 +82,17 @@ namespace Nox.Game {
|
||||
public static EntityAttributes operator +(EntityAttributes a, EntityAttributes b) {
|
||||
return new EntityAttributes {
|
||||
attributes = a.attributes
|
||||
.Select(attr => new Attribute(attr.attribute, attr.value + b.attributes
|
||||
.First(attr2 => attr2.attribute == attr.attribute).value))
|
||||
.Select(attr => {
|
||||
var match = b.attributes?.FirstOrDefault(attr2 => attr2.attribute == attr.attribute);
|
||||
return new Attribute(attr.attribute, attr.value + (match?.value ?? 0));
|
||||
})
|
||||
.ToArray()
|
||||
};
|
||||
}
|
||||
|
||||
public int GetValue(AttributeType attributeType) {
|
||||
return attributes.First(attr => attr.attribute == attributeType).value;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
@@ -100,7 +106,7 @@ namespace Nox.Game {
|
||||
|
||||
[Serializable]
|
||||
public class CharacterDefinition : IEntityDefinition {
|
||||
public Guid ID { get; set; }
|
||||
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; }
|
||||
@@ -112,15 +118,34 @@ namespace Nox.Game {
|
||||
|
||||
public CharacterDefinition Clone() {
|
||||
return new CharacterDefinition {
|
||||
ID = Guid.NewGuid(),
|
||||
Id = Guid.NewGuid(),
|
||||
Name = Name,
|
||||
Role = Role,
|
||||
Race = Race,
|
||||
Class = Class,
|
||||
Attributes = Attributes,
|
||||
Stats = Stats,
|
||||
Perks = Perks,
|
||||
Modifiers = Modifiers
|
||||
Attributes = new EntityAttributes {
|
||||
attributes = Attributes?.attributes?.Select(a => new Attribute(a.attribute, a.value)).ToArray()
|
||||
},
|
||||
Stats = new EntityStats {
|
||||
stats = Stats?.stats?.Select(s => new Stat(s.stat, s.value)).ToArray()
|
||||
},
|
||||
Perks = new PerksData {
|
||||
perks = Perks?.perks?.Select(p => new PerkDefinition {
|
||||
Id = p.Id,
|
||||
Name = p.Name,
|
||||
Modifiers = p.Modifiers
|
||||
}).ToList() ?? new()
|
||||
},
|
||||
Modifiers = new ModifiersData {
|
||||
modifiers = Modifiers?.modifiers?.Select(m => new ModifierDefinition {
|
||||
Id = m.Id,
|
||||
Name = m.Name,
|
||||
StatType = m.StatType,
|
||||
AttributeType = m.AttributeType,
|
||||
Operation = m.Operation,
|
||||
Value = m.Value
|
||||
}).ToList() ?? new()
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user