public static void UpdateVesselProtoResources(VesselResourceMsgData msgData) { if (AllPlayerVessels.TryGetValue(msgData.VesselId, out var vesselProtoUpd)) { if (vesselProtoUpd.ProtoVessel == null) { return; } for (var i = 0; i < msgData.ResourcesCount; i++) { var resource = msgData.Resources[i]; if (resource == null) { continue; } var partSnapshot = VesselCommon.FindProtoPartInProtovessel(vesselProtoUpd.ProtoVessel, resource.PartFlightId); var resourceSnapshot = VesselCommon.FindResourceInProtoPart(partSnapshot, resource.ResourceName); if (resourceSnapshot != null) { resourceSnapshot.amount = resource.Amount; resourceSnapshot.flowState = resource.FlowState; } } } }
private void UpdateVesselFields(Vessel vessel) { if (vessel.protoVessel == null) { return; } for (var i = 0; i < ResourcesCount; i++) { var partSnapshot = VesselCommon.FindProtoPartInProtovessel(vessel.protoVessel, Resources[i].PartFlightId); var resourceSnapshot = VesselCommon.FindResourceInProtoPart(partSnapshot, Resources[i].ResourceName); if (resourceSnapshot != null) { resourceSnapshot.amount = Resources[i].Amount; resourceSnapshot.flowState = Resources[i].FlowState; //Using "resourceSnapshot.resourceRef" sometimes returns null so we also try to get the resource from the part... if (resourceSnapshot.resourceRef == null) { if (partSnapshot.partRef != null) { var foundResource = partSnapshot.partRef.FindResource(resourceSnapshot.resourceName); foundResource.amount = Resources[i].Amount; foundResource.flowState = Resources[i].FlowState; } } else { resourceSnapshot.resourceRef.amount = Resources[i].Amount; resourceSnapshot.resourceRef.flowState = Resources[i].FlowState; } } } }
private static void UpdateProtoVesselResources(ProtoVessel protoVessel, VesselResourceMsgData msgData) { if (protoVessel == null) { return; } for (var i = 0; i < msgData.ResourcesCount; i++) { var resource = msgData.Resources[i]; var partSnapshot = VesselCommon.FindProtoPartInProtovessel(protoVessel, resource.PartFlightId); var resourceSnapshot = VesselCommon.FindResourceInProtoPart(partSnapshot, resource.ResourceName); if (resourceSnapshot != null) { resourceSnapshot.amount = resource.Amount; resourceSnapshot.flowState = resource.FlowState; if (resourceSnapshot.resourceRef == null) { continue; } resourceSnapshot.resourceRef.amount = resource.Amount; resourceSnapshot.resourceRef.flowState = resource.FlowState; } } }
private static void UpdateProtoVesselResources(ProtoVessel protoVessel, VesselResourceMsgData msgData) { if (protoVessel != null) { for (var i = 0; i < msgData.ResourcesCount; i++) { var resource = msgData.Resources[i]; var partSnapshot = VesselCommon.FindProtoPartInProtovessel(protoVessel, resource.PartFlightId); var resourceSnapshot = VesselCommon.FindResourceInProtoPart(partSnapshot, resource.ResourceName); if (resourceSnapshot != null) { resourceSnapshot.amount = resource.Amount; } } } }