protected override bool TryNegotiateRoute( string destinationBody, string destinationBiome, IRoutePayload routePayload) { if (!IsNearTerminal()) { DisplayMessage(string.Format( _noNearbyTerminalsMessage, TERMINAL_RANGE)); return(false); } var originDepot = _registry.GetDepot(OriginBody, OriginBiome); var routeCost = CalculateRouteCost(); if (routeCost > 0) { // Make sure origin depot has enough TransportCredits to support the route var originTransportCredits = originDepot.GetResources() .Where(r => r.ResourceName == "TransportCredits") .FirstOrDefault(); if (originTransportCredits == null) { DisplayMessage(string.Format( INSUFFICIENT_TRANSPORT_CREDITS_MESSAGE, routeCost)); return(false); } if (originTransportCredits.Available < routeCost) { DisplayMessage(string.Format( INSUFFICIENT_TRANSPORT_CREDITS_MESSAGE, routeCost - originTransportCredits.Available)); return(false); } } // Make sure origin depot has enough hab & life support var crewRoutePayload = (CrewRoutePayload)routePayload; if (!CheckBerthCost(originDepot, crewRoutePayload)) { return(false); } // Calculate duration var now = Planetarium.GetUniversalTime(); var duration = now - RouteStart; // Create route and consume route costs var economyBerthCost = crewRoutePayload.EconomyBerths * BERTH_COST_MULTIPLIER; var luxuryBerthCost = crewRoutePayload.LuxuryBerths * BERTH_COST_MULTIPLIER; var totalBerthCost = economyBerthCost + luxuryBerthCost; _registry.CreateCrewRoute( OriginBody, OriginBiome, destinationBody, destinationBiome, crewRoutePayload.EconomyBerths, crewRoutePayload.LuxuryBerths, duration); if (routeCost > 0) { originDepot.NegotiateConsumer(new Dictionary <string, int> { { "TransportCredits", routeCost } }); } originDepot.NegotiateConsumer(new Dictionary <string, int> { { "Habitation", totalBerthCost }, { "LifeSupport", totalBerthCost }, }); if (luxuryBerthCost > 0) { originDepot.NegotiateConsumer(new Dictionary <string, int> { { "ColonySupplies", luxuryBerthCost } }); } if (OriginBody == destinationBody) { DisplayMessage(string.Format( Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, OriginBody)); } else { DisplayMessage(string.Format( Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, $"{OriginBody} and {destinationBody}")); } return(true); }
protected virtual bool TryNegotiateRoute( string destinationBody, string destinationBiome, IRoutePayload routePayload) { var originDepot = _registry.GetDepot(OriginBody, OriginBiome); var routeCost = CalculateRouteCost(); if (routeCost > 0) { // Make sure origin depot has enough TransportCredits to support the route var originTransportCredits = originDepot.GetResources() .Where(r => r.ResourceName == "TransportCredits") .FirstOrDefault(); if (originTransportCredits == null) { DisplayMessage(string.Format( INSUFFICIENT_TRANSPORT_CREDITS_MESSAGE, routeCost)); return(false); } if (originTransportCredits.Available < routeCost) { DisplayMessage(string.Format( INSUFFICIENT_TRANSPORT_CREDITS_MESSAGE, routeCost - originTransportCredits.Available)); return(false); } } var cargoRoutePayload = (CargoRoutePayload)routePayload; _registry.CreateRoute( OriginBody, OriginBiome, destinationBody, destinationBiome, cargoRoutePayload.Payload); if (routeCost > 0) { originDepot.NegotiateConsumer(new Dictionary <string, int> { { "TransportCredits", routeCost } }); } if (OriginBody == destinationBody) { DisplayMessage(string.Format( Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, OriginBody)); } else { DisplayMessage(string.Format( Messenger.SUCCESSFUL_DEPLOYMENT_MESSAGE, $"{OriginBody} and {destinationBody}")); } return(true); }