/// <summary> /// Broadcasts the given <paramref name="tiles"/> at the specified coordinates to all active players. /// </summary> /// <param name="players">The player service.</param> /// <param name="x">The top-left tile's X coordinate.</param> /// <param name="y">The top-left tile's Y coordinate.</param> /// <param name="tiles">The tiles to broadcast.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="players"/> or <paramref name="tiles"/> are <see langword="null"/>. /// </exception> /// <exception cref="NotSupportedException"><paramref name="tiles"/> is not square.</exception> public static void BroadcastTiles(this IPlayerService players, int x, int y, ITileSlice tiles) { if (players is null) { throw new ArgumentNullException(nameof(players)); } if (tiles is null) { throw new ArgumentNullException(nameof(tiles)); } if (tiles.Width != tiles.Height) { // TODO: implement this when the section packet is implemented. throw new NotSupportedException("Tiles is not square"); } var packet = new TileSquare { X = (short)x, Y = (short)y, Tiles = tiles }; for (var i = 0; i < players.Count; ++i) { players[i].SendPacket(packet); } }
/// <summary> /// Returns a slice of the tiles starting at the given coordinates with the specified dimensions. /// </summary> /// <param name="tiles">The tiles.</param> /// <param name="startX">The slice's starting X coordinate.</param> /// <param name="startY">The slice's starting Y coordinate.</param> /// <param name="width">The slice's width.</param> /// <param name="height">The slice's height.</param> /// <returns>The slice of the tiles starting at the given coordinates with the specified dimensions.</returns> /// <exception cref="ArgumentNullException"><paramref name="tiles"/> is <see langword="null"/>.</exception> /// <exception cref="ArgumentOutOfRangeException"> /// <paramref name="startX"/>, <paramref name="startY"/>, <paramref name="width"/>, or <paramref name="height"/> /// are out of range. /// </exception> public static ITileSlice Slice(this ITileSlice tiles, int startX, int startY, int width, int height) { if (tiles is null) { throw new ArgumentNullException(nameof(tiles)); } if (startX < 0 || startX >= tiles.Width) { throw new ArgumentOutOfRangeException( nameof(startX), $"Start X out of range (expected: 0 to {tiles.Width - 1})"); } if (startY < 0 || startY >= tiles.Height) { throw new ArgumentOutOfRangeException( nameof(startY), $"Start Y out of range (expected: 0 to {tiles.Height - 1})"); } if (width <= 0 || startX + width > tiles.Width) { throw new ArgumentOutOfRangeException( nameof(width), $"Width out of range (expected: 1 to {tiles.Width - startX})"); } if (height <= 0 || startY + height > tiles.Height) { throw new ArgumentOutOfRangeException( nameof(height), $"Height out of range (expected: 1 to {tiles.Height - startY})"); } return(new NestedTileSlice(tiles, startX, startY, width, height)); }
public NestedTileSlice(ITileSlice tiles, int startX, int startY, int width, int height) { Debug.Assert(tiles != null); Debug.Assert(0 <= startX && startX + width <= tiles.Width); Debug.Assert(0 <= startY && startY + height <= tiles.Height); Debug.Assert(width > 0); Debug.Assert(height > 0); _tiles = tiles; _startX = startX; _startY = startY; Width = width; Height = height; }
/// <summary> /// Initializes a new instance of the <see cref="TileSquareEvent"/> class with the specified /// <paramref name="world"/>, <paramref name="player"/>, top-left tile coordinates, and /// <paramref name="tiles"/>. /// </summary> /// <param name="world">The world involved in the event.</param> /// <param name="player">The player sending the square of tiles.</param> /// <param name="x">The top-left tile's X coordinate.</param> /// <param name="y">The top-left tile's Y coordinate.</param> /// <param name="tiles">The tiles.</param> /// <exception cref="ArgumentException"><paramref name="tiles"/> is not a square.</exception> /// <exception cref="ArgumentNullException"> /// <paramref name="world"/>, <paramref name="player"/>, or <paramref name="tiles"/> are <see langword="null"/>. /// </exception> public TileSquareEvent(IWorld world, IPlayer player, int x, int y, ITileSlice tiles) : base(world) { if (tiles is null) { throw new ArgumentNullException(nameof(tiles)); } if (tiles.Width != tiles.Height) { throw new ArgumentException("Tiles is not a square", nameof(tiles)); } Player = player ?? throw new ArgumentNullException(nameof(player)); X = x; Y = y; Tiles = tiles; }
/// <summary> /// Sends the given <paramref name="tiles"/> at the specified coordinates to the player. /// </summary> /// <param name="player">The player.</param> /// <param name="x">The top-left tile's X coordinate.</param> /// <param name="y">The top-left tile's Y coordinate.</param> /// <param name="tiles">The tiles to send.</param> /// <exception cref="ArgumentNullException"> /// <paramref name="player"/> or <paramref name="tiles"/> are <see langword="null"/>. /// </exception> /// <exception cref="NotSupportedException"><paramref name="tiles"/> is not square.</exception> public static void SendTiles(this IPlayer player, int x, int y, ITileSlice tiles) { if (player is null) { throw new ArgumentNullException(nameof(player)); } if (tiles is null) { throw new ArgumentNullException(nameof(tiles)); } if (tiles.Width != tiles.Height) { // TODO: implement this when the section packet is implemented. throw new NotSupportedException("Tiles is not square"); } var packet = new TileSquare { X = (short)x, Y = (short)y, Tiles = tiles }; player.SendPacket(packet); }