public override bool Execute(VM vm)
        {
            //the client should ignore these. Can be sent before state sync when joining job lots (by accident)
            if (!vm.BlueprintRestore)
            {
                return(true);
            }

            vm.SetGlobalValue(11, JobLevel); //set job level beforehand

            if (IffData)
            {
                var iff = new IffFile();
                using (var stream = new MemoryStream(XMLData))
                {
                    iff.Read(stream);
                }
                var fsov = iff.List <FSOV>()?.FirstOrDefault();
                if (fsov != null)
                {
                    var marshal = new VMMarshal();
                    using (var read = new BinaryReader(new MemoryStream(fsov.Data)))
                        marshal.Deserialize(read);
                    vm.Load(marshal);
                }
                else
                {
                    var activator = new VMTS1Activator(vm, vm.Context.World, JobLevel);
                    var blueprint = activator.LoadFromIff(iff);
                }
                var entClone = new List <VMEntity>(vm.Entities);
                foreach (var nobj in entClone)
                {
                    nobj.ExecuteEntryPoint(2, vm.Context, true);
                }
                vm.TS1State.VerifyFamily(vm);
            }
            else
            {
                XmlHouseData lotInfo;
                using (var stream = new MemoryStream(XMLData))
                {
                    lotInfo = XmlHouseData.Parse(stream);
                }

                var activator = new VMWorldActivator(vm, vm.Context.World);
                activator.FloorClip  = new Microsoft.Xna.Framework.Rectangle(FloorClipX, FloorClipY, FloorClipWidth, FloorClipHeight);
                activator.Offset     = new Microsoft.Xna.Framework.Point(OffsetX, OffsetY);
                activator.TargetSize = TargetSize;
                var blueprint = activator.LoadFromXML(lotInfo);
            }

            /*if (VM.UseWorld)
             * {
             *  vm.Context.World.InitBlueprint(blueprint);
             *  vm.Context.Blueprint = blueprint;
             * }*/

            return(true);
        }
Ejemplo n.º 2
0
        public override bool Execute(VM vm)
        {
            string[] CharacterInfos = new string[9];

            XmlHouseData lotInfo;

            using (var stream = new MemoryStream(XMLData))
            {
                lotInfo = XmlHouseData.Parse(stream);
            }

            VMWorldActivator activator = new VMWorldActivator(vm, vm.Context.World);

            vm.Activator = activator;

            var blueprint = activator.LoadFromXML(lotInfo);

            if (VM.UseWorld)
            {
                vm.Context.World.InitBlueprint(blueprint);
                vm.Context.Blueprint = blueprint;
            }
            vm.SetGlobalValue(11, JobLevel);

            AppearanceType type;

            foreach (XmlCharacter Char in Characters)
            {
                uint vsimID = (uint)(new Random()).Next();
                Enum.TryParse(Char.Appearance, out type);

                var vheadPurchasable = Content.Content.Get().AvatarPurchasables.Get(Convert.ToUInt64(Char.Head, 16));
                var vbodyPurchasable = Content.Content.Get().AvatarPurchasables.Get(Convert.ToUInt64(Char.Body, 16));
                var vHeadID          = vheadPurchasable != null ? vheadPurchasable.OutfitID :
                                       Convert.ToUInt64(Char.Head, 16);
                var vBodyID = vbodyPurchasable != null ? vbodyPurchasable.OutfitID :
                              Convert.ToUInt64(Char.Body, 16);

                VMAvatar visitor = vm.Activator.CreateAvatar
                                       (Convert.ToUInt32(Char.ObjID, 16), Char, true, Convert.ToInt16(Char.Id));

                if (!vm.Entities.Contains(visitor))
                {
                    vm.SendCommand(new VMNetVisitorCmd
                    {
                        ActorUID = vsimID,
                        HeadID   = vHeadID,
                        BodyID   = vBodyID,
                        SkinTone = (byte)type,
                        Gender   = Char.Gender == "male" ? true : false,
                        Name     = Char.Name
                    });
                }
            }


            return(true);
        }
        public LotDebugScreen()
        {
            var lotInfo = XmlHouseData.Parse(GameFacade.GameFilePath("housedata/blueprints/restaurant01_00.xml"));

            World = new World(GameFacade.Game.GraphicsDevice);
            GameFacade.Scenes.Add(World);

            vm = new TSO.Simantics.VM(new VMContext(World));
            vm.Init();

            var activator = new VMWorldActivator(vm, World);
            var blueprint = activator.LoadFromXML(lotInfo);

            World.InitBlueprint(blueprint);
            vm.Context.Blueprint = blueprint;

            var sim = activator.CreateAvatar();

            //sim.Position = new Vector3(31.5f, 55.5f, 0.0f);
            sim.Position = new Vector3(26.5f, 41.5f, 0.0f);

            VMDebug = new UIButton()
            {
                Caption = "Simantics",
                Y       = 45,
                Width   = 100,
                X       = GlobalSettings.Default.GraphicsWidth - 110
            };
            VMDebug.OnButtonClick += new ButtonClickDelegate(VMDebug_OnButtonClick);
            this.Add(VMDebug);

            LotController = new UILotControl(vm, World);
            this.AddAt(0, LotController);

            ucp   = new UIUCP(this);
            ucp.Y = ScreenHeight - 210;
            ucp.SetInLot(true);
            ucp.SetMode(UIUCP.UCPMode.LotMode);
            ucp.SelectedAvatar = sim;
            ucp.SetPanel(1);

            //ucp.ZoomLevel = 1;
            //ucp.OnZoomChanged += new UCPZoomChangeEvent(ucp_OnZoomChanged);
            //ucp.OnRotateChanged += new UCPRotateChangeEvent(ucp_OnRotateChanged);
            this.Add(ucp);
        }
