private static void UpdateVesselResources(Vessel vessel, VesselResourceMsgData msgData) { for (var i = 0; i < msgData.ResourcesCount; i++) { var resource = msgData.Resources[i]; var part = VesselCommon.FindPartInVessel(vessel, resource.PartFlightId); var partResource = VesselCommon.FindResourceInPart(part, resource.ResourceName); if (partResource != null) { partResource.amount = resource.Amount; } } }
private static PartModule GetKerbalEvaModule(Vessel vessel) { if (vessel == null) { return(null); } var partSnapshot = VesselCommon.FindPartInVessel(vessel, "kerbalEVA"); if (partSnapshot == null) { return(null); } return(VesselCommon.FindModuleInPart(partSnapshot, "KerbalEVA")); }
public static void CreateMissingPartsInCurrentProtoVessel(Vessel vessel, ProtoVessel protoVessel) { //TODO: This is old code where we created parts dinamically but it's quite buggy. It create parts in the CURRENT vessel so it wont work for other vessels //We've run trough all the vessel parts and removed the ones that don't exist in the definition. //Now run trough the parts in the definition and add the parts that don't exist in the vessel. var partsToInit = new List <ProtoPartSnapshot>(); foreach (var partSnapshot in protoVessel.protoPartSnapshots) { if (partSnapshot.FindModule("ModuleDockingNode") != null) { //We are in a docking port part so remove it from our own vessel if we have it var vesselPart = VesselCommon.FindPartInVessel(vessel, partSnapshot.flightID); if (vesselPart != null) { vesselPart.Die(); } } //Skip parts that already exists if (VesselCommon.FindPartInVessel(vessel, partSnapshot.flightID) != null) { continue; } var newPart = partSnapshot.Load(vessel, false); vessel.parts.Add(newPart); partsToInit.Add(partSnapshot); } //Init new parts. This must be done in another loop as otherwise new parts won't have their correct attachment parts. foreach (var partSnapshot in partsToInit) { partSnapshot.Init(vessel); } vessel.RebuildCrewList(); Client.Singleton.StartCoroutine(CallbackUtil.DelayedCallback(0.25f, () => { FlightGlobals.ActiveVessel?.SpawnCrew(); })); Client.Singleton.StartCoroutine(CallbackUtil.DelayedCallback(0.5f, () => { KerbalPortraitGallery.Instance?.SetActivePortraitsForVessel(FlightGlobals.ActiveVessel); })); }