Exemplo n.º 1
0
        /// <summary>
        ///     Check current and next tiles to determine their status and if movement is allowed
        /// </summary>
        private Vector3Int AdjustDirection(Vector3Int currentPosition, Vector3Int direction, bool isReplay, Matrix curMatrix)
        {
            if (isGhost)
            {
                return(direction);
            }

            Vector3Int newPos = currentPosition + direction;

            //isReplay tells AdjustDirection if the move being carried out is a replay move for prediction or not
            //a replay move is a move that has already been carried out on the LocalPlayer's client
            if (!isReplay)
            {
                //Check the high level matrix detector
                if (!playerMatrixDetector.CanPass(currentPosition, direction, curMatrix))
                {
                    return(Vector3Int.zero);
                }
                //Not to be checked while performing a replay:
                if (playerSync.PullingObject != null)
                {
                    if (curMatrix.ContainsAt(newPos, playerSync.PullingObject))
                    {
                        //Vector2 directionToPullObj =
                        //	playerSync.pullingObject.transform.localPosition - transform.localPosition;
                        //if (directionToPullObj.normalized != playerSprites.currentDirection) {
                        //	// Ran into pullObject but was not facing it, saved direction
                        //	return direction;
                        //}
                        //Hit Pull obj
                        pna.CmdStopPulling(playerSync.PullingObject);

                        return(Vector3Int.zero);
                    }
                }
            }
            if (!curMatrix.ContainsAt(newPos, gameObject) && curMatrix.IsPassableAt(currentPosition, newPos) && !isReplay)
            {
                return(direction);
            }
            //This is only for replay (to ignore any interactions with the pulled obj):
            if (playerSync.PullingObject != null)
            {
                if (curMatrix.ContainsAt(newPos, playerSync.PullingObject))
                {
                    return(direction);
                }
            }

            if (isReplay)
            {
                return(direction);
            }
            //could not pass
            //Debug.Log("Couldn't pass");
            return(Vector3Int.zero);
        }
Exemplo n.º 2
0
        /// <summary>
        ///     Check current and next tiles to determine their status and if movement is allowed
        /// </summary>
        private Vector3Int AdjustDirection(Vector3Int currentPosition, Vector3Int direction)
        {
            if (isGhost)
            {
                return(direction);
            }

            //Is the current tile restrictive?
            Vector3Int newPos = currentPosition + direction;

            if (playerSync.pullingObject != null)
            {
                if (matrix.ContainsAt(newPos, playerSync.pullingObject))
                {
                    Vector2 directionToPullObj =
                        playerSync.pullingObject.transform.localPosition - transform.localPosition;
                    if (directionToPullObj.normalized != playerSprites.currentDirection)
                    {
                        // Ran into pullObject but was not facing it, saved direction
                        return(direction);
                    }
                    //Hit Pull obj
                    pna.CmdStopPulling(playerSync.pullingObject);
                }
            }

            if (!matrix.IsPassableAt(currentPosition, newPos))
            {
                return(Vector3Int.zero);
            }

            if (matrix.IsPassableAt(newPos) || matrix.ContainsAt(newPos, gameObject))
            {
                return(direction);
            }

            //could not pass
            return(Vector3Int.zero);
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Check current and next tiles to determine their status and if movement is allowed
        /// </summary>
        private Vector3Int AdjustDirection(Vector3Int currentPosition, Vector3Int direction, bool isReplay)
        {
            if (isGhost)
            {
                return(direction);
            }

            Vector3Int newPos = currentPosition + direction;

            //isReplay tells AdjustDirection if the move being carried out is a replay move for prediction or not
            //a replay move is a move that has already been carried out on the LocalPlayer's client
            if (!isReplay)
            {
                Vector3 newRayPos = transform.position + direction;
                rayHit = Physics2D.RaycastAll(newRayPos, (Vector3)direction, 0.2f, hitCheckLayers);
                //	Debug.DrawLine(newRayPos, newRayPos + ((Vector3)direction * 0.2f), Color.red, 1f);

                //Detect new matrices
                for (int i = 0; i < rayHit.Length; i++)
                {
                    //checks to see if the matrix has changed
                    if (rayHit[i].collider.gameObject.layer == 24 &&
                        rayHit[i].collider != curMatrixCol)
                    {
                        curMatrixCol = rayHit[i].collider;
                        ChangeMatricies(rayHit[i].collider.gameObject.transform.parent);
                        Debug.Log("Change Matricies");
                    }

                    //Detected windows or walls across matrices or from space:
                    if (rayHit[i].collider.gameObject.layer == 9 ||
                        rayHit[i].collider.gameObject.layer == 18)
                    {
                        return(Vector3Int.zero);
                    }

                    //Door closed layer (matrix independent)
                    if (rayHit[i].collider.gameObject.layer == 17)
                    {
                        DoorController doorController = rayHit[i].collider.gameObject.GetComponent <DoorController>();

                        // Attempt to open door that could be on another layer
                        if (doorController != null && allowInput)
                        {
                            pna.CmdCheckDoorPermissions(doorController.gameObject, gameObject);
                            allowInput = false;
                            StartCoroutine(DoorInputCoolDown());
                        }
                        return(Vector3Int.zero);
                    }
                }

                //Not to be checked while performing a replay:
                if (playerSync.PullingObject != null)
                {
                    if (matrix.ContainsAt(newPos, playerSync.PullingObject))
                    {
                        //Vector2 directionToPullObj =
                        //	playerSync.pullingObject.transform.localPosition - transform.localPosition;
                        //if (directionToPullObj.normalized != playerSprites.currentDirection) {
                        //	// Ran into pullObject but was not facing it, saved direction
                        //	return direction;
                        //}
                        //Hit Pull obj
                        pna.CmdStopPulling(playerSync.PullingObject);
                        return(Vector3Int.zero);
                    }
                }
            }

            if (matrix.IsPassableAt(currentPosition, newPos) || matrix.ContainsAt(newPos, gameObject))
            {
                return(direction);
            }

            //This is only for replay (to ignore any interactions with the pulled obj):
            if (playerSync.PullingObject != null)
            {
                if (matrix.ContainsAt(newPos, playerSync.PullingObject))
                {
                    return(direction);
                }
            }

            //could not pass
            return(Vector3Int.zero);
        }