Ejemplo n.º 4
0
        public override bool Execute(VM vm)
        {
            //the client should ignore these. Can be sent before state sync when joining job lots (by accident)
            if (!vm.IsServer)
            {
                return(true);
            }

            vm.SetGlobalValue(11, JobLevel); //set job level beforehand

            if (IffData)
            {
                vm.SetGlobalValue(10, JobLevel); //set house number
                var iff = new IffFile();
                using (var stream = new MemoryStream(XMLData))
                {
                    iff.Read(stream);
                }
                var activator = new VMTS1Activator(vm, vm.Context.World);
                var blueprint = activator.LoadFromIff(iff);
                vm.VerifyFamily();
            }
            else
            {
                XmlHouseData lotInfo;
                using (var stream = new MemoryStream(XMLData))
                {
                    lotInfo = XmlHouseData.Parse(stream);
                }

                var activator = new VMWorldActivator(vm, vm.Context.World);
                activator.FloorClip  = new Microsoft.Xna.Framework.Rectangle(FloorClipX, FloorClipY, FloorClipWidth, FloorClipHeight);
                activator.Offset     = new Microsoft.Xna.Framework.Point(OffsetX, OffsetY);
                activator.TargetSize = TargetSize;
                var blueprint = activator.LoadFromXML(lotInfo);
            }

            /*if (VM.UseWorld)
             * {
             *  vm.Context.World.InitBlueprint(blueprint);
             *  vm.Context.Blueprint = blueprint;
             * }*/

            return(true);
        }
Ejemplo n.º 5
0
        public override bool Execute(VM vm)
        {
            XmlHouseData lotInfo;

            using (var stream = new MemoryStream(XMLData))
            {
                lotInfo = XmlHouseData.Parse(stream);
            }

            var activator = new VMWorldActivator(vm, vm.Context.World);
            var blueprint = activator.LoadFromXML(lotInfo);

            if (VM.UseWorld)
            {
                vm.Context.World.InitBlueprint(blueprint);
                vm.Context.Blueprint = blueprint;
            }
            vm.SetGlobalValue(11, JobLevel);

            return(true);
        }
