/// <summary> /// If the ground has been watered, call ConnectWateredGround /// </summary> /// <param name="gridPropertyDetails"></param> public void DisplayWateredGround(GridPropertyDetails gridPropertyDetails) { if (gridPropertyDetails.DaysSinceWatered > -1) { ConnectWateredGround(gridPropertyDetails); } }
// This method will simply update the gridPropertDetails for the grid square that this crop we want to instantiate will live on private void SetCropGridProperties(Vector3Int cropGridPosition) { // Check if we've specified a seed ItemCode in the editor for this crop we want to instantiate (with this script on it) if (seedItemCode > 0) { GridPropertyDetails gridPropertyDetails; // Get the current gridPropertyDetails on that square (initialize them if they don't exist for some reason) gridPropertyDetails = GridPropertiesManager.Instance.GetGridPropertyDetails(cropGridPosition.x, cropGridPosition.y); if (gridPropertyDetails != null) { gridPropertyDetails = new GridPropertyDetails(); } // Set the daysSinceDug, daysSinceWatered, seedItemCode, and growthDays with those populated in the editor that we want to instantiate gridPropertyDetails.daysSinceDug = daysSinceDug; gridPropertyDetails.daysSinceWatered = daysSinceWatered; gridPropertyDetails.seedItemCode = seedItemCode; gridPropertyDetails.growthDays = growthDays; // Set up the above updated gridPropertyDetails for the given square GridPropertiesManager.Instance.SetGridPropertyDetails(cropGridPosition.x, cropGridPosition.y, gridPropertyDetails); } }
/// <summary> /// Returns the Crop object at the gridX, gridY position, or null if no crop was found /// </summary> public Crop GetCropObjectAtGridLocation(GridPropertyDetails gridPropertyDetails) { // Get the world position from the gridX and gridY positions of the cell in question (stored in gridPropertyDetails) Vector3 worldPosition = grid.GetCellCenterWorld(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY, 0)); // This method finds ALL colliders overlapping the world position given in an array Collider2D[] collider2DArray = Physics2D.OverlapPointAll(worldPosition); // Loop through all of the found colliders to find a crop gameObject Crop crop = null; for (int i = 0; i < collider2DArray.Length; i++) { // First check all of the parent objects. Get all of the Crop objects, and then check if it exists, and at the same grid position crop = collider2DArray[i].gameObject.GetComponentInParent <Crop>(); if (crop != null && crop.cropGridPosition == new Vector2Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY)) { break; } // Then check the children objects. Get all of the Crop objects, and then check if it exists, and at the same grid position crop = collider2DArray[i].gameObject.GetComponentInChildren <Crop>(); if (crop != null && crop.cropGridPosition == new Vector2Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY)) { break; } } // Return the found crop! If one was found, the above loop will break with a non-null value of crop. If not, the loop will // finish and crop will still be null, so nnull is returned because no crop was found. return(crop); }
/// <summary> /// Returns the crop component if there is a crop growing at the passed in GridPropertyDetails /// </summary> /// <param name="gridPropertyDetails"></param> /// <returns></returns> public Crop GetCropObjectAtGridLocation(GridPropertyDetails gridPropertyDetails) { // Get the world position of the gridPropertyDetails Vector3 worldPosition = grid.GetCellCenterWorld(new Vector3Int(gridPropertyDetails.GridX, gridPropertyDetails.GridY, 0)); // Get the colliders overlapping the world position Collider2D[] collider2DArray = Physics2D.OverlapPointAll(worldPosition); // Check if we have a crop at this point Crop crop = null; for (int i = 0; i < collider2DArray.Length; i++) { crop = collider2DArray[i].gameObject.GetComponentInParent <Crop>(); if (crop != null && crop.cropGridPosition == new Vector2Int(gridPropertyDetails.GridX, gridPropertyDetails.GridY)) { break; } crop = collider2DArray[i].gameObject.GetComponentInChildren <Crop>(); if (crop != null && crop.cropGridPosition == new Vector2Int(gridPropertyDetails.GridX, gridPropertyDetails.GridY)) { break; } } return(crop); }
//Returns the Crop object at the gridX, gridY position or null if no crop was found public Crop GetCropObjectAtGridLocation(GridPropertyDetails gridPropertyDetails) { Vector3 worldPosition = grid.GetCellCenterWorld(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY, 0)); Collider2D[] collider2DArray = Physics2D.OverlapPointAll(worldPosition); //Loop through colliders to get crop game object Crop crop = null; for (int i = 0; i < collider2DArray.Length; i++) { crop = collider2DArray[i].gameObject.GetComponentInParent <Crop>(); if (crop != null && crop.cropGridPosition == new Vector2Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY)) { break; } crop = collider2DArray[i].gameObject.GetComponentInParent <Crop>(); if (crop != null && crop.cropGridPosition == new Vector2Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY)) { break; } } return(crop); }
/// <summary> /// Drops the item (if selected) at the current mouse position, Called by the DropItem event. /// </summary> private void DropSelectedItemAtMousePosition() { if (itemDetails != null && isSelected) { Vector3 worldPosition = mainCamera.ScreenToWorldPoint(new Vector3(Input.mousePosition.x, Input.mousePosition.y, -mainCamera.transform.position.z)); //If can drop item here Vector3Int gridPosition = GridPropertiesManager.Instance.grid.WorldToCell(worldPosition); GridPropertyDetails gridPropertyDetails = GridPropertiesManager.Instance.GetGridPropertyDetails(gridPosition.x, gridPosition.y); if (gridPropertyDetails != null && gridPropertyDetails.canDropItem) { //Create item from prefab at mouse.position GameObject itemGameObject = Instantiate(itemPrefab, new Vector3(worldPosition.x, worldPosition.y - Settings.gridCellSize / 2f, worldPosition.z), Quaternion.identity, parentItem); Item item = itemGameObject.GetComponent <Item>(); item.ItemCode = itemDetails.itemCode; //Remove item from players inventory InventoryManager.Instance.RemoveItem(InventoryLocation.player, item.ItemCode); //If no more of item then clear selected if (InventoryManager.Instance.FindItemInInventory(InventoryLocation.player, item.ItemCode) == -1) { ClearSelectedItem(); } } } }
public void DisplayDugGround(GridPropertyDetails gridPropertyDetails) { // Dug if (gridPropertyDetails.daysSinceDug > -1) { ConnectDugGround(gridPropertyDetails); } }
/// <summary> /// If the ground at the grid location has been dug, call ConnectDugGround /// </summary> /// <param name="gridPropertyDetails"></param> public void DisplayDugGround(GridPropertyDetails gridPropertyDetails) { // If the ground has been dug, call ConnectDugGround if (gridPropertyDetails.DaysSinceDug > -1) { ConnectDugGround(gridPropertyDetails); } }
/// <summary> /// Set up the grid properties with their values from the map /// </summary> private void InitializeGridProperties() { // Loop through all the scriptable object assets which store the grid property values foreach (SO_GridProperties so_GridProperties in so_gridPropertiesArray) { // Create a dictionary to store the grid properties Dictionary <string, GridPropertyDetails> gridPropertyDictionary = new Dictionary <string, GridPropertyDetails>(); // Loop through the GridPropertyList & pull out the grid property from the scriptable object foreach (GridProperty gridProperty in so_GridProperties.GridPropertyList) { GridPropertyDetails gridPropertyDetails; // Populate the gridPropertyDetails from the grid property from the scriptable object asset gridPropertyDetails = GetGridPropertyDetails(gridProperty.GridCoordinate.X, gridProperty.GridCoordinate.Y, gridPropertyDictionary); // If gridPropertyDetails is null, it didn't already exist in our dictionary, so create a new one if (gridPropertyDetails == null) { gridPropertyDetails = new GridPropertyDetails(); } switch (gridProperty.GridBoolProperty) { case GridBoolProperty.diggable: gridPropertyDetails.IsDiggable = gridProperty.GridBoolValue; break; case GridBoolProperty.canDropItem: gridPropertyDetails.CanDropItem = gridProperty.GridBoolValue; break; case GridBoolProperty.canPlaceFurniture: gridPropertyDetails.CanPlaceFurniture = gridProperty.GridBoolValue; break; default: break; } SetGridPropertyDetails(gridProperty.GridCoordinate.X, gridProperty.GridCoordinate.Y, gridPropertyDetails, gridPropertyDictionary); } SceneSave sceneSave = new SceneSave(); // Store the gridPropertyDictionary in the SceneSave's GridPropertyDetailsDictionary sceneSave.GridPropertyDetailsDictionary = gridPropertyDictionary; // If the current scene is the starting scene, set the gridPropertyDictionary member variable to the currently populated gridPropertyDictionary if (so_GridProperties.SceneName.ToString() == SceneControllerManager.Instance.startingSceneName.ToString()) { this.gridPropertyDictionary = gridPropertyDictionary; } // Add the SceneSave with the populated GridPropertyDetailsDictionary to the GameObjectSave SceneData GameObjectSave.SceneData.Add(so_GridProperties.SceneName.ToString(), sceneSave); } }
/// <summary> /// This initialises the grid property dictionary with the values from the SO_GridProperties assets and stores the values for each scene in /// GameObjectSave sceneData /// </summary> private void InitialiseGridProperties() { // Loop through all gridproperties in the array foreach (SO_GridProperties so_GridProperties in so_gridPropertiesArray) { // Create dictionary of grid property details Dictionary <string, GridPropertyDetails> gridPropertyDictionary = new Dictionary <string, GridPropertyDetails>(); // Populate grid property dictionary - Iterate through all the grid properties in the so gridproperties list foreach (GridProperty gridProperty in so_GridProperties.gridPropertyList) { GridPropertyDetails gridPropertyDetails; gridPropertyDetails = GetGridPropertyDetails(gridProperty.gridCoordinate.x, gridProperty.gridCoordinate.y, gridPropertyDictionary); if (gridPropertyDetails == null) { gridPropertyDetails = new GridPropertyDetails(); } switch (gridProperty.gridBoolProperty) { case GridBoolProperty.diggable: gridPropertyDetails.isDiggable = gridProperty.gridBoolValue; break; case GridBoolProperty.canDropItem: gridPropertyDetails.canDropItem = gridProperty.gridBoolValue; break; case GridBoolProperty.canPlaceFurniture: gridPropertyDetails.canPlaceFurniture = gridProperty.gridBoolValue; break; case GridBoolProperty.isPath: gridPropertyDetails.isPath = gridProperty.gridBoolValue; break; case GridBoolProperty.isNPCObstacle: gridPropertyDetails.isNPCObstacle = gridProperty.gridBoolValue; break; default: break; } SetGridPropertyDetails(gridProperty.gridCoordinate.x, gridProperty.gridCoordinate.y, gridPropertyDetails, gridPropertyDictionary); } // If starting scene set the gridPropertyDictionary member variable to the current iteration if (so_GridProperties.sceneName.ToString() == SceneControllerManager.Instance.startingSceneName.ToString()) { this.gridPropertyDictionary = gridPropertyDictionary; } } }
private IEnumerator ProcessHarvestActionsAfterAnimation(CropDetails cropDetails, GridPropertyDetails gridPropertyDetails, Animator animator) { while (!animator.GetCurrentAnimatorStateInfo(0).IsName("Harvested")) { yield return(null); } HarvestActions(cropDetails, gridPropertyDetails); }
// This method will call the ConnectWateredGround method, which will set the correct watered tile, and surrounding tiles public void DisplayWateredGround(GridPropertyDetails gridPropertyDetails) { // Check to see if the current square passed in has been watered (0 or more days since watered) if (gridPropertyDetails.daysSinceWatered > -1) { // This method will set the center (currently watered) tile in response to what the surrounding 4 tiles are, and then update the // surrounding tiles corresponding to what was just laid ConnectWateredGround(gridPropertyDetails); } }
/// <summary> /// This method determines which stage of growth the crop is in, and displays that stage's crop prefab and sprite /// </summary> public void DisplayPlantedCrop(GridPropertyDetails gridPropertyDetails) { // If there's no seed on the grid, the seedItemCode will be -1, so no need to display a crop if (gridPropertyDetails.seedItemCode > -1) { // Get the crop details from the SO CropDetailsList, for the given seedItemCode in the current square's gridPropertyDetails CropDetails cropDetails = so_CropDetailsList.GetCropDetails(gridPropertyDetails.seedItemCode); // Only display the crop if it has a cropDetails! These are set up in the SO_CropDetailsList scriptable object - so don't do this if this seed isn't set up if (cropDetails != null) { // crop prefab to use GameObject cropPrefab; // Get the number of stages of growth this crop has(length of the growthDays array, which defines the number of days for each stage) int growthStages = cropDetails.growthDays.Length; // The crop starts off in stage0, and we will count down the total days of growth until it gets to 0 int currentGrowthStage = 0; // This for loop is just to determine which growth stage we are in, based on how many days the crop has been growing for // Loop backwards through all of the growthstages for (int i = growthStages - 1; i >= 0; i--) { // When the number of days of growth on the crop (found in the gridPropertyDetails) is >= to the days counter // for the current stage (cropDetails.growthDays[i]), we have found the currentStage as i if (gridPropertyDetails.growthDays >= cropDetails.growthDays[i]) { // Break out of the loop - we have found the stage! currentGrowthStage = i; break; } } // Instantiate the crop prefab and sprite at the grid location, with the correct stage! cropPrefab = cropDetails.growthPrefab[currentGrowthStage]; Sprite growthSprite = cropDetails.growthSprite[currentGrowthStage]; // Find the world position of this square Vector3 worldPosition = groundDecoration2.CellToWorld(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY, 0)); // adjust the world position so it's at Bottom center of grid square to look correct worldPosition = new Vector3(worldPosition.x + Settings.gridCellSize / 2, worldPosition.y, worldPosition.z); // Instantiate the crop! GameObject cropInstance = Instantiate(cropPrefab, worldPosition, Quaternion.identity); // Set the proper growthSprite, parent it under our cropParent GameObject, and set the crop grid position in it's Crop class cropInstance.GetComponentInChildren <SpriteRenderer>().sprite = growthSprite; cropInstance.transform.SetParent(cropParentTransform); cropInstance.GetComponent <Crop>().cropGridPosition = new Vector2Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY); } } }
/// <summary> /// Set the grid property details to gridPropertyDetails for the tile at (gridX, gridY) in the gridPropertyDictionary /// </summary> public void SetGridPropertyDetails(int gridX, int gridY, GridPropertyDetails gridPropertyDetails, Dictionary <string, GridPropertyDetails> gridPropertyDictionary) { // Construct the key from the coordinates string key = "x" + gridX + "y" + gridY; gridPropertyDetails.gridX = gridX; gridPropertyDetails.gridY = gridY; // Set the value gridPropertyDictionary[key] = gridPropertyDetails; }
private void HarvestCrop(CropDetails cropDetails, GridPropertyDetails gridPropertyDetails) { gridPropertyDetails.SeedItemCode = -1; gridPropertyDetails.GrowthDays = -1; gridPropertyDetails.DaysSinceLastHarvest = -1; gridPropertyDetails.DaysSinceWatered = -1; GridPropertiesManager.Instance.SetGridPropertyDetails(gridPropertyDetails.GridX, gridPropertyDetails.GridY, gridPropertyDetails); HarvestActions(cropDetails, gridPropertyDetails); }
/// <summary> /// Store grid properties in the passed-in dictionary, base the key on the grid coordinates /// </summary> /// <param name="gridX"></param> /// <param name="gridY"></param> /// <param name="gridPropertyDetails"></param> /// <param name="gridPropertyDictionary"></param> public void SetGridPropertyDetails(int gridX, int gridY, GridPropertyDetails gridPropertyDetails, Dictionary <string, GridPropertyDetails> gridPropertyDictionary) { // Build a string based on the coordinates to be used as the dictionary key string key = "x" + gridX + "y" + gridY; gridPropertyDetails.GridX = gridX; gridPropertyDetails.GridY = gridY; // Store the gridPropertyDetails in the dictionary gridPropertyDictionary[key] = gridPropertyDetails; }
private void HarvestActions(CropDetails cropDetails, GridPropertyDetails gridPropertyDetails) { SpawnHarvestedItems(cropDetails); //Does this crop transform into another crop if (cropDetails.harvestedTransformItemCode > 0) { CreateHarvestedTransformCrop(cropDetails, gridPropertyDetails); } Destroy(gameObject); }
public void SetGridPropertyDetails(int gridX, int gridY, GridPropertyDetails gridPropertyDetails, Dictionary <string, GridPropertyDetails> gridPropertyDictionary) { //Debug.Log("SetGridPropertyDetails bottom was called"); // construct key from coordinate string key = "x" + gridX + "y" + gridY; gridPropertyDetails.gridX = gridX; gridPropertyDetails.gridY = gridY; // Set value gridPropertyDictionary[key] = gridPropertyDetails; }
private void DisplayGridPropertyDetails() { // Loop through all grid items foreach (KeyValuePair <string, GridPropertyDetails> item in gridPropertyDictionary) { GridPropertyDetails gridPropertyDetails = item.Value; DisplayDugGround(gridPropertyDetails); DisplayWateredGround(gridPropertyDetails); } }
// private IEnumerator ProcessHarvestActionsAfterAnimation(CropDetails cropDetails, GridPropertyDetails gridPropertyDetails, Animator animator) { // The harvest animation controller has a final state of "Harvested" once it's done. We will keep on returning null every frame // until the animation is complete, before continuing while (!animator.GetCurrentAnimatorStateInfo(0).IsName("Harvested")) { yield return(null); } // Now that the animation is completed, we can spawn the harvested materials, and destroy the crop gameObject HarvestActions(cropDetails, gridPropertyDetails); }
// This method is subscribed to the advnaceGameDay event, so when a day passes, this will be called and it will loop through the sceneSave dictionaries // Saved for each scene, and then loop through all of the gridSquares in each of those sceneSave dictionaries, updating the properties that // respond to advanced gameDays, such as removing watered tiles, crop growth, etc private void AdvanceDay(int gameYear, Season gameSeason, int gameDay, string gameDayOfWeek, int gameHour, int gameMinute, int gameSecond) { // Clear the display on all grid property details (dug, watered, etc.) so we can update them ClearDisplayGridPropertyDetails(); // Loop through all of the scenes by looping through all of the gridProperties in the array foreach (SO_GridProperties so_GridProperties in so_gridPropertiesArray) { // Get the gridPropertyDetails dictionary (in the sceneSave) for the iterated scene if (GameObjectSave.sceneData.TryGetValue(so_GridProperties.sceneName.ToString(), out SceneSave sceneSave)) { if (sceneSave.gridPropertyDetailsDictionary != null) { // If the dictionary exists, loop through all of the gridProperties in it for (int i = sceneSave.gridPropertyDetailsDictionary.Count - 1; i >= 0; i--) { // This will retrieve the element in the dictionary at position i KeyValuePair <string, GridPropertyDetails> item = sceneSave.gridPropertyDetailsDictionary.ElementAt(i); // Populate the gridPropertyDetails, which has things like daysSinceWatered, etc.. GridPropertyDetails gridPropertyDetails = item.Value; #region Update all of the grid properties that reflect the advance in the day (i.e. watered squares, crop growth, etc.) // If a crop has been planted, increase the number of days that crop has been growing for by 1, only // if the plant has been watered (if it requires water) CropDetails cropDetails = so_CropDetailsList.GetCropDetails(gridPropertyDetails.seedItemCode); if ((gridPropertyDetails.growthDays > -1 && gridPropertyDetails.daysSinceWatered == 0) || (gridPropertyDetails.growthDays > -1 && cropDetails.doesNeedWater == false)) // I added these last four checks to see if the plant has been watered before advancing it's growth days, or to see if it doesn't need watering { gridPropertyDetails.growthDays += 1; } // If the ground is wated, then clear out the water if (gridPropertyDetails.daysSinceWatered > -1) { gridPropertyDetails.daysSinceWatered = -1; } // Set the new gridPropertyDetails SetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY, gridPropertyDetails, sceneSave.gridPropertyDetailsDictionary); #endregion Update all of the grid properties that reflect the advance in the day (i.e. watered squares, crop growth, etc.) } } } } // Once we've looped through each scene, and looped through all of the grid Squares in each sceneSave dictionary, updating the tiles that respond to gameDayAdvanced, // updated the DisplayGridPropertyDetails to reflect the changed values (i.e. removing watered ground tiles!) DisplayGridPropertyDetails(); }
/// <summary> /// Goes through every item in gridPropertyDictionary & calls the display methods /// </summary> private void DisplayGridPropertyDetails() { foreach (KeyValuePair <string, GridPropertyDetails> gridProperty in gridPropertyDictionary) { GridPropertyDetails gridPropertyDetails = gridProperty.Value; DisplayDugGround(gridPropertyDetails); DisplayWateredGround(gridPropertyDetails); DisplayPlantedCrop(gridPropertyDetails); } }
private void CreateHarvestedTransformCrop(CropDetails cropDetails, GridPropertyDetails gridPropertyDetails) { //Update crop in grid properties gridPropertyDetails.seedItemCode = cropDetails.harvestedTransformItemCode; gridPropertyDetails.growthDays = 0; gridPropertyDetails.daysSinceLastHarvest = -1; gridPropertyDetails.daysSinceWatered = -1; GridPropertiesManager.Instance.SetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY, gridPropertyDetails); //Display planted crop GridPropertiesManager.Instance.DisplayPlantedCrop(gridPropertyDetails); }
// This method will create the new transformed crop after harvesting the original crop (i.e. tree -> stump) private void CreateHarvestedTransformCrop(CropDetails cropDetails, GridPropertyDetails gridPropertyDetails) { // Update the crop details in the grid properties, with the info from the harvestedTransformItemCode info in the cropDetails, and the default undug, // unwatered, and ungrown gridProperties gridPropertyDetails.seedItemCode = cropDetails.harvestedTransformItemCode; gridPropertyDetails.growthDays = 0; gridPropertyDetails.daysSinceLastHarvest = -1; gridPropertyDetails.daysSinceWatered = -1; GridPropertiesManager.Instance.SetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY, gridPropertyDetails); // Display the new transformed crop as set up in the gridPropertyDetails GridPropertiesManager.Instance.DisplayPlantedCrop(gridPropertyDetails); }
// This method will spawn the harvested items for the player to pickup, and then destroy the Crop gameObject this Crop script is attached to private void HarvestActions(CropDetails cropDetails, GridPropertyDetails gridPropertyDetails) { // This method will spawn the corresponding harvested items depending on it's CropDetails SpawnHarvestedItems(cropDetails); // Check if this crop transforms into another crop once harvested (like tree -> stump) if (cropDetails.harvestedTransformItemCode > 0) { // This method will create the new transformed crop instance at the same location as the original crop CreateHarvestedTransformCrop(cropDetails, gridPropertyDetails); } Destroy(gameObject); }
// Called from the ISaveableRestoreScene method, to display all of the dug grid squares private void DisplayGridPropertyDetails() { // Loop through all of the grid items in the gridproperty dictionary, and displaying the dug ground tile, watered ground tile, // and planted crop tiles as determined in DisplayDugGround(), DisplayWateredGround(), and DisplayPlantedCrop() foreach (KeyValuePair <string, GridPropertyDetails> item in gridPropertyDictionary) { GridPropertyDetails gridPropertyDetails = item.Value; DisplayDugGround(gridPropertyDetails); DisplayWateredGround(gridPropertyDetails); DisplayPlantedCrop(gridPropertyDetails); } }
// Based on the passed in gridPropertyDetails about the square we are about to water, this will determine what tile to place // on the currently watered tile, and the four surrounding tiles private void ConnectWateredGround(GridPropertyDetails gridPropertyDetails) { // Select tile based on surrounding watered tiles // Begin by setting the currently watered tile to what it needs to be based on the 4 surrounding tiles, as determined // by SetWateredTile, which takes in the coordinates of the tile you want to water, and returns the proper tile to use Tile wateredTile0 = SetWateredTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY); groundDecoration2.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY, 0), wateredTile0); // Set 4 tiles if watered surrounding the current tile - up, down, left, right now that this central tile has been watered // With the proper tile GridPropertyDetails adjacentGridPropertyDetails; // Check the up tile (y+1), by getting the GridPropertyDetails there,and if it isn't null and it has been watered, use // The SetWateredTile() method to determine what THAT tile should be based on ITS four neighbors, and so on and so forth.. adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1); if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceWatered > -1) { Tile wateredTile1 = SetWateredTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1); groundDecoration2.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY + 1, 0), wateredTile1); } // Check the down tile (y-1) in the same way adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1); if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceWatered > -1) { Tile wateredTile2 = SetWateredTile(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1); groundDecoration2.SetTile(new Vector3Int(gridPropertyDetails.gridX, gridPropertyDetails.gridY - 1, 0), wateredTile2); } // Check the left tile (x-1) in the same way adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY); if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceWatered > -1) { Tile wateredTile3 = SetWateredTile(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY); groundDecoration2.SetTile(new Vector3Int(gridPropertyDetails.gridX - 1, gridPropertyDetails.gridY, 0), wateredTile3); } // Check the right tile (x+1) in the same way adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY); if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.daysSinceWatered > -1) { Tile wateredTile4 = SetWateredTile(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY); groundDecoration2.SetTile(new Vector3Int(gridPropertyDetails.gridX + 1, gridPropertyDetails.gridY, 0), wateredTile4); } }
/// <summary> /// Set the tiles to make watered ground appear to be connected with watered ground surrounding it /// </summary> /// <param name="gridPropertyDetails"></param> private void ConnectWateredGround(GridPropertyDetails gridPropertyDetails) { // Determine which tile should be set based on the surrounding tiles Tile wateredTile0 = SetWateredTile(gridPropertyDetails.GridX, gridPropertyDetails.GridY); //Set the tile floorDecoration2.SetTile(new Vector3Int(gridPropertyDetails.GridX, gridPropertyDetails.GridY, 0), wateredTile0); GridPropertyDetails adjacentGridPropertyDetails; // Check the tile above the current tile--is it also watered ground? adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.GridX, gridPropertyDetails.GridY + 1); if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.DaysSinceWatered > -1) { // If so, we need to determine which tile should be set based on the surrounding tiles Tile wateredTile1 = SetWateredTile(gridPropertyDetails.GridX, gridPropertyDetails.GridY + 1); // Set the tile floorDecoration2.SetTile(new Vector3Int(gridPropertyDetails.GridX, gridPropertyDetails.GridY + 1, 0), wateredTile1); } // Check the tile below the current tile--is it also watered ground? adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.GridX, gridPropertyDetails.GridY - 1); if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.DaysSinceWatered > -1) { // If so, we need to determine which tile should be set based on the surrounding tiles Tile wateredTile2 = SetWateredTile(gridPropertyDetails.GridX, gridPropertyDetails.GridY - 1); // Set the tile floorDecoration2.SetTile(new Vector3Int(gridPropertyDetails.GridX, gridPropertyDetails.GridY - 1, 0), wateredTile2); } // Check the tile to the left of the current tile--is it also watered ground? adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.GridX - 1, gridPropertyDetails.GridY); if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.DaysSinceWatered > -1) { // If so, we need to determine which tile should be set based on the surrounding tiles Tile wateredTile3 = SetWateredTile(gridPropertyDetails.GridX - 1, gridPropertyDetails.GridY); // Set the tile floorDecoration2.SetTile(new Vector3Int(gridPropertyDetails.GridX - 1, gridPropertyDetails.GridY, 0), wateredTile3); } // Check the tile to the right of the current tile--is it also watered ground? adjacentGridPropertyDetails = GetGridPropertyDetails(gridPropertyDetails.GridX + 1, gridPropertyDetails.GridY); if (adjacentGridPropertyDetails != null && adjacentGridPropertyDetails.DaysSinceWatered > -1) { // If so, we need to determine which tile should be set based on the surrounding tiles Tile wateredTile4 = SetWateredTile(gridPropertyDetails.GridX + 1, gridPropertyDetails.GridY); // Set the tile floorDecoration2.SetTile(new Vector3Int(gridPropertyDetails.GridX + 1, gridPropertyDetails.GridY, 0), wateredTile4); } }
private bool IsGridSquareWatered(int xGrid, int yGrid) { GridPropertyDetails gridPropertyDetails = GetGridPropertyDetails(xGrid, yGrid); if (gridPropertyDetails == null) { return(false); } else if (gridPropertyDetails.daysSinceWatered > -1) { return(true); } else { return(false); } }
private void AdvanceDay(int gameYear, Season gameSeason, int gameDay, string gameDayOfWeek, int gameHour, int gameMinute, int gameSecond) { //Clear Display all Grid Property Details ClearDisplayGridPropertyDetails(); //Loop through all scenes - by looping through all gridpropertyies in the array foreach (SO_GridProperties so_GridProperties in so_gridPropertiesArray) { //Get gridpropertydetails dictionary for scene if (GameObjectSave.sceneData.TryGetValue(so_GridProperties.sceneName.ToString(), out SceneSave sceneSave)) { if (sceneSave.gridPropertyDetailsDictionary != null) { for (int i = sceneSave.gridPropertyDetailsDictionary.Count - 1; i >= 0; i--) { KeyValuePair <string, GridPropertyDetails> item = sceneSave.gridPropertyDetailsDictionary.ElementAt(i); GridPropertyDetails gridPropertyDetails = item.Value; #region Update all grid properties to reflect the advance in the day //If a crop is planted if (gridPropertyDetails.growthDays > -1) { gridPropertyDetails.growthDays += 1; } //If ground is watered, then clear water if (gridPropertyDetails.daysSinceWatered > -1) { gridPropertyDetails.daysSinceWatered = -1; } //Set gridpropertydetails SetGridPropertyDetails(gridPropertyDetails.gridX, gridPropertyDetails.gridY, gridPropertyDetails, sceneSave.gridPropertyDetailsDictionary); #endregion Update all grid properties to reflect the advance in the day } } } } //Display grid property details to reflect changed values DisplayGridPropertyDetails(); }