/
romashov.z
/
PPAGame
Обзор
Документация
Войти
/
romashov.z
/
PPAGame
Код
Запросы
1
Задачи
Вики
Пакеты
0
Релизы
0
CI/CD
Аналитика
Безопасность
master
Units/SquireTargeting.cs
55 строк
2 KB
Zakhar Romashov
Добавили логику с бафами
29 апр 2026, 13:06
29 апр 2026, 13:06
7623dfb
Код
Авторство
О чём код?
using System; using System.Collections.Generic; using System.Linq; namespace ArmyBattleGame { static class SquireTargeting { public const double ApplyBuffChance = 0.30; public static bool TryGetAdjacentHeavy(Army own, UnitPosition litePos, out UnitPosition heavyPos, out IUnit heavy) { int c = litePos.Col; foreach (int dr in new[] { -1, 1 }) { int r = litePos.Row + dr; if (r < 0 || r >= own.RowCount) continue; var u = own.GetAt(r, c); if (u == null || !u.IsAlive) continue; if (BuffedHeavyUnit.IsEligibleHeavy(u)) { heavyPos = new UnitPosition(r, c); heavy = u; return true; } } heavyPos = default; heavy = null!; return false; } public static SquireBuffKind? PickRandomMissingBuff(IUnit heavy) { var taken = new HashSet<SquireBuffKind>(); if (heavy is BuffedHeavyUnit bh) { foreach (var x in bh.Buffs) taken.Add(x); } var pool = new List<SquireBuffKind>(); foreach (SquireBuffKind k in Enum.GetValues<SquireBuffKind>()) { if (!taken.Contains(k)) pool.Add(k); } if (pool.Count == 0) return null; return pool[Random.Shared.Next(pool.Count)]; } } }