/// <summary>
    /// Moves the object slightly towards the next tile. Called every frame this place can transition
    /// Also plays the correct animations
    /// </summary>
    private void Move()
    {
        // If the currentNode exists
        if (_currentNode.WhereToGo != null)
        {
            Vector3 nextPos = this.gameObject.transform.position + _moveDir * _transSpeed * Time.deltaTime;
            // If not finished moving in the x
            if (!_doneTransX)
            {
                // While this is left of the node it wants to get to
                if (_currentNode.WhereToGo.Position.x - nextPos.x > 0.03f && _lastVel.x <= 0)
                {
                    _animRef.SetInteger("MoveState", 1);
                    _sprRendRef.flipX = false;
                    this.gameObject.transform.Translate(Vector3.right * _transSpeed * Time.deltaTime);
                    _lastVel.x = -1;
                    //this.gameObject.transform.position += Vector3.right * transSpeed * Time.deltaTime;
                }
                // While this is right of the node it wants to get to
                else if (_currentNode.WhereToGo.Position.x - nextPos.x < -0.03f && _lastVel.x >= 0)
                {
                    _animRef.SetInteger("MoveState", 1);
                    _sprRendRef.flipX = true;
                    this.gameObject.transform.Translate(Vector3.left * _transSpeed * Time.deltaTime);
                    _lastVel.x = 1;
                    //this.gameObject.transform.position += Vector3.left * transSpeed * Time.deltaTime;
                }
                // Once we get to the x value of the node
                else
                {
                    //this.gameObject.transform.position = new Vector3(Mathf.RoundToInt(currentNode.whereToGo.position.x), Mathf.RoundToInt(this.gameObject.transform.position.y), this.gameObject.transform.position.z);
                    _doneTransX = true;
                    _lastVel.x  = 0;
                }
            }

            // If not finished moving in the y
            if (!_doneTransY)
            {
                // While the node this wants to get to is above where this is
                if (_currentNode.WhereToGo.Position.y - nextPos.y > 0.03f && _lastVel.y >= 0)
                {
                    _sprRendRef.flipX = false;
                    _animRef.SetInteger("MoveState", 2);
                    this.gameObject.transform.Translate(Vector3.up * _transSpeed * Time.deltaTime);
                    _lastVel.y = 1;
                    //this.gameObject.transform.position += Vector3.up * transSpeed * Time.deltaTime;
                }
                // While the node this wants to get to is below where this is
                else if (_currentNode.WhereToGo.Position.y - nextPos.y < -0.03f && _lastVel.y <= 0)
                {
                    _sprRendRef.flipX = false;
                    _animRef.SetInteger("MoveState", 0);
                    this.gameObject.transform.Translate(Vector3.down * _transSpeed * Time.deltaTime);
                    _lastVel.y = -1;
                    //this.gameObject.transform.position += Vector3.down * transSpeed * Time.deltaTime;
                }
                // Once we get to the y value of the node
                else
                {
                    //this.gameObject.transform.position = new Vector3(Mathf.RoundToInt(this.gameObject.transform.position.x), Mathf.RoundToInt(currentNode.whereToGo.position.y), this.gameObject.transform.position.z);
                    _doneTransY = true;
                    _lastVel.y  = 0;
                }
            }

            // Once I have reached the node I was trying to get to
            if (_doneTransX && _doneTransY)
            {
                // If that node is the last node, stop moving
                if (_currentNode.WhereToGo == _currentNode)
                {
                    this.gameObject.transform.position = new Vector3(Mathf.RoundToInt(_currentNode.WhereToGo.Position.x),
                                                                     Mathf.RoundToInt(_currentNode.WhereToGo.Position.y),
                                                                     this.gameObject.transform.position.z);
                    EndMove();
                }
                // Otherwise, find the next node
                else
                {
                    // If there is no character still at the node I just came from, make it have no character on it, so that others can pass through it
                    if (_mAContRef.GetCharacterMAByNode(_currentNode) == null)
                    {
                        _currentNode.Occupying = CharacterType.None;
                    }
                    //animRef.SetInteger("MoveState", -1);
                    _currentNode = _currentNode.WhereToGo;

                    CalculateMoveDirection();
                }
            }
        }
        // If it doesn't exist, we shouldn't be moving
        else
        {
            _transition = false;
            Debug.Log("Current Tile does not exist");
        }
    }
