Beispiel #1
0
    private bool AttackPlayer()
    {
        if (vision.Player != null)
        {
            var apRequired = motor.ValidPath(vision.Player.transform.position);

            if (apRequired >= 0 && actionPoints.CheckValidAction(apRequired))
            {
                // Debug.Log("Attacking player");
                actionPoints.ExecuteAction(apRequired);
                SetInteraction(vision.Player.GetComponent <Interactable>());
                isAttacking = true;
                StartCoroutine(EndAttack());
                return(true);
                // TODO: Set interaction point, (SetInteraction code from player controller).
            }
        }

        return(false);
    }
    void Update()
    {
        if (enabled == false)
        {
            return;
        }
        if (characterMotor.isMoving)
        {
            playerMarker.transform.position = characterMotor.NextPosition;
        }
        MoveCost.transform.position = updatedPos + new Vector3(0, 1, 0);
        MoveCost.transform.LookAt(FindObjectOfType <Cinemachine.CinemachineFreeLook>().transform);
        var main = particleSystem.main;
        // Gets list of current enemies
        Ray        ray = Camera.main.ScreenPointToRay(Mouse.current.position.ReadValue());
        RaycastHit hitData;

        if (!Physics.Raycast(ray))
        {
            isClickable = false;
            return;
        }
        if (!characterMotor.isMoving && Physics.Raycast(ray, out hitData, 1000))
        {
            isClickable = true;
            // Get tile position that cursor is over
            updatedPos = GridHelper.GetNearestTile(hitData.point);
            playerMarker.transform.position = updatedPos;
            playerMarker.SetActive(true);

            // Moves the tile checker to that tile
            tileChecker.transform.position = updatedPos;
            currentAction   = Action.Move;
            main.startColor = Color.cyan;
            textMesh.color  = Color.cyan;

            tileToMove = remainingDistance(updatedPos);

            // Check if an enemy is on that tile
            foreach (IInteractable interactable in interactableObjects)
            {
                if (collider.bounds.Contains(interactable.gameObject.transform.position))
                {
                    //interactable.gameObject.SetActive(false);
                    if (interactable.gameObject.tag.Equals("Enemy"))
                    {
                        main.startColor              = Color.red;
                        textMesh.color               = Color.red;
                        MoveCost.transform.position += new Vector3(0, 3, 0);
                    }
                    else
                    {
                        main.startColor              = Color.yellow;
                        textMesh.color               = Color.yellow;
                        MoveCost.transform.position += new Vector3(0, 1, 0);
                    }
                    currentAction = Action.Interact;
                    currentTarget = interactable;
                    tileToMove++;
                }
            }
            isValid = true;
        }


        textMesh.text = tileToMove.ToString();

        //Debug.Log(remainingDistance(updatedPos));
        if (!actionPointSystem.CheckValidAction(tileToMove) || tileToMove.Equals(0))
        {
            main.startColor = Color.gray;
            textMesh.color  = Color.gray;
        }
    }