// We'll piggyback on the base class ConnectToDepotEvent to // handle making the connection on the destination side protected override void ConnectToDepot() { // Check for issues that would prevent deployment var deployCheckResult = CanConnectToDepot(); if (!string.IsNullOrEmpty(deployCheckResult)) { DisplayMessage(deployCheckResult); return; } var destinationBody = vessel.mainBody.name; var destinationBiome = GetVesselBiome(); if (destinationBody == OriginBody && destinationBiome == OriginBiome) { DisplayMessage(INVALID_CONNECTION_MESSAGE); return; } var routePayload = CalculateRoutePayload(); if (!routePayload.HasMinimumPayload(MINIMUM_PAYLOAD)) { DisplayMessage(INSUFFICIENT_PAYLOAD_MESSAGE); return; } try { if (TryNegotiateRoute(destinationBody, destinationBiome, routePayload)) { // Add rewards var homeworld = FlightGlobals.GetHomeBodyName(); if (destinationBody == homeworld && OriginBody != destinationBody) { RewardsManager.AddTransportFunds(routePayload.GetRewards()); } ResetRoute(); } } catch (Exception ex) { DisplayMessage(ex.Message); } }
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); } }
// We'll piggyback on the base class ConnectToDepotEvent to // handle making the connection on the destination side protected sealed override void ConnectToDepot() { try { // Check for issues that would prevent deployment var deployCheckResult = CanConnectToDepot(); if (!string.IsNullOrEmpty(deployCheckResult)) { DisplayMessage(deployCheckResult); return; } var originDepot = _registry.GetDepot(OriginBody, OriginBiome); var destinationDepot = _registry.GetDepot(vessel.mainBody.name, GetVesselBiome()); if (destinationDepot.Body == originDepot.Body && destinationDepot.Biome == originDepot.Biome) { DisplayMessage(INVALID_CONNECTION_MESSAGE); return; } CalculateAndSetFields(); if (RoutePayload < MINIMUM_PAYLOAD) { DisplayMessage(INSUFFICIENT_PAYLOAD_MESSAGE); return; } if (RouteCost > 0) { // Make sure origin depot has enough TransportCredits to support the route var originTransportCredits = originDepot .GetResources() .FirstOrDefault(r => r.ResourceName == "TransportCredits"); if (originTransportCredits == null) { DisplayMessage(string.Format(INSUFFICIENT_TRANSPORT_CREDITS_MESSAGE, RouteCost)); return; } if (originTransportCredits.Available < RouteCost) { DisplayMessage(string.Format(INSUFFICIENT_TRANSPORT_CREDITS_MESSAGE, RouteCost - originTransportCredits.Available)); return; } } if (!CanConnectToDestination(originDepot, destinationDepot, RouteCost, RoutePayload, out var errorMessage)) { DisplayMessage(errorMessage); return; } _registry.CreateRoute(originDepot.Body, originDepot.Biome, destinationDepot.Body, destinationDepot.Biome, RoutePayload); if (RouteCost > 0) { originDepot.NegotiateConsumer(new Dictionary <string, int> { { "TransportCredits", RouteCost } }); } if (originDepot.Body == destinationDepot.Body) { DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, originDepot.Body)); } else { DisplayMessage(string.Format(Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, $"{originDepot.Body} and {destinationDepot.Body}")); } // Add rewards var homeworld = FlightGlobals.GetHomeBodyName(); if (destinationDepot.Body == homeworld && originDepot.Body != destinationDepot.Body) { RewardsManager.AddTransportFunds(RoutePayload); } OnConnectedToDestingation(); ResetRoute(); } catch (Exception ex) { DisplayMessage(ex.Message); } }