Ejemplo n.º 1
0
        public void LoadGame(Stream reader)
        {
            disposed = false;
            Console.WriteLine("Loading game!");
            PlayerInventory = new Inventory();
            PlayerInventory.LoadFromFile(reader);                                                                       //PlayerInventory
            HatchInv = new HatchInventory();
            HatchInv.LoadFromFile(reader);                                                                              //HatchInv
            if (reader.ReadByte() != 0)                                                                                 //Check if CurrentCast is not null
            {
                CurrentCast = (CastItem)StreamIO.LoadItem(reader);                                                      //CurrentCast
            }
            CastMetal = reader.ReadByte();                                                                              //CastMetal
            var buffer = new byte[sizeof(float) * 4];

            reader.Read(buffer, 0, sizeof(float) * 4);                                                                          //CastMetaPurity, CastFilling, CastingTemperature, OldFoundryAmount
            CastMetalPurity   = BitConverter.ToSingle(buffer, 0);
            CastFilling       = BitConverter.ToSingle(buffer, sizeof(float));
            CastingTemprature = BitConverter.ToSingle(buffer, 2 * sizeof(float));
            OldFoundryAmount  = BitConverter.ToSingle(buffer, 3 * sizeof(float));
            FoundryIngots     = new SolidList <IngotItem> (FoundryMeshInfo.IngotAmount);
            for (int i = 0; i < FoundryIngots.Capacity; i++)
            {
                if (reader.ReadByte() != 0)                                                             //Check if the item is not null
                {
                    FoundryIngots [i] = (IngotItem)StreamIO.LoadItem(reader);                           //Read IngotItems
                }
            }
            FoundryAlloy = StreamIO.LoadAlloy(reader);                                                                  //FoundryAlloy
            reader.Read(buffer, 0, sizeof(float) * 3);                                                                  //Read3
            AirQuality        = BitConverter.ToSingle(buffer, 0);                                                       //AirQuality
            CoalPercent       = BitConverter.ToSingle(buffer, sizeof(float));                                           //CoalPercent
            FoundryTemprature = BitConverter.ToSingle(buffer, sizeof(float) * 2);                                       //FoundryTemperature
            Console.Out.WriteLine(reader.Position);
        }
Ejemplo n.º 2
0
 public void SaveGame(Stream writer)
 {
     Console.Out.WriteLine("Game saved!");
     PlayerInventory.SaveToFile(writer);                                                                 //PlayerInventory
     HatchInv.SaveToFile(writer);                                                                        //HatchInv
     writer.WriteByte((byte)(CurrentCast != null ? 1 : 0));                                              //Is CurrentCast not null?
     if (CurrentCast != null)
     {
         StreamIO.SaveItem(CurrentCast, writer);                                         //CurrentCast if it's not null.
     }
     writer.WriteByte((byte)CastMetal);                                                  //CastMetal
     writer.Write(BitConverter.GetBytes(CastMetalPurity), 0, sizeof(float));             //CastMetalPurity
     writer.Write(BitConverter.GetBytes(CastFilling), 0, sizeof(float));                 //CastFilling
     writer.Write(BitConverter.GetBytes(CastingTemprature), 0, sizeof(float));           //CastingTemerature
     writer.Write(BitConverter.GetBytes(OldFoundryAmount), 0, sizeof(float));            //OldFoundryAmount
     for (int i = 0; i < FoundryIngots.Capacity; i++)
     {
         writer.WriteByte((byte)(FoundryIngots[i] != null?1 : 0));                                       //Is The Ingot at i not null?
         if (FoundryIngots [i] != null)
         {
             StreamIO.SaveItem(FoundryIngots [i], writer);
         }
     }
     StreamIO.SaveAlloy(FoundryAlloy, writer);                                           //FoundryAlloy
     writer.Write(BitConverter.GetBytes(AirQuality), 0, sizeof(float));                  //AirQualtiy
     writer.Write(BitConverter.GetBytes(CoalPercent), 0, sizeof(float));                 //CoalPercent
     writer.Write(BitConverter.GetBytes(FoundryTemprature), 0, sizeof(float));           //FoundryTemperature
     Console.Out.WriteLine(writer.Position);
 }
Ejemplo n.º 3
0
        public void SaveToFile(Stream writer)
        {
            writer.WriteByte((byte)items.Count);

            foreach (Item i in items)
            {
                StreamIO.SaveItem(i, writer);
            }
        }
Ejemplo n.º 4
0
        public void LoadFromFile(Stream reader)
        {
            int itemCount = reader.ReadByte();

            items.Clear();

            for (int i = 0; i < itemCount; i++)
            {
                items.Add(StreamIO.LoadItem(reader));
            }
        }
Ejemplo n.º 5
0
        public void LoadFromFile(Stream reader)
        {
            int itemCount = reader.ReadByte();

            items.Clear();

            for (int i = 0; i < itemCount; i++)
            {
                Item item = StreamIO.LoadItem(reader);
                items.Add(item);
                freeSpace -= item.GetSize();
            }
        }