Example #1
0
    public IEnumerator gatheringResources(PlayerBehavior playerBehavior, Citizen citizen)
    {
        yield return(new WaitForSeconds(0.3f));

        if (!gatheringsResourcesRunning)
        {
            gatheringsResourcesRunning = true;

            if (citizen)
            {
                citizen.setResourceBeingMined(this);
                citizen.lookAt(this.gameObject);
                player = citizen.transform;
                player.GetComponent <Animator>().SetBool("isGatheringResources", true);
            }
            if (playerBehavior)
            {
                playerBehavior.playerLookAt(this.gameObject);
                player = playerBehavior.transform;
                player.GetComponent <Animator>().SetBool("isGatheringResources", true);
            }

            // TREES
            if (resourceName == "Tree")
            {
                float progress      = 0;
                float progressSpeed = player.GetComponent <Skills>().getSkillByName("Woodcutting").getSpeedMultiplier();
                bool  instantiated  = false;

                while (progress <= 360)
                {
                    progress += Time.deltaTime * progressSpeed * 10;
                    if (player.tag == "player")
                    {
                        progressbar.updateProgressBar(progress);
                    }


                    if (player.tag == "player")
                    {
                        if (gameManager.getPlayerBehavior().getIsMovingToDestination())
                        {
                            gatheringsResourcesRunning = false;
                            player.GetComponent <Animator>().SetBool("isGatheringResources", false);
                            progressbar.resetProgressBar();
                            break;
                        }
                    }

                    /*if(player.tag == "Citizen"){
                     *  if(player.GetComponent<Citizen>().getIsMovingToDestination()){
                     *      gatheringsResourcesRunning = false;
                     *      player.GetComponent<Animator>().SetBool("isGatheringResources" , false);
                     *      break;
                     *  }
                     * }*/
                    if (progress >= 360 && !instantiated)
                    {
                        instantiated = true;
                        GameObject woodLog1 = Instantiate(resourceMined, new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z - 0.5f), Quaternion.identity);
                        GameObject woodLog2 = Instantiate(resourceMined, new Vector3(transform.position.x, transform.position.y + 1.5f, transform.position.z + 0.5f), Quaternion.identity);
                        GameObject woodLog3 = Instantiate(resourceMined, new Vector3(transform.position.x, transform.position.y + 2f, transform.position.z), Quaternion.identity);
                        woodLog1.name = resourceMined.name;
                        woodLog2.name = resourceMined.name;
                        woodLog3.name = resourceMined.name;

                        player.GetComponent <Animator>().SetBool("isGatheringResources", false);

                        if (playerBehavior)
                        {
                            progressbar.resetProgressBar();
                        }

                        player.GetComponent <Skills>().increaseExperience("Woodcutting", experienceGain);

                        if (citizen)
                        {
                            citizen.setResourceBeingMined(null);
                            citizen.addItemToItemsToPickUp(woodLog1.GetComponent <ItemAttributes>());
                            citizen.addItemToItemsToPickUp(woodLog2.GetComponent <ItemAttributes>());
                            citizen.addItemToItemsToPickUp(woodLog3.GetComponent <ItemAttributes>());
                        }


                        Destroy(gameObject);
                    }
                    yield return(null);
                }
            }

            // MINING DEPOTS
            if (resourceName == "Tin depot" ||
                resourceName == "Copper depot" ||
                resourceName == "Iron depot" ||
                resourceName == "Silver depot" ||
                resourceName == "Gold depot" ||
                resourceName == "Kimberlite depot" ||
                resourceName == "Neonium depot" ||
                resourceName == "Ethereum depot")
            {
                float progress      = 0;
                float progressSpeed = player.GetComponent <Skills>().getSkillByName("Woodcutting").getSpeedMultiplier();
                bool  instantiated  = false;

                while (progress <= 360)
                {
                    progress += Time.deltaTime * progressSpeed * 10;
                    if (player.tag == "player")
                    {
                        progressbar.updateProgressBar(progress);
                    }


                    if (player.tag == "player")
                    {
                        if (gameManager.getPlayerBehavior().getIsMovingToDestination())
                        {
                            gatheringsResourcesRunning = false;
                            player.GetComponent <Animator>().SetBool("isGatheringResources", false);
                            progressbar.resetProgressBar();
                            break;
                        }
                    }

                    /*if(player.tag == "Citizen"){
                     *  if(player.GetComponent<Citizen>().getIsMovingToDestination()){
                     *      gatheringsResourcesRunning = false;
                     *      player.GetComponent<Animator>().SetBool("isGatheringResources" , false);
                     *      break;
                     *  }
                     * }*/
                    if (progress >= 360 && !instantiated)
                    {
                        // CHANGE HOW MANY IS SPAWNED??
                        instantiated = true;
                        GameObject woodLog1 = Instantiate(resourceMined, new Vector3(transform.position.x, transform.position.y + 1f, transform.position.z - 0.5f), Quaternion.identity);
                        GameObject woodLog2 = Instantiate(resourceMined, new Vector3(transform.position.x, transform.position.y + 1.5f, transform.position.z + 0.5f), Quaternion.identity);
                        GameObject woodLog3 = Instantiate(resourceMined, new Vector3(transform.position.x, transform.position.y + 2f, transform.position.z), Quaternion.identity);
                        woodLog1.name = resourceMined.name;
                        woodLog2.name = resourceMined.name;
                        woodLog3.name = resourceMined.name;

                        player.GetComponent <Animator>().SetBool("isGatheringResources", false);

                        if (playerBehavior)
                        {
                            progressbar.resetProgressBar();
                        }

                        player.GetComponent <Skills>().increaseExperience("Mining", experienceGain);

                        if (citizen)
                        {
                            citizen.setResourceBeingMined(null);
                            citizen.addItemToItemsToPickUp(woodLog1.GetComponent <ItemAttributes>());
                            citizen.addItemToItemsToPickUp(woodLog2.GetComponent <ItemAttributes>());
                            citizen.addItemToItemsToPickUp(woodLog3.GetComponent <ItemAttributes>());
                        }


                        Destroy(gameObject);
                    }
                    yield return(null);
                }
            }
            // STONEDEPOT; IRONDEPOT; COALDEPOT
            if (resourceName == "Stone depot" || resourceName == "Coal depot" || resourceName == "Marble depot")
            {
                float progressSpeed   = player.GetComponent <Skills>().getSkillByName("Mining").getSpeedMultiplier();
                bool  firstTriggered  = false;
                bool  secondTriggered = false;
                bool  thirdTriggered  = false;
                bool  fourthTriggered = false;
                bool  fifthTriggered  = false;
                bool  sixtTriggered   = false;

                while (progress <= 360)
                {
                    progress += Time.deltaTime * progressSpeed;
                    if (player.tag == "player")
                    {
                        progressbar.updateProgressBar(progress);
                    }

                    if (playerBehavior)
                    {
                        if (gameManager.getPlayerBehavior().getIsMovingToDestination())
                        {
                            gatheringsResourcesRunning = false;
                            player.GetComponent <Animator>().SetBool("isGatheringResources", false);
                            progressbar.resetProgressBar();
                            break;
                        }
                    }
                    if (citizen)
                    {
                        if (citizen.getIsMovingToDestination())
                        {
                            gatheringsResourcesRunning = false;
                            player.GetComponent <Animator>().SetBool("isGatheringResources", false);
                            break;
                        }
                    }
                    if (progress >= 60 && !firstTriggered)
                    {
                        gatheringResourceSteps("first");
                        firstTriggered = true;
                    }
                    if (progress >= 120 && !secondTriggered)
                    {
                        gatheringResourceSteps("second");
                        secondTriggered = true;
                    }
                    if (progress >= 180 && !thirdTriggered)
                    {
                        gatheringResourceSteps("third");
                        thirdTriggered = true;
                    }
                    if (progress >= 240 && !fourthTriggered)
                    {
                        gatheringResourceSteps("fourth");
                        fourthTriggered = true;
                    }
                    if (progress >= 300 && !fifthTriggered)
                    {
                        gatheringResourceSteps("fifth");
                        fifthTriggered = true;
                    }
                    if (progress >= 360 && !sixtTriggered)
                    {
                        gatheringResourceSteps("sixt");
                        sixtTriggered = true;
                        yield return(new WaitForSeconds(2));
                    }
                    yield return(null);
                }
            }
        }
        yield return(new WaitForSeconds(1));

        gatheringsResourcesRunning = false;
    }