Ejemplo n.º 1
0
        public MyServerAction Travel(MyMwcTravelTypeEnum travelType, MyMwcSectorIdentifier targetSector)
        {
            Debug.Assert(targetSector.SectorType == MyMwcSectorTypeEnum.STORY, "Travel is allowed only in story");

            TryPause();

            var sector = MyLocalCache.LoadSector(targetSector);

            if (sector == null)
            {
                var storySectorId = targetSector;
                storySectorId.UserId = null;
                sector = MyLocalCache.LoadSector(storySectorId);
            }

            if (sector != null)
            {
                TravelSectorLoaded(travelType, targetSector.Position, null, sector);
                return(null);
            }
            else // Not using server...so sector is "from generator"
            {
                TravelSectorLoaded(travelType, targetSector.Position, null, MyMwcObjectBuilder_Sector.UseGenerator());
                return(null);
            }
        }
Ejemplo n.º 2
0
        private MyServerAction CheckpointLoaded(MyMwcObjectBuilder_Checkpoint checkpoint)
        {
            MyGameplayConstants.SetGameplayDifficulty(checkpoint.SessionObjectBuilder.Difficulty);

            Debug.Assert((checkpoint.CheckpointName == null && checkpoint.CurrentSector.UserId != null) || (checkpoint.CheckpointName != null && checkpoint.CurrentSector.UserId == null));

            var cacheSector = MyLocalCache.LoadSector(checkpoint.CurrentSector);

            if (cacheSector != null)
            {
                checkpoint.SectorObjectBuilder = cacheSector;
                MyGuiScreenGamePlay.ReloadGameplayScreen(checkpoint, MyMwcStartSessionRequestTypeEnum.LOAD_CHECKPOINT, MyGuiScreenGamePlayType.GAME_STORY);
                return(null);
            }
            else
            {
                // Checkpoint and sector is stored on filesystem
                throw new MyDataCorruptedException("Last checkpoint sector corrupted");

                //MyServerAction loadAction = new MyServerAction(MyTextsWrapperEnum.EnterSectorInProgressPleaseWait);
                //loadAction.BeginAction = c => c.BeginLoadSector(null, c);
                //loadAction.EndAction = (c, r) => LastCheckpointSectorLoaded(checkpoint, c.EndLoadSector(r));
                //loadAction.Start();
                //return loadAction;
            }
        }
Ejemplo n.º 3
0
        private MyServerAction NewGameStarted(MyMwcObjectBuilder_Checkpoint checkpoint, MyMissionID missionId)
        {
            MyLocalCache.ClearCurrentSave();
            MyClientServer.LoggedPlayer.HasAnyCheckpoints = false;

            Debug.Assert(checkpoint.CurrentSector.UserId == null, "New game checkpoint.CurrentSector must be story sector");

            var cachedSector = MyLocalCache.LoadSector(checkpoint.CurrentSector);

            if (cachedSector != null)
            {
                checkpoint.SectorObjectBuilder  = cachedSector;
                checkpoint.CurrentSector.UserId = MyClientServer.LoggedPlayer.GetUserId();
                ReloadGameplayNewGame(checkpoint, missionId);
                return(null);
            }
            throw new MyDataCorruptedException("New game story checkpoint does not contain first sector!");
        }
Ejemplo n.º 4
0
        // This method works on foreground, on current thread
        public MyMwcObjectBuilder_SectorObjectGroups LoadSectorGroups(MyMwcVector3Int sectorPosition)
        {
            var sectorId = new MyMwcSectorIdentifier(MyMwcSectorTypeEnum.STORY, null, sectorPosition, String.Empty);
            var sector   = MyLocalCache.LoadSector(sectorId);
            int?version  = sector != null ? (int?)sector.Version : null;

            var groupBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.SectorObjectGroups, null) as MyMwcObjectBuilder_SectorObjectGroups;

            if (sector == null)
            {
                throw new MyDataCorruptedException("Sector cannot be loaded");
            }

            // Server said: use cache
            groupBuilder.Generated = sector.Generated;
            groupBuilder.Entities  = sector.SectorObjects;
            groupBuilder.Groups    = sector.ObjectGroups;
            return(groupBuilder);
        }
