public override void Update(float deltaTime) { if (!isRunning) { return; } base.Update(deltaTime); if (ContextualTutorial.Initialized) { ContextualTutorial.Update(deltaTime); } if (!GUI.DisableHUD && !GUI.DisableUpperHUD) { endRoundButton.UpdateManually(deltaTime); } if (!crewDead) { if (!CrewManager.GetCharacters().Any(c => !c.IsDead)) { crewDead = true; } } else { endTimer -= deltaTime; if (endTimer <= 0.0f) { EndRound(leavingSub: null); } } }
private bool SelectInfoFrameTab(GUIButton button, object userData) { selectedTab = (InfoFrameTab)userData; CreateInfoFrame(); switch (selectedTab) { case InfoFrameTab.Crew: CrewManager.CreateCrewListFrame(CrewManager.GetCharacters(), infoFrameContent); break; case InfoFrameTab.Mission: CreateMissionInfo(infoFrameContent); break; case InfoFrameTab.MyCharacter: if (GameMain.NetworkMember == null) { return(false); } GameMain.NetLobbyScreen.CreatePlayerFrame(infoFrameContent); break; case InfoFrameTab.ManagePlayers: //TODO: fix //GameMain.Server.ManagePlayersFrame(infoFrameContent); break; } return(true); }
public override void Update(float deltaTime) { if (!isRunning || GUI.DisableHUD) { return; } base.Update(deltaTime); endRoundButton.UpdateManually(deltaTime); if (!crewDead) { if (!CrewManager.GetCharacters().Any(c => !c.IsDead)) { crewDead = true; } } else { endTimer -= deltaTime; if (endTimer <= 0.0f) { EndRound(null, null); } } }
public override void Update(float deltaTime) { base.Update(deltaTime); if (!IsRunning) { return; } if (GameMain.NetworkMember != null && GameMain.NetworkMember.IsClient) { return; } if (!watchmenSpawned) { if (Level.Loaded.StartOutpost != null) { startWatchman = SpawnWatchman(Level.Loaded.StartOutpost); } if (Level.Loaded.EndOutpost != null) { endWatchman = SpawnWatchman(Level.Loaded.EndOutpost); } watchmenSpawned = true; #if SERVER (this as MultiPlayerCampaign).LastUpdateID++; #endif } else { foreach (Character character in Character.CharacterList) { #if SERVER if (string.IsNullOrEmpty(character.OwnerClientEndPoint)) { continue; } #else if (!CrewManager.GetCharacters().Contains(character)) { continue; } #endif if (character.Submarine == Level.Loaded.StartOutpost && Vector2.DistanceSquared(character.WorldPosition, startWatchman.WorldPosition) < 500.0f * 500.0f) { CreateDialog(new List <Character> { startWatchman }, "EnterStartOutpost", 5 * 60.0f); } else if (character.Submarine == Level.Loaded.EndOutpost && Vector2.DistanceSquared(character.WorldPosition, endWatchman.WorldPosition) < 500.0f * 500.0f) { CreateDialog(new List <Character> { endWatchman }, "EnterEndOutpost", 5 * 60.0f); } } } }
public override void End(TransitionType transitionType = TransitionType.None) { base.End(transitionType); ForceMapUI = ShowCampaignUI = false; UpgradeManager.CanUpgrade = true; // remove all event dialogue boxes GUIMessageBox.MessageBoxes.ForEachMod(mb => { if (mb is GUIMessageBox msgBox) { if (ReadyCheck.IsReadyCheck(mb) || mb.UserData is Pair <string, ushort> pair && pair.First.Equals("conversationaction", StringComparison.OrdinalIgnoreCase)) { msgBox.Close(); } } }); if (transitionType == TransitionType.End) { EndCampaign(); } else { IsFirstRound = false; CoroutineManager.StartCoroutine(DoLevelTransition(), "LevelTransition"); bool success = CrewManager.GetCharacters().Any(c => !c.IsDead); GUI.SetSavingIndicatorState(success && (Level.IsLoadedOutpost || transitionType != TransitionType.None)); } }
public override void Update(float deltaTime) { base.Update(deltaTime); if (!IsRunning) { return; } #if CLIENT if (GameMain.Client != null) { return; } #endif if (!watchmenSpawned) { if (Level.Loaded.StartOutpost != null) { startWatchman = SpawnWatchman(Level.Loaded.StartOutpost); } if (Level.Loaded.EndOutpost != null) { endWatchman = SpawnWatchman(Level.Loaded.EndOutpost); } watchmenSpawned = true; #if SERVER (this as MultiPlayerCampaign).LastUpdateID++; #endif } else { foreach (Character character in Character.CharacterList) { #if SERVER if (string.IsNullOrEmpty(character.OwnerClientIP)) { continue; } #else if (!CrewManager.GetCharacters().Contains(character)) { continue; } #endif if (character.Submarine == Level.Loaded.StartOutpost && character.CurrentHull == startWatchman.CurrentHull) { CreateDialog(new List <Character> { startWatchman }, "EnterStartOutpost", 5 * 60.0f); } else if (character.Submarine == Level.Loaded.EndOutpost && character.CurrentHull == endWatchman.CurrentHull) { CreateDialog(new List <Character> { endWatchman }, "EnterEndOutpost", 5 * 60.0f); } } } }
private bool EndRound(Submarine leavingSub) { isRunning = false; //var cinematic = new RoundEndCinematic(leavingSub, GameMain.GameScreen.Cam, 5.0f); SoundPlayer.OverrideMusicType = CrewManager.GetCharacters().Any(c => !c.IsDead) ? "endround" : "crewdead"; SoundPlayer.OverrideMusicDuration = 18.0f; //CoroutineManager.StartCoroutine(EndCinematic(cinematic), "EndCinematic"); End(""); return(true); }
private bool SelectInfoFrameTab(GUIButton button, object userData) { selectedTab = (InfoFrameTab)userData; CreateInfoFrame(); switch (selectedTab) { case InfoFrameTab.Crew: CrewManager.CreateCrewFrame(CrewManager.GetCharacters(), infoFrame.children[0] as GUIFrame); break; case InfoFrameTab.Mission: CreateMissionInfo(infoFrame.children[0] as GUIFrame); break; case InfoFrameTab.ManagePlayers: GameMain.Server.ManagePlayersFrame(infoFrame.children[0] as GUIFrame); break; } return(true); }
private bool EndRound(GUIButton button, object obj) { isRunning = false; List <Submarine> leavingSubs = obj as List <Submarine>; if (leavingSubs == null) { leavingSubs = new List <Submarine>() { GetLeavingSub() } } ; var cinematic = new TransitionCinematic(leavingSubs, GameMain.GameScreen.Cam, 5.0f); SoundPlayer.OverrideMusicType = CrewManager.GetCharacters().Any(c => !c.IsDead) ? "endround" : "crewdead"; SoundPlayer.OverrideMusicDuration = 18.0f; CoroutineManager.StartCoroutine(EndCinematic(cinematic), "EndCinematic"); return(true); }
private IEnumerable <object> DoLevelTransition() { SoundPlayer.OverrideMusicType = CrewManager.GetCharacters().Any(c => !c.IsDead) ? "endround" : "crewdead"; SoundPlayer.OverrideMusicDuration = 18.0f; Level prevLevel = Level.Loaded; bool success = CrewManager.GetCharacters().Any(c => !c.IsDead); crewDead = false; var continueButton = GameMain.GameSession.RoundSummary?.ContinueButton; if (continueButton != null) { continueButton.Visible = false; } Character.Controlled = null; yield return(new WaitForSeconds(0.1f)); GameMain.Client.EndCinematic?.Stop(); var endTransition = new CameraTransition(Submarine.MainSub, GameMain.GameScreen.Cam, null, Alignment.Center, fadeOut: false, duration: EndTransitionDuration); GameMain.Client.EndCinematic = endTransition; Location portraitLocation = Map?.SelectedLocation ?? Map?.CurrentLocation ?? Level.Loaded?.StartLocation; if (portraitLocation != null) { overlaySprite = portraitLocation.Type.GetPortrait(portraitLocation.PortraitId); } float fadeOutDuration = endTransition.Duration; float t = 0.0f; while (t < fadeOutDuration || endTransition.Running) { t += CoroutineManager.UnscaledDeltaTime; overlayColor = Color.Lerp(Color.Transparent, Color.White, t / fadeOutDuration); yield return(CoroutineStatus.Running); } overlayColor = Color.White; yield return(CoroutineStatus.Running); //-------------------------------------- //wait for the new level to be loaded DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, seconds: 30); while (Level.Loaded == prevLevel || Level.Loaded == null) { if (DateTime.Now > timeOut || Screen.Selected != GameMain.GameScreen) { break; } yield return(CoroutineStatus.Running); } endTransition.Stop(); overlayColor = Color.Transparent; if (DateTime.Now > timeOut) { GameMain.NetLobbyScreen.Select(); } if (!(Screen.Selected is RoundSummaryScreen)) { if (continueButton != null) { continueButton.Visible = true; } } yield return(CoroutineStatus.Success); }
public override void End(string endMessage = "") { isRunning = false; bool success = CrewManager.GetCharacters().Any(c => !c.IsDead); crewDead = false; if (success) { if (subsToLeaveBehind == null || leavingSub == null) { DebugConsole.ThrowError("Leaving submarine not selected -> selecting the closest one"); leavingSub = GetLeavingSub(); subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub); } } GameMain.GameSession.EndRound(""); if (success) { if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub)) { Submarine.MainSub = leavingSub; GameMain.GameSession.Submarine = leavingSub; foreach (Submarine sub in subsToLeaveBehind) { MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine); LinkedSubmarine.CreateDummy(leavingSub, sub); } } if (atEndPosition) { Map.MoveToNextLocation(); } else { Map.SelectLocation(-1); } Map.ProgressWorld(); //save and remove all items that are in someone's inventory foreach (Character c in Character.CharacterList) { if (c.Info == null || c.Inventory == null) { continue; } var inventoryElement = new XElement("inventory"); c.SaveInventory(c.Inventory, inventoryElement); c.Info.InventoryData = inventoryElement; c.Inventory?.DeleteAllItems(); } SaveUtil.SaveGame(GameMain.GameSession.SavePath); } if (!success) { var summaryScreen = GUIMessageBox.VisibleBox; if (summaryScreen != null) { summaryScreen = summaryScreen.Children.First(); var buttonArea = summaryScreen.Children.First().FindChild("buttonarea"); buttonArea.ClearChildren(); summaryScreen.RemoveChild(summaryScreen.Children.FirstOrDefault(c => c is GUIButton)); var okButton = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform), TextManager.Get("LoadGameButton")) { OnClicked = (GUIButton button, object obj) => { GameMain.GameSession.LoadPrevious(); GameMain.LobbyScreen.Select(); GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); return(true); } }; var quitButton = new GUIButton(new RectTransform(new Vector2(0.2f, 1.0f), buttonArea.RectTransform), TextManager.Get("QuitButton")); quitButton.OnClicked += GameMain.LobbyScreen.QuitToMainMenu; quitButton.OnClicked += (GUIButton button, object obj) => { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); return(true); }; quitButton.OnClicked += (GUIButton button, object obj) => { if (ContextualTutorial.Initialized) { ContextualTutorial.Stop(); } return(true); }; } } CrewManager.EndRound(); for (int i = Character.CharacterList.Count - 1; i >= 0; i--) { Character.CharacterList[i].Remove(); } Submarine.Unload(); GameMain.LobbyScreen.Select(); }
public override void Update(float deltaTime) { if (CoroutineManager.IsCoroutineRunning("LevelTransition") || CoroutineManager.IsCoroutineRunning("SubmarineTransition") || gameOver) { return; } base.Update(deltaTime); if (PlayerInput.SecondaryMouseButtonClicked() || PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.Escape)) { ShowCampaignUI = false; if (GUIMessageBox.VisibleBox?.UserData is RoundSummary roundSummary && roundSummary.ContinueButton != null && roundSummary.ContinueButton.Visible) { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.VisibleBox); } } #if DEBUG if (PlayerInput.KeyHit(Microsoft.Xna.Framework.Input.Keys.R)) { if (GUIMessageBox.MessageBoxes.Any()) { GUIMessageBox.MessageBoxes.Remove(GUIMessageBox.MessageBoxes.Last()); } GUIFrame summaryFrame = GameMain.GameSession.RoundSummary.CreateSummaryFrame(GameMain.GameSession, "", null); GUIMessageBox.MessageBoxes.Add(summaryFrame); GameMain.GameSession.RoundSummary.ContinueButton.OnClicked = (_, __) => { GUIMessageBox.MessageBoxes.Remove(summaryFrame); return(true); }; } #endif if (ShowCampaignUI || ForceMapUI) { Character.DisableControls = true; } if (!GUI.DisableHUD && !GUI.DisableUpperHUD) { endRoundButton.UpdateManually(deltaTime); if (CoroutineManager.IsCoroutineRunning("LevelTransition") || ForceMapUI) { return; } } if (Level.Loaded.Type == LevelData.LevelType.Outpost) { KeepCharactersCloseToOutpost(deltaTime); if (wasDocked) { var connectedSubs = Submarine.MainSub.GetConnectedSubs(); bool isDocked = Level.Loaded.StartOutpost != null && connectedSubs.Contains(Level.Loaded.StartOutpost); if (!isDocked) { //undocked from outpost, need to choose a destination ForceMapUI = true; CampaignUI.SelectTab(InteractionType.Map); } } else { //wasn't initially docked (sub doesn't have a docking port?) // -> choose a destination when the sub is far enough from the start outpost if (!Submarine.MainSub.AtStartPosition) { ForceMapUI = true; CampaignUI.SelectTab(InteractionType.Map); } } } else { var transitionType = GetAvailableTransition(out _, out Submarine leavingSub); if (transitionType == TransitionType.End) { EndCampaign(); } if (transitionType == TransitionType.ProgressToNextLocation && Level.Loaded.EndOutpost != null && Level.Loaded.EndOutpost.DockedTo.Contains(leavingSub)) { LoadNewLevel(); } else if (transitionType == TransitionType.ReturnToPreviousLocation && Level.Loaded.StartOutpost != null && Level.Loaded.StartOutpost.DockedTo.Contains(leavingSub)) { LoadNewLevel(); } else if (transitionType == TransitionType.None && CampaignUI.SelectedTab == InteractionType.Map) { ShowCampaignUI = false; } } if (!crewDead) { if (!CrewManager.GetCharacters().Any(c => !c.IsDead)) { crewDead = true; } } else { endTimer -= deltaTime; if (endTimer <= 0.0f) { GameOver(); } } }
protected override IEnumerable <object> DoLevelTransition(TransitionType transitionType, LevelData newLevel, Submarine leavingSub, bool mirror, List <TraitorMissionResult> traitorResults = null) { NextLevel = newLevel; bool success = CrewManager.GetCharacters().Any(c => !c.IsDead); SoundPlayer.OverrideMusicType = success ? "endround" : "crewdead"; SoundPlayer.OverrideMusicDuration = 18.0f; crewDead = false; GameMain.GameSession.EndRound("", traitorResults, transitionType); var continueButton = GameMain.GameSession.RoundSummary?.ContinueButton; RoundSummary roundSummary = null; if (GUIMessageBox.VisibleBox?.UserData is RoundSummary) { roundSummary = GUIMessageBox.VisibleBox?.UserData as RoundSummary; } if (continueButton != null) { continueButton.Visible = false; } lastControlledCharacter = Character.Controlled; Character.Controlled = null; switch (transitionType) { case TransitionType.None: throw new InvalidOperationException("Level transition failed (no transitions available)."); case TransitionType.ReturnToPreviousLocation: //deselect destination on map map.SelectLocation(-1); break; case TransitionType.ProgressToNextLocation: Map.MoveToNextLocation(); break; } Map.ProgressWorld(transitionType, (float)(Timing.TotalTime - GameMain.GameSession.RoundStartTime)); var endTransition = new CameraTransition(Submarine.MainSub, GameMain.GameScreen.Cam, null, transitionType == TransitionType.LeaveLocation ? Alignment.BottomCenter : Alignment.Center, fadeOut: false, duration: EndTransitionDuration); GUI.ClearMessages(); Location portraitLocation = Map.SelectedLocation ?? Map.CurrentLocation; overlaySprite = portraitLocation.Type.GetPortrait(portraitLocation.PortraitId); float fadeOutDuration = endTransition.Duration; float t = 0.0f; while (t < fadeOutDuration || endTransition.Running) { t += CoroutineManager.UnscaledDeltaTime; overlayColor = Color.Lerp(Color.Transparent, Color.White, t / fadeOutDuration); yield return(CoroutineStatus.Running); } overlayColor = Color.White; yield return(CoroutineStatus.Running); //-------------------------------------- bool save = false; if (success) { if (leavingSub != Submarine.MainSub && !leavingSub.DockedTo.Contains(Submarine.MainSub)) { Submarine.MainSub = leavingSub; GameMain.GameSession.Submarine = leavingSub; var subsToLeaveBehind = GetSubsToLeaveBehind(leavingSub); foreach (Submarine sub in subsToLeaveBehind) { MapEntity.mapEntityList.RemoveAll(e => e.Submarine == sub && e is LinkedSubmarine); LinkedSubmarine.CreateDummy(leavingSub, sub); } } GameMain.GameSession.SubmarineInfo = new SubmarineInfo(GameMain.GameSession.Submarine); if (PendingSubmarineSwitch != null) { SubmarineInfo previousSub = GameMain.GameSession.SubmarineInfo; GameMain.GameSession.SubmarineInfo = PendingSubmarineSwitch; PendingSubmarineSwitch = null; for (int i = 0; i < GameMain.GameSession.OwnedSubmarines.Count; i++) { if (GameMain.GameSession.OwnedSubmarines[i].Name == previousSub.Name) { GameMain.GameSession.OwnedSubmarines[i] = previousSub; break; } } } SaveUtil.SaveGame(GameMain.GameSession.SavePath); } else { PendingSubmarineSwitch = null; EnableRoundSummaryGameOverState(); } //-------------------------------------- SelectSummaryScreen(roundSummary, newLevel, mirror, () => { GameMain.GameScreen.Select(); if (continueButton != null) { continueButton.Visible = true; } GUI.DisableHUD = false; GUI.ClearCursorWait(); overlayColor = Color.Transparent; }); yield return(CoroutineStatus.Success); }
public void UpdateCharacters() { CreateGUIFrame(); List <GUIComponent> prevCharacterFrames = new List <GUIComponent>(); foreach (GUIComponent child in frame.children) { if (!(child.UserData is Character)) { continue; } prevCharacterFrames.Add(child); } foreach (GUIComponent child in prevCharacterFrames) { frame.RemoveChild(child); } List <Character> aliveCharacters = crewManager.GetCharacters().FindAll(c => !c.IsDead && c.AIController is HumanAIController); characterFrameBottom = 0; int charactersPerRow = 4; int spacing = 5; int i = 0; foreach (Character character in aliveCharacters) { int rowCharacterCount = Math.Min(charactersPerRow, aliveCharacters.Count); //if (i >= aliveCharacters.Count - charactersPerRow && aliveCharacters.Count % charactersPerRow > 0) rowCharacterCount = aliveCharacters.Count % charactersPerRow; // rowCharacterCount = Math.Min(rowCharacterCount, aliveCharacters.Count - i); int startX = -(150 * rowCharacterCount + spacing * (rowCharacterCount - 1)) / 2; int x = startX + (150 + spacing) * (i % Math.Min(charactersPerRow, aliveCharacters.Count)); int y = (105 + spacing) * ((int)Math.Floor((double)i / charactersPerRow)); GUIButton characterButton = new GUIButton(new Rectangle(x + 75, y, 150, 40), "", null, Alignment.TopCenter, "GUITextBox", frame); characterButton.UserData = character; characterButton.Padding = new Vector4(5.0f, 5.0f, 5.0f, 5.0f); characterButton.Color = Character.Controlled == character ? Color.Gold : Color.White; /*characterButton.HoverColor = Color.LightGray * 0.5f; * characterButton.SelectedColor = Color.Gold * 0.6f; * characterButton.OutlineColor = Color.LightGray * 0.8f;*/ characterFrameBottom = Math.Max(characterFrameBottom, characterButton.Rect.Bottom); string name = character.Info.Name; if (character.Info.Job != null) { name += '\n' + "(" + character.Info.Job.Name + ")"; } GUITextBlock textBlock = new GUITextBlock( new Rectangle(40, 0, 0, 25), name, Color.Transparent, null, Alignment.Left, Alignment.Left, "", characterButton, false); textBlock.Font = GUI.SmallFont; textBlock.Padding = new Vector4(5.0f, 0.0f, 5.0f, 0.0f); new GUIImage(new Rectangle(-5, -5, 0, 0), character.AnimController.Limbs[0].sprite, Alignment.Left, characterButton); var humanAi = character.AIController as HumanAIController; if (humanAi != null && humanAi.CurrentOrder != null) { CreateCharacterOrderFrame(characterButton, humanAi.CurrentOrder, humanAi.CurrentOrderOption); } i++; } foreach (GUIComponent child in frame.children) { if (!(child.UserData is Order)) { continue; } Rectangle rect = child.Rect; rect.Y += characterFrameBottom; child.Rect = rect; } }