Exemplo n.º 1
0
        private IEnumerable <ObjectDef> GetNewStatics(int xBase, int yBase)
        {
            var ret = new List <ObjectDef>();

            foreach (var i in Sight.Cast(this, WorldInstance.Difficulty, SIGHTRADIUS))
            {
                var x = i.X + xBase;
                var y = i.Y + yBase;
                if (x < 0 || x >= mapWidth ||
                    y < 0 || y >= mapHeight)
                {
                    continue;
                }

                var tile = Owner.Map[x, y];

                if (tile.ObjId == 0 || tile.ObjType == 0 || !clientStatic.Add(new IntPoint(x, y)))
                {
                    continue;
                }
                var def = tile.ToDef(x, y);
                var cls = Manager.GameData.ObjectDescs[tile.ObjType].Class;
                if (cls == "ConnectedWall" || cls == "CaveWall")
                {
                    if (def.Stats.Stats.Count(_ => _.Key == StatsType.ObjectConnection && _.Value != null) == 0)
                    {
                        var stats = def.Stats.Stats.ToList();
                        stats.Add(new KeyValuePair <StatsType, object>(StatsType.ObjectConnection, (int)ConnectionComputer.Compute((xx, yy) => Owner.Map[x + xx, y + yy].ObjType == tile.ObjType).Bits));
                        def.Stats.Stats = stats.ToArray();
                    }
                }
                ret.Add(def);
            }
            return(ret);
        }
Exemplo n.º 2
0
 private IEnumerable <ObjectDef> GetNewStatics(int _x, int _y)
 {
     return((from i in Sight.GetSightCircle(SightRadius)
             let x = i.X + _x
                     let y = i.Y + _y
                             where x >= 0 && x < _mapWidth && y >= 0 && y < _mapHeight
                             let tile = Owner.Map[x, y]
                                        where tile.ObjId != 0 && tile.ObjType != 0 && _clientStatic.Add(new IntPoint(x, y))
                                        select tile.ToDef(x, y)).ToList());
 }
Exemplo n.º 3
0
        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.Cast(this, WorldInstance.Difficulty, 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++;
        }
Exemplo n.º 4
0
        void SendUpdate(RealmTime time)
        {
            int _x = (int)X;
            int _y = (int)Y;

            if (Owner == null)
            {
                return;
            }
            SightTiles = (Owner.IsBlocked() ? Sight.RayCast(this, RADIUS) : Sight.GetSightCircle(this, RADIUS).ToList());

            mapWidth  = Owner.Map.Width;
            mapHeight = Owner.Map.Height;

            var sendEntities = new HashSet <Entity>(GetNewEntities());

            var list = new List <UpdatePacket.TileData>(APPOX_AREA_OF_SIGHT);
            int sent = 0;

            foreach (var i in SightTiles)
            {
                int x = i.X;
                int y = i.Y;

                WmapTile tile = Owner.Map[x, y];
                if (x < 0 || x >= mapWidth ||
                    y < 0 || y >= mapHeight ||
                    _tiles[x, y] >= (tile = Owner.Map[x, y]).UpdateCount)
                {
                    continue;
                }

                list.Add(new UpdatePacket.TileData()
                {
                    X    = (short)x,
                    Y    = (short)y,
                    Tile = tile.TileId
                });
                _tiles[x, y] = tile.UpdateCount;
                sent++;
            }
            foreach (var i in newSightTiles)
            {
                SightTiles.Add(i);
            }
            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();
            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)
            {
                Client.SendPacket(new UpdatePacket()
                {
                    Tiles            = list.ToArray(),
                    NewObjects       = sendEntities.Select(_ => _.ToDefinition()).Concat(newStatics).ToArray(),
                    RemovedObjectIds = dropEntities.Concat(removedIds).ToArray()
                });
            }
            SendNewTick(time);
        }
Exemplo n.º 5
0
        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);
        }
        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;
                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();
            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);
        }
Exemplo n.º 7
0
        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;

            var sendEntities = new HashSet <Entity>(GetNewEntities());

            var list = new List <UpdatePacket.TileData>(AppoxAreaOfSight);
            int sent = 0;

            foreach (IntPoint i in Sight.GetSightCircle(SightRadius))
            {
                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 ||
                    tiles[x, y] >= (tile = map[x, y]).UpdateCount)
                {
                    continue;
                }

                World world = Owner;
                if (world.IsDungeon())
                {
                    if (x < X)
                    {
                        for (int XX = _x; XX > x; XX--)
                        {
                            common.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++)
                        {
                            common.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--)
                        {
                            common.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++)
                        {
                            common.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--)
                        {
                            common.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++)
                        {
                            common.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--)
                        {
                            common.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++)
                        {
                            common.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);

            int[] dropEntities = GetRemovedEntities().Distinct().ToArray();
            _clientEntities.RemoveWhere(_ => Array.IndexOf(dropEntities, _.Id) != -1);

            //purge unused entities
            List <Entity> toRemove = new List <Entity>();

            foreach (Entity i in _lastUpdate.Keys.Where(i => !_clientEntities.Contains(i)))
            {
                toRemove.Add(i);
            }
            toRemove.ForEach(i => _lastUpdate.Remove(i));

            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
                {
                    Tiles            = list.ToArray(),
                    NewObjects       = sendEntities.Select(_ => _.ToDefinition()).Concat(newStatics).ToArray(),
                    RemovedObjectIds = dropEntities.Concat(removedIds).ToArray()
                };
                psr.SendPacket(packet);
            }
        }