Files
trail-into-darkness/Assets/Code/GameState/Entities/EntitiesDefinitions.cs
2026-03-22 18:28:33 +01:00

126 lines
3.4 KiB
C#

using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
namespace Nox.Game {
public interface IEntityDefinition {
string ID { get; }
string DisplayName { get; }
EntityAttributes Attributes { get; }
EntityStats Stats { get; }
}
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 EntityAttributes {
public int might;
public int reflex;
public int knowledge;
public int perception;
public static EntityAttributes operator +(EntityAttributes a, EntityAttributes b) {
return new EntityAttributes {
might = a.might + b.might,
reflex = a.reflex + b.reflex,
knowledge = a.knowledge + b.knowledge,
perception = a.perception + b.perception
};
}
}
[Serializable]
public sealed class EntityStats {
public int health;
public int stamina;
public int level;
public int experience;
}
[Serializable]
public sealed class CharacterDefinition : IEntityDefinition {
[SerializeField] private string id;
[SerializeField] private string displayName;
public CharacterRace race;
public CharacterClass @class;
public CharacterRole role;
[SerializeField] EntityAttributes attributes;
[SerializeField] EntityStats stats;
public PerksData perksData = new();
public ModifiersData activeModifiers = new();
public CharacterDefinition Clone() {
return new CharacterDefinition {
id = id,
displayName = displayName,
role = role,
race = race,
@class = @class,
attributes = new EntityAttributes {
might = attributes?.might ?? 1,
reflex = attributes?.reflex ?? 1,
knowledge = attributes?.knowledge ?? 1
},
stats = new EntityStats {
health = stats?.health ?? 1,
stamina = stats?.stamina ?? 1
},
perksData = new PerksData(),
activeModifiers = new ModifiersData()
};
}
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]
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();
}
}