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;
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;
//if (x < X)
//{
// for (int XX = _x; XX > x; XX--)
// {
// db.data.XmlDatas.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.XmlDatas.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.XmlDatas.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.XmlDatas.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.XmlDatas.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.XmlDatas.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.XmlDatas.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.XmlDatas.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);
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()
};
psr.SendPacket(packet);
}
SendNewTick(time);
}