Example #1
0
 private void RpcPlantSeed(Vector3Int location, string plantName, float growthRate)
 {
     Debug.Log("Have plant growth of: " + growthRate);
     WorldData2.AddPlantedLocation(location, plantName, growthRate);
 }
Example #2
0
    public void UseSelectedItem(Vector2 location)
    {
        if (selectedSlot.Count != 0)
        {
            Item2      item      = selectedSlot.First.Value;
            Vector3Int tileCoord = WorldData2.p1DiggableLayer.WorldToCell(location);  //Get cell location
            // if item is a seed it adds a tile based on the editor
            if (item.is_seed)
            {
                if ((WorldData2.p1DiggableLayer.GetTile(tileCoord) == null && WorldData2.p2DiggableLayer.GetTile(tileCoord) == null) &&
                    (WorldData2.plantableLayer.GetTile(tileCoord) != null) && (WorldData2.CheckPlantedLocation(tileCoord)))
                {
                    float growthRate = PlayerData2.localGrowSpeed;

                    //Extract vegetable name by taking off last 5 characters (" seed")
                    string vegetableString = item.itemName.Substring(0, item.itemName.Length - 5);

                    // Place item in middle of cell, track planted location. All handled by world data
                    bool plantAttempt = WorldData2.AddPlantedLocation(tileCoord, vegetableString, growthRate);

                    //On succesful plant, tell other clients to add a plant at that location as well
                    if (plantAttempt)
                    {
                        SoundControl.PlayPlantSound();
                        Debug.Log("here");
                        //Tell others to add the plant
                        Debug.Log("Sending through growth rate of " + growthRate.ToString());
                        CmdPlantSeed(tileCoord, vegetableString, growthRate);
                        ItemUsed();
                    }
                }
            }
            else
            {
                switch (item.itemName)
                {
                case "Shovel":
                    // locally update our tile
                    WorldData2.p1DiggableLayer.SetTile(tileCoord, null);
                    WorldData2.p2DiggableLayer.SetTile(tileCoord, null);
                    SoundControl.PlayShovelSound();
                    // tell the server to tell other clients about our click
                    if (isServer)
                    {
                        RpcSetTile(tileCoord);
                    }
                    else
                    {
                        CmdSetTile(tileCoord);
                    }
                    break;

                case "BearTrap":
                    //selectedItemObject = selectedItem.actionPrefab;

/*                        if (isServer)
 *                          RpcSetBearTrap(location, gameObject.tag);
 *                      else*/
                    CmdSetBearTrap(location, gameObject.tag);
                    break;
                }
            }
        }
    }