public void Water() { //Don't execute if not the local player //if (!isLocalPlayer) return; //Don't water if in the air or out of water or currently watering if (!isOnGround || waterAmount <= 0f || !canWater) { return; } //Disable movement during watering DisableMove(); DisableWater(); Debug.Log("Water"); //For a 2 wide by 4 tall group of grid tiles in front of the player, attempt to water any plants in those tiles for (int x = 0; x < 2; x++) { for (int y = -2; y < 2; y++) { //Get grid tile GameManager.GridData gridTarget = GameManager.instance.GetGridDataAtLocation( (int)(Mathf.Round(transform.position.x) + 0.5f + ((facingRight ? (x) : (-x - 1)))), (int)(Mathf.Floor(transform.position.y) + y + 0.5f)); //If this is a valid grid position, and there's a plant present if (gridTarget != null && gridTarget.objectTile != null) { //If the objectTile is a Plant object if (gridTarget.objectTile is Plant) { //Water the plant CmdwaterPlant(x, y, facingRight); ((Plant)gridTarget.objectTile).WaterPlant(); } } } } //Track remaining water DecreaseWaterAmount(); //Play water SFX (audioClips[2]) audioManager.PlaySFX(audioClips[2], true); InstantiateWater(facingRight); /* * InstantiateWater * GameObject waterParticle = Instantiate(FindObjectOfType<NetManager>().spawnPrefabs.Find(prefab => prefab.name == "WaterParticle"), transform.position + (Vector3.right * (facingRight ? 1 : -1)), Quaternion.identity); * waterParticle.transform.rotation = Quaternion.Euler(new Vector3(0f, (facingRight ? 0f : 180f), 0f)); * NetworkServer.Spawn(waterParticle.gameObject); */ //Reenable movement and watering after one second Invoke("EnableMove", 1f); Invoke("EnableWater", 1f); }
public void UseItem() { //Don't execute if not the local player //if (!isLocalPlayer) return; Debug.Log("UseItem"); //If we're holding an item, and the targeted Tile is empty if (heldPickupItemTilePrefab != null) { Debug.Log("Held Item Exists"); //If the environment tile exists and is interactable GameManager.GridData gridTarget = GetGridDataAtMousePosition(); if (gridTarget.environmentTile != null && gridTarget.environmentTile.canInteract) { ////If the tile above this isn't empty, don't allow placing this tile //if(!GameManager.instance.GetTileUp(targetedTileX, targetedTileY).IsEmpty()) //{ // //TODO: Play a negative feedback sound---------------------- // Debug.Log("NEGATIVE FEEDBACK SOUND"); //} //else { Debug.Log("Placing tile " + heldPickupItemTilePrefab.name + " at position " + targetedTileX + ", " + targetedTileY); //Instantiate it at the targetedTilePosition SpawnAndInitTileServer(targetedTileX, targetedTileY, heldPickupItemTilePrefab.name); //Remove item from heldItem slot heldPickupItemTilePrefab = null; } } } }
void CmdwaterPlant(float x, float y, bool facingRight) { GameManager.GridData gridTarget = GameManager.instance.GetGridDataAtLocation( (int)(Mathf.Round(transform.position.x) + 0.5f + ((facingRight ? (x) : (-x - 1)))), (int)(Mathf.Floor(transform.position.y) + y + 0.5f)); Debug.Log(gridTarget.objectTile + " " + count++); ((Plant)gridTarget.objectTile).WaterPlant(); WaterPlantClients(x, y, facingRight); }
public void WaterPlantClients(float x, float y, bool facingRight) { if (isLocalPlayer) { return; } GameManager.GridData gridTarget = GameManager.instance.GetGridDataAtLocation( (int)(Mathf.Round(transform.position.x) + 0.5f + ((facingRight ? (x) : (-x - 1)))), (int)(Mathf.Floor(transform.position.y) + y + 0.5f)); Debug.Log("Watered"); ((Plant)gridTarget.objectTile).WaterPlant(); }
public void RemoveItem() { //Don't execute if not the local player //if (!isLocalPlayer) return; Debug.Log("RemoveItem"); //Get grid tile GameManager.GridData gridTarget = GetGridDataAtMousePosition(); //If this is a valid grid position, and there's a plant present if (gridTarget != null && gridTarget.objectTile != null) { //If the objectTile is a Plant object if (gridTarget.objectTile is Plant) { //Water the plant ((Plant)gridTarget.objectTile).RemoveWithItemDrop(); } } }