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(); }
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(); }
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(); }
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(); }
public void Wander() { if (Jobs.Count != 0) { return; } var position = gameObject.transform.position; var direction = new Vector2(position.x, position.z) + Random.insideUnitCircle * 8f; var destination = new Vector3(direction.x, 0f, direction.y); var ground = GroundUtil.FindGround(destination); if (ground) { Debug.Log(ground.name); JobManager.AddJob(new Job(new JobInfo(this, ground, ground.GetType().GetMethod("Walk"), new object[] { this }))); } }
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(); }
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(); }