private void SendUpdate(RealmTime time) { mapWidth = Owner.Map.Width; mapHeight = Owner.Map.Height; Wmap map = Owner.Map; var _x = (int) X; var _y = (int) Y; curRadius = RADIUS; if (Reveal) curRadius = 50; Reveal = false; curSight = (int)(Math.PI * curRadius * curRadius + 1); var sendEntities = new HashSet<Entity>(GetNewEntities()); var list = new List<UpdatePacket.TileData>(curSight); int sent = 0; foreach (IntPoint i in Sight.GetSightCircle(curRadius)) { int x = i.X + _x; int y = i.Y + _y; bool sightblockedx = false; bool sightblockedy = false; bool sightblockedxy = false; bool sightblockedyx = false; WmapTile tile; ObjectDesc desc; if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight || map[x, y].TileId == 0xff || tiles[x, y] >= (tile = map[x, y]).UpdateCount) continue; World world = Manager.GetWorld(Owner.Id); if (world.dungeon) { if (x < X) { for (int XX = _x; XX > x; XX--) { Manager.GameData.ObjectDescs.TryGetValue(map[XX, _y].ObjType, out desc); if (desc != null) { if (desc.BlocksSight) { sightblockedx = true; } } } } if (x > X) { for (int XX = _x; XX < x; XX++) { Manager.GameData.ObjectDescs.TryGetValue(map[XX, _y].ObjType, out desc); if (desc != null) { if (desc.BlocksSight) { sightblockedx = true; } } } } if (y < Y) { for (int YY = _y; YY > y; YY--) { Manager.GameData.ObjectDescs.TryGetValue(map[_x, YY].ObjType, out desc); if (desc != null) { if (desc.BlocksSight) { sightblockedy = true; } } } } if (y > Y) { for (int YY = _y; YY < y; YY++) { Manager.GameData.ObjectDescs.TryGetValue(map[_x, YY].ObjType, out desc); if (desc != null) { if (desc.BlocksSight) { sightblockedy = true; } } } } if (x < X) { for (int XX = _x; XX > x; XX--) { Manager.GameData.ObjectDescs.TryGetValue(map[XX, y].ObjType, out desc); if (desc != null) { if (desc.BlocksSight) { sightblockedyx = true; } } } } if (x > X) { for (int XX = _x; XX < x; XX++) { Manager.GameData.ObjectDescs.TryGetValue(map[XX, y].ObjType, out desc); if (desc != null) { if (desc.BlocksSight) { sightblockedyx = true; } } } } if (y < Y) { for (int YY = _y; YY > y; YY--) { Manager.GameData.ObjectDescs.TryGetValue(map[x, YY].ObjType, out desc); if (desc != null) { if (desc.BlocksSight) { sightblockedxy = true; } } } } if (y > Y) { for (int YY = _y; YY < y; YY++) { Manager.GameData.ObjectDescs.TryGetValue(map[x, YY].ObjType, out desc); if (desc != null) { if (desc.BlocksSight) { sightblockedxy = true; } } } } if ((sightblockedy && sightblockedxy) || (sightblockedx && sightblockedyx) || (sightblockedyx && sightblockedxy)) { desc = null; continue; } desc = null; } list.Add(new UpdatePacket.TileData { X = (short) x, Y = (short) y, Tile = (Tile) tile.TileId }); tiles[x, y] = tile.UpdateCount; sent++; } fames.TileSent(sent); int[] dropEntities = GetRemovedEntities().Distinct().ToArray(); clientEntities.RemoveWhere(_ => Array.IndexOf(dropEntities, _.Id) != -1); foreach (Entity i in sendEntities) lastUpdate[i] = i.UpdateCount; ObjectDef[] newStatics = GetNewStatics(_x, _y).ToArray(); IntPoint[] removeStatics = GetRemovedStatics(_x, _y).ToArray(); var removedIds = new List<int>(); foreach (IntPoint i in removeStatics) { removedIds.Add(Owner.Map[i.X, i.Y].ObjId); clientStatic.Remove(i); } if (sendEntities.Count > 0 || list.Count > 0 || dropEntities.Length > 0 || newStatics.Length > 0 || removedIds.Count > 0) { var packet = new UpdatePacket(); packet.Tiles = list.ToArray(); packet.NewObjects = sendEntities.Select(_ => _.ToDefinition()).Concat(newStatics).ToArray(); packet.RemovedObjectIds = dropEntities.Concat(removedIds).ToArray(); client.SendPacket(packet); } SendNewTick(time); }
public void SendUpdate(RealmTime time) { mapWidth = Owner.Map.Width; mapHeight = Owner.Map.Height; var map = Owner.Map; var xBase = (int)X; var yBase = (int)Y; var sendEntities = new HashSet<Entity>(GetNewEntities()); var list = new List<UpdatePacket.TileData>(APPOX_AREA_OF_SIGHT); var sent = 0; foreach (var i in Sight.GetSightCircle(SIGHTRADIUS)) { var x = i.X + xBase; var y = i.Y + yBase; WmapTile tile; if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight || tiles[x, y] >= (tile = map[x, y]).UpdateCount) continue; var world = Manager.GetWorld(Owner.Id); if (world.Dungeon) { //Todo add blocksight } list.Add(new UpdatePacket.TileData() { X = (short)x, Y = (short)y, Tile = tile.TileId }); tiles[x, y] = tile.UpdateCount; sent++; } FameCounter.TileSent(sent); var dropEntities = GetRemovedEntities().Distinct().ToArray(); clientEntities.RemoveWhere(_ => Array.IndexOf(dropEntities, _.Id) != -1); var toRemove = lastUpdate.Keys.Where(i => !clientEntities.Contains(i)).ToList(); toRemove.ForEach(i => lastUpdate.Remove(i)); foreach (var i in sendEntities) lastUpdate[i] = i.UpdateCount; var newStatics = GetNewStatics(xBase, yBase).ToArray(); var removeStatics = GetRemovedStatics(xBase, yBase).ToArray(); var removedIds = new List<int>(); foreach (var i in removeStatics) { removedIds.Add(Owner.Map[i.X, i.Y].ObjId); clientStatic.Remove(i); } if (sendEntities.Count <= 0 && list.Count <= 0 && dropEntities.Length <= 0 && newStatics.Length <= 0 && removedIds.Count <= 0) return; var packet = new UpdatePacket() { Tiles = list.ToArray(), NewObjects = sendEntities.Select(_ => _.ToDefinition()).Concat(newStatics).ToArray(), RemovedObjectIds = dropEntities.Concat(removedIds).ToArray() }; Client.SendPacket(packet); UpdatesSend++; }
private void SendUpdate(RealmTime time) { mapWidth = Owner.Map.Width; mapHeight = Owner.Map.Height; var map = Owner.Map; int _x = (int)X; int _y = (int)Y; var sendEntities = new HashSet<Entity>(GetNewEntities()); var list = new List<UpdatePacket.TileData>(APPOX_AREA_OF_SIGHT); int sent = 0; foreach (var i in Sight.GetSightCircle(SIGHT_RADIUS)) { int x = i.X + _x; int y = i.Y + _y; WmapTile tile; if (x < 0 || x >= mapWidth || y < 0 || y >= mapHeight || map[x, y].TileId == 0xff || tiles[x, y] >= (tile = map[x, y]).UpdateCount) continue; list.Add(new UpdatePacket.TileData() { X = (short)x, Y = (short)y, Tile = (Tile)tile.TileId }); tiles[x, y] = tile.UpdateCount; sent++; } fames.TileSent(sent); var dropEntities = GetRemovedEntities().Distinct().ToArray(); clientEntities.RemoveWhere(_ => Array.IndexOf(dropEntities, _.Id) != -1); foreach (var i in sendEntities) lastUpdate[i] = i.UpdateCount; var newStatics = GetNewStatics(_x, _y).ToArray(); var removeStatics = GetRemovedStatics(_x, _y).ToArray(); List<int> removedIds = new List<int>(); foreach (var i in removeStatics) { removedIds.Add(Owner.Map[i.X, i.Y].ObjId); clientStatic.Remove(i); } if (sendEntities.Count > 0 || list.Count > 0 || dropEntities.Length > 0 || newStatics.Length > 0 || removedIds.Count > 0) { UpdatePacket packet = new UpdatePacket(); packet.Tiles = list.ToArray(); packet.NewObjects = sendEntities.Select(_ => _.ToDefinition()).Concat(newStatics).ToArray(); packet.RemovedObjectIds = dropEntities.Concat(removedIds).ToArray(); client.SendPacket(packet); } SendNewTick(time); }