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(); psr.SendPacket(packet); } SendNewTick(time); }
private void SendUpdate(RealmTime time) { _mapWidth = Owner.Map.Width; _mapHeight = Owner.Map.Height; var map = Owner.Map; var _x = (int)X; var _y = (int)Y; var sendEntities = new HashSet<Entity>(GetNewEntities()); var list = new List<UpdatePacket.TileData>(AppoxAreaOfSight); var sent = 0; foreach (var i in Sight.GetSightCircle(SightRadius)) { var x = i.X + _x; var y = i.Y + _y; var sightblockedx = false; var sightblockedy = false; var sightblockedxy = false; var 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; //if (x < X) //{ // for (int XX = _x; XX > x; XX--) // { // db.data.XmlData.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++) // { // db.data.XmlData.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--) // { // db.data.XmlData.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++) // { // db.data.XmlData.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--) // { // db.data.XmlData.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++) // { // db.data.XmlData.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--) { // db.data.XmlData.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++) { db.data.XmlData.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++; } FameCounter.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(); 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) { var packet = new UpdatePacket { Tiles = list.ToArray(), NewObjects = sendEntities.Select(_ => _.ToDefinition()).Concat(newStatics).ToArray(), RemovedObjectIds = dropEntities.Concat(removedIds).ToArray() }; Client.SendPacket(packet); } SendNewTick(time); }