Ejemplo n.º 6
0
        public void InitTestLot()
        {
            var lotInfo = XmlHouseData.Parse(GameFacade.GameFilePath("housedata/blueprints/restaurant08_00.xml"));

            World = new World(GameFacade.Game.GraphicsDevice);
            GameFacade.Scenes.Add(World);

            vm = new TSO.Simantics.VM(new VMContext(World));
            vm.Init();

            var activator = new VMWorldActivator(vm, World);
            var blueprint = activator.LoadFromXML(lotInfo);

            World.InitBlueprint(blueprint);
            vm.Context.Blueprint = blueprint;

            var sim = activator.CreateAvatar();

            sim.Position = new Vector3(26.5f, 41.5f, 0.0f);

            var sim2 = activator.CreateAvatar();

            sim2.Position = new Vector3(27.5f, 41.5f, 0.0f);

            LotController = new UILotControl(vm, World);
            this.AddAt(0, LotController);

            vm.Context.Clock.Hours = 6;

            ucp.SelectedAvatar = sim;
            ucp.SetInLot(true);
            if (m_ZoomLevel > 3)
            {
                World.Visible = false;
            }
        }
Ejemplo n.º 7
0
        public LotDebugScreen()
        {
            var lotInfo = XmlHouseData.Parse(GameFacade.GameFilePath("housedata/blueprints/restaurant01_00.xml"));

            World = new World(GameFacade.Game.GraphicsDevice);
            GameFacade.Scenes.Add(World);

            vm = new tso.simantics.VM(new VMContext(World));
            vm.Init();

            var activator = new VMWorldActivator(vm, World);
            var blueprint = activator.LoadFromXML(lotInfo);

            World.InitBlueprint(blueprint);
            vm.Context.Blueprint = blueprint;

            var sim = activator.CreateAvatar();

            //sim.Position = new Vector3(31.5f, 55.5f, 0.0f);
            sim.Position = new Vector3(26.5f, 41.5f, 0.0f);

            VMDebug = new UIButton()
            {
                Caption = "Simantics",
                Y       = 45,
                Width   = 100,
                X       = GlobalSettings.Default.GraphicsWidth - 110
            };
            VMDebug.OnButtonClick += new ButtonClickDelegate(VMDebug_OnButtonClick);
            this.Add(VMDebug);

            //var lotInfo = HouseData.Parse("C:\\restaurant00_00_small.xml");
            //for (int i = 1; i < 64; i++)
            //{
            //    lotInfo.World.Floors.Add(new HouseDataFloor {
            //         X = 1,
            //         Y = i,
            //         Level = 0,
            //         Value = 9
            //    });
            //}

            //lotInfo.World.Floors.Add(new HouseDataFloor {
            //    X = 0, Y = 0,
            //    Level = 0, Value = 20
            //});

            //lotInfo.World.Floors.Add(new HouseDataFloor
            //{
            //    X = 63,
            //    Y = 63,
            //    Level = 0,
            //    Value = 40
            //});

            //lotInfo.World.Floors.Add(new HouseDataFloor
            //{
            //    X = 0,
            //    Y = 63,
            //    Level = 0,
            //    Value = 20
            //});

            //lotInfo.World.Floors.Add(new HouseDataFloor
            //{
            //    X = 63,
            //    Y = 0,
            //    Level = 0,
            //    Value = 20
            //});



            //Renderer = new HouseRenderer();
            //Renderer.SetModel(lotInfo);
            ////Renderer.Position = new Microsoft.Xna.Framework.Vector3(-32.0f, -40.0f, 0.0f);

            //var scene = new ThreeDScene();
            //var focusPoint = Vector3.Zero;

            //var yValue = (float)Math.Cos(MathHelper.ToRadians(30.0f)) * 96.0f;
            //var cameraOffset = new Vector3(-96.0f, yValue, 96.0f);
            //var rotatedOffset = Vector3.Transform(cameraOffset, Microsoft.Xna.Framework.Matrix.CreateRotationY(MathHelper.PiOver2 * 0.5f));

            ////rotatedOffset = Vector3.Transform(rotatedOffset, Microsoft.Xna.Framework.Matrix.CreateScale(3f));
            ////Renderer.Position = new Vector3(-96.0f, 0.0f, -96.0f);

            //scene.Camera.Position = cameraOffset;// new Microsoft.Xna.Framework.Vector3(0, 0, 80);
            //scene.Add(Renderer);
            //Renderer.Scale = new Vector3(0.005f);

            //GameFacade.Scenes.AddScene(scene);


            ucp   = new UIUCP();
            ucp.Y = ScreenHeight - 210;
            //ucp.OnZoomChanged += new UCPZoomChangeEvent(ucp_OnZoomChanged);
            //ucp.OnRotateChanged += new UCPRotateChangeEvent(ucp_OnRotateChanged);
            this.Add(ucp);
        }
        public void InitTestLot(string path, bool host)
        {
            if (Connecting)
            {
                return;
            }

            lotName = path;



            Characters = new List <XmlCharacter>();

            SaveHouseButton.Visible = true;
            CreateChar.Visible      = false;

            if (vm != null)
            {
                CleanupLastWorld();
            }

            World = new LotView.World(GameFacade.Game.GraphicsDevice);
            GameFacade.Scenes.Add(World);



            vm = new VM(new VMContext(World), new UIHeadlineRendererProvider());
            vm.Init();
            vm.LotName = (path == null) ? "localhost" : path.Split('/').LastOrDefault(); //quick hack just so we can remember where we are


            var DirectoryInfo = new DirectoryInfo(Path.Combine(FSOEnvironment.UserDir, "Characters/"));

            for (int i = 0; i <= DirectoryInfo.GetFiles().Count() - 1; i++)
            {
                var file = DirectoryInfo.GetFiles()[i];
                CharacterInfos[i] = Path.GetFileNameWithoutExtension(file.FullName);

                if (CharacterInfos[i] != null && CharacterInfos[i] != gizmo.SelectedCharInfo.Name)
                {
                    Characters.Add(XmlCharacter.Parse(file.FullName));
                }
            }


            VMNetDriver driver;

            if (host)
            {
                driver = new VMServerDriver(37564, null);
            }
            else
            {
                Connecting       = true;
                ConnectingDialog = new UILoginProgress();

                ConnectingDialog.Caption         = GameFacade.Strings.GetString("211", "1");
                ConnectingDialog.ProgressCaption = GameFacade.Strings.GetString("211", "24");
                //this.Add(ConnectingDialog);

                UIScreen.ShowDialog(ConnectingDialog, true);

                driver = new VMClientDriver(path, 37564, ClientStateChange);
            }


            vm.VM_SetDriver(driver);



            if (host)
            {
                //check: do we have an fsov to try loading from?

                string filename = Path.GetFileName(path);
                try
                {
                    using (var file = new BinaryReader(File.OpenRead(Path.Combine(FSOEnvironment.UserDir, "Houses/") + filename.Substring(0, filename.Length - 4) + ".fsov")))
                    {
                        var marshal = new SimAntics.Marshals.VMMarshal();
                        marshal.Deserialize(file);
                        vm.Load(marshal);
                        vm.Reset();
                    }
                }
                catch (Exception)
                {
                    short jobLevel = -1;

                    //quick hack to find the job level from the chosen blueprint
                    //the final server will know this from the fact that it wants to create a job lot in the first place...

                    try
                    {
                        if (filename.StartsWith("nightclub") || filename.StartsWith("restaurant") || filename.StartsWith("robotfactory"))
                        {
                            jobLevel = Convert.ToInt16(filename.Substring(filename.Length - 9, 2));
                        }
                    }
                    catch (Exception) { }

                    vm.SendCommand(new VMBlueprintRestoreCmd
                    {
                        JobLevel   = jobLevel,
                        XMLData    = File.ReadAllBytes(path),
                        Characters = Characters
                    });
                }
            }

            //Check the clients loaded;
            List <VMAvatar> Clients = new List <VMAvatar>();

            foreach (VMEntity entity in vm.Entities)
            {
                if (entity is VMAvatar && entity.PersistID > 0)
                {
                    Clients.Add((VMAvatar)entity);
                }
            }


            if (Clients.Count == 0)
            {
                Permissions = true;
            }

            uint simID = (uint)(new Random()).Next();

            vm.MyUID = simID;


            var headPurchasable = Content.Content.Get().AvatarPurchasables.Get(Convert.ToUInt64(gizmo.SelectedCharInfo.Head, 16));
            var bodyPurchasable = Content.Content.Get().AvatarPurchasables.Get(Convert.ToUInt64(gizmo.SelectedCharInfo.Body, 16));
            var HeadID          = headPurchasable != null ? headPurchasable.OutfitID :
                                  Convert.ToUInt64(gizmo.SelectedCharInfo.Head, 16);
            var BodyID = bodyPurchasable != null ? bodyPurchasable.OutfitID :
                         Convert.ToUInt64(gizmo.SelectedCharInfo.Body, 16);

            AppearanceType type;

            Enum.TryParse(gizmo.SelectedCharInfo.Appearance, out type);
            bool Male = (gizmo.SelectedCharInfo.Gender == "male") ? true:false;

            vm.SendCommand(new VMNetSimJoinCmd
            {
                ActorUID    = simID,
                HeadID      = HeadID,
                BodyID      = BodyID,
                SkinTone    = (byte)type,
                Gender      = Male,
                Name        = gizmo.SelectedCharInfo.Name,
                Permissions = (Permissions == true) ?
                              VMTSOAvatarPermissions.Owner : VMTSOAvatarPermissions.Visitor
            });

            VMWorldActivator activator = new VMWorldActivator(vm, World);

            if (host)
            {
            }
            else
            {
                foreach (XmlCharacter Char in Characters)
                {
                    uint vsimID = (uint)(new Random()).Next();
                    Enum.TryParse(Char.Appearance, out type);

                    var vheadPurchasable = Content.Content.Get().AvatarPurchasables.Get(Convert.ToUInt64(Char.Head, 16));
                    var vbodyPurchasable = Content.Content.Get().AvatarPurchasables.Get(Convert.ToUInt64(Char.Body, 16));
                    var vHeadID          = vheadPurchasable != null ? vheadPurchasable.OutfitID :
                                           Convert.ToUInt64(Char.Head, 16);
                    var vBodyID = vbodyPurchasable != null ? vbodyPurchasable.OutfitID :
                                  Convert.ToUInt64(Char.Body, 16);

                    VMEntity vEntity = vm.Entities.FirstOrDefault(x => (x.Object.OBJ.GUID == 0x7FD96B54 && x.Name == Char.Name));

                    if (vEntity != null)
                    {
                        ((VMAvatar)vEntity).SetAvatarData(Char);
                    }
                }
            }

            LotController = new UILotControl(vm, World);
            this.AddAt(0, LotController);

            vm.Context.Clock.Hours = 10;

            if (m_ZoomLevel > 3)
            {
                World.Visible         = false;
                LotController.Visible = false;
            }


            if (host)
            {
                ZoomLevel = 1;
                ucp.SetInLot(true);
            }
            else
            {
                ZoomLevel = Math.Max(ZoomLevel, 4);
            }

            vm.OnFullRefresh += VMRefreshed;
            vm.OnChatEvent   += Vm_OnChatEvent;
            vm.OnEODMessage  += LotController.EODs.OnEODMessage;
        }
