Files

48 lines
1.3 KiB
C#
Raw Permalink Normal View History

2025-10-01 13:16:41 +02:00
using System;
using System.Collections.Generic;
2025-09-21 14:54:55 +02:00
using System.Linq;
namespace Babushka.scripts.CSharp.Common.Fight;
public static class FightUtils
{
public static IEnumerable<FightWorld.Fighter> WhereIsAlive(this IEnumerable<FightWorld.Fighter> self)
2025-09-21 14:54:55 +02:00
{
return self.Where(e => e.IsAlive());
2025-09-21 14:54:55 +02:00
}
public static IEnumerable<FightWorld.Fighter> WhereIsNotInFormation(this IEnumerable<FightWorld.Fighter> self, FighterFormation formation)
2025-09-21 14:54:55 +02:00
{
return self.Where(e => !e.IsInFormation(formation));
2025-09-21 14:54:55 +02:00
}
public static bool IsAlive(this FightWorld.Fighter self)
{
2025-10-01 13:16:41 +02:00
return self.GetHealth() > 0;
2025-09-21 14:54:55 +02:00
}
2025-09-30 16:23:05 +02:00
2025-09-21 14:54:55 +02:00
public static bool IsDead(this FightWorld.Fighter self)
{
return !self.IsAlive();
}
2025-09-30 16:23:05 +02:00
2025-09-21 14:54:55 +02:00
public static int GetHealth(this FightWorld.Fighter self)
{
2025-10-01 13:16:41 +02:00
return Math.Max(self.health ?? self.maxHealth, 0);
2025-09-21 14:54:55 +02:00
}
2025-09-30 16:23:05 +02:00
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);
}
2025-09-30 16:23:05 +02:00
public static bool AreAllDead(this FightWorld.FighterGroup self)
2025-09-21 14:54:55 +02:00
{
return self.fighters.All(e => e.IsDead());
2025-09-21 14:54:55 +02:00
}
}