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; } }
private MyGuiScreenLoading JoinMultiplayerSession(MyGameTypes gameType, MyMwcObjectBuilder_Checkpoint checkpoint) { MyMultiplayerGameplay.Static.IsHost = false; //var checkpoint = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.Checkpoint, null) as MyMwcObjectBuilder_Checkpoint; // This is just dummy ship for load //var ship = MyMwcObjectBuilder_SmallShip_Player.CreateDefaultShip(MyMwcObjectBuilder_SmallShip_TypesEnum.GETTYSBURG, MySession.Static.Player.Faction); MySession.Static.Player.Faction = checkpoint.PlayerObjectBuilder.ShipObjectBuilder.Faction; MyGuiManager.CloseAllScreensExcept(MyGuiScreenGamePlay.Static); MyGuiScreenGamePlayType? gameplayType = null; MyMwcStartSessionRequestTypeEnum?sessionType = null; switch (gameType) { case MyGameTypes.Story: gameplayType = MyGuiScreenGamePlayType.GAME_STORY; sessionType = MyMwcStartSessionRequestTypeEnum.JOIN_FRIEND_STORY; break; case MyGameTypes.Deathmatch: gameplayType = MyGuiScreenGamePlayType.GAME_SANDBOX; sessionType = MyMwcStartSessionRequestTypeEnum.SANDBOX_FRIENDS; break; default: break; } return(MyGuiScreenGamePlay.ReloadGameplayScreen(checkpoint, sessionType, gameplayType)); }
protected override void OnActionCompleted(IAsyncResult asyncResult, MySectorServiceClient client) { try { byte[] result = client.EndLoadCheckpoint(asyncResult); m_checkpoint = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Checkpoint>(result); //if (m_checkpoint.SectorObjectBuilder == null) // Server told us to use cache //{ // LoadSector(); // return; //} MyGuiScreenGamePlay.StoreLastLoadedCheckpoint(m_checkpoint); m_loadCheckpointSuccessfulAction(m_checkpoint); CloseScreen(); } catch (FaultException <MyCustomFault> faultException) { if (faultException.Detail.ErrorCode == MyCustomFaultCode.CheckpointTemplateNotExists) { HandleNonexistentCheckpoint(); } else { // Handled by base class throw faultException; } } }
public void BeforeLoad(MyMwcObjectBuilder_Checkpoint checkpoint) { MyEntityIdentifier.AllocationSuspended = true; //if (MyMultiplayerGameplay.IsRunning && !MyMultiplayerGameplay.IsHost) //{ // MyMwcPositionAndOrientation position = MyMultiplayerGameplay.Static.GetSafeRespawnPositionNearPlayer(checkpoint.PlayerObjectBuilder.ShipObjectBuilder.ShipType); // checkpoint.PlayerObjectBuilder.ShipObjectBuilder.PositionAndOrientation = position; // return; //} // Try find player start location and set player location if (checkpoint.SectorObjectBuilder != null && checkpoint.SectorObjectBuilder.SectorObjects != null) { int playerStartsCount = 0; foreach (var builder in checkpoint.SectorObjectBuilder.SectorObjects) { MyMwcObjectBuilder_DummyPoint dummyBuilder = builder as MyMwcObjectBuilder_DummyPoint; if (dummyBuilder != null) { if ((dummyBuilder.DummyFlags & MyDummyPointFlags.PLAYER_START) > 0) { checkpoint.PlayerObjectBuilder.ShipObjectBuilder.PositionAndOrientation = dummyBuilder.PositionAndOrientation; playerStartsCount++; } } } } MotherShipPosition.Load(checkpoint.Dictionary); }
public MyGuiScreenEditorSaveProgress(MyMwcSectorIdentifier sectorIdentifier, MyMwcObjectBuilder_Checkpoint checkpoint, bool savePlayer, bool visibleSave = true, bool pause = false) : base(MyTextsWrapperEnum.SaveSectorInProgressPleaseWait, false, TimeSpan.FromSeconds(120)) // Enought time to save sector - full of asteroids, etc { m_checkpoint = checkpoint; m_sectorIdentifier = sectorIdentifier; m_savePlayer = savePlayer; m_forceHide = !visibleSave; m_pause = pause; }
private void NewGameSectorLoaded(MyMwcObjectBuilder_Checkpoint checkpoint, byte[] sectorData, MyMissionID missionId) { checkpoint.SectorObjectBuilder = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Sector>(sectorData); // Save sector to cache MyLocalCache.Save(null, checkpoint.SectorObjectBuilder, checkpoint.CurrentSector); checkpoint.CurrentSector.UserId = MyClientServer.LoggedPlayer.GetUserId(); //TODO: should this be send by server? ReloadGameplayNewGame(checkpoint, missionId); }
public static void CopyCoopPlayers(this MyMwcObjectBuilder_Checkpoint loadFrom, MyMwcObjectBuilder_Checkpoint copyTo) { if (loadFrom != null && loadFrom.InventoryObjectBuilder != null && loadFrom.InventoryObjectBuilder.InventoryItems != null) { var result = loadFrom.InventoryObjectBuilder.InventoryItems.Select(s => s.ItemObjectBuilder).OfType <MyMwcObjectBuilder_Player>().Where(s => s.Name.StartsWith(CoopPlayerPrefix)); foreach (var pl in result.ToArray()) { copyTo.StoreCoopPlayer((MyMwcObjectBuilder_Player)pl.Clone()); } } }
private void SandboxSectorLoaded(MyMwcVector3Int targetSector, MyMwcObjectBuilder_Checkpoint checkpoint, MyMwcObjectBuilder_Sector cachedSector, MyMwcStartSessionRequestTypeEnum startSessionType, MyMissionID?startMission) { if (checkpoint.SectorObjectBuilder == null) // Server said, use cache { checkpoint.SectorObjectBuilder = cachedSector; } else { MyLocalCache.SaveCheckpoint(checkpoint); } MyGuiScreenGamePlay.ReloadGameplayScreen(checkpoint, startSessionType, MyGuiScreenGamePlayType.GAME_SANDBOX, startMission); }
private static void StoreCoopPlayer(this MyMwcObjectBuilder_Checkpoint checkpoint, MyMwcObjectBuilder_Player playerBuilder) { if (checkpoint != null) { if (checkpoint.InventoryObjectBuilder == null) { checkpoint.InventoryObjectBuilder = (MyMwcObjectBuilder_Inventory)MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.Inventory, null); } // Remove old and add new checkpoint.InventoryObjectBuilder.InventoryItems.RemoveAll(new Predicate <MyMwcObjectBuilder_InventoryItem>(s => s.ItemObjectBuilder.Name == playerBuilder.Name)); checkpoint.InventoryObjectBuilder.InventoryItems.Add(new MyMwcObjectBuilder_InventoryItem(playerBuilder, 1)); } }
public MyMwcObjectBuilder_Checkpoint GetCheckpointBuilder(bool includeSector) { MyMwcObjectBuilder_Checkpoint checkpoint = new MyMwcObjectBuilder_Checkpoint(); if (includeSector) { checkpoint.SectorObjectBuilder = new MyMwcObjectBuilder_Sector(); List <MyMwcObjectBuilder_Base> sectorObjectBuilders = GetSectorObjectBuilders(); foreach (MyMwcObjectBuilder_Base objectBuilder in sectorObjectBuilders) { System.Diagnostics.Debug.Assert(objectBuilder != null, "If object is not to be saved, unset his EntityFlags::Save!"); } checkpoint.SectorObjectBuilder.SectorObjects = sectorObjectBuilders; checkpoint.SectorObjectBuilder.ObjectGroups = MyEditor.Static.ObjectGroups.ConvertAll(a => a.GetObjectBuilder()); checkpoint.SectorObjectBuilder.SnapPointLinks = MyEditor.Static.GetSnapPointLinkBuilders(); if (MyGuiScreenGamePlay.Static.Checkpoint.SectorObjectBuilder != null) { checkpoint.SectorObjectBuilder.Name = MyGuiScreenGamePlay.Static.Checkpoint.SectorObjectBuilder.Name; checkpoint.SectorObjectBuilder.Position = MyGuiScreenGamePlay.Static.Checkpoint.SectorObjectBuilder.Position; } } checkpoint.CurrentSector = MyGuiScreenGamePlay.Static.GetSectorIdentifier(); checkpoint.CheckpointName = null; checkpoint.PlayerObjectBuilder = MySession.Static.Player.GetObjectBuilder(true); checkpoint.SessionObjectBuilder = GetObjectBuilder(); checkpoint.EventLogObjectBuilder = EventLog.GetObjectBuilder(); checkpoint.FactionRelationChangesBuilder = FactionRelationChanges.GetObjectBuilders(); checkpoint.GameTime = GameDateTime; checkpoint.ActiveMissionID = MyMissions.ActiveMission == null ? -1 : (int)MyMissions.ActiveMission.ID; if (CanSaveAndLoadSessionInventory) { checkpoint.InventoryObjectBuilder = Inventory.GetObjectBuilder(true); } else { checkpoint.InventoryObjectBuilder = new MyMwcObjectBuilder_Inventory(new List <MyMwcObjectBuilder_InventoryItem>(), MyInventory.DEFAULT_MAX_ITEMS); } MotherShipPosition.Save(checkpoint.Dictionary); if (MyMultiplayerGameplay.GameType == MyGameTypes.Story) { MyGuiScreenGamePlay.Static.Checkpoint.CopyCoopPlayers(checkpoint); } CheckEntityIds(checkpoint); return(checkpoint); }
public static string GetChapterName(MyMwcObjectBuilder_Checkpoint checkpoint) { StringBuilder chapterName = new StringBuilder(); chapterName.Append(checkpoint.ActiveMissionID.ToString()); var lastEvent = checkpoint.EventLogObjectBuilder.Where(e => e.EventType == (int)MinerWars.AppCode.Game.Journal.EventTypeEnum.SubmissionFinished).OrderByDescending(e => e.Time).FirstOrDefault(); if (lastEvent != null) { chapterName.Append("_"); chapterName.Append(lastEvent.EventTypeID); } return(chapterName.ToString()); }
public static MyMwcObjectBuilder_Player LoadCoopPlayer(this MyMwcObjectBuilder_Checkpoint checkpoint, string displayName) { string name = CoopPlayerPrefix + displayName; if (checkpoint != null && checkpoint.InventoryObjectBuilder != null && checkpoint.InventoryObjectBuilder.InventoryItems != null) { var result = checkpoint.InventoryObjectBuilder.InventoryItems.Select(s => s.ItemObjectBuilder).OfType <MyMwcObjectBuilder_Player>().FirstOrDefault(s => s.Name == name); if (result != null) { result.Name = displayName; return(result); } } return(null); }
/// <summary> /// Checks missing objects, returns true when save sector, false when abort saving /// </summary> StringBuilder CheckMissingObject(MyMwcObjectBuilder_Checkpoint checkpoint) { if (MyMwcFinalBuildConstants.IS_DEVELOP && (MyFakes.DUMP_MISSING_OBJECTS || MyFakes.SHOW_MISSING_OBJECTS)) { var missing = MyGuiScreenGamePlay.FindMissingObjectBuilders(checkpoint); if (MyFakes.DUMP_MISSING_OBJECTS) { DumpMissingObjects(missing); } if (MyFakes.SHOW_MISSING_OBJECTS) { return(GetMissingObjects(missing)); // false to abort saving } } return(null); }
internal void Init(MyMwcObjectBuilder_Checkpoint checkpointObjectBuilder) { Debug.Assert(checkpointObjectBuilder != null); if (checkpointObjectBuilder.EventLogObjectBuilder == null) { return; } Events.Clear(); foreach (MyMwcObjectBuilder_Event eventLogEntryObjectBuilder in checkpointObjectBuilder.EventLogObjectBuilder) { var eventLogEntry = new MyEventLogEntry(); eventLogEntry.Init(eventLogEntryObjectBuilder); Events.Add(eventLogEntry); } }
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!"); }
/// <summary> /// This method is called when sector and all entities are loaded (created from object builder - or generated other way). /// It raises LinkEntities event, and calls method MyEntities.Link. /// </summary> public void AfterLoad(MyMwcObjectBuilder_Checkpoint checkpoint) { CheckpointName = checkpoint.CheckpointName; MyEntityIdentifier.AllocationSuspended = false; var handler = LinkEntities; if (handler != null) { handler(); } MyEntities.Link(); MyWayPointGraph.DeleteNullVerticesFromPaths(); MyWayPointGraph.RemoveWaypointsAroundLargeStaticObjects(); FactionRelationChanges.Init(checkpoint.FactionRelationChangesBuilder); // GPS waypoints must be created after the first physics pass: see end of MyGuiScreenGamePlay.Update() }
private void CheckEntityIds(MyMwcObjectBuilder_Checkpoint checkpoint) { if (checkpoint.SectorObjectBuilder == null) { return; } foreach (var builder in checkpoint.SectorObjectBuilder.SectorObjects) { if (builder.EntityId.HasValue) { if (builder.EntityId.Value == checkpoint.PlayerObjectBuilder.ShipObjectBuilder.EntityId || checkpoint.PlayerObjectBuilder.ShipObjectBuilder.Inventory.InventoryItems.Select(s => s.EntityId).Any(id => id == builder.EntityId)) { Debug.Fail("Entity ID of object is same as playership or something in playership inventory"); } } } }
private MyGuiScreenEditorSaveProgress Save(bool saveSector, string checkpointName, bool asTemplate, bool visibleSave, bool pause) { MyMwcSectorIdentifier sectorId = MyGuiScreenGamePlay.Static.GetSectorIdentifier(); bool isEditor = MyGuiScreenGamePlay.Static.IsEditorActive(); if (CanBeSaved(asTemplate, sectorId, isEditor)) { MyMwcObjectBuilder_Checkpoint checkpoint = GetCheckpointBuilder(saveSector); checkpoint.CheckpointName = checkpointName; // Need to store actual checkpoint...because when we travel, we receive only sector, not checkpoint MyGuiScreenGamePlay.Static.AddEnterSectorResponse(checkpoint, null); bool savePlayerShip = MyGuiScreenGamePlay.Static.GetGameType() == MyGuiScreenGamePlayType.EDITOR_STORY ? MyEditor.SavePlayerShip : true; if (savePlayerShip && saveSector) { UpdatePlayerStartDummy(checkpoint); } MyHudNotification.MyNotification notification = null; if (!visibleSave) { notification = new MyHudNotification.MyNotification(Localization.MyTextsWrapperEnum.SavingSectorToServer, 2500); MyHudNotification.AddNotification(notification); } StringBuilder errors = null; if (isEditor) { errors = CheckMissingObject(checkpoint); } MyGuiScreenEditorSaveProgress screen = new MyGuiScreenEditorSaveProgress(sectorId, checkpoint, savePlayerShip, visibleSave, pause); //screen.Closed += new MyGuiScreenBase.ScreenHandler((s) => { if (notification != null) notification.Disappear(); }); CheckErrors(errors, screen); return(screen); } return(null); }
void OnGameJoined(MyGameInfo game, MyResultCodeEnum resultCode, MyMwcObjectBuilder_Checkpoint checkpointBuilder) { Debug.Assert(m_waitingScreen != null); m_waitingScreen.CloseScreen(); if (resultCode == MyResultCodeEnum.OK) { var loadingScreen = MySession.StartJoinMultiplayerSession(game.GameType, game.Difficulty, checkpointBuilder); loadingScreen.Closed += new MyGuiScreenBase.ScreenHandler(OnLoadFinished); } else if (resultCode == MyResultCodeEnum.GAME_NOT_EXISTS) { MyGuiManager.AddModalScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.MP_GameHasEnded, MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null), null); GetDataFromServer(true); } else { MyGuiManager.AddModalScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.ErrorCreatingNetworkConnection, MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null), null); GetDataFromServer(true); } }
private static void UpdatePlayerStartDummy(MyMwcObjectBuilder_Checkpoint checkpoint) { var dummyBuilder = checkpoint.SectorObjectBuilder.SectorObjects.OfType <MyMwcObjectBuilder_DummyPoint>().FirstOrDefault(s => (s.DummyFlags & MyDummyPointFlags.PLAYER_START) > 0); if (dummyBuilder == null) { dummyBuilder = MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.DummyPoint, null) as MyMwcObjectBuilder_DummyPoint; dummyBuilder.DummyFlags = MyDummyPointFlags.PLAYER_START; checkpoint.SectorObjectBuilder.SectorObjects.Add(dummyBuilder); var dummyEntity = new MyDummyPoint(); dummyEntity.Init(String.Empty, dummyBuilder, MySession.PlayerShip.WorldMatrix); MyEntities.Add(dummyEntity); } MyGuiScreenGamePlay.Static.ClampPlayerToBorderSafeArea(); dummyBuilder.PositionAndOrientation.Position = MySession.PlayerShip.WorldMatrix.Translation; dummyBuilder.PositionAndOrientation.Forward = MySession.PlayerShip.WorldMatrix.Forward; dummyBuilder.PositionAndOrientation.Up = MySession.PlayerShip.WorldMatrix.Up; }
public static MyMwcObjectBuilder_Checkpoint LoadCheckpoint(string checkpointPath) { // TODO: This should be replaced by LoadData<> method MyMwcObjectBuilder_Checkpoint result = null; if (File.Exists(checkpointPath)) { using (BinaryReader checkpointReader = new BinaryReader(new FileStream(checkpointPath, FileMode.Open, FileAccess.Read))) { var version = checkpointReader.ReadInt32(); if (version < MyMwcObjectBuilder_Base.FIRST_COMPATIBILITY_VERSION) { MyMwcLog.WriteLine("Loading data from " + checkpointPath + " failed because of incompatible version, save version: " + version); return(null); } result = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Checkpoint>(checkpointReader.ReadBytes((int)checkpointReader.BaseStream.Length), version); //result.SectorObjectBuilder = LoadSector(result.CurrentSector); } } return(result); }
public static void Save(MyMwcObjectBuilder_Checkpoint checkpoint, MyMwcObjectBuilder_Sector sector, MyMwcSectorIdentifier sectorIdentifier, bool createChapter = false) { if (sector == null) // Nothing to save, saving only checkpoint { return; } string sectorPath = GetSectorPath(sectorIdentifier); string storeDirectory = Path.GetDirectoryName(sectorPath); // Store current sector SaveData(sector, sectorPath); // Store checkpoint if (checkpoint != null) { string checkpointPath = Path.Combine(storeDirectory, "Checkpoint.mwc"); var oldValue = checkpoint.SectorObjectBuilder; checkpoint.SectorObjectBuilder = null; SaveData(checkpoint, checkpointPath); checkpoint.SectorObjectBuilder = oldValue; } if (createChapter) { var chapterDirectory = GetChapterDirectory(GetChapterName(checkpoint)); if (Directory.Exists(chapterDirectory)) { Directory.Delete(chapterDirectory, true); } DirectoryExtensions.CopyAll(storeDirectory, chapterDirectory); } Log("update", sectorIdentifier, sector.Version); }
public static MyGuiScreenLoading StartJoinMultiplayerSession(MyGameTypes gameType, MyGameplayDifficultyEnum difficulty, MyMwcObjectBuilder_Checkpoint checkpoint) { // Temporary MySession.Static = new MySinglePlayerSession(difficulty); MySession.Static.Init(); return(MySession.Static.JoinMultiplayerSession(gameType, checkpoint)); }
public void AddEnterSectorResponse(MyMwcObjectBuilder_Checkpoint checkpoint, MyMissionID?missionID) { m_screenToLoad.AddEnterSectorResponse(checkpoint, missionID); }
public static void StoreCoopPlayer(this MyMwcObjectBuilder_Checkpoint checkpoint, MyMwcObjectBuilder_Player playerBuilder, string displayName) { playerBuilder.Name = CoopPlayerPrefix + displayName; StoreCoopPlayer(checkpoint, playerBuilder); }
public static bool CanBeSaved(MyMwcObjectBuilder_Checkpoint checkpoint) { // Story checkpoint (STORY && UserId != null) return(IsSupported(checkpoint.CurrentSector.SectorType, checkpoint.CurrentSector.UserId)); }
//public static bool SectorExists(MyMwcSectorIdentifier sector) //{ // return File.Exists(GetSectorPath(sector)); //} public static void SaveCheckpoint(MyMwcObjectBuilder_Checkpoint checkpoint, bool createChapter = false) { Save(checkpoint, checkpoint.SectorObjectBuilder, checkpoint.CurrentSector, createChapter); }
public bool Read(MyMessageReader msg) { Checkpoint = MyMwcObjectBuilder_Base.ReadAndCreateNewObject(msg.Reader, msg.EndPoint) as MyMwcObjectBuilder_Checkpoint; return(Checkpoint != null && Checkpoint.Read(msg.Reader, msg.EndPoint, MyMwcFinalBuildConstants.SERVER_PROTOCOL_VERSION)); }
private void LastCheckpointSectorLoaded(MyMwcObjectBuilder_Checkpoint checkpoint, byte[] sectorData) { checkpoint.SectorObjectBuilder = MyMwcObjectBuilder_Base.FromBytes <MyMwcObjectBuilder_Sector>(sectorData); MyGuiScreenGamePlay.ReloadGameplayScreen(checkpoint, MyMwcStartSessionRequestTypeEnum.LOAD_CHECKPOINT, MyGuiScreenGamePlayType.GAME_STORY); }
private void ReloadGameplayNewGame(MyMwcObjectBuilder_Checkpoint checkpoint, MyMissionID missionId) { MyGuiScreenGamePlay.ReloadGameplayScreen(checkpoint, MyMwcStartSessionRequestTypeEnum.NEW_STORY, MyGuiScreenGamePlayType.GAME_STORY, missionId, MyMwcTravelTypeEnum.SOLAR); }