Beispiel #1
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);
        }
Beispiel #3
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);
        }
Beispiel #4
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;
            }
        }