// Used when the player goes to bed public void NightUpdate() { /*Used to reset the global lightning*/ var tempColor = Lighting.color; tempColor.a = 0.0f; Lighting.color = tempColor; /************************************/ /* This used to counter if it has been a week, used to reset the rocks in the mines currently */ WeekCounter++; if (WeekCounter == 7) { for (int i = 0; i < 3; i++) { WeeklyReset[i] = true; } WeekCounter = 0; } /************************************/ TimeTimer = SecondsPerMin; Min = -1; Hour = 8; ++Day; /* This is used to update the players gold */ for (int i = 0; i < cChest.ItemList.Length; i++) { /*If the current index marker is true then we have something to sell*/ if (cChest.Markers[i]) { // An item will have an amount attached so we also want to sell these too float Temp = cChest.ItemList[i].GetSellPrice() * cChest.ItemList[i].GetAmount(); GoldManager.AddAmount(Temp); // Reset the current chest slot as it should be empty cChest.ItemList[i] = null; } } // Reset the markers as they should all be false cChest.ResetMarkers(); // Update the text //string Output = GoldManager.GetMoney().ToString(); //GoldText.text = Output; AssignGoldSprites(); /************************************/ // THIS FUNCTION WILL BE USED TO UPDATED EVERYTHING WE WANT TO CHANGE WHEN THE PLAYER FALLS ALSEEP! foreach (var v in Dictioary.TileMapData.ElementAt(0).Value) { if (v.Value.HasPlant()) { PlantAbstractClass P = v.Value.GetPlant(); P.UpdatePlant(1); } else { v.Value.SetWatered(false); } } }
public override void UpdatePlant(int DayAmount) { if (mHarvestable != true) { if (Dictioary == null) { Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>(); } PlantAbstractClass P = Dictioary.TileMapData.ElementAt(0).Value[ID].GetPlant(); P.mGrowth = true; if (!P.mWatered) { DestoryPlant(); } else { Dictioary.TileMapData.ElementAt(0).Value[ID].SetWatered(false); } CurrentDays += DayAmount; if (CurrentDays >= 0 && CurrentDays < 1) { mSpriteIndex = 0; } if (CurrentDays >= 4 && CurrentDays < 8) { mSpriteIndex = 1; } if (CurrentDays >= 8) { mSpriteIndex = 2; mHarvestable = true; } } }
public override void useTool() { // Set the plant prefab to be the base one PlantPrefab = bPrefab; Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>(); //TODO - when we add more grids and tilemaps, this will break // Convert mouse to world point pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int posInt = grid.LocalToCell(pos); // Check that point doesn't have a plant and contains the key if (Dictioary.TileMapData.ElementAt(0).Value.ContainsKey(posInt) && !Dictioary.TileMapData.ElementAt(0).Value[posInt].HasPlant()) { /*Subtract one as we only use 1 seed at a time, if it drops below 0 then remove the item*/ this.SubstractAmount(1); HotBarClass HotBar = GameObject.FindGameObjectWithTag("InventoryManager").GetComponent <HotBarClass>(); if (this.GetAmount() <= 0) { HotBar.RemoveItem(this.GetName()); } /********************************************************************************************/ ID = posInt; /*Get the audio the play it*/ AudioSource Audio = gameObject.GetComponentInParent <AudioSource>(); Audio.clip = GetSoundEffect(); Audio.Play(); /***************************/ Debug.Log("Seed Planted"); ToolUsed = true; /*Create a clone and instantiate it*/ GameObject Clone; Clone = Instantiate(PlantPrefab, new Vector3(posInt.x + 0.5f, posInt.y + 0.5f, posInt.z), Quaternion.identity); /*****************************/ /* Set up the plant for the clone on that spot in the database */ PlantAbstractClass TempPlant = Clone.GetComponent <PlantAbstractClass>(); TempPlant.ID = ID; TempPlant.pos = pos; TempPlant.AddAmount(1); Dictioary.TileMapData.ElementAt(0).Value[posInt].SetPlant(TempPlant); Dictioary.TileMapData.ElementAt(0).Value[posInt].Clone = Clone; if (Dictioary.TileMapData.ElementAt(0).Value[posInt].IsWatered()) { TempPlant.mWatered = true; } else { TempPlant.mWatered = false; } HotBar.UpdateUI(); /*******************************************************************/ } else { Debug.Log(tileMap.GetTile(posInt).name); Debug.Log("Plot already has a plant placed there"); } }
public override void UpdatePlantSprite() { if (Dictioary == null) { Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>(); } Seeds = GameObject.FindObjectOfType <PlantSeed>(); PlantAbstractClass PrefabTurnip = Dictioary.TileMapData.ElementAt(0).Value[ID].GetPlant(); SpriteRenderer S = Dictioary.TileMapData.ElementAt(0).Value[ID].Clone.GetComponent <SpriteRenderer>(); S.sprite = PrefabTurnip.mGrowthSprites[PrefabTurnip.mSpriteIndex]; }
public TileDataClass() { if (SceneManager.GetActiveScene().name != "LoadSaveScene") { TileMap = GameObject.Find("Floor").GetComponent <Tilemap>(); } else { NeedsFloor = true; } Plant = null; Watered = false; }
public override void UpdatePlantSprite() { // Get the dictioary because we will be in another scene when this happens if (Dictioary == null) { Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>(); } /* Get the plant and update the sprite for the UI */ //Seeds = GameObject.FindObjectOfType<PlantSeed>(); PlantAbstractClass Prefab = Dictioary.TileMapData.ElementAt(0).Value[ID].GetPlant(); SpriteRenderer S = Dictioary.TileMapData.ElementAt(0).Value[ID].Clone.GetComponent <SpriteRenderer>(); S.sprite = Prefab.mGrowthSprites[Prefab.mSpriteIndex]; }
public override void useTool() { if (SceneManager.GetActiveScene().name == "Farmland") { Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>(); //TODO - when we add more grids and tilemaps, this will break // Get the mouse pos to world Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int posInt = grid.LocalToCell(pos); if (Dictioary.TileMapData.ElementAt(0).Value.ContainsKey(posInt)) { // Shows the name of the tile at the specified coordinates // Check if it has already been watered if (!Dictioary.TileMapData.ElementAt(0).Value[posInt].IsWatered()) { //Debug.Log(tileMap.GetTile(posInt).name); /*Play the sound effect*/ AudioSource Audio = gameObject.GetComponentInParent <AudioSource>(); Audio.clip = GetSoundEffect(); Audio.Play(); /*************************/ Debug.Log("This is watered"); ToolUsed = true; /*Edit the tile so it is watered*/ Dictioary.TileMapData.ElementAt(0).Value[posInt].TileMap.SetTile(posInt, GetTile()); Dictioary.TileMapData.ElementAt(0).Value[posInt].Tile = tileMap.GetTile(posInt); Dictioary.TileMapData.ElementAt(0).Value[posInt].SetWatered(true); PlantAbstractClass P = Dictioary.TileMapData.ElementAt(0).Value[posInt].GetPlant(); } else { Debug.Log("This is already watered"); } } else { Debug.Log(tileMap.GetTile(posInt).name); Debug.Log("Needs to be Hoed first"); } } }
// Used to update the plant public override void UpdatePlant(int DayAmount) { // Only update if the plant isn't full grown. if (mHarvestable != true) { // Get the dictioary because we will be in another scene when this happens if (Dictioary == null) { Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>(); } // Gets the current plant PlantAbstractClass P = Dictioary.TileMapData.ElementAt(0).Value[ID].GetPlant(); P.mGrowth = true; // If its not watered then destory the plant else set tile watered variable to false if (!P.mWatered) { DestoryPlant(); } else { Dictioary.TileMapData.ElementAt(0).Value[ID].SetWatered(false); } /*Update the sprite if a number of days have passed*/ CurrentDays += DayAmount; if (CurrentDays >= 0 && CurrentDays < 1) { mSpriteIndex = 0; } if (CurrentDays >= 3 && CurrentDays < 6) { mSpriteIndex = 1; } if (CurrentDays >= 6) { mSpriteIndex = 2; mHarvestable = true; } } }
public override void useTool() { if (SceneManager.GetActiveScene().name == "Farmland") { Dictioary = GameObject.FindGameObjectWithTag("TileMapManager").GetComponent <TileDictionaryClass>(); //TODO - when we add more grids and tilemaps, this will break // Get the mouse positon in world Vector3 pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); Vector3Int posInt = grid.LocalToCell(pos); // Check if the dictionary has a plant there if (Dictioary.TileMapData.ElementAt(0).Value[posInt].HasPlant()) { // check if that plant is harvestable PlantAbstractClass Plant = Dictioary.TileMapData.ElementAt(0).Value[posInt].GetPlant(); if (Plant.mHarvestable) { cInventory = GameObject.FindGameObjectWithTag("InventoryManager").GetComponent <InventoryClass>(); // Play the sound effect AudioSource Audio = gameObject.GetComponentInParent <AudioSource>(); Audio.clip = GetSoundEffect(); Audio.Play(); ToolUsed = true; /************************/ //Debug.Log("GATHERED PLANT"); // Asset the plant and destory the planted one. InventoryAssessment(GetPlantItem(Plant.XMLName), posInt); Plant.DestoryPlant(); } } else { Debug.Log(tileMap.GetTile(posInt).name); Debug.Log("No Plant to Gather"); } } }
public void SetPlant(PlantAbstractClass P) { Plant = P; }
public SaveData(Vector3Int date, Vector3 pos, Vector3Int time, float[] lighting, bool[] resets, int[] slots, float playerGold, int playerEnergy, ItemBase[] inventory, ItemBase[] hotbar, ItemBase[] chest, Dictionary <string, Dictionary <Vector3Int, TileDataClass> > dataBase) { // Set up all the arrays we will be saving to Inventory = new ItemData[slots[0]]; HotBar = new ItemData[slots[1]]; Chest = new ItemData[slots[2]]; Lighting = new float[4]; Farm = new PlantData[dataBase.ElementAt(0).Value.Count]; Mines = new RockData[dataBase.ElementAt(1).Value.Count]; Mines1 = new RockData[dataBase.ElementAt(2).Value.Count]; Mines2 = new RockData[dataBase.ElementAt(3).Value.Count]; Forest = new TreeData[dataBase.ElementAt(4).Value.Count]; Date[0] = date.x; Date[1] = date.y; Date[2] = date.z; Time[0] = time.x; Time[1] = time.y; Time[2] = time.z; PlayerPos[0] = pos.x; PlayerPos[1] = pos.y; PlayerPos[2] = pos.z; WeeklyResets = resets; InventorySlotAmount = slots; PlayerGold = playerGold; PlayerEnergy = playerEnergy; Lighting = lighting; string TileName = ""; string PrefabName = ""; for (int i = 0; i < slots[0]; i++) { if (inventory[i] != null) { if (inventory[i].GetTile() != null) { TileName = inventory[i].GetTile().name; } if (inventory[i].GetPrefab() != null) { PrefabName = inventory[i].GetPrefab().name; } Inventory[i].SetUp(inventory[i].GetName(), inventory[i].mItemType.ToString(), inventory[i].GetSrcImage(), TileName, inventory[i].GetSoundEffect().name, PrefabName, inventory[i].GetAmount(), inventory[i].GetStackable(), inventory[i].GetSellPrice(), inventory[i].GetDesc()); } TileName = ""; PrefabName = ""; } for (int i = 0; i < slots[1]; i++) { if (hotbar[i] != null) { if (hotbar[i].GetTile() != null) { TileName = hotbar[i].GetTile().name; } if (hotbar[i].GetPrefab() != null) { PrefabName = hotbar[i].GetPrefab().name; } HotBar[i].SetUp(hotbar[i].GetName(), hotbar[i].mItemType.ToString(), hotbar[i].GetSrcImage(), TileName, hotbar[i].GetSoundEffect().name, PrefabName, hotbar[i].GetAmount(), hotbar[i].GetStackable(), hotbar[i].GetSellPrice(), hotbar[i].GetDesc()); } TileName = ""; PrefabName = ""; } for (int i = 0; i < slots[2]; i++) { if (chest[i] != null) { if (chest[i].GetTile() != null) { TileName = chest[i].GetTile().name; } if (chest[i].GetPrefab() != null) { PrefabName = chest[i].GetPrefab().name; } Chest[i].SetUp(chest[i].GetName(), chest[i].mItemType.ToString(), chest[i].GetSrcImage(), TileName, chest[i].GetSoundEffect().name, PrefabName, chest[i].GetAmount(), chest[i].GetStackable(), chest[i].GetSellPrice(), chest[i].GetDesc()); } TileName = ""; PrefabName = ""; } int counter = 0; foreach (var var in dataBase.ElementAt(0).Value) { if (var.Value.GetPlant() != null) { PlantAbstractClass Plant = var.Value.GetPlant(); Vector3Int Key = new Vector3Int(var.Key.x, var.Key.y, var.Key.z); string[] GrowthSprites = new string[Plant.mGrowthSprites.Length]; GrowthSprites[0] = Plant.mGrowthSprites[0].name; GrowthSprites[1] = Plant.mGrowthSprites[1].name; GrowthSprites[2] = Plant.mGrowthSprites[2].name; Farm[counter].SetUp(Plant.mCurrentDays, Plant.mGrowthTime, Plant.GetType().ToString(), Plant.GetSrcImage(), Plant.GetAmount(), GrowthSprites, Key, Key, var.Value.Tile.name, Plant.mHarvestable, Plant.mGrowth, Plant.XMLName, Plant.mWatered); } counter++; } counter = 0; foreach (var var in dataBase.ElementAt(1).Value) { OreAbstractClass Ore = var.Value.GetOre(); float[] Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z; Mines[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount()); counter++; } counter = 0; foreach (var var in dataBase.ElementAt(2).Value) { OreAbstractClass Ore = var.Value.GetOre(); float[] Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z; Mines1[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount()); counter++; } counter = 0; foreach (var var in dataBase.ElementAt(3).Value) { OreAbstractClass Ore = var.Value.GetOre(); float[] Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z; Mines2[counter].SetUp(Ore.mItemType.ToString(), Ore.GetName(), Key, Key, var.Value.Tile.name, Ore.XMLName, Ore.GetAmount()); counter++; } counter = 0; foreach (var var in dataBase.ElementAt(4).Value) { ItemBase Wood = var.Value.GetItem(); float[] Key = new float[3]; Key[0] = var.Key.x; Key[1] = var.Key.y; Key[2] = var.Key.z; Forest[counter].SetUp(Wood.mItemType.ToString(), Wood.GetName(), Key, Key, var.Value.Tile.name, Wood.GetName(), Wood.GetAmount()); counter++; } counter = 0; }
IEnumerator eLoadNextLevel(string LevelName, float time) { if (SceneManager.GetActiveScene().name != "LoadSaveScene" && SceneManager.GetActiveScene().name != "InitScene") { Transition.SetTrigger("Start"); // Wait 1 second so the animation can play Debug.Log("CoroutineExample started at " + Time.time.ToString() + "s"); yield return(new WaitForSeconds(time)); Debug.Log("Coroutine Iteration Successful at " + Time.time.ToString() + "s"); } // Tell the Async operation to load the level AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(LevelName); while (!asyncLoad.isDone) { yield return(null); } if (asyncLoad.isDone) { Loading = false; //UICanvas = GameObject.FindGameObjectWithTag("Canvas"); //UICanvas.SetActive(true); // if we aren't on the farm then set all the clone to be not active foreach (var BaseV in Dictionary.TileMapData) { foreach (var ChildV in Dictionary.TileMapData.ElementAt(0).Value) { if (ChildV.Value.Clone != null) { ChildV.Value.Clone.SetActive(false); DontDestroyOnLoad(ChildV.Value.Clone); DOLDatabase DOLD = GameObject.FindGameObjectWithTag("LoadManager").GetComponent <DOLDatabase>(); DOLD.Add(ChildV.Value.Clone); } } } // Set up the player at the location Player.transform.position = StartLocation; Debug.Log(StartLocation); if (LevelName == "Farmland") { // If we are on the player farm then we want to loop through all the clones and set them all to active foreach (var Childv in Dictionary.TileMapData.ElementAt(0).Value) { // we also want to set the tile to be tilled Childv.Value.GetTileMap(); Childv.Value.TileMap.SetTile(Childv.Key, Childv.Value.Tile); if (Childv.Value.Clone != null) { Childv.Value.Clone.SetActive(true); PlantAbstractClass P = Childv.Value.GetPlant(); P.UpdatePlantSprite(); // if we have been to sleep then we want to reset the watered tile if (P.mGrowth == true) { Childv.Value.SetWatered(false); P.mGrowth = false; Childv.Value.TileMap.SetTile(Childv.Key, TilledTile); } } else if (!Childv.Value.IsWatered()) { Childv.Value.SetWatered(false); PlantAbstractClass P = Childv.Value.GetPlant(); Childv.Value.TileMap.SetTile(Childv.Key, TilledTile); } } } } }