Пример #1
0
        public override void Deserialize(GenericReader reader)
        {
            base.Deserialize(reader);

            int version = reader.GetVersion();

            switch (version)
            {
            case 1:
            {
                _Placeholder = reader.ReadItem <CellarPlaceholder>();
                _FloorTiles  = reader.ReadStrongItemList <CellarFloor>();
                _WallTiles   = reader.ReadStrongItemList <CellarWall>();
                _Style       = reader.ReadFlag <CellarStyle>();
                House        = reader.ReadItem <BaseHouse>();
                StairsDown   = reader.ReadItem <CellarStairs>();
                StairsUp     = reader.ReadItem <CellarStairs>();
            }
                goto case 0;

            case 0:
            {
                if (version < 1)
                {
                    _FloorTiles = new List <CellarFloor>();
                    _WallTiles  = new List <CellarWall>();
                }
            }
            break;
            }
        }
Пример #2
0
 public CellarAddon(CellarStyle style)
 {
     _Style       = style;
     _FloorTiles  = new List <CellarFloor>();
     _WallTiles   = new List <CellarWall>();
     _Placeholder = AddComponent(new CellarPlaceholder(0xF39), Point3D.Zero);
 }
Пример #3
0
        public void ClearComponents(bool holdPlace)
        {
            var comp = Components.ToArray();

            _FloorTiles.Clear();
            _WallTiles.Clear();
            Components.Clear();

            foreach (var c in comp)
            {
                c.Addon = null;
                c.Delete();
            }

            if (holdPlace)
            {
                _Placeholder = AddComponent(new CellarPlaceholder(0xF39), Point3D.Zero);
            }
        }
Пример #4
0
        public void ClearComponents(bool holdPlace)
        {
            var comp = Components.Where(c => c != null && !c.Deleted).ToArray();

            _FloorTiles.Free(true);
            _WallTiles.Free(true);
            Components.Free(true);

            foreach (var c in comp)
            {
                c.Addon = null;
                c.Delete();
            }

            if (holdPlace)
            {
                _Placeholder = _Placeholder ?? AddComponent(new CellarPlaceholder(0xF39), Point3D.Zero);
            }
        }
Пример #5
0
        public void GenerateComponents()
        {
            if (Deleted || Map == null || Map == Map.Internal || Location == Point3D.Zero)
            {
                return;
            }

            if (House == null || House.Deleted)
            {
                House = BaseHouse.FindHouseAt(this);
            }

            if (House == null || House.Deleted || House.Area == null || House.Area.Length == 0 || _Placeholder == null ||
                _Placeholder.Deleted)
            {
                House = null;
                return;
            }

            if (_Style == CellarStyle.None)
            {
                _Style = CellarStyle.Dirt;
            }

            Point3D p = _Placeholder.Location;
            Point3D o = _Placeholder.Offset;
            Point3D t = House.Location;

            Components.Remove(_Placeholder);

            _Placeholder.Addon = null;
            _Placeholder.Delete();
            _Placeholder = null;

            var s = Style.GetInfo();

            AddComponent(StairsDown = new CellarStairs(s.StairsDown), o);

            var floorPoints = new List <Point2D>();
            var wallPoints  = new List <Point2D>();

            foreach (var r2d in House.Region.Area.Select(r3d => new Rectangle2D(r3d.Start, r3d.End)))
            {
                floorPoints.AddRange(r2d.EnumeratePoints().Not(floorPoints.Contains));
            }

            floorPoints.ForEach(
                f =>
            {
                var points = new[]
                {
                    f.Clone2D(-1, -1),                        //nw
                    f.Clone2D(0, -1),                         //n
                    f.Clone2D(1, -1),                         //ne
                    f.Clone2D(1),                             //e
                    f.Clone2D(1, 1),                          //se
                    f.Clone2D(0, 1),                          //s
                    f.Clone2D(-1, 1),                         //sw
                    f.Clone2D(-1)                             //w
                };

                wallPoints.AddRange(points.Not(floorPoints.Contains).Not(wallPoints.Contains));
            });

            foreach (var p3d in floorPoints.Select(p2d => p2d.ToPoint3D(t.Z - 40).Clone3D(-p.X, -p.Y, -p.Z)))
            {
                _FloorTiles.Add(AddComponent(new CellarFloor(s.FloorTiles.GetRandom()), p3d));
            }

            foreach (var p3d in wallPoints.Select(p2d => p2d.ToPoint3D(t.Z - 40).Clone3D(-p.X, -p.Y, -p.Z)))
            {
                _WallTiles.Add(AddComponent(new CellarWall(s.WallTiles.GetRandom()), p3d));
            }

            AddComponent(StairsUp = new CellarStairs(s.StairsUp), p.ToPoint3D(t.Z - 40).Clone3D(-p.X, -p.Y, -p.Z));

            StairsDown.LinkWith(StairsUp);

            if (!House.Addons.Contains(this))
            {
                House.Addons.Add(this);
            }
        }