forked from Shardstone/trail-into-darkness
142 lines
3.8 KiB
C#
142 lines
3.8 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
namespace Nox.Game {
|
|
public interface IEntityDefinition {
|
|
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 {
|
|
None,
|
|
Health,
|
|
Stamina,
|
|
Level,
|
|
Experience
|
|
}
|
|
|
|
public enum AttributeType {
|
|
None,
|
|
Might,
|
|
Reflex,
|
|
Knowledge,
|
|
Perception
|
|
}
|
|
|
|
public enum CharacterRole {
|
|
None,
|
|
Protagonist,
|
|
Companion
|
|
}
|
|
|
|
public enum CharacterClass {
|
|
None,
|
|
Warrior,
|
|
Rogue,
|
|
Mage,
|
|
Herald
|
|
}
|
|
|
|
public enum CharacterRace {
|
|
None,
|
|
Human,
|
|
DarkElf,
|
|
Tunneler
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class Stat {
|
|
public StatType stat;
|
|
public int value;
|
|
public Stat(StatType stat, int value) {
|
|
this.stat = stat;
|
|
this.value = value;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed record Attribute {
|
|
public AttributeType attribute;
|
|
public int value;
|
|
public Attribute(AttributeType attribute, int value) {
|
|
this.attribute = attribute;
|
|
this.value = value;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class EntityAttributes {
|
|
public Attribute[] attributes;
|
|
|
|
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))
|
|
.ToArray()
|
|
};
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class EntityStats {
|
|
public Stat[] stats;
|
|
|
|
public int GetValue(StatType statType) {
|
|
return stats.First(stat => stat.stat == statType).value;
|
|
}
|
|
}
|
|
|
|
[Serializable]
|
|
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 = Guid.NewGuid(),
|
|
Name = Name,
|
|
Role = Role,
|
|
Race = Race,
|
|
Class = Class,
|
|
Attributes = Attributes,
|
|
Stats = Stats,
|
|
Perks = Perks,
|
|
Modifiers = Modifiers
|
|
};
|
|
}
|
|
|
|
|
|
}
|
|
|
|
[Serializable]
|
|
public sealed class PartyDefinition {
|
|
public int maxPartySize;
|
|
public List<CharacterDefinition> members = new();
|
|
|
|
[JsonIgnore]
|
|
public CharacterDefinition Protagonist => members.FirstOrDefault(m => m.Role == CharacterRole.Protagonist);
|
|
|
|
[JsonIgnore]
|
|
public IReadOnlyList<CharacterDefinition> Companions => members.Where(m => m.Role == CharacterRole.Companion).ToList();
|
|
}
|
|
}
|