/
expens1ve
/
project_war
Обзор
Документация
Войти
/
expens1ve
/
project_war
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
solid
Engine/Formations/BridgeFormation.cs
67 строк
2 KB
Диана Казиева
fixed ability using + added formation before battle
30 апр 2026, 20:45
30 апр 2026, 20:45
14bce98
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using System.Linq; using project_war.Engine.Interfaces; using project_war.Models.Interfaces; using project_war.Models.Utils; namespace project_war.Engine.Formations { /// <summary> /// Узкий мост: юниты идут в колонне по одному. /// Front = первый живой юнит в списке. /// </summary> public sealed class BridgeFormation : IBattleFormation { public string DisplayName => "Узкий мост"; public IReadOnlyList<IUnit?> GetFrontUnits(IArmy army) { if (army == null) return Array.Empty<IUnit?>(); return new IUnit?[] { army.Units.FirstOrDefault(u => u != null && u.Health > 0) }; } public IUnit? GetFrontUnit(IArmy army) { var fronts = GetFrontUnits(army); return fronts.Count > 0 ? fronts[0] : null; } public void OnUnitDied(IUnit deadUnit, IArmy army) { // Ничего не делаем: // мертвый автоматически выбывает, следующий в этой формации станет фронтовым. } public bool CanUseSpecialAbility(IUnit unit, IArmy ownArmy, IArmy enemyArmy) { if (unit == null || ownArmy == null) return false; int index = IndexOfUnit(ownArmy, unit); return index > 0; } private static int IndexOfUnit(IArmy army, IUnit unit) { var needle = unit.Unwrap(); for (int i = 0; i < army.Units.Count; i++) { var current = army.Units[i]; if (current == null) continue; if (ReferenceEquals(current.Unwrap(), needle)) return i; } return -1; } } }