コード例 #1
0
ファイル: GameInfo.cs プロジェクト: haved/3DSmithGameCs
        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);
        }
コード例 #2
0
        public void InteractionPerformed(object source)
        {
            Inventory playerInv = game.GameStats.PlayerInventory;

            if (game.GameStats.CastFilling > 0)
            {
                if (game.GameStats.CastingTemprature > 25)
                {
                    return;                     //The cast is too hot to take out of the cast
                }
                if (game.GameStats.CastFilling >= 1)
                {
                    Item i = game.GameStats.CurrentCast.CreateItem(game, game.GameStats.CastMetal, game.GameStats.CastMetalPurity);
                    if (i == null)
                    {
                        return;
                    }
                    if (playerInv.CanFitItem(i))
                    {
                        playerInv.AddItem(i);
                        game.GameStats.CastFilling = 0;
                    }
                    else
                    {
                        playerInv.InventoryTooFull(i);
                    }
                }
            }
            else
            {
                if (game.GameStats.CurrentCast == null & playerInv.HasSelectedItem())
                {
                    CastItem cast = playerInv.GetSelectedItem() as CastItem;
                    if (cast != null)
                    {
                        game.GameStats.CurrentCast = cast;
                        UpdateCastMatrix();
                        playerInv.RemoveItem(playerInv.GetSelectedItemIndex());
                    }
                }
                else if (game.GameStats.CurrentCast != null && !playerInv.HasSelectedItem())
                {
                    if (playerInv.CanFitItem(game.GameStats.CurrentCast))
                    {
                        playerInv.AddItem(game.GameStats.CurrentCast);
                        game.GameStats.CurrentCast = null;
                    }
                    else
                    {
                        playerInv.InventoryTooFull(game.GameStats.CurrentCast);
                    }
                }
            }
        }