protected override void ConnectToDepot() { // Check for issues that would prevent deployment var deployCheckResult = CanConnectToDepot(); if (!string.IsNullOrEmpty(deployCheckResult)) { DisplayMessage(deployCheckResult); return; } // Get recipes from all attached WOLF PartModules var recipes = vessel .FindPartModulesImplementing <WOLF_AbstractPartModule>() .Where(p => !(p is WOLF_SurveyModule)) .Select(p => p.WolfRecipe) .ToList(); // Add crew recipe var crewModule = vessel.vesselModules .Where(m => m is WOLF_CrewModule) .FirstOrDefault() as WOLF_CrewModule; IRecipe crewRecipe; if (crewModule == null) { DisplayMessage("BUG: Could not find crew module."); return; } else if (!crewModule.IsCrewEligible()) { DisplayMessage(CREW_NOT_ELIGIBLE_MESSAGE); return; } else { crewRecipe = crewModule.GetCrewRecipe(); recipes.Add(crewRecipe); } // Negotiate recipes with the depot var body = vessel.mainBody.name; var biome = GetVesselBiome(); var depot = _registry.GetDepot(body, biome); var result = depot.Negotiate(recipes); if (result is FailedNegotiationResult) { var failureResult = result as FailedNegotiationResult; foreach (var missingResource in failureResult.MissingResources) { DisplayMessage(string.Format(Messenger.MISSING_RESOURCE_MESSAGE, missingResource.Value, missingResource.Key)); } return; } DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, body)); // Add rewards if (crewRecipe != null) { var totalCrewPoints = crewRecipe.OutputIngredients .Sum(i => i.Value); if (totalCrewPoints > 0) { RewardsManager.AddReputation(totalCrewPoints, vessel.mainBody.isHomeWorld); } } Poof.GoPoof(vessel); }
protected void EstablishDepot(bool isSurvey) { // Check for issues that would prevent deployment var body = vessel.mainBody.name; var biome = GetVesselBiome(); if (biome == string.Empty) { DisplayMessage(INVALID_SITUATION_MESSAGE); return; } if (biome.StartsWith("Orbit") && biome != "Orbit") { DisplayMessage(INVALID_ORBIT_SITUATION_MESSAGE); return; } bool depotAlreadyExists = _registry.TryGetDepot(body, biome, out IDepot depot); if (isSurvey) { if (depotAlreadyExists && depot.IsSurveyed) { DisplayMessage(SURVEY_ALREADY_COMPLETED_MESSAGE); return; } } else { if (depotAlreadyExists && depot.IsEstablished) { DisplayMessage(DEPOT_ALREADY_ESTABLISHED_MESSAGE); return; } var otherWolfPartModules = vessel .FindPartModulesImplementing <WOLF_AbstractPartModule>() .Where(p => p != this); var otherWolfHoppers = vessel.FindPartModulesImplementing <WOLF_HopperModule>(); if (otherWolfPartModules.Any() || otherWolfHoppers.Any()) { DisplayMessage(Messenger.INVALID_DEPOT_PART_ATTACHMENT_MESSAGE); return; } var crew = vessel.GetVesselCrew(); if (crew != null && crew.Count > 0) { DisplayMessage(CANNOT_ADD_CREW_MESSAGE); return; } } // Create depot if necessary if (!depotAlreadyExists) { depot = _registry.CreateDepot(body, biome); } var isHomeWorld = vessel.mainBody.isHomeWorld; if (isSurvey) { // Survey biome depot.Survey(); // Calculate resource abundance and cache resource vein names in scenario module var harvestableResources = CalculateAbundance(); depot.NegotiateProvider(harvestableResources); DisplayMessage(string.Format(SUCCESSFUL_SURVEY_MESSAGE, biome, body)); // Add rewards RewardsManager.AddScience(isHomeWorld); } else { // Establish depot depot.Establish(); // Setup bootstrap resource streams if (isHomeWorld && vessel.situation != Situations.ORBITING) { depot.NegotiateProvider(HOME_PLANET_STARTING_RESOURCES); } else { depot.NegotiateProvider(DEFAULT_STARTING_RESOURCES); } depot.NegotiateProvider(WolfRecipe.OutputIngredients); depot.NegotiateConsumer(WolfRecipe.InputIngredients); DisplayMessage(string.Format(SUCCESSFUL_DEPLOYMENT_MESSAGE, biome, body)); Poof.GoPoof(vessel); // Add rewards RewardsManager.AddScience(isHomeWorld); RewardsManager.AddDepotFunds(isHomeWorld); RewardsManager.AddReputation(10, isHomeWorld); } }