public void HandleMessage(IServerMessageBase msg) { if (!(msg.Data is VesselFairingMsgData msgData) || !System.FairingSystemReady) { return; } //Vessel might exist in the store but not in game (if the vessel is in safety bubble for example) VesselsProtoStore.UpdateVesselProtoPartFairing(msgData); var vessel = FlightGlobals.FindVessel(msgData.VesselId); if (vessel == null) { return; } var part = VesselCommon.FindProtoPartInProtovessel(vessel.protoVessel, msgData.PartFlightId); if (part != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(part, "ModuleProceduralFairing"); module?.moduleValues.SetValue("fsm", "st_flight_deployed"); module?.moduleValues.RemoveNodesStartWith("XSECTION"); (module?.moduleRef as ModuleProceduralFairing)?.DeployFairing(); } }
public void ProcessPartMethodCallSync() { var vessel = FlightGlobals.fetch.LmpFindVessel(VesselId); if (vessel == null || !vessel.loaded) { return; } if (!VesselCommon.DoVesselChecks(VesselId)) { return; } var part = VesselCommon.FindProtoPartInProtovessel(vessel.protoVessel, PartFlightId); if (part != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(part, ModuleName); if (module != null) { if (module.moduleRef != null) { module.moduleRef.GetType().GetMethod(MethodName, AccessTools.all)?.Invoke(module.moduleRef, null); PartModuleEvent.onPartModuleMethodProcessed.Fire(module, MethodName); } } } }
public void ProcessPartMethodSync() { var vessel = FlightGlobals.fetch.LmpFindVessel(VesselId); if (vessel == null) { return; } if (!VesselCommon.DoVesselChecks(VesselId)) { return; } var part = VesselCommon.FindProtoPartInProtovessel(vessel.protoVessel, PartFlightId); if (part != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(part, ModuleName); if (module != null) { switch (FieldType) { case PartSyncFieldType.Boolean: module.moduleValues.SetValue(FieldName, BoolValue); if (module.moduleRef != null) { module.moduleRef.Fields[FieldName].SetValue(BoolValue, module.moduleRef); } PartModuleEvent.onPartModuleBoolFieldProcessed.Fire(module, FieldName, BoolValue); break; case PartSyncFieldType.Integer: module.moduleValues.SetValue(FieldName, IntValue); if (module.moduleRef != null) { module.moduleRef.Fields[FieldName].SetValue(IntValue, module.moduleRef); } PartModuleEvent.onPartModuleIntFieldProcessed.Fire(module, FieldName, IntValue); break; case PartSyncFieldType.Float: module.moduleValues.SetValue(FieldName, FloatValue); if (module.moduleRef != null) { module.moduleRef.Fields[FieldName].SetValue(FloatValue, module.moduleRef); } PartModuleEvent.onPartModuleFloatFieldProcessed.Fire(module, FieldName, FloatValue); break; default: throw new ArgumentOutOfRangeException(); } } } }
private static ProtoPartModuleSnapshot GetKerbalEvaProtoModule(ProtoVessel protoVessel) { if (protoVessel == null) { return(null); } var partSnapshot = VesselCommon.FindProtoPartInProtovessel(protoVessel, "kerbalEVA"); if (partSnapshot == null) { return(null); } return(VesselCommon.FindProtoPartModuleInProtoPart(partSnapshot, "KerbalEVA")); }
private static void ProcessFairingChange(ProtoPartSnapshot protoPart) { var module = VesselCommon.FindProtoPartModuleInProtoPart(protoPart, "ModuleProceduralFairing"); module?.moduleValues.SetValue("fsm", "st_flight_deployed"); module?.moduleValues.RemoveNodesStartWith("XSECTION"); try { (module?.moduleRef as ModuleProceduralFairing)?.DeployFairing(); } catch (Exception) { //TODO reload the module } }
public static void UpdateVesselProtoPartModules(VesselPartSyncMsgData msgData) { if (AllPlayerVessels.TryGetValue(msgData.VesselId, out var vesselProtoUpd)) { if (vesselProtoUpd.ProtoVessel == null) { return; } var partSnapshot = VesselCommon.FindProtoPartInProtovessel(vesselProtoUpd.ProtoVessel, msgData.PartFlightId); if (partSnapshot != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(partSnapshot, msgData.ModuleName); module?.moduleValues.SetValue(msgData.FieldName, msgData.Value); } } }
public static void UpdateVesselProtoPartFairing(VesselFairingMsgData msgData) { if (AllPlayerVessels.TryGetValue(msgData.VesselId, out var vesselProtoUpd)) { if (vesselProtoUpd.ProtoVessel == null) { return; } var part = VesselCommon.FindProtoPartInProtovessel(vesselProtoUpd.ProtoVessel, msgData.PartFlightId); if (part != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(part, "ModuleProceduralFairing"); module?.moduleValues.SetValue("fsm", "st_flight_deployed"); module?.moduleValues.RemoveNodesStartWith("XSECTION"); } } }
private static void UpdateVesselValues(ProtoVessel protoVessel, VesselPartSyncMsgData msgData) { if (protoVessel == null) { return; } var part = VesselCommon.FindProtoPartInProtovessel(protoVessel, msgData.PartFlightId); if (part != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(part, msgData.ModuleName); if (module != null) { module.moduleValues.SetValue(msgData.FieldName, msgData.Value); UpdateVesselModuleIfNeeded(protoVessel.vesselID, part.flightID, msgData, module, part); } } }
public string GetFairingStateFromStore(Guid vesselId, uint partFlightId) { if (VesselsProtoStore.AllPlayerVessels.TryGetValue(vesselId, out var vesselProtoUpd)) { var protoVessel = vesselProtoUpd.ProtoVessel; var protoPart = VesselCommon.FindProtoPartInProtovessel(protoVessel, partFlightId); if (protoPart == null) { return(null); } var protoModule = VesselCommon.FindProtoPartModuleInProtoPart(protoPart, "ModuleProceduralFairing"); return(protoModule?.moduleValues.GetValue("fsm")); } return(null); }
public void HandleMessage(IServerMessageBase msg) { if (!(msg.Data is VesselFairingMsgData msgData) || !System.FairingSystemReady) { return; } //We received a msg for our own controlled/updated vessel so ignore it if (!VesselCommon.DoVesselChecks(msgData.VesselId)) { return; } //Vessel might exist in the store but not in game (if the vessel is in safety bubble for example) VesselsProtoStore.UpdateVesselProtoPartFairing(msgData); var vessel = FlightGlobals.FindVessel(msgData.VesselId); if (vessel == null) { return; } var part = VesselCommon.FindProtoPartInProtovessel(vessel.protoVessel, msgData.PartFlightId); if (part != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(part, "ModuleProceduralFairing"); module?.moduleValues.SetValue("fsm", "st_flight_deployed"); module?.moduleValues.RemoveNodesStartWith("XSECTION"); try { (module?.moduleRef as ModuleProceduralFairing)?.DeployFairing(); } catch (Exception) { //TODO reload the module } } }
public void UpdateFairingsValuesInProtoVessel(ProtoVessel protoVessel, uint partFlightId) { if (protoVessel == null) { return; } var protoPart = VesselCommon.FindProtoPartInProtovessel(protoVessel, partFlightId); if (protoPart == null) { return; } var protoModule = VesselCommon.FindProtoPartModuleInProtoPart(protoPart, "ModuleProceduralFairing"); if (protoModule == null) { return; } protoModule.moduleValues.SetValue("fsm", "st_flight_deployed"); protoModule.moduleValues.RemoveNodesStartWith("XSECTION"); }
public void ProcessPartMethodSync() { var vessel = FlightGlobals.fetch.LmpFindVessel(VesselId); if (vessel == null) { return; } if (!VesselCommon.DoVesselChecks(VesselId)) { return; } var part = VesselCommon.FindProtoPartInProtovessel(vessel.protoVessel, PartFlightId); if (part != null) { var module = VesselCommon.FindProtoPartModuleInProtoPart(part, ModuleName); if (module != null) { switch (FieldType) { case PartSyncFieldType.Boolean: module.moduleValues.SetValue(FieldName, BoolValue); PartModuleEvent.onPartModuleBoolFieldProcessed.Fire(module, FieldName, BoolValue); break; case PartSyncFieldType.Integer: module.moduleValues.SetValue(FieldName, IntValue); PartModuleEvent.onPartModuleIntFieldProcessed.Fire(module, FieldName, IntValue); break; case PartSyncFieldType.Float: module.moduleValues.SetValue(FieldName, FloatValue); PartModuleEvent.onPartModuleFloatFieldProcessed.Fire(module, FieldName, FloatValue); break; case PartSyncFieldType.Double: module.moduleValues.SetValue(FieldName, DoubleValue); PartModuleEvent.onPartModuleDoubleFieldProcessed.Fire(module, FieldName, DoubleValue); break; case PartSyncFieldType.Vector3: module.moduleValues.SetValue(FieldName, VectorValue); PartModuleEvent.onPartModuleVectorFieldProcessed.Fire(module, FieldName, VectorValue); break; case PartSyncFieldType.Quaternion: module.moduleValues.SetValue(FieldName, QuaternionValue); PartModuleEvent.onPartModuleQuaternionFieldProcessed.Fire(module, FieldName, QuaternionValue); break; case PartSyncFieldType.String: module.moduleValues.SetValue(FieldName, StrValue); PartModuleEvent.onPartModuleStringFieldProcessed.Fire(module, FieldName, StrValue); break; case PartSyncFieldType.Enum: module.moduleValues.SetValue(FieldName, StrValue); PartModuleEvent.onPartModuleEnumFieldProcessed.Fire(module, FieldName, IntValue, StrValue); break; case PartSyncFieldType.Object: module.moduleValues.SetValue(FieldName, StrValue); PartModuleEvent.onPartModuleObjectFieldProcessed.Fire(module, FieldName, StrValue); //We do not set the value of objects in the module as we cannot be sure if they can be transformed from a string back to the object break; default: throw new ArgumentOutOfRangeException(); } } } }