Пример #1
0
        public void ParseWolfRecipe()
        {
            var inputIngredients = WOLF_AbstractPartModule.ParseRecipeIngredientList(InputResources);
            if (inputIngredients == null)
            {
                return;
            }

            WolfRecipe = new Recipe(inputIngredients, new Dictionary<string, int>());
        }
Пример #2
0
 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);
         }
     }
 }
Пример #3
0
        public override string GetInfo()
        {
            StringBuilder output = new StringBuilder();

            output
            .AppendLine(ConverterName)
            .AppendLine();

            if (!string.IsNullOrEmpty(InputResources))
            {
                var resources = WOLF_AbstractPartModule.ParseRecipeIngredientList(InputResources);

                output.AppendLine("<color=#99FF00>Inputs:</color>");
                foreach (var resource in resources)
                {
                    output
                    .Append(" - WOLF ")
                    .Append(resource.Key)
                    .Append(": ")
                    .AppendLine(resource.Value.ToString());
                }
            }
            if (outputList.Count > 0)
            {
                output.AppendLine("<color=#99FF00>Outputs:</color>");
                foreach (var resource in outputList)
                {
                    output
                    .Append(" - ")
                    .Append(resource.ResourceName)
                    .Append(": ");

                    if (resource.ResourceName == "ElectricCharge")
                    {
                        output
                        .AppendFormat("{0:F2}/sec", resource.Ratio)
                        .AppendLine();
                    }
                    else
                    {
                        output
                        .AppendFormat("{0:F2}/day", resource.Ratio * KSPUtil.dateTimeFormatter.Day)
                        .AppendLine();
                    }
                }
            }

            return(output.ToString());
        }
Пример #4
0
        public override void OnStart(StartState state)
        {
            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_RC_SWAP_SUCCESS_MESSAGE", out string swapSuccessMessage))
            {
                SWAP_SUCCESS_MESSAGE = swapSuccessMessage;
            }

            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_RC_SELECTED_RECIPE_GUI_NAME", out string selectedRecipeGuiName))
            {
                SELECTED_RECIPE_GUI_NAME = selectedRecipeGuiName;
            }
            Fields["selectedRecipeName"].guiName = SELECTED_RECIPE_GUI_NAME;

            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_RC_NEXT_RECIPE_GUI_NAME", out string nextRecipeGuiName))
            {
                NEXT_RECIPE_GUI_NAME = nextRecipeGuiName;
            }
            Events["MoveNext"].guiName = NEXT_RECIPE_GUI_NAME;

            if (Localizer.TryGetStringByTag("#autoLOC_USI_WOLF_RC_PREVIOUS_RECIPE_GUI_NAME", out string previousRecipeGuiName))
            {
                PREVIOUS_RECIPE_GUI_NAME = previousRecipeGuiName;
            }
            Events["MovePrevious"].guiName = PREVIOUS_RECIPE_GUI_NAME;

            var recipeOptions = part.FindModulesImplementing <WOLF_RecipeOption>();

            if (!recipeOptions.Any())
            {
                Debug.LogError(string.Format("[WOLF] {0}: Needs at least one WOLF_RecipeOption. Check part config.", GetType().Name));
            }

            _converter = part.FindModuleImplementing <WOLF_AbstractPartModule>();
            if (_converter == null)
            {
                Debug.LogError(string.Format("[WOLF] {0}: Needs a module derived from WOLF_AbstractPartModule. Check part config.", GetType().Name));
            }

            foreach (var option in recipeOptions)
            {
                _recipeOptions.Add(option);
            }

            ApplyRecipe();
            MoveNext();
        }
Пример #5
0
        public override string GetInfo()
        {
            var info = new StringBuilder();

            info
            .AppendLine(RecipeDisplayName)
            .AppendLine();

            if (!string.IsNullOrEmpty(InputResources))
            {
                var inputs = WOLF_AbstractPartModule.ParseRecipeIngredientList(InputResources);
                info.AppendFormat("<color=#99FF00>{0}:</color>", NEEDS_TEXT);
                info.AppendLine();
                foreach (var resource in inputs)
                {
                    info
                    .Append(" - ")
                    .Append(resource.Key)
                    .Append(": ")
                    .AppendFormat("{0:D}", resource.Value)
                    .AppendLine();
                }
            }
            if (!string.IsNullOrEmpty(OutputResources))
            {
                var outputs = WOLF_AbstractPartModule.ParseRecipeIngredientList(OutputResources);
                info.AppendFormat("<color=#99FF00>{0}:</color>", PROVIDES_TEXT);
                info.AppendLine();
                foreach (var resource in outputs)
                {
                    info
                    .Append(" - ")
                    .Append(resource.Key)
                    .Append(": ")
                    .AppendFormat("{0:D}", resource.Value)
                    .AppendLine();
                }
            }

            return(info.ToString());
        }
Пример #6
0
        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));
        }
Пример #7
0
        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;
        }