M2 回合制调度:速度/阵营/队伍顺序规则、先制第一轮、4v4 调试入口与调度测试

- BattleRuntime 调度替换为完整规则:速度高优先、同速玩家优先、同阵营同速 PartyOrder 小优先;先制第一轮玩家全先行,第二轮恢复普通排序;RemainingTurnOrder 同步按调度序输出
- TurnBattleComponent 开局行动者为敌人时自动推进,协程等待 UI 监听注册避免先手事件丢失
- 调试入口支持 1v1 / 2v2 / 4v4 与先制开关;新增敌人队伍预设 4005(四普通敌人)
- UI:修复 UIForm 复用导致第二次开战按钮监听丢失;EnemySlots/TurnSlots 改为按数量复用 item,图标同一单位不重复加载
- EditMode 新增 10 个调度用例(共 35 个):排序规则、先制两轮、重复敌人分别击杀、4v4 创建、死亡移出候选、固定随机序列复现
This commit is contained in:
huangjun
2026-09-02 10:12:30 +08:00
parent 7dcac0ac87
commit 202ab337f9
14 changed files with 605 additions and 85 deletions
@@ -244,12 +244,9 @@ namespace SepCore.Battle
List<int> remainingOrder = new List<int>();
if (!IsCompleted)
{
foreach (BattleUnit unit in Units)
foreach (BattleUnit unit in GetRemainingCandidates())
{
if (IsActive(unit) && !ActedUnitIds.Contains(unit.UnitId))
{
remainingOrder.Add(unit.UnitId);
}
remainingOrder.Add(unit.UnitId);
}
}
@@ -412,9 +409,14 @@ namespace SepCore.Battle
}
/// <summary>
/// 选择本轮下一个未行动的活跃单位;全部行动过则进入下一轮。
/// M1 按单位创建顺序(玩家在前)轮流,每轮每个单位最多行动一次;
/// M2 起由完整调度规则(速度、阵营、队伍顺序、先制)替换。
/// 选择本轮下一个未行动的活跃单位;候选集为空时开启下一轮。
/// 调度规则(文档 6.1):
/// 1. 先制第一轮仍有玩家未行动时只在玩家中选择;
/// 2. 当前速度高者优先;
/// 3. 同速时玩家优先于敌人;
/// 4. 同阵营同速时 PartyOrder 小者优先;
/// 5. 已行动单位不因速度变化再次行动(M2 无速度变化效果);
/// 6. 候选集为空时开启下一轮,先制限制只适用于第一轮。
/// </summary>
private void SelectNextActor()
{
@@ -435,17 +437,93 @@ namespace SepCore.Battle
CurrentActorUnitId = next != null ? next.UnitId : 0;
}
/// <summary>
/// 按调度规则选本轮优先级最高的候选;没有候选时返回 null。
/// </summary>
private BattleUnit FindNextActor()
{
BattleUnit best = null;
foreach (BattleUnit unit in Units)
{
if (IsActive(unit) && !ActedUnitIds.Contains(unit.UnitId))
if (!IsActive(unit) || ActedUnitIds.Contains(unit.UnitId))
{
return unit;
continue;
}
if (IsPreemptiveRound && unit.Faction == BattleFaction.Enemy && HasUnactedPlayer())
{
continue;
}
if (best == null || CompareActors(unit, best) < 0)
{
best = unit;
}
}
return null;
return best;
}
/// <summary>
/// 先制限制只适用于第一轮。
/// </summary>
private bool IsPreemptiveRound => IsPreemptive && RoundNumber == 1;
private bool HasUnactedPlayer()
{
foreach (BattleUnit unit in Units)
{
if (unit.Faction == BattleFaction.Player && IsActive(unit) && !ActedUnitIds.Contains(unit.UnitId))
{
return true;
}
}
return false;
}
/// <summary>
/// 速度高优先;同速玩家优先;同阵营同速 PartyOrder 小优先。返回负值表示 a 优先于 b。
/// </summary>
private static int CompareActors(BattleUnit a, BattleUnit b)
{
if (a.Speed != b.Speed)
{
return b.Speed - a.Speed;
}
if (a.Faction != b.Faction)
{
return a.Faction == BattleFaction.Player ? -1 : 1;
}
return a.PartyOrder - b.PartyOrder;
}
/// <summary>
/// 本轮尚未行动的候选单位,按调度优先级排序;当前行动者是首个。
/// 先制第一轮只返回玩家候选(敌人等玩家全部行动后进入候选集)。
/// </summary>
private List<BattleUnit> GetRemainingCandidates()
{
List<BattleUnit> candidates = new List<BattleUnit>();
foreach (BattleUnit unit in Units)
{
if (!IsActive(unit) || ActedUnitIds.Contains(unit.UnitId))
{
continue;
}
if (IsPreemptiveRound && unit.Faction == BattleFaction.Enemy && HasUnactedPlayer())
{
continue;
}
candidates.Add(unit);
}
candidates.Sort(CompareActors);
return candidates;
}
/// <summary>