public void Read(NetIncomingMessage message) { this.Registries = new List <FreightRegistry>(); this.NetworkID = message.ReadString(); int count = message.ReadInt32(); for (int n = 0; n < count; n++) { int itemid = message.ReadInt32(); ushort type; ushort val; ItemBase item; if (itemid == -1) { type = message.ReadUInt16(); val = message.ReadUInt16(); item = ItemManager.SpawnCubeStack(type, val, 1); } else { item = ItemManager.SpawnItem(itemid); } FreightRegistry reg = new FreightRegistry(this.NetworkID, null, item, 0, 0, FreightRegistry.RegistryType.Registry); reg.Deficit = message.ReadInt32(); reg.Surplus = message.ReadInt32(); reg.Inventory = message.ReadInt32(); reg.Stock = message.ReadInt32(); this.Registries.Add(reg); } }
private void ReadRegistries(NetIncomingMessage message, bool IsDef) { int count = message.ReadInt32(); List <FreightRegistry> regs = new List <FreightRegistry>(count); FreightRegistry reg; for (int n = 0; n < count; n++) { reg = new FreightRegistry(null, null, ItemReader(message), 0, 0, FreightRegistry.RegistryType.Registry); if (IsDef) { reg.Deficit = message.ReadInt32(); } else { reg.Surplus = message.ReadInt32(); } regs.Add(reg); } if (IsDef) { this.StationDeficits = regs; } else { this.StationSurplus = regs; } }
public void Write(BinaryWriter writer) { if (string.IsNullOrEmpty(NetworkID)) { Debug.LogWarning("FreightCarts NetworkSync tried to write a NetworkStatusWrapper with null/empty networkid"); writer.Write(string.Empty); } else { writer.Write(this.NetworkID); } int count = this.Registries.Count; writer.Write(count); for (int n = 0; n < count; n++) { FreightRegistry reg = Registries[n]; if (reg.FreightItem.mType == ItemType.ItemCubeStack) { writer.Write(-1); writer.Write((reg.FreightItem as ItemCubeStack).mCubeType); writer.Write((reg.FreightItem as ItemCubeStack).mCubeValue); } else { writer.Write(reg.FreightItem.mnItemID); } writer.Write(reg.Deficit); writer.Write(reg.Surplus); writer.Write(reg.Inventory); writer.Write(reg.Stock); } }
private List <FreightRegistry> FreightListingConversion(List <FreightListing> items) { List <FreightRegistry> regs = new List <FreightRegistry>(); foreach (FreightListing item in items) { FreightRegistry reg = new FreightRegistry(null, null, item.Item, 0, 0, FreightRegistry.RegistryType.Registry); reg.Deficit = item.Quantity; reg.Surplus = item.Quantity; regs.Add(reg); } return(regs); }
public void UpdateRegistries() { if (string.IsNullOrEmpty(Station.NetworkID)) { return; } List <FreightRegistry> registries = new List <FreightRegistry>(); lock (offerlock) { foreach (FreightListing entry in Interface.FreightOfferings) { if (entry.Item == null) { continue; } FreightRegistry reg = new FreightRegistry(Station.NetworkID, null, entry.Item, 0, entry.Quantity, FreightRegistry.RegistryType.InterfaceData); reg.Surplus = entry.Quantity; registries.Add(reg); } } lock (requestlock) { foreach (FreightListing entry in Interface.FreightRequests) { if (entry.Item == null) { continue; } FreightRegistry reg = registries.Where(x => x.FreightItem.Compare(entry.Item)).FirstOrDefault(); if (reg != null) { reg.Deficit = entry.Quantity; reg.LowStock = entry.Quantity; } else { reg = new FreightRegistry(Station.NetworkID, null, entry.Item, entry.Quantity, int.MaxValue, FreightRegistry.RegistryType.InterfaceData); reg.Deficit = entry.Quantity; registries.Add(reg); } } } foreach (FreightRegistry reg in registries) { //Debug.Log("FreightInterfaceContainer updating registry with reg item: " + reg.FreightItem.ToString() + " lowstock: " + reg.LowStock + "highstock: " + reg.HighStock + " deficit: " + reg.Deficit + " surplus: " + reg.Surplus); } // Check existing registries -> if the new update doesn't have the entry then zero it in the network to remove later foreach (FreightRegistry reg in this.Registries) { if (!registries.Exists(x => x.FreightItem.Compare(reg.FreightItem))) { FreightCartManager.instance.ZeroInterfaceRegistry(Station.NetworkID, reg.FreightItem); //Debug.Log("FreightInterfaceContainer had to zero an interface registry for " + reg.FreightItem.ToString()); } } this.Registries = registries; }