private void InteractDoor(Vector3 currentPosition, Vector3 direction) { // Make sure there is a door controller Vector3Int position = Vector3Int.RoundToInt(currentPosition + direction); DoorController doorController = matrix.GetFirst <DoorController>(position); if (!doorController) { doorController = matrix.GetFirst <DoorController>(Vector3Int.RoundToInt(currentPosition)); if (doorController) { RegisterDoor registerDoor = doorController.GetComponent <RegisterDoor>(); if (registerDoor.IsPassable(position)) { doorController = null; } } } // Attempt to open door if (doorController != null && allowInput) { pna.CmdCheckDoorPermissions(doorController.gameObject, gameObject); allowInput = false; StartCoroutine(DoorInputCoolDown()); } }
/// Cross-matrix now! uses world positions private void InteractDoor(Vector3Int currentPos, Vector3Int targetPos) { // Make sure there is a door controller DoorController doorController = MatrixManager.Instance.GetFirst <DoorController>(targetPos); if (!doorController) { doorController = MatrixManager.Instance.GetFirst <DoorController>(Vector3Int.RoundToInt(currentPos)); if (doorController) { RegisterDoor registerDoor = doorController.GetComponent <RegisterDoor>(); Vector3Int localPos = MatrixManager.Instance.WorldToLocalInt(targetPos, matrix); if (registerDoor.IsPassable(localPos)) { doorController = null; } } } // Attempt to open door if (doorController != null && allowInput) { pna.CmdCheckDoorPermissions(doorController.gameObject, gameObject); allowInput = false; StartCoroutine(DoorInputCoolDown()); } }
public override void Interact(GameObject originator, Vector3 position, string hand) { PlayerNetworkActions pna = PlayerManager.LocalPlayer.GetComponent <PlayerNetworkActions>(); // Close the door if it's open if (doorController.IsOpened && allowInput) { pna.CmdTryCloseDoor(gameObject); allowInput = false; StartCoroutine(DoorInputCoolDown()); } // Attempt to open if it's closed if (doorController != null && allowInput) { pna.CmdCheckDoorPermissions(gameObject, PlayerManager.LocalPlayerScript.gameObject); allowInput = false; StartCoroutine(DoorInputCoolDown()); } }
/// <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); }