Exemplo n.º 1
0
        /// <summary>
        /// Loads the save file with the given file name, or returns an empty save
        /// if the file doens't exist.
        /// </summary>
        /// <param name="fileName"></param>
        /// <returns></returns>
        private SaveFile LoadFile(string fileName)
        {
            SaveFile file = new SaveFile(fileName);

            StorageContainer container = SmileyUtil.GetStorageContainer();

            if (!container.FileExists(fileName))
            {
                file.IsEmpty = true;
                return(file);
            }

            //Select the specified save file
            using (BitStream input = new BitStream(container, fileName, BitStreamMode.Read))
            {
                file.TimePlayed = TimeSpan.FromTicks(input.ReadBits(64));

                //Load abilties
                foreach (Ability ability in Enum.GetValues(typeof(Ability)))
                {
                    file.HasAbility[ability] = input.ReadBit();
                }

                //Load keys
                for (int i = 0; i < 5; i++)
                {
                    for (int j = 0; j < 4; j++)
                    {
                        file.NumKeys[i, j] = input.ReadByte();
                    }
                }

                //Load gems
                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    foreach (Gem gem in Enum.GetValues(typeof(Gem)))
                    {
                        file.NumGems[level][gem] = input.ReadByte();
                    }
                }

                //Load money
                file.Money = input.ReadByte();

                //Load upgrades
                foreach (Upgrade upgrade in Enum.GetValues(typeof(Upgrade)))
                {
                    file.NumUpgrades[upgrade] = input.ReadByte();
                }

                //Load which bosses have been slain
                foreach (Boss boss in Enum.GetValues(typeof(Boss)))
                {
                    file.HasKilledBoss[boss] = input.ReadBit();
                }

                //Load player zone and location
                file.Level       = (Level)input.ReadByte();
                file.PlayerGridX = input.ReadByte();
                file.PlayerGridY = input.ReadByte();

                //Health and mana
                file.PlayerHealth = (float)(input.ReadByte() / 4);
                file.PlayerMana   = (float)(input.ReadByte());

                //Load changed shit
                int numChanges = input.ReadBits(16);
                for (int i = 0; i < numChanges; i++)
                {
                    file.ChangeTile((Level)input.ReadByte(), input.ReadByte(), input.ReadByte());
                }

                //Load Stats
                file.NumTongueLicks   = input.ReadByte();
                file.NumEnemiesKilled = input.ReadByte();
                file.PixelsTraversed  = input.ReadBits(24);

                //Tutorial Man
                file.AdviceManEncounterCompleted = input.ReadBit();

                for (int i = 0; i < 3; i++)
                {
                    SMH.GUI.SetAbilityInSlot((Ability)input.ReadBits(5), i);
                }

                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    file.HasVisitedLevel[level] = input.ReadBit();
                }

                file.Difficulty = (Difficulty)input.ReadByte();

                //Exploration data
                foreach (Level level in Enum.GetValues(typeof(Level)))
                {
                    for (int j = 0; j < 256; j++)
                    {
                        for (int k = 0; k < 256; k++)
                        {
                            file.Explored[level][j, k] = input.ReadBit();
                        }
                    }
                }
            }

            file.TimeFileLoaded = DateTime.Now.TimeOfDay;

            return(file);
        }