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 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 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 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; } } } }
/// <summary> /// Updates the proto vessel file with the values we received about a position of a vessel /// </summary> private static string UpdateProtoVesselFileWithNewResourceData(string[] protoVesselLines, VesselResourceMsgData msgData) { throw new NotImplementedException(); }
/// <summary> /// Updates the proto vessel with the values we received about the resources of a vessel /// </summary> private static string UpdateProtoVesselFileWithNewResourceData(string vesselData, VesselResourceMsgData msgData) { var document = new XmlDocument(); document.LoadXml(vesselData); foreach (var resourceInfo in msgData.Resources) { var xpath = $@"/{ConfigNodeXmlParser.StartElement}/{ConfigNodeXmlParser.ParentNode}[@name='PART']/{ConfigNodeXmlParser.ValueNode}[@name='uid' and text()=""{resourceInfo.PartFlightId}""]/" + $"following-sibling::RESOURCE/{ConfigNodeXmlParser.ValueNode}" + $@"[@name='name' and text()=""{resourceInfo.ResourceName}""]/parent::RESOURCE"; var resourceNode = document.SelectSingleNode(xpath); var amountNode = resourceNode?.SelectSingleNode($"/{ConfigNodeXmlParser.StartElement}/{ConfigNodeXmlParser.ParentNode}[@name='PART']/{ConfigNodeXmlParser.ParentNode}[@name='RESOURCE']/{ConfigNodeXmlParser.ValueNode}[@name='amount']"); if (amountNode != null) { amountNode.InnerText = resourceInfo.Amount.ToString(CultureInfo.InvariantCulture); } var flowNode = resourceNode?.SelectSingleNode($"/{ConfigNodeXmlParser.StartElement}/{ConfigNodeXmlParser.ParentNode}[@name='PART']/{ConfigNodeXmlParser.ParentNode}[@name='RESOURCE']/{ConfigNodeXmlParser.ValueNode}[@name='flowState']"); if (flowNode != null) { flowNode.InnerText = resourceInfo.FlowState.ToString(CultureInfo.InvariantCulture); } } return(document.ToIndentedString()); }