Ejemplo n.º 1
0
    private void StateHarvesting()
    {
        // Play harvest sounds every x seconds
        HarvestSoundTimeRemaining -= Time.deltaTime;

        if (HarvestSoundTimeRemaining < 0.0f)
        {
            HarvestSoundTimeRemaining = HarvestSoundTime;
            GameObject.Find("Game").GetComponent <Game>().AudioManager.Play(HarvestTarget.GatherSound);
        }

        HarvestTimeRemaining -= Time.deltaTime;

        if (HarvestTimeRemaining <= 0.0f)
        {
            // Harvest tiles in a radius
            var game = GameObject.Find("Game").GetComponent <Game>();
            var res = game.GetComponent <Game>().Resources;
            var environment = GameObject.Find("Environment").GetComponent <Environment>();
            var tiles = environment.GetHarvestableTilesInRadius(HarvestTarget.GetComponent <EnvironmentTile>(), CurrentTool.HarvestRadius);
            int totalWood = 0, totalStone = 0;

            foreach (var t in tiles)
            {
                if (t.Type == EResource.Wood)
                {
                    totalWood += t.Amount;
                }
                else if (t.Type == EResource.Stone)
                {
                    totalStone += t.Amount;
                }

                environment.Harvest(t);
            }

            // Add total resources
            res.Wood  += totalWood;
            res.Stone += totalStone;

            game.AudioManager.Play("Rubble");

            // Reset states
            mAnimator.SetBool("IsHarvesting", false);
            State         = EState.Idle;
            HarvestTarget = null;
        }
    }
Ejemplo n.º 2
0
    public void ExecuteHarvestTask(Vector3 position)
    {
        HarvestTarget = Task.HarvestTarget;

        if (HarvestTarget != null && !HarvestTarget.Equals(null))
        {
            State = EState.Harvesting;
            HarvestTimeRemaining = CurrentTool.HarvestTime;

            Vector3 target = HarvestTarget.GetComponent <EnvironmentTile>().Position;
            transform.LookAt(new Vector3(target.x, position.y, target.z)); // Look at the tile we are harvesting
            mAnimator.SetBool("IsHarvesting", true);
        }
        else
        {
            HarvestTarget = null;
        }
    }