Ejemplo n.º 9
0
        public void ResetVM()
        {
            VMNetDriver driver;

            driver = new VMServerDriver(Port, NetClosed);

            var vm = new VM(new VMContext(null), new VMNullHeadlineProvider());

            state = vm;
            vm.Init();
            vm.VM_SetDriver(driver);
            vm.OnChatEvent += Vm_OnChatEvent;

            Console.WriteLine("Select the lot type");
            Console.WriteLine("1-Empty");
            Console.WriteLine("2-Blueprint");
            Console.WriteLine("3-House");

            string path = "";
            int    lot  = Convert.ToInt32(Console.ReadLine());

            if (lot == 1)
            {
                if (Settings.Default.DebugLot != String.Empty)
                {
                    path = AppDomain.CurrentDomain.BaseDirectory + "Content/Houses/" + Settings.Default.DebugLot;
                }
                else
                {
                    path = AppDomain.CurrentDomain.BaseDirectory + "Content/Houses/empty_lot.xml";
                }
            }
            else if (lot == 2)
            {
                Console.WriteLine("Specify lot name");
                path = AppDomain.CurrentDomain.BaseDirectory + "Content/Houses/" + Console.ReadLine() + ".xml";
            }
            else if (lot == 3)
            {
                Console.WriteLine("Specify house name");
                path = AppDomain.CurrentDomain.BaseDirectory + "Content/Houses/" + Console.ReadLine() + ".iff";
                TS1  = true;
            }


            XmlHouseData lotInfo;
            IffFile      HouseInfo = null;
            string       filename  = Path.GetFileName(path);

            if (!TS1)
            {
                try
                {
                    //try to load from FSOV first.
                    LoadState(vm, "Content/LocalHouse/" + filename.Substring(0, filename.Length - 4) + ".fsov");
                }
                catch (Exception)
                {
                    try
                    {
                        Console.WriteLine("Failed FSOV load... Trying Backup");
                        LoadState(vm, "Content/LocalHouse/" + filename.Substring(0, filename.Length - 4) + "_backup.fsov");
                    }
                    catch (Exception)
                    {
                        Console.WriteLine("CRITICAL::: Failed FSOV load... Trying Blueprint (first run or something went wrong)");
                        short jobLevel = -1;

                        //quick hack to find the job level from the chosen blueprint
                        //the final server will know this from the fact that it wants to create a job lot in the first place...

                        try
                        {
                            if (filename.StartsWith("nightclub") || filename.StartsWith("restaurant") || filename.StartsWith("robotfactory"))
                            {
                                jobLevel = Convert.ToInt16(filename.Substring(filename.Length - 9, 2));
                            }
                        }
                        catch (Exception) { }

                        //vm.SendCommand(new VMBlueprintRestoreCmd
                        //{
                        // JobLevel = jobLevel,
                        // XMLData = File.ReadAllBytes(path)
                        //});

                        using (var stream = new MemoryStream(File.ReadAllBytes(path)))
                        {
                            lotInfo = XmlHouseData.Parse(stream);
                        }

                        VMWorldActivator activator = new VMWorldActivator(vm, vm.Context.World);

                        vm.Activator = activator;

                        var blueprint = activator.LoadFromXML(lotInfo);

                        if (VM.UseWorld)
                        {
                            vm.Context.World.InitBlueprint(blueprint);
                            vm.Context.Blueprint = blueprint;
                        }


                        vm.Context.Clock.Hours = 10;

                        vm.MyUID = uint.MaxValue - 1;
                    }
                }
            }
            else
            {
                if (File.Exists(path))
                {
                    HouseInfo = new IffFile(path);
                }

                VMWorldActivator activator = new VMWorldActivator(vm, vm.Context.World);

                vm.Activator = activator;

                var blueprint = activator.LoadFromIff(HouseInfo);

                if (VM.UseWorld)
                {
                    vm.Context.World.InitBlueprint(blueprint);
                    vm.Context.Blueprint = blueprint;
                }


                vm.Context.Clock.Hours = 10;

                vm.MyUID = uint.MaxValue - 1;
            }



            Console.WriteLine("Select the server type");
            Console.WriteLine("1-Host");
            Console.WriteLine("2-Dedicated");

            int host = Convert.ToInt32(Console.ReadLine());

            if (host == 1)
            {
                vm.SendCommand(new VMNetSimJoinCmd
                {
                    ActorUID = uint.MaxValue - 1,
                    Name     = "server"
                });
            }
            else if (host == 2)
            {
                Dedicated = true;
            }
        }