Ejemplo n.º 1
0
    public IEnumerator Plant(Responsible responsible)
    {
        var ground = GroundUtil.FindGround(responsible.gameObject.transform.position);

        if (ground != null)
        {
            if (!ground.occupied)
            {
                responsible.Target = ground.gameObject;
                yield return(StartCoroutine(responsible.Walk(ground.gameObject.transform.position)));
            }
            else
            {
                Debug.Log("Ground is occupied!");
                responsible.FinishJob(true);
                yield return(null);
            }
        }

        responsible.animator.SetTrigger("plant");
        yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), 6f));

        if (ground != null)
        {
            ground.occupied = true;
        }
        responsible.animator.ResetTrigger("plant");
        responsible.Inventory.Remove(gameObject);
        var newProduct = Instantiate(_product, new Vector3(ground.gameObject.transform.position.x, _product.transform.position.y, ground.gameObject.transform.position.z), _product.transform.rotation);

        newProduct.GetComponent <Plant>().SetHarvestable(false);
        Destroy(gameObject, 1f);
        responsible.FinishJob();
    }
Ejemplo n.º 2
0
        public IEnumerator Sleep(Responsible responsible)
        {
            yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

            yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), sleepDuration));

            responsible.FinishJob();
        }
Ejemplo n.º 3
0
    public IEnumerator Walk(Responsible responsible)
    {
        yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

        responsible.FinishJob();
        Debug.Log("Finished walking!");
        yield break;
    }
Ejemplo n.º 4
0
    public virtual IEnumerator Drop(Responsible responsible)
    {
        yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), dropDuration));

        responsible.Inventory.Remove(gameObject);
        gameObject.transform.position = responsible.directionPosition.transform.position;
        SetPicked(false);
        responsible.FinishJob();
    }
Ejemplo n.º 5
0
    public IEnumerator Shower(Responsible responsible)
    {
        yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

        responsible.GetCurrentJob().SetProgressDuration(10);
        yield return(new WaitForSeconds(10));

        responsible.FinishJob();
    }
Ejemplo n.º 6
0
    public virtual IEnumerator Pick(Responsible responsible)
    {
        yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

        yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), _pickDuration));

        responsible.Inventory.Add(this.gameObject);
        SetPicked(true);
        responsible.FinishJob();
    }
Ejemplo n.º 7
0
    public IEnumerator Eat(Responsible responsible)
    {
        yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

        yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), eatDuration));

        responsible.Heal(20);
        Destroy(gameObject, 0.5f);
        responsible.FinishJob();
    }
Ejemplo n.º 8
0
        public IEnumerator Chop(Responsible responsible)
        {
            yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

            yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), SkillManager.GetSkillBonusForDuration(responsible, chopDuration)));

            GroundUtil.Clear(gameObject.transform.position);
            responsible.Inventory.Add(CreateProduct());
            Destroy(gameObject);
            responsible.FinishJob();
        }
Ejemplo n.º 9
0
    public IEnumerator Mine(Responsible responsible)
    {
        yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

        yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), mineDuration));

        GroundUtil.Clear(gameObject.transform.position);
        responsible.Inventory.Add(CreateStone());
        Destroy(gameObject, 0.5f);
        responsible.FinishJob();
    }
Ejemplo n.º 10
0
        public IEnumerator Harvest(Responsible responsible)
        {
            yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

            responsible.animator.SetBool("isHarvesting", true);
            yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), harvestDuration));

            responsible.animator.SetBool("isHarvesting", false);
            GroundUtil.Clear(gameObject.transform.position);
            responsible.Inventory.Add(CreateProduct());
            Destroy(gameObject, 0.5f);
            responsible.FinishJob();
        }
Ejemplo n.º 11
0
    public virtual IEnumerator Unequip(Responsible responsible)
    {
        if (equipped)
        {
            yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), _unequipDuration));

            responsible.Equipment.Unequip(gameObject);
            UIManager.Instance.SetInventory(responsible);
        }

        yield return(null);

        responsible.FinishJob();
    }
Ejemplo n.º 12
0
    public new virtual IEnumerator Drop(Responsible responsible)
    {
        yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), dropDuration));

        if (equipped)
        {
            responsible.Equipment.Unequip(gameObject);
        }
        responsible.Inventory.Remove(gameObject);
        gameObject.transform.position = responsible.gameObject.transform.position;
        gameObject.GetComponent <Rigidbody>().isKinematic = false;
        SetPicked(false);
        SetEquipped(false);
        responsible.FinishJob();
    }
