using System.Collections.Generic; using SepCore.Definition; namespace SepCore.Battle { /// /// 单位剩余状态快照。 /// public sealed class BattleStatusSnapshot { /// /// 状态类型。 /// public readonly BattleStatusType StatusType; /// /// 剩余持续次数(行动机会);重复施加取较大值,移除后为 0。 /// public readonly int RemainingRounds; public BattleStatusSnapshot(BattleStatusType statusType, int remainingRounds) { StatusType = statusType; RemainingRounds = remainingRounds; } } /// /// 单个战斗单位的只读视图。 /// public sealed class BattleUnitSnapshot { /// /// 本场战斗单位的唯一运行时标识;重复配置的敌人拥有不同 ID。 /// public readonly int BattleUnitId; /// /// 阵营。 /// public readonly BattleFaction Faction; /// /// 配置标识:玩家为 CharacterId,敌人为 EnemyConfigId。 /// public readonly int ConfigId; /// /// 同阵营同速度的最终并列规则顺序。 /// public readonly int PartyOrder; /// /// 当前 HP。 /// public readonly int CurrentHp; /// /// HP 上限。 /// public readonly int MaxHp; /// /// 当前 MP。 /// public readonly int CurrentMp; /// /// MP 上限。 /// public readonly int MaxMp; /// /// 攻击。 /// public readonly int Atk; /// /// 魔力。 /// public readonly int Mat; /// /// 当前速度。 /// public readonly int Speed; /// /// 是否阵亡。 /// public readonly bool IsDefeated; /// /// 是否已逃跑。 /// public readonly bool IsEscaped; /// /// 剩余状态列表。 /// public readonly IReadOnlyList Statuses; /// /// 可用行动配置 ID 列表。 /// public readonly IReadOnlyList AvailableActionIds; public BattleUnitSnapshot(int battleUnitId, BattleFaction faction, int configId, int partyOrder, int currentHp, int maxHp, int currentMp, int maxMp, int atk, int mat, int speed, bool isDefeated, bool isEscaped, IReadOnlyList statuses, IReadOnlyList availableActionIds) { BattleUnitId = battleUnitId; Faction = faction; ConfigId = configId; PartyOrder = partyOrder; CurrentHp = currentHp; MaxHp = maxHp; CurrentMp = currentMp; MaxMp = maxMp; Atk = atk; Mat = mat; Speed = speed; IsDefeated = isDefeated; IsEscaped = isEscaped; Statuses = statuses != null ? Copy(statuses) : new BattleStatusSnapshot[0]; AvailableActionIds = availableActionIds != null ? Copy(availableActionIds) : new int[0]; } private static BattleStatusSnapshot[] Copy(IReadOnlyList source) { BattleStatusSnapshot[] copy = new BattleStatusSnapshot[source.Count]; for (int i = 0; i < source.Count; i++) { copy[i] = source[i]; } return copy; } private static int[] Copy(IReadOnlyList source) { int[] copy = new int[source.Count]; for (int i = 0; i < source.Count; i++) { copy[i] = source[i]; } return copy; } } /// /// 只读战斗快照,是 UI 和敌人策略唯一允许读取的战斗状态。 /// 每次推进都创建逻辑上的只读快照,不把可修改的内部列表或战斗单位引用暴露给调用方。 /// public sealed class BattleSnapshot { /// /// 当前轮次,从 1 开始。 /// public readonly int RoundNumber; /// /// 当前是否为先制战斗第一轮。 /// public readonly bool IsPreemptiveRound; /// /// 当前行动者;战斗完成时为 0。 /// public readonly int CurrentActorUnitId; /// /// 全部单位的只读视图,保持稳定显示顺序。 /// public readonly IReadOnlyList Units; /// /// 本轮从当前行动者开始的剩余运行时单位 ID;速度变化后重建。 /// public readonly IReadOnlyList RemainingTurnOrder; /// /// 流程状态。 /// public readonly BattleFlowState FlowState; public BattleSnapshot(int roundNumber, bool isPreemptiveRound, int currentActorUnitId, IReadOnlyList units, IReadOnlyList remainingTurnOrder, BattleFlowState flowState) { RoundNumber = roundNumber; IsPreemptiveRound = isPreemptiveRound; CurrentActorUnitId = currentActorUnitId; Units = units != null ? Copy(units) : new BattleUnitSnapshot[0]; RemainingTurnOrder = remainingTurnOrder != null ? Copy(remainingTurnOrder) : new int[0]; FlowState = flowState; } private static BattleUnitSnapshot[] Copy(IReadOnlyList source) { BattleUnitSnapshot[] copy = new BattleUnitSnapshot[source.Count]; for (int i = 0; i < source.Count; i++) { copy[i] = source[i]; } return copy; } private static int[] Copy(IReadOnlyList source) { int[] copy = new int[source.Count]; for (int i = 0; i < source.Count; i++) { copy[i] = source[i]; } return copy; } } }