Exemplo n.º 1
0
        public static void LoadFile()
        {
            string             serializedObjectivesSaveData = "";
            ObjectivesSaveFile savedObjectivesData;

            if (SaveDataHandler.Load(ref serializedObjectivesSaveData, "GunhouseObjectivesSave"))
            {
                savedObjectivesData = JsonUtility.FromJson <ObjectivesSaveFile>(serializedObjectivesSaveData);
            }
            else
            {
                savedObjectivesData = JsonUtility.FromJson <ObjectivesSaveFile>(SaveFile());
            }

            defeatWithGun                      = (Gun.Ammo)(savedObjectivesData.defeatWithGun != 0 ? savedObjectivesData.defeatWithGun : Random.Range((int)Gun.Ammo.DRAGON, (int)Gun.Ammo.SIN));
            previousDefeatWithGun              = (Gun.Ammo)(savedObjectivesData.previousDefeatWithGun != 0 ? savedObjectivesData.previousDefeatWithGun : (int)defeatWithGun);
            amountToDefeat                     = savedObjectivesData.amountToDefeat != 0 ? savedObjectivesData.amountToDefeat : Random.Range(5, 10);
            ammoToUpgrade                      = (Gun.Ammo)(savedObjectivesData.ammoToUpgrade != 0 ? savedObjectivesData.ammoToUpgrade : Random.Range((int)Gun.Ammo.DRAGON, (int)Gun.Ammo.SIN));
            previousAmmoToUpgrade              = (Gun.Ammo)(savedObjectivesData.previousAmmoToUpgrade != 0 ? savedObjectivesData.previousAmmoToUpgrade : (int)ammoToUpgrade);
            leveToUpgrade                      = savedObjectivesData.leveToUpgrade != 0 ? savedObjectivesData.leveToUpgrade : (DataStorage.GunPower[(int)ammoToUpgrade] + 2);
            levelToHealing                     = savedObjectivesData.levelToHealing != 0 ? savedObjectivesData.levelToHealing : (DataStorage.Healing + 2);
            levelToHeart                       = savedObjectivesData.levelToHeart != 0 ? savedObjectivesData.levelToHeart : Mathf.Clamp(DataStorage.Hearts + 1, 0, 6);
            isLevelingHeart                    = (savedObjectivesData.isLevelingHeart != 0 ? savedObjectivesData.isLevelingHeart : 1) == 1 ? true : false;
            amountofBlocksToMake               = savedObjectivesData.amountofBlocksToMake != 0 ? savedObjectivesData.amountofBlocksToMake : Random.Range(3, 10);
            makeXSize                          = savedObjectivesData.makeXSize != 0 ? savedObjectivesData.makeXSize : Random.Range(2, 4);
            makeYSize                          = savedObjectivesData.makeYSize != 0 ? savedObjectivesData.makeYSize : Random.Range(2, 4);
            amountOfSizedBlocksToLoadToGun     = savedObjectivesData.amountOfSizedBlocksToLoadToGun != 0 ? savedObjectivesData.amountOfSizedBlocksToLoadToGun : Random.Range(3, 10);
            loadGunXSize                       = savedObjectivesData.loadGunXSize != 0 ? savedObjectivesData.loadGunXSize : Random.Range(2, 4);
            loadGunYSize                       = savedObjectivesData.loadGunYSize != 0 ? savedObjectivesData.loadGunYSize : Random.Range(2, 4);
            amountOfSizedBlocksToLoadToSpecial = savedObjectivesData.amountOfSizedBlocksToLoadToSpecial != 0 ? savedObjectivesData.amountOfSizedBlocksToLoadToSpecial : Random.Range(3, 10);
            loadSpecialXSize                   = savedObjectivesData.loadSpecialXSize != 0 ? savedObjectivesData.loadSpecialXSize : Random.Range(2, 4);
            loadSpecialYSize                   = savedObjectivesData.loadSpecialYSize != 0 ? savedObjectivesData.loadSpecialYSize : Random.Range(2, 4);
            currentFreeTask                    = savedObjectivesData.currentFreeTask;

            int difference = 0;

            if (DataStorage.Money > 10000)
            {
                int targetAmount = (DataStorage.Money + 10000);
                int whole        = (int)Mathf.Pow(10, Mathf.FloorToInt(Mathf.Log10(targetAmount)) - 2);
                int remainder    = targetAmount % whole;
                difference = whole - remainder;
            }

            amountToHaveInBank       = savedObjectivesData.amountToHaveInBank != 0 ? savedObjectivesData.amountToHaveInBank : (DataStorage.Money + 10000 + difference);
            ammoGunToSend            = (Gun.Ammo)(savedObjectivesData.ammoGunToSend != 0 ? savedObjectivesData.ammoGunToSend : Random.Range((int)Gun.Ammo.DRAGON, (int)Gun.Ammo.GATLING));
            ammoSpecialToSend        = (Gun.Ammo)(savedObjectivesData.ammoSpecialToSend != 0 ? savedObjectivesData.ammoSpecialToSend : Random.Range((int)Gun.Ammo.DRAGON, (int)Gun.Ammo.GATLING));
            amountOfElementsMatching = savedObjectivesData.amountOfElementsMatching != 0 ? savedObjectivesData.amountOfElementsMatching : Random.Range(2, 5);
            amountOfBossesToDefeat   = savedObjectivesData.amountOfBossesToDefeat != 0 ? savedObjectivesData.amountOfBossesToDefeat : Random.Range(2, 5);
            currentBossesDefeated    = savedObjectivesData.currentBossesDefeated;

            int currentDay = (DataStorage.StartOnWave / 3 + 1);

            daysToReach = savedObjectivesData.daysToReach != 0 ? savedObjectivesData.daysToReach : Mathf.Clamp(currentDay, currentDay + 1, currentDay + 4);
        }
