public void Mine(GameManager gameManager) { _gameManager = gameManager; _terrain = _gameManager.CurrentTerain; _terrainData = _terrain.terrainData; _terrainPos = _terrain.transform.position; Animation.Play("Mine"); RaycastHit hit; Physics.Raycast(transform.position, -Vector3.up, out hit, 10); if (hit.collider != null && hit.collider.gameObject != null && hit.collider.transform.tag == "Terrain") { var setted = false; HolderObject item = null; _surfaceIndex = GetMainTexture(transform.position); var texName = _terrainData.splatPrototypes[_surfaceIndex].texture.name; var amount = Random.Range(1, 4); foreach (var sandTexture in SandTextures) { if (sandTexture.name == texName) { item = HolderObjectFactory.GetItem(typeof(SandResource), amount); setted = true; break; } } if (!setted) { foreach (var clayTexture in ClayTextures) { if (clayTexture.name == texName) { if (Random.Range(0, 100) < 40) { item = HolderObjectFactory.GetItem(typeof(ClayResource), amount); } else { item = HolderObjectFactory.GetItem(typeof(GroundResource), amount); } setted = true; break; } } } if (item != null) { if (_gameManager.PlayerModel.Inventory.AddItem(item)) { _gameManager.Player.MainHud.ShowAddedResource(item.Item.IconName, item.Amount, item.Item.LocalizationName); } else { _gameManager.Player.MainHud.ShowHudText(Localization.Get("no_place_in_inventory"), HudTextColor.Red); } } } SoundManager.PlaySFX(WorldConsts.AudioConsts.ShovelDigging); }
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); }