123 lines
3.9 KiB
C#
123 lines
3.9 KiB
C#
using System;
|
||
using System.Collections.Generic;
|
||
|
||
namespace Models;
|
||
|
||
/// <summary>
|
||
/// Unit 组件集合(组合优于继承)
|
||
/// 设计说明:
|
||
/// 1) UnitModel 只是“组件容器”,具体能力拆分到小组件中,便于复用与替换。
|
||
/// 2) 组件保持低内聚小职责,避免“巨型基类”造成的隐式耦合。
|
||
/// 3) 这些组件只描述数据,不包含具体行为,行为交给系统/控制器层。
|
||
/// 注意事项:
|
||
/// - 不引用 Godot 类型,保持纯数据层,利于测试与序列化。
|
||
/// - 标识/标签使用 string Id,方便 Mod 扩展新增内容。
|
||
/// 未来扩展:
|
||
/// - 可以给组件增加“快照/脏标记”,用于高效 UI 刷新。
|
||
/// - 需要网络联机时,可在这里加入序列化版本号。
|
||
/// </summary>
|
||
public static class UnitComponents {
|
||
/// <summary>
|
||
/// 网格位置组件
|
||
/// </summary>
|
||
public readonly struct GridPosition {
|
||
public int X { get; }
|
||
public int Y { get; }
|
||
|
||
public GridPosition(int x, int y) {
|
||
X = x;
|
||
Y = y;
|
||
}
|
||
|
||
public static GridPosition Zero => new(0, 0);
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单位身份组件
|
||
/// </summary>
|
||
public sealed class UnitIdentity {
|
||
public UnitIdentity(string name, string nameKey = null) {
|
||
Name = name;
|
||
NameKey = nameKey;
|
||
}
|
||
|
||
public Guid Id { get; } = Guid.NewGuid();
|
||
public string Name { get; set; }
|
||
public string NameKey { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单位属性组件
|
||
/// </summary>
|
||
public sealed class UnitAttributes {
|
||
public UnitAttributes(Random random = null) {
|
||
var rng = random ?? Random.Shared;
|
||
Academic = new PropertyValue(rng.Next(0, 100));
|
||
Engineering = new PropertyValue(rng.Next(0, 100));
|
||
Writing = new PropertyValue(rng.Next(0, 100));
|
||
Financial = new PropertyValue(rng.Next(0, 100));
|
||
Social = new PropertyValue(rng.Next(0, 100));
|
||
Activation = new PropertyValue(rng.Next(0, 100));
|
||
}
|
||
|
||
public PropertyValue Academic { get; set; }
|
||
public PropertyValue Engineering { get; set; }
|
||
public PropertyValue Writing { get; set; }
|
||
public PropertyValue Financial { get; set; }
|
||
public PropertyValue Social { get; set; }
|
||
public PropertyValue Activation { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单位状态组件
|
||
/// </summary>
|
||
public sealed class UnitStatuses {
|
||
public UnitStatuses() {
|
||
Stress = new StatusValue();
|
||
Sanity = new StatusValue(100);
|
||
Mood = new PropertyValue(50);
|
||
MoveSpeed = new PropertyValue(50, 0, 200);
|
||
}
|
||
|
||
public StatusValue Stress { get; set; }
|
||
public StatusValue Sanity { get; set; }
|
||
public PropertyValue Mood { get; set; }
|
||
public PropertyValue MoveSpeed { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单位标签组件
|
||
/// </summary>
|
||
public sealed class UnitTags {
|
||
public string DisciplineId { get; set; }
|
||
public List<string> ArchetypeIds { get; } = new();
|
||
public List<string> RoleIds { get; } = new();
|
||
public List<string> TraitIds { get; } = new();
|
||
|
||
public bool HasTrait(string traitId) {
|
||
return TraitIds.Contains(traitId);
|
||
}
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单位指派组件
|
||
/// </summary>
|
||
public sealed class UnitAssignment {
|
||
public Guid? CurrentTaskId { get; set; }
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单位位置组件
|
||
/// </summary>
|
||
public sealed class UnitPlacement {
|
||
public GridPosition Current { get; set; } = GridPosition.Zero;
|
||
public GridPosition Target { get; set; } = GridPosition.Zero;
|
||
}
|
||
|
||
/// <summary>
|
||
/// 单位装备组件
|
||
/// </summary>
|
||
public sealed class UnitEquipment {
|
||
public List<string> EquippedItemIds { get; } = new();
|
||
}
|
||
} |