Exemplo n.º 2
0
        public static void LoadFile()
        {
            Reset();

            string   serializedSaveData = "";
            SaveData savedData;

            if (SaveDataHandler.Load(ref serializedSaveData, "GunhouseSave"))
            {
                savedData = JsonUtility.FromJson <SaveData>(serializedSaveData);
            }
            else
            {
                serializedSaveData = SaveFile();
                savedData          = JsonUtility.FromJson <SaveData>(serializedSaveData);
            }

            version                    = savedData.version != 0 ? savedData.version : 1;
            Money                      = savedData.Money;
            Hearts                     = savedData.Hearts != 0 ? savedData.Hearts : 2;
            Armor                      = savedData.Armor;
            Healing                    = savedData.Healing != 0 ? savedData.Healing : 1;
            StartOnWave                = savedData.StartOnWave;
            GunOwned                   = savedData.GunOwned != null ? savedData.GunOwned : new bool[NumberOfGuns];
            GunPower                   = savedData.GunPower != null ? savedData.GunPower : new int[NumberOfGuns];
            GunEquipped                = savedData.GunEquipped != null ? savedData.GunEquipped : new bool[NumberOfGuns];
            Choom.MusicVolume          = savedData.MusicVolume != 0 ? savedData.MusicVolume : 0.75f;
            Choom.EffectVolume         = savedData.EffectVolume != 0 ? savedData.EffectVolume : 0.75f;
            IgnoreSignIn               = savedData.IgnoreSignIn;
            Objectives.activeTasks     = savedData.ObjectivesActive != null ? savedData.ObjectivesActive : new int[3];
            AmountOfObjectivesComplete = savedData.AmountOfObjectivesComplete;

            int[] scores = savedData.BestHardcoreScores != null ? savedData.BestHardcoreScores : new int[0];
            BestHardcoreScores.Clear();
            for (int i = 0; i < scores.Length / 2; i++)
            {
                if (scores[i * 2] > 0)
                {
                    BestHardcoreScores.Add(new Tuple <int, int>(scores[i * 2], scores[i * 2 + 1]));
                }
            }

            BlocksLoaded  = savedData.BlocksLoaded != null ? savedData.BlocksLoaded : new int[10];
            AmmoLoaded    = savedData.AmmoLoaded != null ? savedData.AmmoLoaded : new int[10];
            MatchStreak   = savedData.MatchStreak;
            ShotsFired    = savedData.ShotsFired;
            TimesDefeated = savedData.TimesDefeated;
            DisconcertingObjectivesSeen = savedData.DisconcertingObjectivesSeen;
        }