public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { receivedItemIDs = new ushort[capacity]; for (int i = 0; i < capacity; i++) { receivedItemIDs[i] = msg.ReadUInt16(); } //delay applying the new state if less than 1 second has passed since this client last sent a state to the server //prevents the inventory from briefly reverting to an old state if items are moved around in quick succession //also delay if we're still midround syncing, some of the items in the inventory may not exist yet if (syncItemsDelay > 0.0f || GameMain.Client.MidRoundSyncing) { if (syncItemsCoroutine != null) { CoroutineManager.StopCoroutines(syncItemsCoroutine); } syncItemsCoroutine = CoroutineManager.StartCoroutine(SyncItemsAfterDelay()); } else { if (syncItemsCoroutine != null) { CoroutineManager.StopCoroutines(syncItemsCoroutine); syncItemsCoroutine = null; } ApplyReceivedState(); } }
public void CreateAutonomousObjectives() { foreach (var delayedObjective in DelayedObjectives) { CoroutineManager.StopCoroutines(delayedObjective.Value); } DelayedObjectives.Clear(); Objectives.Clear(); AddObjective(new AIObjectiveFindSafety(character, this)); AddObjective(new AIObjectiveIdle(character, this)); int objectiveCount = Objectives.Count; foreach (var automaticOrder in character.Info.Job.Prefab.AutomaticOrders) { var orderPrefab = Order.GetPrefab(automaticOrder.identifier); if (orderPrefab == null) { throw new Exception($"Could not find a matching prefab by the identifier: '{automaticOrder.identifier}'"); } var item = orderPrefab.MustSetTarget ? orderPrefab.GetMatchingItems(character.Submarine, false)?.GetRandom() : null; var order = new Order(orderPrefab, item ?? character.CurrentHull as Entity, item?.Components.FirstOrDefault(ic => ic.GetType() == orderPrefab.ItemComponentType), orderGiver: character); if (order == null) { continue; } var objective = CreateObjective(order, automaticOrder.option, character, automaticOrder.priorityModifier); if (objective != null && objective.CanBeCompleted) { AddObjective(objective, delay: Rand.Value() / 2); objectiveCount++; } } _waitTimer = Math.Max(_waitTimer, Rand.Range(0.5f, 1f) * objectiveCount); }
private IEnumerable <object> WaitForCampaignSetup() { GUI.SetCursorWaiting(); string headerText = TextManager.Get("CampaignStartingPleaseWait"); var msgBox = new GUIMessageBox(headerText, TextManager.Get("CampaignStarting"), new string[] { TextManager.Get("Cancel") }); msgBox.Buttons[0].OnClicked = (btn, userdata) => { GameMain.NetLobbyScreen.HighlightMode(GameMain.NetLobbyScreen.SelectedModeIndex); GameMain.NetLobbyScreen.SelectMode(GameMain.NetLobbyScreen.SelectedModeIndex); GUI.ClearCursorWait(); CoroutineManager.StopCoroutines("WaitForCampaignSetup"); return(true); }; msgBox.Buttons[0].OnClicked += msgBox.Close; DateTime timeOut = DateTime.Now + new TimeSpan(0, 0, 10); while (GameMain.NetLobbyScreen.CampaignUI == null && DateTime.Now < timeOut) { msgBox.Header.Text = headerText + new string('.', ((int)Timing.TotalTime % 3 + 1)); yield return(CoroutineStatus.Running); } msgBox.Close(); GUI.ClearCursorWait(); yield return(CoroutineStatus.Success); }
private static bool QuitClicked(GUIButton button, object obj) { bool save = button.UserData as string == "save"; if (save) { SaveUtil.SaveGame(GameMain.GameSession.SavePath); } if (GameMain.NetworkMember != null) { GameMain.NetworkMember.Disconnect(); GameMain.NetworkMember = null; } CoroutineManager.StopCoroutines("EndCinematic"); if (GameMain.GameSession != null) { Mission mission = GameMain.GameSession.Mission; GameAnalyticsManager.AddDesignEvent("QuitRound:" + (save ? "Save" : "NoSave")); GameAnalyticsManager.AddDesignEvent("EndRound:" + (mission == null ? "NoMission" : (mission.Completed ? "MissionCompleted" : "MissionFailed"))); GameMain.GameSession = null; } GameMain.MainMenuScreen.Select(); return(true); }
public static void QuitToMainMenu(bool save) { if (save) { SaveUtil.SaveGame(GameMain.GameSession.SavePath); } if (GameMain.Client != null) { GameMain.Client.Disconnect(); GameMain.Client = null; } CoroutineManager.StopCoroutines("EndCinematic"); if (GameMain.GameSession != null) { if (Tutorial.Initialized) { ((TutorialMode)GameMain.GameSession.GameMode).Tutorial?.Stop(); } if (GameSettings.SendUserStatistics) { Mission mission = GameMain.GameSession.Mission; GameAnalyticsManager.AddDesignEvent("QuitRound:" + (save ? "Save" : "NoSave")); GameAnalyticsManager.AddDesignEvent("EndRound:" + (mission == null ? "NoMission" : (mission.Completed ? "MissionCompleted" : "MissionFailed"))); } GameMain.GameSession = null; } GUIMessageBox.CloseAll(); GameMain.MainMenuScreen.Select(); }
public void AddObjective <T>(T objective, float delay, Action callback = null) where T : AIObjective { if (objective == null) { #if DEBUG DebugConsole.ThrowError($"{character.Name}: Attempted to add a null objective to AIObjectiveManager\n" + Environment.StackTrace.CleanupStackTrace()); #endif return; } if (DelayedObjectives.TryGetValue(objective, out CoroutineHandle coroutine)) { CoroutineManager.StopCoroutines(coroutine); DelayedObjectives.Remove(objective); } coroutine = CoroutineManager.InvokeAfter(() => { //round ended before the coroutine finished #if CLIENT if (GameMain.GameSession == null || Level.Loaded == null && !(GameMain.GameSession.GameMode is TestGameMode)) { return; } #else if (GameMain.GameSession == null || Level.Loaded == null) { return; } #endif DelayedObjectives.Remove(objective); AddObjective(objective); callback?.Invoke(); }, delay); DelayedObjectives.Add(objective, coroutine); }
/// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { CoroutineManager.StopCoroutines("Load"); Video.Close(); VoipCapture.Instance?.Dispose(); SoundManager?.Dispose(); }
public void ClientRead(ServerNetObject type, NetBuffer msg, float sendingTime) { receivedItemIDs = new ushort[capacity]; for (int i = 0; i < capacity; i++) { receivedItemIDs[i] = msg.ReadUInt16(); } if (syncItemsDelay > 0.0f) { //delay applying the new state if less than 1 second has passed since this client last sent a state to the server //prevents the inventory from briefly reverting to an old state if items are moved around in quick succession if (syncItemsCoroutine != null) { CoroutineManager.StopCoroutines(syncItemsCoroutine); } syncItemsCoroutine = CoroutineManager.StartCoroutine(SyncItemsAfterDelay()); } else { ApplyReceivedState(); } }
public void Stop() { CoroutineManager.StopCoroutines(updateCoroutine); Running = false; #if CLIENT GUI.ScreenOverlayColor = Color.TransparentBlack; #endif }
partial void FadeOutColors() { if (fadeOutRoutine != null) { CoroutineManager.StopCoroutines(fadeOutRoutine); } fadeOutRoutine = CoroutineManager.StartCoroutine(FadeOutColors(Config.DeadEntityColorFadeOutTime)); }
/// <summary> /// UnloadContent will be called once per game and is the place to unload /// all content. /// </summary> protected override void UnloadContent() { TextureLoader.CancelAll(); CoroutineManager.StopCoroutines("Load"); Video.Close(); VoipCapture.Instance?.Dispose(); SoundManager?.Dispose(); MainThread = null; }
public static void StopAll() { CoroutineManager.StopCoroutines("statuseffect"); DelayedEffect.DelayList.Clear(); DurationList.Clear(); #if CLIENT //ActiveLoopingSounds.Clear(); #endif }
public void ShowBorderHighlight(Color color, float fadeInDuration, float fadeOutDuration) { if (highlightCoroutine != null) { CoroutineManager.StopCoroutines(highlightCoroutine); highlightCoroutine = null; } highlightCoroutine = CoroutineManager.StartCoroutine(UpdateBorderHighlight(color, fadeInDuration, fadeOutDuration)); }
public void CreateAutonomousObjectives() { if (character.IsDead) { #if DEBUG DebugConsole.ThrowError("Attempted to create autonomous orders for a dead character"); #else return; #endif } foreach (var delayedObjective in DelayedObjectives) { CoroutineManager.StopCoroutines(delayedObjective.Value); } DelayedObjectives.Clear(); Objectives.Clear(); FailedAutonomousObjectives = false; AddObjective(new AIObjectiveFindSafety(character, this)); AddObjective(new AIObjectiveIdle(character, this)); int objectiveCount = Objectives.Count; foreach (var autonomousObjective in character.Info.Job.Prefab.AutonomousObjectives) { var orderPrefab = Order.GetPrefab(autonomousObjective.identifier); if (orderPrefab == null) { throw new Exception($"Could not find a matching prefab by the identifier: '{autonomousObjective.identifier}'"); } Item item = null; if (orderPrefab.MustSetTarget) { item = orderPrefab.GetMatchingItems(character.Submarine, mustBelongToPlayerSub: false, requiredTeam: character.Info.TeamID, interactableFor: character)?.GetRandom(); } var order = new Order(orderPrefab, item ?? character.CurrentHull as Entity, orderPrefab.GetTargetItemComponent(item), orderGiver: character); if (order == null) { continue; } if (autonomousObjective.ignoreAtOutpost && Level.IsLoadedOutpost && character.TeamID != CharacterTeamType.FriendlyNPC) { if (Submarine.MainSub != null && Submarine.MainSub.DockedTo.None(s => s.TeamID != CharacterTeamType.FriendlyNPC && s.TeamID != character.TeamID)) { continue; } } var objective = CreateObjective(order, autonomousObjective.option, character, isAutonomous: true, autonomousObjective.priorityModifier); if (objective != null && objective.CanBeCompleted) { AddObjective(objective, delay: Rand.Value() / 2); objectiveCount++; } } _waitTimer = Math.Max(_waitTimer, Rand.Range(0.5f, 1f) * objectiveCount); }
public void Stop() { CoroutineManager.StopCoroutines(updateCoroutine); Running = false; #if CLIENT if (FadeOut) { GUI.ScreenOverlayColor = Color.TransparentBlack; } if (prevControlled != null && !prevControlled.Removed) { Character.Controlled = prevControlled; } #endif }
public void AddObjective(AIObjective objective, float delay, Action callback = null) { if (DelayedObjectives.TryGetValue(objective, out CoroutineHandle coroutine)) { CoroutineManager.StopCoroutines(coroutine); DelayedObjectives.Remove(objective); } coroutine = CoroutineManager.InvokeAfter(() => { DelayedObjectives.Remove(objective); AddObjective(objective); callback?.Invoke(); }, delay); DelayedObjectives.Add(objective, coroutine); }
public void SetOrder(Order order, string option, Character orderGiver, bool speak) { if (character.IsDead) { #if DEBUG DebugConsole.ThrowError("Attempted to set an order for a dead character"); #else return; #endif } ClearIgnored(); CurrentOrder = CreateObjective(order, option, orderGiver, isAutonomous: false); if (CurrentOrder == null) { // Recreate objectives, because some of them may be removed, if impossible to complete (e.g. due to path finding) CreateAutonomousObjectives(); } else { // This should be redundant, because all the objectives are reset when they are selected as active. CurrentOrder.Reset(); if (speak) { character.Speak(TextManager.Get("DialogAffirmative"), null, 1.0f); if (speakRoutine != null) { CoroutineManager.StopCoroutines(speakRoutine); } speakRoutine = CoroutineManager.InvokeAfter(() => { if (GameMain.GameSession == null || Level.Loaded == null) { return; } if (CurrentOrder != null && character.SpeechImpediment < 100.0f) { if (CurrentOrder is AIObjectiveRepairItems repairItems && repairItems.Targets.None()) { character.Speak(TextManager.Get("DialogNoRepairTargets"), null, 3.0f, "norepairtargets"); } else if (CurrentOrder is AIObjectiveChargeBatteries chargeBatteries && chargeBatteries.Targets.None()) { character.Speak(TextManager.Get("DialogNoBatteries"), null, 3.0f, "nobatteries"); } else if (CurrentOrder is AIObjectiveExtinguishFires extinguishFires && extinguishFires.Targets.None()) { character.Speak(TextManager.Get("DialogNoFire"), null, 3.0f, "nofire"); }
public CameraTransition(ISpatialEntity targetEntity, Camera cam, Alignment?cameraStartPos, Alignment?cameraEndPos, bool fadeOut = true, float duration = 10.0f, float?startZoom = null, float?endZoom = null) { Duration = duration; FadeOut = fadeOut; this.cameraStartPos = cameraStartPos; this.cameraEndPos = cameraEndPos; this.startZoom = startZoom; this.endZoom = endZoom; AssignedCamera = cam; if (targetEntity == null) { return; } Running = true; CoroutineManager.StopCoroutines("CameraTransition"); updateCoroutine = CoroutineManager.StartCoroutine(Update(targetEntity, cam), "CameraTransition"); }
public void CreateAutonomousObjectives() { foreach (var delayedObjective in DelayedObjectives) { CoroutineManager.StopCoroutines(delayedObjective.Value); } DelayedObjectives.Clear(); Objectives.Clear(); AddObjective(new AIObjectiveFindSafety(character, this)); AddObjective(new AIObjectiveIdle(character, this)); int objectiveCount = Objectives.Count; foreach (var automaticOrder in character.Info.Job.Prefab.AutomaticOrders) { var orderPrefab = Order.GetPrefab(automaticOrder.identifier); if (orderPrefab == null) { throw new Exception($"Could not find a matching prefab by the identifier: '{automaticOrder.identifier}'"); } // TODO: Similar code is used in CrewManager:815-> DRY var matchingItems = orderPrefab.ItemIdentifiers.Any() ? Item.ItemList.FindAll(it => orderPrefab.ItemIdentifiers.Contains(it.Prefab.Identifier) || it.HasTag(orderPrefab.ItemIdentifiers)) : Item.ItemList.FindAll(it => it.Components.Any(ic => ic.GetType() == orderPrefab.ItemComponentType)); matchingItems.RemoveAll(it => it.Submarine != character.Submarine); var item = matchingItems.GetRandom(); var order = new Order( orderPrefab, item ?? character.CurrentHull as Entity, item?.Components.FirstOrDefault(ic => ic.GetType() == orderPrefab.ItemComponentType), orderGiver: character); if (order == null) { continue; } var objective = CreateObjective(order, automaticOrder.option, character, automaticOrder.priorityModifier); if (objective != null) { AddObjective(objective, delay: Rand.Value() / 2); objectiveCount++; } } _waitTimer = Math.Max(_waitTimer, Rand.Range(0.5f, 1f) * objectiveCount); }
public void CreateAutonomousObjectives() { if (character.IsDead) { #if DEBUG DebugConsole.ThrowError("Attempted to create autonomous orders for a dead character"); #else return; #endif } foreach (var delayedObjective in DelayedObjectives) { CoroutineManager.StopCoroutines(delayedObjective.Value); } DelayedObjectives.Clear(); Objectives.Clear(); AddObjective(new AIObjectiveFindSafety(character, this)); AddObjective(new AIObjectiveIdle(character, this)); int objectiveCount = Objectives.Count; foreach (var autonomousObjective in character.Info.Job.Prefab.AutonomousObjective) { var orderPrefab = Order.GetPrefab(autonomousObjective.identifier); if (orderPrefab == null) { throw new Exception($"Could not find a matching prefab by the identifier: '{autonomousObjective.identifier}'"); } var item = orderPrefab.MustSetTarget ? orderPrefab.GetMatchingItems(character.Submarine, mustBelongToPlayerSub: false, requiredTeam: character.Info.TeamID)?.GetRandom() : null; var order = new Order(orderPrefab, item ?? character.CurrentHull as Entity, item?.Components.FirstOrDefault(ic => ic.GetType() == orderPrefab.ItemComponentType), orderGiver: character); if (order == null) { continue; } var objective = CreateObjective(order, autonomousObjective.option, character, isAutonomous: true, autonomousObjective.priorityModifier); if (objective != null && objective.CanBeCompleted) { AddObjective(objective, delay: Rand.Value() / 2); objectiveCount++; } } _waitTimer = Math.Max(_waitTimer, Rand.Range(0.5f, 1f) * objectiveCount); }
public void AddObjective(AIObjective objective, float delay, Action callback = null) { if (objective == null) { #if DEBUG DebugConsole.ThrowError("Attempted to add a null objective to AIObjectiveManager\n" + Environment.StackTrace); #endif return; } if (DelayedObjectives.TryGetValue(objective, out CoroutineHandle coroutine)) { CoroutineManager.StopCoroutines(coroutine); DelayedObjectives.Remove(objective); } coroutine = CoroutineManager.InvokeAfter(() => { DelayedObjectives.Remove(objective); AddObjective(objective); callback?.Invoke(); }, delay); DelayedObjectives.Add(objective, coroutine); }
private static bool QuitClicked(GUIButton button, object obj) { if (button.UserData as string == "save") { SaveUtil.SaveGame(GameMain.GameSession.SavePath); } if (GameMain.NetworkMember != null) { GameMain.NetworkMember.Disconnect(); GameMain.NetworkMember = null; } CoroutineManager.StopCoroutines("EndCinematic"); GameMain.GameSession = null; GameMain.MainMenuScreen.Select(); //Game1.MainMenuScreen.SelectTab(null, (int)MainMenuScreen.Tabs.Main); return(true); }
public static void StopAll() { CoroutineManager.StopCoroutines("statuseffect"); DelayedEffect.DelayList.Clear(); DurationList.Clear(); }
public static void StopAll() { CoroutineManager.StopCoroutines("statuseffect"); }