public static IEnumerable <Vector2> GetPositionsRelativeToTarget(this AbilityShape shape) { var positions = new List <Vector2>(); var targetPosition = Vector2.Zero; for (var y = 0; y < shape.Size; ++y) { for (var x = 0; x < shape.Size; ++x) { if (shape[y, x] != AbilityShape.EmptyPoint) { if (shape[y, x] == AbilityShape.TargetPoint) { targetPosition = new Vector2(x, y); } else { positions.Add(new Vector2(x, y)); } } } } foreach (var position in positions) { yield return(new Vector2(position.X - targetPosition.X, position.Y - targetPosition.Y)); } yield return(Vector2.Zero); }
public static int ActiveCellCount(this AbilityShape shape) { var count = 0; for (var y = 0; y < shape.Size; ++y) { for (var x = 0; x < shape.Size; ++x) { if (shape[y, x] != AbilityShape.EmptyPoint) { count++; } } } return(count); }
public static AbilityShape Rotate90(this AbilityShape shape) { var result = new byte[shape.Size, shape.Size]; for (var y = 0; y < shape.Size; ++y) { for (var x = 0; x < shape.Size; ++x) { result[y, x] = shape.ShapeData[shape.Size - x - 1, y]; } } var newDirection = (byte)(shape.FacingDirection + 1); if (newDirection > DirectionTypes.Left) { newDirection = DirectionTypes.Up; } return(new AbilityShape(shape.Size, result, newDirection)); }
public HasEnemiesInShapeModifier(Level level, AbilityShape shape) { Level = level; Shape = shape; _maxTargetableCount = Shape.ActiveCellCount(); }
public static AbilityShape Rotate180(this AbilityShape shape) { return(Rotate90(Rotate90(shape))); }
public static IEnumerable <Vector2> GetLocationsFromShape(this Vector2 position, AbilityShape shape) { var relativePositions = shape.GetPositionsRelativeToTarget(); foreach (var relativePosition in relativePositions) { yield return(position + relativePosition); } }
public static int CountUnitsInShape(this Level level, Vector2 targetPosition, AbilityShape shape, bool aliveOnly = true) { var allUnits = GetAllUnitsInShape(level, targetPosition, shape); return(aliveOnly ? allUnits.ThatAreAlive().Count() : allUnits.Count()); }
public static IEnumerable <GameUnit> GetAllUnitsInShape(this Level level, Vector2 targetPosition, AbilityShape shape) { var targetPositions = targetPosition.GetLocationsFromShape(shape); foreach (var position in targetPositions) { var possibleUnit = GetUnitAt(level, position); if (possibleUnit != null) { yield return(possibleUnit); } } }