public virtual void InstallDefaultSellOrders()
 {
     this.sellOrders = new ProtoBuf.VendingMachine.SellOrderContainer()
     {
         ShouldPool = false,
         sellOrders = new List <ProtoBuf.VendingMachine.SellOrder>()
     };
 }
示例#2
0
 public virtual void WriteToStreamDelta(Stream stream, VendingMachine.SellOrderContainer previous)
 {
     if (previous == null)
     {
         VendingMachine.SellOrderContainer.Serialize(stream, this);
         return;
     }
     VendingMachine.SellOrderContainer.SerializeDelta(stream, this, previous);
 }
示例#3
0
 public static VendingMachine.SellOrderContainer Deserialize(byte[] buffer)
 {
     VendingMachine.SellOrderContainer sellOrderContainer = Pool.Get <VendingMachine.SellOrderContainer>();
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         VendingMachine.SellOrderContainer.Deserialize(memoryStream, sellOrderContainer, false);
     }
     return(sellOrderContainer);
 }
示例#4
0
 public static byte[] SerializeToBytes(VendingMachine.SellOrderContainer instance)
 {
     byte[] array;
     using (MemoryStream memoryStream = new MemoryStream())
     {
         VendingMachine.SellOrderContainer.Serialize(memoryStream, instance);
         array = memoryStream.ToArray();
     }
     return(array);
 }
 public override void Load(BaseNetworkable.LoadInfo info)
 {
     base.Load(info);
     if (info.msg.vendingMachine != null)
     {
         this.shopName = info.msg.vendingMachine.shopName;
         if (info.msg.vendingMachine.sellOrderContainer != null)
         {
             this.sellOrders            = info.msg.vendingMachine.sellOrderContainer;
             this.sellOrders.ShouldPool = false;
         }
         if (info.fromDisk && base.isServer)
         {
             this.RefreshSellOrderStockLevel(null);
         }
     }
 }
示例#6
0
            public static void SerializeDelta(Stream stream, VendingMachine.SellOrderContainer instance, VendingMachine.SellOrderContainer previous)
            {
                MemoryStream memoryStream = Pool.Get <MemoryStream>();

                if (instance.sellOrders != null)
                {
                    for (int i = 0; i < instance.sellOrders.Count; i++)
                    {
                        VendingMachine.SellOrder item = instance.sellOrders[i];
                        stream.WriteByte(10);
                        memoryStream.SetLength((long)0);
                        VendingMachine.SellOrder.SerializeDelta(memoryStream, item, item);
                        uint length = (uint)memoryStream.Length;
                        ProtocolParser.WriteUInt32(stream, length);
                        stream.Write(memoryStream.GetBuffer(), 0, (int)length);
                    }
                }
                Pool.FreeMemoryStream(ref memoryStream);
            }
示例#7
0
 public static void ResetToPool(VendingMachine.SellOrderContainer instance)
 {
     if (!instance.ShouldPool)
     {
         return;
     }
     if (instance.sellOrders != null)
     {
         for (int i = 0; i < instance.sellOrders.Count; i++)
         {
             if (instance.sellOrders[i] != null)
             {
                 instance.sellOrders[i].ResetToPool();
                 instance.sellOrders[i] = null;
             }
         }
         List <VendingMachine.SellOrder> sellOrders = instance.sellOrders;
         Pool.FreeList <VendingMachine.SellOrder>(ref sellOrders);
         instance.sellOrders = sellOrders;
     }
     Pool.Free <VendingMachine.SellOrderContainer>(ref instance);
 }
示例#8
0
 public void UpdateDisplayName(string newName, ProtoBuf.VendingMachine.SellOrderContainer sellOrderContainer)
 {
     this.displayName  = newName;
     this.toolTip.Text = this.displayName;
     if (this.isInStock && sellOrderContainer != null && sellOrderContainer.sellOrders != null && sellOrderContainer.sellOrders.Count > 0)
     {
         Tooltip tooltip = this.toolTip;
         tooltip.Text = string.Concat(tooltip.Text, "\n");
         foreach (ProtoBuf.VendingMachine.SellOrder sellOrder in sellOrderContainer.sellOrders)
         {
             if (sellOrder.inStock <= 0)
             {
                 continue;
             }
             string  str      = string.Concat(ItemManager.FindItemDefinition(sellOrder.itemToSellID).displayName.translated, (sellOrder.itemToSellIsBP ? " (BP)" : ""));
             string  str1     = string.Concat(ItemManager.FindItemDefinition(sellOrder.currencyID).displayName.translated, (sellOrder.currencyIsBP ? " (BP)" : ""));
             Tooltip tooltip1 = this.toolTip;
             tooltip1.Text = string.Concat(new object[] { tooltip1.Text, "\n", sellOrder.itemToSellAmount, " ", str, " | ", sellOrder.currencyAmountPerItem, " ", str1 });
             tooltip1      = this.toolTip;
             tooltip1.Text = string.Concat(new object[] { tooltip1.Text, " (", sellOrder.inStock, " Left)" });
         }
     }
     this.toolTip.enabled = this.toolTip.Text != "";
 }
