示例#1
0
    public void AttackAction()
    {
        if (turnState != HeroTurnState.WaitingForCommand)
        {
            CancelCommand();
        }

        turnState = HeroTurnState.AttackCommand;

        targetMarker.Activate(true);
        targetMarker.SetPosition(transform.position - height);

        // find targets in hit area
        CapsuleCollider capsule = targetMarker.GetComponent <CapsuleCollider>();

        Collider[] colliders = OverlapCollider(capsule);
        foreach (Collider coll in colliders)
        {
            if (coll.gameObject.layer == Layers.Actors && coll.gameObject != this.gameObject)
            {
                coll.gameObject.GetComponent <MeshRenderer>().sharedMaterial.color = Color.blue;
                targets.Add(coll.gameObject);
            }
        }
    }
示例#2
0
    public void CombatResolved()
    {
        turnState = HeroTurnState.WaitingForCommand;
        turnManager.UpdateCurrentActorHUD();

        turnManager.DisableCommand(attackCommand);
        turnManager.CombatResolved();
    }
示例#3
0
    public void TakeTurn()
    {
        SetSelected(true);
        turnState     = HeroTurnState.WaitingForCommand;
        moveRemaining = maxMove;

        turnManager.EnablePlayerInput();
        turnManager.UpdateCurrentActorHUD();
    }
示例#4
0
    public void MoveAction()
    {
        if (turnState != HeroTurnState.WaitingForCommand)
        {
            CancelCommand();
        }

        turnState = HeroTurnState.MoveCommand;
        moveHelper.Activate(true, transform.position - height);
    }
示例#5
0
    public void FinishTurn()
    {
        if (turnState != HeroTurnState.WaitingForCommand)
        {
            CancelCommand();
        }

        SetSelected(false);
        turnState = HeroTurnState.NotMyTurn;

        moveHelper.Activate(false, Vector3.zero);

        turnManager.DisablePlayerInput();
    }
示例#6
0
    private IEnumerator MoveTo(Vector3 point)
    {
        turnManager.DisablePlayerInput();
        turnState = HeroTurnState.Moving;

        float   t        = 0;
        Vector3 startpos = transform.localPosition;
        Vector3 endpoint;
        float   distanceToPoint = (point - startpos).magnitude;

        if (distanceToPoint > moveRemaining)
        {
            Vector3 A = startpos;
            Vector3 B = point;
            endpoint = (B - A) * (moveRemaining / distanceToPoint) + A;
        }
        else
        {
            endpoint = point;
        }

        endpoint.y = startpos.y;

        while (t < 1)
        {
            transform.localPosition = Vector3.MoveTowards(startpos, endpoint, t * maxMove);
            moveHelper.UpdatePosition(transform.position - height);
            t += Time.deltaTime;
            yield return(null);
        }

        moveRemaining -= distanceToPoint > moveRemaining ? moveRemaining : distanceToPoint;
        if (moveRemaining <= 0)
        {
            turnManager.DisableCommand(moveCommand);
        }

        transform.localPosition = endpoint;

        CancelCommand();
    }
示例#7
0
    private void CancelCommand()
    {
        moveHelper.Activate(false, Vector3.zero);
        targetMarker.Activate(false);
        if (targets.Count != 0)
        {
            foreach (GameObject target in targets)
            {
                target.GetComponent <MeshRenderer>().sharedMaterial.color = Color.white;
            }

            targets.Clear();
            targetArrow.Hide();
            currentTarget = null;
        }


        turnState = HeroTurnState.WaitingForCommand;

        turnManager.EnablePlayerInput();
        turnManager.UpdateCurrentActorHUD();
    }
示例#8
0
    void Update()
    {
        switch (turnState)
        {
        case HeroTurnState.AttackCommand:
            if (Input.GetMouseButtonDown(1))
            {
                CancelCommand();
                break;
            }
            else if (Input.GetMouseButtonDown(0) && currentTarget != null)
            {
                // attack!
                turnManager.CommenceAttackSequence(this, currentTarget.GetComponent <ActorController>());
                turnState = HeroTurnState.ResolvingCombat;
            }

            ray = mainCamera.ScreenPointToRay(Input.mousePosition);

            RaycastHit[] hits = Physics.RaycastAll(ray, Mathf.Infinity);

            for (int i = 0; i < hits.Length; ++i)
            {
                Transform objectFound = hits[i].transform;
                if (targets.Contains(objectFound.gameObject))
                {
                    if (objectFound.gameObject != currentTarget)
                    {
                        currentTarget = objectFound.gameObject;
                        targetArrow.Show(currentTarget);
                    }
                }
            }


            break;

        case HeroTurnState.MoveCommand:
            ray = mainCamera.ScreenPointToRay(Input.mousePosition);

            if (Input.GetMouseButtonDown(1))
            {
                CancelCommand();
            }
            else if (Physics.Raycast(ray, out hit))
            {
                Transform objectFound = hit.transform;
                if (objectFound.CompareTag("Ground"))
                {
                    moveHelper.CreateLineToTarget(hit.point,
                                                  transform.position - height, moveRemaining, true);

                    if (Input.GetMouseButtonDown(0))
                    {
                        if (moveRemaining > 0)
                        {
                            // move
                            StartCoroutine(MoveTo(hit.point));
                        }
                    }
                }
                else
                {
                    moveHelper.CreateLineToTarget(hit.point,
                                                  transform.position - height, moveRemaining, false);
                }
            }

            break;

        case HeroTurnState.NotMyTurn:
        default:
            break;
        }
    }