protected virtual void Update() { // Display current biome in PAW if (HighLogic.LoadedSceneIsFlight) { var now = Planetarium.GetUniversalTime(); if (now >= _nextBiomeUpdate) { _nextBiomeUpdate = now + 1d; // wait one second between biome updates CurrentBiome = WOLF_AbstractPartModule.GetVesselBiome(vessel); } } }
public void ConnectToDepotEvent() { // Check for issues that would prevent deployment if (IsConnectedToDepot) { Messenger.DisplayMessage(ALREADY_CONNECTED_MESSAGE); return; } var body = vessel.mainBody.name; var biome = WOLF_AbstractPartModule.GetVesselBiome(vessel); if (biome == string.Empty) { Messenger.DisplayMessage(Messenger.INVALID_SITUATION_MESSAGE); return; } if (biome.StartsWith("Orbit") && biome != "Orbit") { Messenger.DisplayMessage(Messenger.INVALID_ORBIT_SITUATION_MESSAGE); return; } if (!_registry.HasEstablishedDepot(body, biome)) { Messenger.DisplayMessage(Messenger.MISSING_DEPOT_MESSAGE); return; } var otherDepotModules = vessel.FindPartModulesImplementing <WOLF_DepotModule>(); if (otherDepotModules.Any()) { Messenger.DisplayMessage(Messenger.INVALID_DEPOT_PART_ATTACHMENT_MESSAGE); return; } var otherWolfPartModules = vessel.FindPartModulesImplementing <WOLF_AbstractPartModule>(); if (otherWolfPartModules.Any(p => !(p is ICorporeal))) { Messenger.DisplayMessage(Messenger.INVALID_HOPPER_PART_ATTACHMENT_MESSAGE); return; } // Negotiate recipes with the depot var depot = _registry.GetDepot(body, biome); var result = depot.Negotiate(WolfRecipe); if (result is FailedNegotiationResult) { var failureResult = result as FailedNegotiationResult; foreach (var missingResource in failureResult.MissingResources) { Messenger.DisplayMessage(string.Format(Messenger.MISSING_RESOURCE_MESSAGE, missingResource.Value, missingResource.Key)); } return; } // Register hopper HopperId = _registry.CreateHopper(depot, WolfRecipe); DepotBody = body; DepotBiome = biome; IsConnectedToDepot = true; Events["ConnectToDepotEvent"].guiActive = false; Events["DisconnectFromDepotEvent"].guiActive = true; // Hook into vessel destroyed event to release resources back to depot if (vessel != null) { vessel.OnJustAboutToBeDestroyed += OnVesselDestroyed; GameEvents.OnVesselRecoveryRequested.Add(OnVesselRecovered); } Messenger.DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, body)); }
public override void OnStart(StartState state) { base.OnStart(state); if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_HOPPER_ALREADY_CONNECTED_MESSAGE", out string alreadyConnectedMessage)) { ALREADY_CONNECTED_MESSAGE = alreadyConnectedMessage; } if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_HOPPER_DISCONNECTED_MESSAGE", out string disconnectedMessage)) { DISCONNECTED_MESSAGE = disconnectedMessage; } if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_HOPPER_LOST_CONNECTION_MESSAGE", out string lostConnectionMessage)) { LOST_CONNECTION_MESSAGE = lostConnectionMessage; } if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_HOPPER_NOT_CONNECTED_MESSAGE", out string notConnectedMessage)) { NOT_CONNECTED_MESSAGE = notConnectedMessage; } if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_CONNECT_TO_DEPOT_GUI_NAME", out string connectGuiName)) { CONNECT_TO_DEPOT_GUI_NAME = connectGuiName; } if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_DISCONNECT_FROM_DEPOT_GUI_NAME", out string disconnectGuiName)) { DISCONNECT_FROM_DEPOT_GUI_NAME = disconnectGuiName; } if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_CURRENT_BIOME_GUI_NAME", out string currentBiomeGuiName)) { CURRENT_BIOME_GUI_NAME = currentBiomeGuiName; } Fields["CurrentBiome"].guiName = CURRENT_BIOME_GUI_NAME; Events["ConnectToDepotEvent"].guiName = CONNECT_TO_DEPOT_GUI_NAME; Events["DisconnectFromDepotEvent"].guiName = DISCONNECT_FROM_DEPOT_GUI_NAME; // Find the WOLF scenario and parse the hopper recipe var scenario = FindObjectOfType <WOLF_ScenarioModule>(); _registry = scenario.ServiceManager.GetService <IRegistryCollection>(); ParseWolfRecipe(); // If we were previously connected to a depot, make sure we still are if (IsConnectedToDepot) { var body = vessel.mainBody.name; var biome = WOLF_AbstractPartModule.GetVesselBiome(vessel); var depot = _registry.GetDepot(DepotBody, DepotBiome); if (depot == null || depot.Body != body || depot.Biome != biome) { Debug.LogWarning("[WOLF] Hopper lost connection to its depot."); Messenger.DisplayMessage(LOST_CONNECTION_MESSAGE); StopResourceConverter(); ReleaseResources(); } else { // Hook into vessel destroyed event to release resources back to depot if (vessel != null) { vessel.OnJustAboutToBeDestroyed += OnVesselDestroyed; GameEvents.OnVesselRecoveryRequested.Add(OnVesselRecovered); } } } Events["ConnectToDepotEvent"].guiActive = !IsConnectedToDepot; Events["DisconnectFromDepotEvent"].guiActive = IsConnectedToDepot; }