Ejemplo n.º 13
0
    public IEnumerator Eat(Responsible responsible)
    {
        if (!picked)
        {
            yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));
        }

        yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), eatDuration));

        if (picked)
        {
            responsible.Inventory.Remove(GetGroupName());
        }

        Destroy(this.gameObject, 0.1f);
        responsible.FinishJob();
    }
Ejemplo n.º 14
0
    public virtual IEnumerator Equip(Responsible responsible)
    {
        if (picked)
        {
            yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), _equipDuration));
        }
        else
        {
            yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

            responsible.Inventory.Add(this.gameObject);
            yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), _equipDuration));
        }

        responsible.Equipment.Equip(gameObject);
        UIManager.Instance.SetInventory(responsible);
        responsible.FinishJob();
    }
Ejemplo n.º 15
0
    public IEnumerator Craft(Responsible responsible)
    {
        yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

        RecipeManager.Instance.OpenCraftingMenu(recipes, responsible);
        yield return(new WaitUntil(() => recipeSet));

        yield return(currentRecipe.Craft(responsible));

        foreach (var quest in responsible.quests)
        {
            quest.Progress(ActivityType.Craft, currentRecipe.Name);
        }

        var product = RecipeManager.Instance.CreateProduct(currentRecipe, gameObject);

        product.GetComponent <Pickable>().SetPicked(true);
        responsible.Inventory.Add(product);

        responsible.FinishJob();
        ResetRecipe();
    }
Ejemplo n.º 16
0
        public IEnumerator Eat(Responsible responsible)
        {
            if (_harvestable)
            {
                yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));
            }

            yield return(Util.WaitForSeconds(responsible.GetCurrentJob(), eatDuration));

            if (_harvestable)
            {
                GroundUtil.Clear(gameObject.transform.position);
            }
            else
            {
                responsible.Inventory.Remove(gameObject);
            }

            responsible.Inventory.Add(CreateSeed());
            responsible.Heal(20);
            Destroy(gameObject, 0.5f);
            responsible.FinishJob();
        }
Ejemplo n.º 17
0
        public IEnumerator Walk(Responsible responsible)
        {
            yield return(StartCoroutine(responsible.Walk(interactionPoint.transform.position)));

            responsible.FinishJob();
        }
Ejemplo n.º 18
0
    public IEnumerator Place(Responsible responsible)
    {
        if (_placed)
        {
            GroundUtil.Clear(transform.position);
        }

        Time.timeScale = 0;
        while (!Input.GetMouseButtonDown(0))
        {
            var        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;

            if (Physics.Raycast(ray, out hit))
            {
                float x = hit.point.x % 2;
                if (x > 1)
                {
                    x = Mathf.Ceil(hit.point.x);
                }
                else
                {
                    x = Mathf.Floor(hit.point.x);
                }

                float z = hit.point.z % 2;
                if (z > 1)
                {
                    z = Mathf.Ceil(hit.point.z);
                }
                else
                {
                    z = Mathf.Floor(hit.point.z);
                }

                /*
                 * var  rand  = Random.insideUnitCircle * 5f;
                 * rand.x += responsible.gameObject.transform.position.x;
                 * rand.y += responsible.gameObject.transform.position.z;
                 *
                 * if (x <= rand.x && z <= rand.y)
                 * {
                 *  gameObject.transform.position = new Vector3(x, gameObject.transform.localScale.y/2, z);
                 * }
                 */
                gameObject.transform.position = new Vector3(x, gameObject.transform.localScale.y / 2, z);
                var ground_ = GroundUtil.FindGround(transform.position);
                if (ground_ != null)
                {
                    if (ground_.occupied)
                    {
                        gameObject.GetComponent <ShaderAdjuster>().SetColor(Color.red);
                    }
                    else
                    {
                        gameObject.GetComponent <ShaderAdjuster>().SetColor(Color.green);
                    }
                }

                gameObject.transform.rotation = Quaternion.identity;
            }
            yield return(null);
        }
        _placed = true;
        yield return(new WaitUntil(() => _placed));

        Time.timeScale = 1;
        var ground = GroundUtil.FindGround(transform.position);

        if (!ground.occupied)
        {
            GroundUtil.Occupy(gameObject.transform.position);
            SetPicked(!_placed);
            responsible.Inventory.Remove(GetGroupName());
        }
        else
        {
            transform.position = new Vector3(0, -100f, 0);
        }

        responsible.FinishJob();
    }