Пример #1
0
        private void FromWorldMap(Stream dat)
        {
            var map = new Wmap(Manager.GameData);

            Map        = map;
            entityInc  = 0;
            entityInc += Map.Load(dat, 0);

            int w = Map.Width, h = Map.Height;

            Obstacles = new byte[w, h];
            for (var y = 0; y < h; y++)
            {
                for (var x = 0; x < w; x++)
                {
                    try
                    {
                        var        tile = Map[x, y];
                        ObjectDesc desc;
                        if (Manager.GameData.Tiles[tile.TileId].NoWalk)
                        {
                            Obstacles[x, y] = 3;
                        }
                        if (Manager.GameData.ObjectDescs.TryGetValue(tile.ObjType, out desc))
                        {
                            if (desc.Class == "Wall" ||
                                desc.Class == "ConnectedWall" ||
                                desc.Class == "CaveWall")
                            {
                                Obstacles[x, y] = 2;
                            }
                            else if (desc.OccupySquare || desc.EnemyOccupySquare)
                            {
                                Obstacles[x, y] = 1;
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        Log.Error(ex);
                    }
                }
            }
            EnemiesCollision = new CollisionMap <Entity>(0, w, h);
            PlayersCollision = new CollisionMap <Entity>(1, w, h);

            Projectiles.Clear();
            StaticObjects.Clear();
            Enemies.Clear();
            Players.Clear();
            foreach (var i in Map.InstantiateEntities(Manager))
            {
                if (i.ObjectDesc != null &&
                    (i.ObjectDesc.OccupySquare || i.ObjectDesc.EnemyOccupySquare))
                {
                    Obstacles[(int)(i.X - 0.5), (int)(i.Y - 0.5)] = 2;
                }
                EnterWorld(i);
            }
        }
Пример #2
0
        protected void FromWorldMap(Stream dat)
        {
            log.InfoFormat("Loading map for world {0}({1})...", Id, Name);

            Map        = new Wmap(Manager.GameData);
            entityInc  = 0;
            entityInc += Map.Load(dat, 0);

            int w = Map.Width, h = Map.Height;

            EnemiesCollision = new CollisionMap <Entity>(0, w, h);
            PlayersCollision = new CollisionMap <Entity>(1, w, h);
            PetsCollision    = new CollisionMap <Entity>(1, w, h);

            Projectiles.Clear();
            StaticObjects.Clear();
            Enemies.Clear();
            Players.Clear();
            Pets.Clear();
            foreach (Entity i in Map.InstantiateEntities(Manager))
            {
                EnterWorld(i);
            }
            CheckDisposable();
        }
Пример #3
0
        private void CalcBlockedLineOfSight(Wmap map)
        {
            _sCircle.Clear();
            foreach (var ray in _sightRays)
            {
                for (var i = 0; i < ray.Value.Length; i++)
                {
                    _ip.X = LastX + ray.Value[i].X;
                    _ip.Y = LastY + ray.Value[i].Y;

                    if (!map.Contains(_ip))
                    {
                        continue;
                    }

                    _sCircle.Add(_ip);

                    var t = map[_ip.X, _ip.Y];
                    if (t.ObjType != 0 && t.ObjDesc != null && t.ObjDesc.BlocksSight)
                    {
                        break;
                    }
                    foreach (var sPoint in SurroundingPoints)
                    {
                        IntPoint _intPoint = new IntPoint(sPoint.X + _ip.X, sPoint.Y + _ip.Y);
                        if (map.Contains(_intPoint))
                        {
                            _sCircle.Add(_intPoint);
                        }
                    }
                }
            }
        }
Пример #4
0
        protected void FromWorldMap(Stream dat)
        {
            log.InfoFormat("Loading map for world {0}({1})...", Id, Name);

            var map = new Wmap();

            Map        = map;
            entityInc  = 0;
            entityInc += Map.Load(dat, 0);

            int w = Map.Width, h = Map.Height;

            Obstacles = new byte[w, h];
            for (var y = 0; y < h; y++)
            {
                for (var x = 0; x < w; x++)
                {
                    var        tile = Map[x, y];
                    ObjectDesc desc;
                    if (XmlDatas.TileDescs[tile.TileId].NoWalk)
                    {
                        Obstacles[x, y] = 3;
                    }
                    if (XmlDatas.ObjectDescs.TryGetValue(tile.ObjType, out desc))
                    {
                        if (desc.Class == "Wall" ||
                            desc.Class == "ConnectedWall" ||
                            desc.Class == "CaveWall")
                        {
                            Obstacles[x, y] = 2;
                        }
                        else if (desc.OccupySquare || desc.EnemyOccupySquare)
                        {
                            Obstacles[x, y] = 3;
                        }
                    }
                }
            }
            EnemiesCollision = new CollisionMap <Entity>(0, w, h);
            PlayersCollision = new CollisionMap <Entity>(1, w, h);

            Projectiles.Clear();
            StaticObjects.Clear();
            Enemies.Clear();
            Players.Clear();
            foreach (var i in Map.InstantiateEntities(Manager))
            {
                if (i.ObjectDesc != null &&
                    (i.ObjectDesc.OccupySquare || i.ObjectDesc.EnemyOccupySquare))
                {
                    Obstacles[(int)(i.X - 0.5), (int)(i.Y - 0.5)] = 2;
                }
                EnterWorld(i);
            }
        }
Пример #5
0
        protected void FromWorldMap(System.IO.Stream dat)
        {
            Wmap map = new Wmap();

            this.Map   = map;
            entityInc  = 0;
            entityInc += map.Load(dat, 0);

            int w = map.Width, h = map.Height;

            Obstacles = new byte[w, h];
            for (int y = 0; y < h; y++)
            {
                for (int x = 0; x < w; x++)
                {
                    var        tile = map[x, y];
                    ObjectDesc desc;
                    if (XmlDatas.TileDescs[tile.TileId].NoWalk)
                    {
                        Obstacles[x, y] = 3;
                    }
                    if (XmlDatas.ObjectDescs.TryGetValue(tile.ObjType, out desc))
                    {
                        if (desc.Class == "Wall" ||
                            desc.Class == "ConnectedWall" ||
                            desc.Class == "CaveWall")
                        {
                            Obstacles[x, y] = 2;
                        }
                        else if (desc.OccupySquare || desc.EnemyOccupySquare)
                        {
                            Obstacles[x, y] = 1;
                        }
                    }
                }
            }
            EnemiesCollision = new CollisionMap <Entity>(0, w, h);
            PlayersCollision = new CollisionMap <Entity>(1, w, h);

            Projectiles.Clear();
            StaticObjects.Clear();
            Enemies.Clear();
            Players.Clear();
            foreach (var i in map.InstantiateEntities())
            {
                if (i.ObjectDesc != null &&
                    (i.ObjectDesc.OccupySquare || i.ObjectDesc.EnemyOccupySquare))
                {
                    Obstacles[(int)(i.X - 0.5), (int)(i.Y - 0.5)] = 2;
                }
                EnterWorld(i);
            }
        }
Пример #6
0
 public bool Delete()
 {
     lock (this)
     {
         if (Players.Count > 0) return false;
         Id = 0;
     }
     Map = null;
     Players = null;
     Enemies = null;
     Projectiles = null;
     StaticObjects = null;
     return true;
 }
Пример #7
0
        private void CalcBlockedRoomSight(Wmap map)
        {
            var height = map.Height;
            var width  = map.Width;

            _sCircle.Clear();
            _visibleTilesList.Clear();

            _sTile = new IntPoint(LastX, LastY);
            _visibleTilesList.Add(_sTile);

            for (var i = 0; i < _visibleTilesList.Count; i++)
            {
                var tile = _visibleTilesList[i];

                if (tile.Generation > Radius)
                {
                    continue;
                }

                foreach (var sPoint in SurroundingPoints)
                {
                    var x = (_sTile.X = tile.X + sPoint.X);
                    var y = (_sTile.Y = tile.Y + sPoint.Y);

                    var dx = LastX - x;
                    var dy = LastY - y;

                    if (_sCircle.Contains(_sTile) ||
                        x < 0 || x >= width ||
                        y < 0 || y >= height ||
                        dx * dx + dy * dy > RadiusSqr)
                    {
                        continue;
                    }

                    _sTile.Generation = tile.Generation + 1;
                    _sCircle.Add(_sTile);

                    var t = map[x, y];
                    if (IsBlocking(t))
                    {
                        continue;
                    }

                    _visibleTilesList.Add(_sTile);
                }
            }
        }
Пример #8
0
        protected World()
        {
            Players = new ConcurrentDictionary<int, Player>();
            Enemies = new ConcurrentDictionary<int, Enemy>();
            Quests = new ConcurrentDictionary<int, Enemy>();
            Projectiles = new ConcurrentDictionary<Tuple<int, byte>, Projectile>();
            StaticObjects = new ConcurrentDictionary<int, StaticObject>();
            Timers = new List<WorldTimer>();
            ClientXML = ExtraXML = Empty<string>.Array;
            Map = new Wmap();
            AllowTeleport = true;
            ShowDisplays = true;

            ExtraXML = new string[] { XmlDatas.ItemXml, XmlDatas.AdditionXml, XmlDatas.RemoteXml };
        }
Пример #9
0
        protected World()
        {
            Players       = new ConcurrentDictionary <int, Player>();
            Enemies       = new ConcurrentDictionary <int, Enemy>();
            Quests        = new ConcurrentDictionary <int, Enemy>();
            Projectiles   = new ConcurrentDictionary <Tuple <int, byte>, Projectile>();
            StaticObjects = new ConcurrentDictionary <int, StaticObject>();
            Timers        = new List <WorldTimer>();
            ClientXML     = ExtraXML = Empty <string> .Array;
            Map           = new Wmap();
            AllowTeleport = true;
            ShowDisplays  = true;

            ExtraXML = new string[] { XmlDatas.AdditionXml };
        }
Пример #10
0
        protected World()
        {
            Players = new ConcurrentDictionary<int, Player>();
            Enemies = new ConcurrentDictionary<int, Enemy>();
            Quests = new ConcurrentDictionary<int, Enemy>();
            Pets = new ConcurrentDictionary<int, Entity>();
            Projectiles = new ConcurrentDictionary<Tuple<int, byte>, Projectile>();
            StaticObjects = new ConcurrentDictionary<int, StaticObject>();
            Timers = new List<WorldTimer>();
            ClientXML = ExtraXML = Empty<string>.Array;
            Map = new Wmap();
            AllowTeleport = true;
            ShowDisplays = true;

            ExtraXML = XmlDatas.ServerXmls.ToArray();
        }
Пример #11
0
        private void CalcUnblockedSight(Wmap map)
        {
            _sCircle.Clear();
            foreach (var p in _unblockedView)
            {
                _ip.X = LastX + p.X;
                _ip.Y = LastY + p.Y;

                if (!map.Contains(_ip))
                {
                    continue;
                }

                _sCircle.Add(_ip);
            }
        }
Пример #12
0
 public bool Delete()
 {
     lock (this)
     {
         if (Players.Count > 0)
         {
             return(false);
         }
         Id = 0;
     }
     Map           = null;
     Players       = null;
     Enemies       = null;
     Projectiles   = null;
     StaticObjects = null;
     return(true);
 }
Пример #13
0
        protected World()
        {
            Players       = new ConcurrentDictionary <int, Player>();
            Enemies       = new ConcurrentDictionary <int, Enemy>();
            Quests        = new ConcurrentDictionary <int, Enemy>();
            Pets          = new ConcurrentDictionary <int, Entity>();
            Projectiles   = new ConcurrentDictionary <Tuple <int, byte>, Projectile>();
            StaticObjects = new ConcurrentDictionary <int, StaticObject>();
            Timers        = new List <WorldTimer>();
            ClientXML     = ExtraXML = Empty <string> .Array;
            Map           = new Wmap();
            AllowTeleport = true;
            ShowDisplays  = true;
            Mining        = false;

            ExtraXML = XmlDatas.ServerXmls.ToArray();
        }
Пример #14
0
        public static void CalcRegionBlocks(Wmap map)
        {
            var i = 0;

            for (var x = 0; x < map.Width; x++)
            {
                for (var y = 0; y < map.Height; y++)
                {
                    var t = map[x, y];
                    if (t.SightRegion != 1 || IsBlocking(t))
                    {
                        continue;
                    }

                    CalcRegion(map, i++, x, y);
                }
            }
        }
Пример #15
0
        protected void FromWorldMap(System.IO.Stream dat)
        {
            Wmap map = new Wmap();
            this.Map = map;
            entityInc = 0;
            entityInc += map.Load(dat, 0);

            int w = map.Width, h = map.Height;
            Obstacles = new byte[w, h];
            for (int y = 0; y < h; y++)
                for (int x = 0; x < w; x++)
                {
                    var tile = map[x, y];
                    ObjectDesc desc;
                    if (XmlDatas.TileDescs[tile.TileId].NoWalk)
                        Obstacles[x, y] = 3;
                    if (XmlDatas.ObjectDescs.TryGetValue(tile.ObjType, out desc))
                    {
                        if (desc.Class == "Wall" ||
                            desc.Class == "ConnectedWall" ||
                            desc.Class == "CaveWall")
                            Obstacles[x, y] = 2;
                        else if (desc.OccupySquare || desc.EnemyOccupySquare)
                            Obstacles[x, y] = 1;
                    }

                }
            EnemiesCollision = new CollisionMap<Entity>(0, w, h);
            PlayersCollision = new CollisionMap<Entity>(1, w, h);

            Projectiles.Clear();
            StaticObjects.Clear();
            Enemies.Clear();
            Players.Clear();
            foreach (var i in map.InstantiateEntities())
            {
                if (i.ObjectDesc != null &&
                    (i.ObjectDesc.OccupySquare || i.ObjectDesc.EnemyOccupySquare))
                    Obstacles[(int)(i.X - 0.5), (int)(i.Y - 0.5)] = 2;
                EnterWorld(i);
            }
        }
Пример #16
0
        private static void CalcRegion(Wmap map, int pIndex, int sx, int sy)
        {
            VisibleTilesList.Clear();
            VisibleTilesSet.Clear();

            var p     = new IntPoint(sx, sy);
            var prime = Primes[pIndex];

            map[p.X, p.Y].SightRegion = prime;

            VisibleTilesList.Add(p);

            for (var i = 0; i < VisibleTilesList.Count; i++)
            {
                var op = VisibleTilesList[i];
                foreach (var sp in SurroundingPoints)
                {
                    p.X = op.X + sp.X;
                    p.Y = op.Y + sp.Y;

                    if (!map.Contains(p) || VisibleTilesSet.Contains(p))
                    {
                        continue;
                    }

                    VisibleTilesSet.Add(p);

                    var t = map[p.X, p.Y];

                    if (IsBlocking(t))
                    {
                        checked { t.SightRegion *= prime; }
                        continue;
                    }

                    t.SightRegion = prime;
                    VisibleTilesList.Add(p);
                }
            }
        }
Пример #17
0
        private void CalcRegionBlockSight(Wmap map)
        {
            var sRegion = map[LastX, LastY].SightRegion;

            _sCircle.Clear();
            foreach (var p in _unblockedView)
            {
                _ip.X = LastX + p.X;
                _ip.Y = LastY + p.Y;

                if (!map.Contains(_ip))
                {
                    continue;
                }

                var t = map[_ip.X, _ip.Y];
                if (t.SightRegion % sRegion == 0)
                {
                    _sCircle.Add(_ip);
                }
            }
        }
Пример #18
0
        protected void FromWorldMap(Stream dat)
        {
            log.InfoFormat("Loading map for world {0}({1})...", Id, Name);

            var map = new Wmap();
            Map = map;
            entityInc = 0;
            entityInc += Map.Load(dat, 0);

            int w = Map.Width, h = Map.Height;
            Obstacles = new byte[w, h];
            for (var y = 0; y < h; y++)
                for (var x = 0; x < w; x++)
                {
                    var tile = Map[x, y];
                    ObjectDesc desc;
                    if (XmlData.Tiles[tile.TileId].NoWalk)
                        Obstacles[x, y] = 3;
                    if (XmlData.ObjectDescs.TryGetValue(tile.ObjType, out desc))
                    {
                        if (desc.Class == "Wall" ||
                            desc.Class == "ConnectedWall" ||
                            desc.Class == "CaveWall")
                            Obstacles[x, y] = 2;
                        else if (desc.OccupySquare || desc.EnemyOccupySquare)
                            Obstacles[x, y] = 1;
                    }
                }
            EnemiesCollision = new CollisionMap<Entity>(0, w, h);
            PlayersCollision = new CollisionMap<Entity>(1, w, h);

            Projectiles.Clear();
            StaticObjects.Clear();
            Enemies.Clear();
            Players.Clear();
            foreach (var i in Map.InstantiateEntities(Manager))
            {
                if (i.ObjectDesc != null &&
                    (i.ObjectDesc.OccupySquare || i.ObjectDesc.EnemyOccupySquare))
                    Obstacles[(int)(i.X - 0.5), (int)(i.Y - 0.5)] = 2;
                EnterWorld(i);
            }
        }
Пример #19
0
        public static void UpdateRegion(Wmap map, int ox, int oy)
        {
            var op             = new IntPoint(ox, oy);
            var p              = new IntPoint();
            var connectRegions = new List <long>(4);

            // get non blocked sight regions
            foreach (var sp in SurroundingPoints)
            {
                p.X = op.X + sp.X;
                p.Y = op.Y + sp.Y;

                var t = map[p.X, p.Y];
                if (!IsBlocking(t))
                {
                    connectRegions.Add(t.SightRegion);
                }
            }

            // shouldn't happen but just in case...
            if (connectRegions.Count == 0)
            {
                map[op.X, op.Y].SightRegion = 1;
                return;
            }

            // pick new binding region
            var nr = connectRegions.Min();

            map[op.X, op.Y].SightRegion = nr;

            // make uninitialized blocked sight regions visible
            foreach (var sp in SurroundingPoints)
            {
                p.X = op.X + sp.X;
                p.Y = op.Y + sp.Y;

                var t = map[p.X, p.Y];
                if (IsBlocking(t))
                {
                    foreach (var r in connectRegions)
                    {
                        if (t.SightRegion % r == 0)
                        {
                            t.SightRegion /= r;
                        }
                    }
                    checked { t.SightRegion *= nr; }
                }
            }

            // connect sight regions
            for (var i = 0; i < connectRegions.Count; i++)
            {
                var wr = connectRegions[i];
                if (wr == nr)
                {
                    continue;
                }

                for (var x = 0; x < map.Width; x++)
                {
                    for (var y = 0; y < map.Height; y++)
                    {
                        var t = map[x, y];
                        if (t.SightRegion % wr != 0)
                        {
                            continue;
                        }

                        t.SightRegion /= wr;
                        checked { t.SightRegion *= nr; }
                    }
                }
            }
        }