/// <summary> /// Used to get a random enemy from the current region /// </summary> /// <param name="currentRegion">The current region, used to determine what enemy to return</param> /// <returns>An instance of a random enemy of type IPixel</returns> public static IPixel GetEnemies(Islands island, RegionType currentRegion, Rarity rarity, int x, int y) { if (island == Islands.home) { possibleEnemies = GetPossible(rarity, currentRegion, x, y); } //if (currentRegion == RegionType.forest) //{ // var pixel = forestEnemies[rand.Next(0, forestEnemies.Count - 1)]; // IPixel pix = (IPixel)Activator.CreateInstance(pixel.GetType()); // return pix; //} IPixel pixel = null; if (possibleEnemies.Count > 1) { pixel = possibleEnemies[rand.Next(0, possibleEnemies.Count)]; } else if (possibleEnemies.Count == 1) { pixel = possibleEnemies[0]; } else { return(null); } IPixel pix = (IPixel)Activator.CreateInstance(pixel.GetType()); return(pix); }
public static byte ToColorBucket(this IPixel color) { if (color is Rgb24 rgbColor) { return(ToColorBucket(rgbColor)); } if (color is Rgba32 rgbaColor) { return(ToColorBucket(rgbaColor)); } throw new NotSupportedException($"Format {color.GetType().Name} is not supported"); }