public void AddAmmunition(int add) { actions act = atb.GetActions(); int limit = act.GetWeaponInfs().GetLimitBulets(); /*ammunition += add; * * if (ammunition <= 0) * { * act.SetWeapon(null); * textAmmunition.gameObject.SetActive(false); * } * else * { * if (!textAmmunition.gameObject.activeInHierarchy) * textAmmunition.gameObject.SetActive(true); * * textAmmunition.text = "" + ammunition; * * if (ammunition > limit) * ammunition = limit; * }*/ }
IEnumerator IAAtive() { while (true) { if (atb && !atb.IsDead()) { if (stateNow == statesIa.awareness) { if (!moveTarget) { //Dando direção aletoria para patrulhar float walkDist = Random.Range(3f, 9f), angZ = Random.Range(0f, 360f); Vector2 dire = Quaternion.Euler(Vector3.forward * angZ) * Vector2.up; //Debug.Log(dire); targetPosition = transform.position; targetPosition += dire * walkDist; distTarget = 1f; moveTarget = true; //Olhar apara direção do movimento //atb.GetMovement().TurnTo(Vector2.SignedAngle(Vector2.up, dire)); } //Visão da IA //Area da que a camera pega Camera cam = Camera.main; Vector2 size; size.y = 2f * cam.orthographicSize; size.x = size.y * cam.aspect; Vector2 point1 = transform.position, point2 = point1 + size / 2f; point1 -= size / 2f; Collider2D[] colls = Physics2D.OverlapAreaAll(point1, point2, repository.GetLayerMaskChars()); //Todos os personagens na area for (int i = 0; i < colls.Length; i++) { Collider2D c = colls[i]; if (!c.CompareTag(tag)) { //Angulo de visão Vector2 delta = c.transform.position - transform.position; float angZ = Vector2.SignedAngle(transform.up, delta); if (angZ * angZ <= 90 * 90) { //Dizendo que é o alvo attributes atbX = c.GetComponent <attributes>(); if (!atbX.IsDead()) { atbTarget = atbX; stateNow = statesIa.chase; } } } } } else if (stateNow == statesIa.chase) { actions act = atb.GetActions(); act.StopFire(); if (atbTarget.IsDead()) { atbTarget = null; stateNow = statesIa.awareness; } else { Vector2 delta = atbTarget.transform.position - transform.position; if (delta.magnitude < act.ReachNow() && renderer.isVisible) { stateNow = statesIa.shooting; moveTarget = false; } else { targetPosition = atbTarget.transform.position; Vector2 dire = targetPosition; dire.x -= transform.position.x; dire.y -= transform.position.y; //atb.GetMovement().TurnTo(Vector2.SignedAngle(Vector2.up, dire)); distTarget = 2f; moveTarget = true; } } } else if (stateNow == statesIa.shooting) { Vector2 delta = atbTarget.transform.position - transform.position; actions act = atb.GetActions(); if (delta.magnitude < act.ReachNow() && renderer.isVisible && !atbTarget.IsDead()) { /*float angZNeed = Vector2.SignedAngle(Vector2.up, delta), angZNow = transform.eulerAngles.z; * if (angZNeed < 0f) * angZNeed += 360f; * if (angZNow < 0f) * angZNow += 360f; * * float angZDif = angZNeed - angZNow; * * if (angZDif*angZDif > 400) * { * atb.GetMovement().TurnTo(angZNeed); * } * else * { * act.Fire(); * }*/ } else { stateNow = statesIa.chase; } } } yield return(new WaitForSeconds(timeAction)); } }
public virtual void DamgeAplication(attributes atb, float multiply, Vector2 force) { atb.AddHp((int)(-weaponInfs.GetDamage() * multiply), force, ownerAtb.GetActions().GetPlayerControll()); }