Ejemplo n.º 5
0
        public override void Load()
        {
            // HACK: ...adding dead entities (dead by solar wind or anything)
            // These entities probably died after Reichstag A mission was successful, so they were not indestructible, solar wind came and eat them
            var colonel  = MyScriptWrapper.TryGetEntity((uint)EntityID.Bot_WaltherStauffenberg);
            var valkyrie = MyScriptWrapper.TryGetEntity((uint)EntityID.Bot_Disabled_03);

            if (colonel == null || valkyrie == null)
            {
                var sector = MyLocalCache.LoadSector(new MyMwcSectorIdentifier(MyMwcSectorTypeEnum.STORY, null, this.GetCurrentSector(), String.Empty));
                var bots   = sector.SectorObjects.OfType <MyMwcObjectBuilder_SmallShip_Bot>();
                foreach (var bot in bots)
                {
                    if (colonel == null && bot.EntityId == (uint)EntityID.Bot_WaltherStauffenberg ||
                        valkyrie == null && bot.EntityId == (uint)EntityID.Bot_Disabled_03)
                    {
                        MyEntities.CreateFromObjectBuilderAndAdd(bot.DisplayName, bot, bot.PositionAndOrientation.GetMatrix());
                    }
                }
            }

            base.Load();

            MyScriptWrapper.SetFactionRelation(MyMwcObjectBuilder_FactionEnum.FourthReich, MyMwcObjectBuilder_FactionEnum.Rainiers, MyFactions.RELATION_BEST);

            MySmallShipBot FoRrepresentative = (MySmallShipBot)MyScriptWrapper.TryGetEntity((uint)EntityID.Bot_WaltherStauffenberg);

            MyScriptWrapper.ChangeFaction(FoRrepresentative, MyMwcObjectBuilder_FactionEnum.FourthReich);
            FoRrepresentative.IsDestructible = false;
            MySmallShipBot Hans = (MySmallShipBot)MyScriptWrapper.TryGetEntity((uint)EntityID.Bot_Hans);
            MySmallShipBot Karl = (MySmallShipBot)MyScriptWrapper.TryGetEntity((uint)EntityID.Bot_Karl);

            Hans.IsDestructible = false;
            Karl.IsDestructible = false;
            Hans.Follow(FoRrepresentative);
            Karl.Follow(FoRrepresentative);

            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.Bot_Disabled_01), true, false);
            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.Bot_Disabled_02), true, false);
            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.Bot_Disabled_03), true, false);
            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.Bot_Disabled_04), true, false);
            MyScriptWrapper.DisableShip(MyScriptWrapper.GetEntity((uint)EntityID.Bot_Disabled_05), true, false);
        }
Ejemplo n.º 6
0
        private MyServerAction LoadSandbox(MyMwcVector3Int position, int?userId, MyMissionID?startMission)
        {
            var sectorId = new MyMwcSectorIdentifier(MyMwcSectorTypeEnum.SANDBOX, userId, position, null);
            var sector   = MyLocalCache.LoadSector(sectorId);
            int?version  = sector != null ? (int?)sector.Version : null;

            MyMwcStartSessionRequestTypeEnum startSessionType = userId == MyClientServer.LoggedPlayer.GetUserId() ? MyMwcStartSessionRequestTypeEnum.SANDBOX_OWN : MyMwcStartSessionRequestTypeEnum.SANDBOX_FRIENDS;

            if (userId != null)
            {
                MyServerAction loadAction = new MyServerAction(MyTextsWrapperEnum.EnterSectorInProgressPleaseWait, TimeSpan.FromSeconds(360));
                loadAction.BeginAction = c => c.BeginLoadSandbox(position, userId, version, null, c);
                loadAction.EndAction   = (c, r) => SandboxSectorLoaded(position, MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Checkpoint>(c.EndLoadSandbox(r)), sector, startSessionType, startMission);
                loadAction.Start();
                return(loadAction);
            }
            else if (sector != null)
            {
                var checkpoint = MyLocalCache.MultiplayerCheckpoint();
                if (checkpoint == null)
                {
                    throw new MyDataCorruptedException("Cannot load MP checkpoint");
                }

                if (!MySteam.IsActive && MyClientServer.IsMwAccount)
                {
                    checkpoint.PlayerObjectBuilder.Money = (float)MySectorServiceClient.GetCheckedInstance().GetGameMoney();
                    MySectorServiceClient.SafeClose();
                }

                checkpoint.SectorObjectBuilder = sector;
                SandboxSectorLoaded(position, checkpoint, sector, startSessionType, startMission);
                return(null);
            }
            else
            {
                throw new MyDataCorruptedException("Cannot load sandbox/MP sector");
            }
        }