Esempio n. 2
0
    /// <summary>
    /// Called every frame, logics out what should happen upon a selection from the user
    /// </summary>
    private void CheckForSelection()
    {
        // If the user can select things right now and they tried to select something
        if (_canSelect && _inpContRef.SelectClick())
        {
            // Get the node that was just selected
            Node selectedNode = GetSelectedNode();
            // Deselect whatever charcter we had select if the user clicked somewhere that is not a node
            if (selectedNode == null)
            {
                Deselect();
                // Don't execute any more of this iteration, since the selected node is null
                return;
            }

            // If the user has not already selected some character
            if (_charSelected == null)
            {
                AttemptSelect(selectedNode);
            }
            // Otherwise, they have a character selected already
            else
            {
                MoveAttack mARef = _mAContRef.GetCharacterMAByNode(selectedNode);
                // We no longer display stats
                //// If the selected node is the one housing the currently selected character
                //if (mARef != null && mARef == _charSelected)
                //{
                //    //// If we aren't displaying stats, we want to do that
                //    //if (!mARef.MyStats.AreStatsDisplayed())
                //    //{
                //    //    mARef.MyStats.DisplayStats(true);
                //    //}
                //    //// If we are, we want to stop
                //    //else
                //    //{
                //    //    mARef.MyStats.DisplayStats(false);
                //    //}
                //}
                // If the selected node contains an ally (and the currently selected ally isn't targetting friendlies),
                // deselect the current selected character, and select the new character.
                // Or if the selected node contains an enemy and we have an enemy selected
                if ((selectedNode.Occupying == CharacterType.Ally && !_charSelected.TargetFriendly) ||
                    _charSelected.WhatAmI == CharacterType.Enemy)
                {
                    // If that ally is not the currently selected ally, attempt to select them
                    if (_charSelected == null || (mARef != null && mARef.gameObject != _charSelected.gameObject))
                    {
                        Deselect();
                        AttemptSelect(selectedNode);
                    }
                    // Otherwise, just deselect
                    else
                    {
                        Deselect();
                    }
                }
                // Otherwise, If the currently selected character is an ally, try to move them to the location
                // the user just selected, attack something there, or interact with something there
                else if (_charSelected.WhatAmI == CharacterType.Ally)
                {
                    // If the character has not moved yet
                    if (!_charSelected.HasMoved)
                    {
                        // Try to move/attack with them. If it fails (since the node was an invalid one to move/attack), try to select an enemy if its there
                        if (!AttemptMoveOrAttackOrInteract(selectedNode))
                        {
                            AttemptSelect(selectedNode);
                        }
                        // If it was successful, we need to hide their stats
                        else
                        {
                            _charSelected.MyStats.DisplayStats(false);
                        }
                    }
                    // If the character has moved, but not attacked yet
                    else if (!_charSelected.HasAttacked)
                    {
                        // Try to attack
                        if (AttemptAttack(selectedNode, mARef))
                        {
                            // Deselect the already selected character
                            Deselect();
                        }
                        // Try to help/buff
                        // Try to interact
                        else if (AttemptInteract(selectedNode))
                        {
                            // Deselect the already selected character
                            Deselect();
                        }
                        // Otherwise, the node was invalid to attack or interact with, so try to select a character if there is one there
                        else
                        {
                            Deselect();
                            AttemptSelect(selectedNode);
                        }
                    }
                    // If they can do neither just deselect (this would probably never happen)
                    else
                    {
                        Deselect();
                    }
                }
                // If the character is not an ally, just deselect them
                else
                {
                    Deselect();
                }
            }
        }
    }