/// <summary> /// Raises the OnTileChanged event. /// </summary> /// <param name="tileRef">A reference to the new tile.</param> /// <param name="oldTile">The old tile that got replaced.</param> public void RaiseOnTileChanged(TileRef tileRef, Tile oldTile) { if (SuppressOnTileChanged) { return; } TileChanged?.Invoke(this, new TileChangedEventArgs(tileRef, oldTile)); if (_netManager.IsClient) { return; } var message = _netManager.CreateNetMessage <MsgMap>(); message.MessageType = MapMessage.TurfUpdate; message.SingleTurf = new MsgMap.Turf { X = tileRef.X, Y = tileRef.Y, Tile = (uint)tileRef.Tile }; message.GridIndex = tileRef.LocalPos.GridID; _netManager.ServerSendToAll(message); }
/// <summary> /// Raises the OnTileChanged event. /// </summary> /// <param name="gridId">The ID of the grid that was modified.</param> /// <param name="tileRef">A reference to the new tile.</param> /// <param name="oldTile">The old tile that got replaced.</param> public void RaiseOnTileChanged(int gridId, TileRef tileRef, Tile oldTile) { if (SuppressOnTileChanged) { return; } OnTileChanged?.Invoke(gridId, tileRef, oldTile); }
/// <inheritdoc /> public bool IndicesToTile(MapGrid.Indices indices, out TileRef tile) { MapGrid.Indices chunkindices = new MapGrid.Indices(indices.X / ChunkSize, indices.Y / ChunkSize); if (!_chunks.ContainsKey(chunkindices)) { tile = new TileRef(); //Nothing should ever use or access this, bool check should occur first return(false); } Chunk chunk = _chunks[chunkindices]; tile = chunk.GetTile(new MapGrid.Indices(indices.X % ChunkSize, indices.Y % ChunkSize)); return(true); }
/// <summary> /// Event handler for when a tile is modified in the MapManager. /// </summary> /// <param name="gridId">The id of the grid being modified.</param> /// <param name="tileRef">A reference to the new tile.</param> /// <param name="oldTile">The old tile being modified.</param> private void MapMgrOnTileChanged(int gridId, TileRef tileRef, Tile oldTile) { Debug.Assert(_netManager.IsServer, "Why is the client calling this?"); var message = _netManager.CreateNetMessage <MsgMap>(); message.MessageType = MapMessage.TurfUpdate; message.SingleTurf = new MsgMap.Turf { X = tileRef.X, Y = tileRef.Y, Tile = (uint)tileRef.Tile }; _netManager.ServerSendToAll(message); }
/// <inheritdoc /> public void SetTile(ushort xChunkTile, ushort yChunkTile, Tile tile) { if (xChunkTile >= ChunkSize || yChunkTile >= ChunkSize) { throw new ArgumentException("Tile indices out of bounds."); } var gridTile = ChunkTileToGridTile(new MapGrid.Indices(xChunkTile, yChunkTile)); var newTileRef = new TileRef(_grid.MapID, _grid.Index, gridTile.X, gridTile.Y, tile); var oldTile = _tiles[xChunkTile, yChunkTile]; _mapManager.RaiseOnTileChanged(_grid.Index, newTileRef, oldTile); _grid.UpdateAABB(gridTile); _tiles[xChunkTile, yChunkTile] = tile; }
/// <inheritdoc /> public IEnumerable <TileRef> GetTilesIntersecting(Box2 worldArea, bool ignoreEmpty = true, Predicate <TileRef> predicate = null) { //TODO: needs world -> local -> tile translations. var gridTileLt = new Indices((int)Math.Floor(worldArea.Left), (int)Math.Floor(worldArea.Top)); var gridTileRb = new Indices((int)Math.Floor(worldArea.Right), (int)Math.Floor(worldArea.Bottom)); var tiles = new List <TileRef>(); for (var x = gridTileLt.X; x <= gridTileRb.X; x++) { for (var y = gridTileLt.Y; y <= gridTileRb.Y; y++) { var gridChunk = GridTileToGridChunk(new Indices(x, y)); Chunk chunk; if (_chunks.TryGetValue(gridChunk, out chunk)) { var chunkTile = chunk.GridTileToChunkTile(new Indices(x, y)); var tile = chunk.GetTile((ushort)chunkTile.X, (ushort)chunkTile.Y); if (ignoreEmpty && tile.Tile.IsEmpty) { continue; } if (predicate == null || predicate(tile)) { tiles.Add(tile); } } else if (!ignoreEmpty) { var tile = new TileRef(MapID, Index, x, y, new Tile()); if (predicate == null || predicate(tile)) { tiles.Add(tile); } } } } return(tiles); }
/// <inheritdoc /> public void SetTile(ushort xChunkTile, ushort yChunkTile, Tile tile) { if (xChunkTile >= ChunkSize || yChunkTile >= ChunkSize) { throw new ArgumentException("Tile indices out of bounds."); } // same tile, no point to continue if (_tiles[xChunkTile, yChunkTile].TileId == tile.TileId) { return; } var gridTile = ChunkTileToGridTile(new MapIndices(xChunkTile, yChunkTile)); var newTileRef = new TileRef(_grid.MapID, _grid.Index, gridTile.X, gridTile.Y, tile); var oldTile = _tiles[xChunkTile, yChunkTile]; _grid.LastModifiedTick = LastModifiedTick = _mapManager._gameTiming.CurTick; _mapManager.RaiseOnTileChanged(newTileRef, oldTile); _grid.UpdateAABB(gridTile); _tiles[xChunkTile, yChunkTile] = tile; }
/// <summary> /// Creates a new instance of this class. /// </summary> public TileChangedEventArgs(TileRef newTile, Tile oldTile) { NewTile = newTile; OldTile = oldTile; }