示例#9
0
            public static VendingMachine.SellOrderContainer DeserializeLengthDelimited(Stream stream, VendingMachine.SellOrderContainer instance, bool isDelta)
            {
                if (!isDelta && instance.sellOrders == null)
                {
                    instance.sellOrders = Pool.Get <List <VendingMachine.SellOrder> >();
                }
                long position = (long)ProtocolParser.ReadUInt32(stream);

                position += stream.Position;
                while (stream.Position < position)
                {
                    int num = stream.ReadByte();
                    if (num == -1)
                    {
                        throw new EndOfStreamException();
                    }
                    if (num != 10)
                    {
                        Key key = ProtocolParser.ReadKey((byte)num, stream);
                        if (key.Field == 0)
                        {
                            throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
                        }
                        ProtocolParser.SkipKey(stream, key);
                    }
                    else
                    {
                        instance.sellOrders.Add(VendingMachine.SellOrder.DeserializeLengthDelimited(stream));
                    }
                }
                if (stream.Position != position)
                {
                    throw new ProtocolBufferException("Read past max limit");
                }
                return(instance);
            }
示例#10
0
 public static VendingMachine.SellOrderContainer DeserializeLengthDelimited(Stream stream)
 {
     VendingMachine.SellOrderContainer sellOrderContainer = Pool.Get <VendingMachine.SellOrderContainer>();
     VendingMachine.SellOrderContainer.DeserializeLengthDelimited(stream, sellOrderContainer, false);
     return(sellOrderContainer);
 }
示例#11
0
 public static VendingMachine.SellOrderContainer DeserializeLength(Stream stream, int length)
 {
     VendingMachine.SellOrderContainer sellOrderContainer = Pool.Get <VendingMachine.SellOrderContainer>();
     VendingMachine.SellOrderContainer.DeserializeLength(stream, length, sellOrderContainer, false);
     return(sellOrderContainer);
 }
示例#12
0
 public static VendingMachine.SellOrderContainer Deserialize(Stream stream, VendingMachine.SellOrderContainer instance, bool isDelta)
 {
     if (!isDelta && instance.sellOrders == null)
     {
         instance.sellOrders = Pool.Get <List <VendingMachine.SellOrder> >();
     }
     while (true)
     {
         int num = stream.ReadByte();
         if (num == -1)
         {
             break;
         }
         if (num != 10)
         {
             Key key = ProtocolParser.ReadKey((byte)num, stream);
             if (key.Field == 0)
             {
                 throw new ProtocolBufferException("Invalid field id: 0, something went wrong in the stream");
             }
             ProtocolParser.SkipKey(stream, key);
         }
         else
         {
             instance.sellOrders.Add(VendingMachine.SellOrder.DeserializeLengthDelimited(stream));
         }
     }
     return(instance);
 }
示例#13
0
 public static VendingMachine.SellOrderContainer Deserialize(byte[] buffer, VendingMachine.SellOrderContainer instance, bool isDelta = false)
 {
     using (MemoryStream memoryStream = new MemoryStream(buffer))
     {
         VendingMachine.SellOrderContainer.Deserialize(memoryStream, instance, isDelta);
     }
     return(instance);
 }
示例#14
0
 public void CopyTo(VendingMachine.SellOrderContainer instance)
 {
     throw new NotImplementedException();
 }
示例#15
0
 public VendingMachine.SellOrderContainer Copy()
 {
     VendingMachine.SellOrderContainer sellOrderContainer = Pool.Get <VendingMachine.SellOrderContainer>();
     this.CopyTo(sellOrderContainer);
     return(sellOrderContainer);
 }
示例#16
0
 public static void SerializeLengthDelimited(Stream stream, VendingMachine.SellOrderContainer instance)
 {
     byte[] bytes = VendingMachine.SellOrderContainer.SerializeToBytes(instance);
     ProtocolParser.WriteUInt32(stream, (uint)bytes.Length);
     stream.Write(bytes, 0, (int)bytes.Length);
 }