示例#1
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="model"></param>
        public Blueprint LoadFromXML(XmlHouseData model)
        {
            this.Blueprint = new Blueprint(model.Size, model.Size);
            VM.Context.Blueprint = Blueprint;
            VM.Context.Architecture = new VMArchitecture(model.Size, model.Size, Blueprint, VM.Context);

            var arch = VM.Context.Architecture;

            foreach (var floor in model.World.Floors){
                arch.SetFloor(floor.X, floor.Y, (sbyte)(floor.Level+1), new FloorTile { Pattern = (ushort)floor.Value }, true);
            }

            foreach (var wall in model.World.Walls)
            {
                arch.SetWall((short)wall.X, (short)wall.Y, (sbyte)(wall.Level+1), new WallTile() //todo: these should read out in their intended formats - a cast shouldn't be necessary
                {
                    Segments = wall.Segments,
                    TopLeftPattern = (ushort)wall.TopLeftPattern,
                    TopRightPattern = (ushort)wall.TopRightPattern,
                    BottomLeftPattern = (ushort)wall.BottomLeftPattern,
                    BottomRightPattern = (ushort)wall.BottomRightPattern,
                    TopLeftStyle = (ushort)wall.LeftStyle,
                    TopRightStyle = (ushort)wall.RightStyle
                });
            }
            arch.RegenRoomMap();
            VM.Context.RegeneratePortalInfo();

            foreach (var obj in model.Objects)
            {
                //if (obj.Level == 0) continue;
                //if (obj.GUID == "0xE9CEB12F") obj.GUID = "0x01A0FD79"; //replace onlinejobs door with a normal one
                //if (obj.GUID == "0x346FE2BC") obj.GUID = "0x98E0F8BD"; //replace kitchen door with a normal one
                CreateObject(obj);
            }

            if (VM.UseWorld)
            {
                foreach (var obj in model.Sounds)
                {
                    VM.Context.Ambience.SetAmbience(VM.Context.Ambience.GetAmbienceFromGUID(obj.ID), (obj.On == 1));
                    World.State.WorldSize = model.Size;

                }
                Blueprint.Terrain = CreateTerrain(model);
            }

            var testObject = new XmlHouseDataObject(); //test npc controller, not normally present on a job lot.
            testObject.GUID = "0x70F69082";
            testObject.X = 0;
            testObject.Y = 0;
            testObject.Level = 1;
            testObject.Dir = 0;
            CreateObject(testObject);

            arch.Tick();
            return this.Blueprint;
        }
示例#2
0
        public static void Save(string xmlFilePath, XmlHouseData data)
        {
            XmlSerializer serialize = new XmlSerializer(typeof(XmlHouseData));

            using (var writer = new StreamWriter(xmlFilePath))
            {
                serialize.Serialize(writer, data);
            }
        }
示例#3
0
        public void SaveHouse(VM vm, string path)
        {
            if (vm.Context.Architecture != null)
            {
                housedata = new XmlHouseData();
                housedata.World = new XmlHouseDataWorld();
                housedata.World.Floors = new List<XmlHouseDataFloor>();
                housedata.World.Walls = new List<XmlHouseDataWall>();
                housedata.Objects = new List<XmlHouseDataObject>();

            }

            var HouseWidth = vm.Context.Architecture.Width;
            var HouseHeight = vm.Context.Architecture.Height;
            var Levels = vm.Context.Architecture.Stories;
            housedata.Size = HouseWidth;

            for (short x = 0; x < HouseWidth; x++)
            {
                for (short y = 0; y < HouseHeight; y++)
                {
                    for (sbyte z = 1; z <= Levels; z++)
                        if (vm.Context.Architecture.GetFloor(x, y, z).Pattern != 0)
                        {
                            var Floor = vm.Context.Architecture.GetFloor(x, y, z);
                            housedata.World.Floors.Add(new XmlHouseDataFloor()
                            {
                                X = x,
                                Y = y,
                                Value = Floor.Pattern,
                                Level = z - 1
                            });
                        }

                    for (sbyte z = 1; z <= Levels; z++)
                    {
                        if (vm.Context.Architecture.GetWall(x, y, z).Segments != 0)
                        {
                            var Wall = vm.Context.Architecture.GetWall(x, y, z);
                            housedata.World.Walls.Add(new XmlHouseDataWall()
                            {
                                X = x,
                                Y = y,
                                Segments = Wall.Segments,
                                Placement = 0,
                                TopLeftPattern = Wall.TopLeftPattern,
                                TopRightPattern = Wall.TopRightPattern,
                                LeftStyle = Wall.TopLeftStyle,
                                RightStyle = Wall.TopRightStyle,
                                BottomLeftPattern = Wall.BottomLeftPattern,
                                BottomRightPattern = Wall.BottomRightPattern,
                                Level = z - 1

                            });
                        }
                    }
                }
            }

            foreach (var entity in vm.Entities)
            {
                if (entity != entity.MultitileGroup.BaseObject || entity is VMAvatar) continue;

                uint GUID = (entity.MultitileGroup.MultiTile)?entity.MasterDefinition.GUID:entity.Object.OBJ.GUID;

                housedata.Objects.Add(new XmlHouseDataObject()
                {
                    GUID = "0x" + GUID.ToString("X"),
                    X = entity.Position.TileX,
                    Y = entity.Position.TileY,
                    Level = (entity.Position == LotTilePos.OUT_OF_WORLD) ? 0 : entity.Position.Level,
                    Dir = (int)Math.Round(Math.Log((double)entity.Direction, 2))
                });
            }

            XmlHouseData.Save(path, housedata);
        }
示例#4
0
        public static void Save(string xmlFilePath, XmlHouseData data)
        {
            XmlSerializer serialize = new XmlSerializer(typeof(XmlHouseData));

            using (var writer = new StreamWriter(xmlFilePath))
            {
                serialize.Serialize(writer, data);
            }
        }
示例#5
0
 private TerrainComponent CreateTerrain(XmlHouseData model)
 {
     var terrain = new TerrainComponent(new Rectangle(1, 1, model.Size - 2, model.Size - 2));
     this.InitWorldComponent(terrain);
     return terrain;
 }