You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.4 KiB
49 lines
1.4 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
|
|
namespace Babushka.scripts.CSharp.Common.Fight;
|
|
|
|
public static class FightUtils
|
|
{
|
|
public static IEnumerable<FightWorld.Fighter> WhereIsAlive(this IEnumerable<FightWorld.Fighter> self)
|
|
{
|
|
return self.Where(e => e.IsAlive());
|
|
}
|
|
|
|
public static IEnumerable<FightWorld.Fighter> WhereIsNotInFormation(this IEnumerable<FightWorld.Fighter> self,
|
|
FighterFormation formation)
|
|
{
|
|
return self.Where(e => !e.IsInFormation(formation));
|
|
}
|
|
|
|
public static bool IsAlive(this FightWorld.Fighter self)
|
|
{
|
|
return self.Health > 0;
|
|
}
|
|
|
|
public static bool IsDead(this FightWorld.Fighter self)
|
|
{
|
|
return !self.IsAlive();
|
|
}
|
|
|
|
/// <summary>
|
|
/// Changes the health of a fighter
|
|
/// </summary>
|
|
/// <param name="self">The fighter itself</param>
|
|
/// <param name="amount">The amount of health to add. Make negative to remove health</param>
|
|
public static void ChangeHealth(this FightWorld.Fighter self, int amount)
|
|
{
|
|
self.Health += amount;
|
|
}
|
|
|
|
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());
|
|
}
|
|
} |