using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
namespace LD_24.Code
{
///
/// Utility class for storing unrelated methods
///
public static class TaskUtils
{
///
/// Find the actors which have the most health by class
///
///
///
public static Dictionary FindMostHealthByClass(List actors)
{
Dictionary mostHealth = new Dictionary();
foreach (var actor in actors)
{
if (mostHealth.ContainsKey(actor.Class))
{
mostHealth[actor.Class] = Math.Max(mostHealth[actor.Class], actor.Health);
} else
{
mostHealth.Add(actor.Class, actor.Health);
}
}
return mostHealth;
}
///
/// Find all unique classes from a list of actors
///
///
///
public static List FindAllClasses(List actors)
{
List result = new List();
foreach (var actor in actors)
{
if (!result.Contains(actor.Class))
{
result.Add(actor.Class);
}
}
return result;
}
///
/// Find all unique races from a list of actors
///
///
///
public static List FindAllRaces(List actors)
{
List races = new List();
foreach (var actor in actors)
{
if (!races.Contains(actor.Race))
{
races.Add(actor.Race);
}
}
return races;
}
///
/// Finds which races are missing an NPC or Hero
///
///
/// A tuple where Item1 is missing Heros, and Item2 is missing NPCs
public static Tuple, List> FindMissingActors(List actors)
{
var races = FindAllRaces(actors);
var missingHeroes = races;
var missingNPCs = new List(races);
foreach (var actor in actors)
{
if (actor is Hero)
{
missingHeroes.Remove(actor.Race);
} else if (actor is NPC)
{
missingNPCs.Remove(actor.Race);
}
}
return Tuple.Create(missingHeroes, missingNPCs);
}
///
/// Find the actors which have the most health in their respective classes
///
///
///
public static List FilterMostHealthByClass(List actors)
{
List filtered = new List();
var mostHealths = FindMostHealthByClass(actors);
foreach (var actor in actors)
{
if (mostHealths[actor.Class] == actor.Health)
{
filtered.Add(actor);
}
}
return filtered;
}
///
/// Filter out heros which, don't meet the min intellect (exclusively)
///
///
///
///
public static List FilterHeroesByIntellect(List actors, int minIntellect)
{
List filtered = new List();
foreach (var actor in actors)
{
if (actor is Hero && (actor as Hero).Intellect > minIntellect)
{
filtered.Add(actor as Hero);
}
}
return filtered;
}
///
/// Filter out NPC which, don't meet the max attack (exclusively)
///
///
///
///
public static List FilterNPCsByAttack(List actors, int maxAttack)
{
List filtered = new List();
foreach (var actor in actors)
{
if (actor is NPC && actor.Attack < maxAttack)
{
filtered.Add(actor as NPC);
}
}
return filtered;
}
}
}