Пример #1
0
 public void AddCaps(int amount)
 {
     CurrencyManager.AddCurrency(amount);
     ProgressManager.SaveProgress(_gameManager);
 }
Пример #2
0
        public static void LoadProgress(GameManager gameManager)
        {
            var saveData = ObscuredPrefs.GetString(WorldConsts.Save0, "");

            if (string.IsNullOrEmpty(saveData))
            {
                saveData = PlayerPrefs.GetString(WorldConsts.Save0);
            }

            if (PlayerPrefs.GetInt(WorldConsts.LoadFromCloud, 0) == 1)
            {
                saveData = PlayerPrefs.GetString(WorldConsts.CurrentCloudSave);
            }

            Debug.LogError(saveData);

            if (string.IsNullOrEmpty(saveData))
            {
                LoadDefaultProgress(gameManager);
                return;
            }

            var progress = AES.Decrypt(saveData, WorldConsts.CryptKey);

            //fastJSON.JSON.Instance.Parameters.EnableAnonymousTypes = true;
            MainSaveModel.Instanse.ParseJsonStringToSaveItemModel(progress);

            CurrencyManager.AddCurrency(MainSaveModel.Instanse.CurrentCurrency);

            gameManager.CurrentTerain = MainSaveModel.Instanse.CurrentTerratinId == 0
                ? gameManager.Terrain1
                : gameManager.Terrain2;

            gameManager.IapManager.IsBuyStarterPack = MainSaveModel.Instanse.IsBuyStarterPack;
            gameManager.IapManager.IsBuyFirst30000  = MainSaveModel.Instanse.IsBuyFirst30000;
            gameManager.IapManager.IsBuyNoAds       = MainSaveModel.Instanse.IsBuyNoAds;

            gameManager.PlayerModel.Health = MainSaveModel.Instanse.Stats[WorldConsts.Health];
            gameManager.PlayerModel.Hunger = MainSaveModel.Instanse.Stats[WorldConsts.Hunger];
            gameManager.PlayerModel.Thirst = MainSaveModel.Instanse.Stats[WorldConsts.Thirst];
            gameManager.PlayerModel.Energy = MainSaveModel.Instanse.Stats[WorldConsts.Energy];
            TimeSpan difference = DateTime.Now.Subtract(MainSaveModel.Instanse.LogoutTs);

            gameManager.PlayerModel.AddSleepEnergy(difference);
            gameManager.PlayerModel.Breath = 100f;

            TOD_Sky.Instance.Cycle.Hour = MainSaveModel.Instanse.CurrentTime;

            gameManager.Player.transform.localPosition = new Vector3(
                MainSaveModel.Instanse.PlayerPosition[0],
                MainSaveModel.Instanse.PlayerPosition[1],
                MainSaveModel.Instanse.PlayerPosition[2]);
            gameManager.Player.transform.eulerAngles = new Vector3(
                0,
                MainSaveModel.Instanse.PlayerRotation,
                0);

            #region Inventory

            gameManager.PlayerModel.CurrentBackpack = (BackpackType)MainSaveModel.Instanse.CurrentBackpack;
            gameManager.PlayerModel.PrepareInventorySlots();

            if (MainSaveModel.Instanse.PlayerInventory != null)
            {
                for (int i = 0; i < gameManager.PlayerModel.Inventory.MaxSlots; i++)
                {
                    if (MainSaveModel.Instanse.PlayerInventory.ItemInSlots != null &&
                        MainSaveModel.Instanse.PlayerInventory.ItemInSlots.ContainsKey(i.ToString()))
                    {
                        var itemName   = MainSaveModel.Instanse.PlayerInventory.ItemInSlots[i.ToString()];
                        var itemAmount = MainSaveModel.Instanse.PlayerInventory.ItemAmountInSlots[i.ToString()];
                        var durability = MainSaveModel.Instanse.PlayerInventory.ItemDurabilityInSlots[i.ToString()];

                        gameManager.PlayerModel.Inventory.Slots[i] = HolderObjectFactory.GetItem(itemName, itemAmount, durability);
                    }
                }
                for (int i = 0; i < WorldConsts.QuickSlotsAmount; i++)
                {
                    if (MainSaveModel.Instanse.PlayerInventory.ItemInQuickSlots != null &&
                        MainSaveModel.Instanse.PlayerInventory.ItemInQuickSlots.ContainsKey(i.ToString()))
                    {
                        var itemName   = MainSaveModel.Instanse.PlayerInventory.ItemInQuickSlots[i.ToString()];
                        var itemAmount = MainSaveModel.Instanse.PlayerInventory.ItemAmountInQuickSlots[i.ToString()];
                        var durability = MainSaveModel.Instanse.PlayerInventory.ItemDurabilityInQuickSlots[i.ToString()];

                        gameManager.PlayerModel.Inventory.QuickSlots[i] = HolderObjectFactory.GetItem(itemName, itemAmount, durability);
                    }
                }
                for (int i = 0; i < WorldConsts.EquipSlotsAmount; i++)
                {
                    if (MainSaveModel.Instanse.PlayerInventory.ItemInEquipSlots != null &&
                        MainSaveModel.Instanse.PlayerInventory.ItemInEquipSlots.ContainsKey(i.ToString()))
                    {
                        var itemName   = MainSaveModel.Instanse.PlayerInventory.ItemInEquipSlots[i.ToString()];
                        var itemAmount = MainSaveModel.Instanse.PlayerInventory.ItemAmountInEquipSlots[i.ToString()];
                        var durability = MainSaveModel.Instanse.PlayerInventory.ItemDurabilityInEquipSlots[i.ToString()];

                        gameManager.PlayerModel.Inventory.EquipSlots[i] = HolderObjectFactory.GetItem(itemName, itemAmount, durability);
                    }
                }
            }
            #endregion

            if (MainSaveModel.Instanse.GroundItems != null)
            {
                gameManager.PlacementItemsController.PlaceSavedItems(MainSaveModel.Instanse.GroundItems);
            }

            if (MainSaveModel.Instanse.CarModel != null)
            {
                if (gameManager.CarInteractive != null)
                {
                    var carTransform = gameManager.CarInteractive.transform;
                    carTransform.position = new Vector3(MainSaveModel.Instanse.CarModel.PosX,
                                                        MainSaveModel.Instanse.CarModel.PosY, MainSaveModel.Instanse.CarModel.PosZ);
                    carTransform.eulerAngles = new Vector3(MainSaveModel.Instanse.CarModel.RotX,
                                                           MainSaveModel.Instanse.CarModel.RotY, MainSaveModel.Instanse.CarModel.RotZ);
                    gameManager.CarInteractive.Petrol = MainSaveModel.Instanse.CarModel.Petrol;
                }
            }
            else
            {
                if (gameManager.CarInteractive != null)
                {
                    gameManager.CarInteractive.Petrol = 0.5f;
                }
            }

            if (MainSaveModel.Instanse.InCar)
            {
                //var posY = Terrain.activeTerrain.SampleHeight(gameManager.CarInteractive.PlayerOutPosition.position) + 2.0f;
                var posY = gameManager.CurrentTerain.SampleHeight(gameManager.CarInteractive.PlayerOutPosition.position) + 2.0f;
                gameManager.Player.transform.position = new Vector3(gameManager.CarInteractive.PlayerOutPosition.position.x, posY, gameManager.CarInteractive.PlayerOutPosition.position.z);
            }

            //Debug.Log("Load Progress " + progress);

            //AddTestItems(gameManager);
        }