using System; using System.Collections.Generic; using System.Linq; namespace Babushka.scripts.CSharp.Common.Fight; public static class FightUtils { public static IEnumerable WhereIsAlive(this IEnumerable self) { return self.Where(e => e.IsAlive()); } public static IEnumerable WhereIsNotInFormation(this IEnumerable self, FighterFormation formation) { return self.Where(e => !e.IsInFormation(formation)); } public static bool IsAlive(this FightWorld.Fighter self) { return self.GetHealth() > 0; } public static bool IsDead(this FightWorld.Fighter self) { return !self.IsAlive(); } public static int GetHealth(this FightWorld.Fighter self) { return Math.Max(self.health ?? self.maxHealth, 0); } public static void AddHealth(this FightWorld.Fighter self, int addHealth) { self.health = self.GetHealth() + addHealth; } public static bool IsInFormation(this FightWorld.Fighter self, FighterFormation formation) { return formation.ContainsFighter(self); } public static bool AreAllDead(this FightWorld.FighterGroup self) { return self.fighters.All(e => e.IsDead()); } }