/// <summary> /// This is where the enemy logic goes, for the base class should be a basic line of sight = attack processing. /// </summary> public bool takeTurn(bool init) { RaycastHit2D hit; hitbox.enabled = false; hit = Physics2D.Linecast(new Vector2(transform.position.x, transform.position.y), new Vector2(target.position.x, target.position.y), blockingLayer); hitbox.enabled = true; float range = sightRange - player.sneak; if (hit.transform == target && hit.distance <= range) { targetLoc = new Vector2(target.position.x, target.position.y); if (path.Count == 0) { GameManager.instance.print("You hear a shout!"); } path = board.findPath(new Vector2((int)transform.position.x, (int)transform.position.y), targetLoc); /*for(int i = 0; i < path.Count; i++){ * Vector2 targ = path[i]; * Instantiate(indicator, new Vector2(targ.x,targ.y), Quaternion.identity); * }*/ //Debug.Log(targetLoc); } if (init) { AP += speed; } if (AP < 1) { return(false); } int xDir = 0; int yDir = 0; //Attempt to pursue target if (path.Count > 0) { yDir = 0; xDir = 0; //Debug.Log(path[0]+" "+path[path.Count-1]); while (Mathf.Abs(yDir) + Mathf.Abs(xDir) < float.Epsilon) { yDir = (int)(path[path.Count - 1].y - transform.position.y); xDir = (int)(path[path.Count - 1].x - transform.position.x); if (Mathf.Abs(yDir) + Mathf.Abs(xDir) < float.Epsilon) { path.RemoveAt(path.Count - 1); if (path.Count == 0) { Debug.Log("\"Target Lost.\" - " + this.name.ToString()); break; } } } /*if (Mathf.Abs(targetLoc.y - transform.position.y) > float.Epsilon) * yDir = targetLoc.y > transform.position.y ? 1 : -1; * * else if (Mathf.Abs(targetLoc.x - transform.position.x) > float.Epsilon) * xDir = targetLoc.x > transform.position.x ? 1 : -1; * else * targetLoc = new Vector2();*/ } //If no target is known, move randomly else { int moveType = Mathf.FloorToInt(Random.Range(0, 5)); switch (moveType) { case 0: break; case 1: xDir = 1; break; case 2: xDir = -1; break; case 3: yDir = 1; break; case 4: yDir = -1; break; } } AttemptMove <Player>(xDir, yDir); AP--; //Return true if the enemy can move again return(AP >= 1); }