/// <summary> /// Launches an attempt to connect the SSH and VNC clients to the VNC server machine. /// If it fails on its first attempt, will launch a periodic process in charge of trying to connect /// periodically to the specified host <see cref="AttemptToConnect"/>. /// If the connection attempt succeeds, calls the process that will arrange the live desktop visualization. /// </summary> private void ConnectToHost() { bool connect = true; try { // Attempt to contact the server both via SSH and VNC. SetUpSshConnection(); SetUpVncConnection(); } catch (Exception) // If the server could not be contacted, periodically try again. { connect = false; if (!_attemptingConnection) { StartCoroutine(AttemptToConnect()); } } if (connect) { StartCoroutine(ConfirmVncConnection()); StartCoroutine(CheckConnectionStatus()); serverStatus.Notify(); } }
/// <summary> /// Checks for collision events between the AbstractInteractable object and other objects with collision capabilities. /// If the object colliding with the object is the player, can mark that the player is in range and signals the /// player that an interactive object is close. /// </summary> /// <param name="other">Collider object that initiated contact.</param> protected virtual void OnTriggerEnter2D(Collider2D other) { if (other.CompareTag("Player") && !other.isTrigger) { PlayerInRange = true; if (context != null) { context.Notify(); } } }
/// <summary> /// Handles the logic operations made when the object is picked up. /// </summary> public virtual void PickUp() { receiveItem.Notify(); isPickedUp.runtimeValue = true; SpriteRenderer.enabled = false; AudioManager.Instance.PlayEffectClip(AudioManager.PickUpItem); }
/// <summary> /// Manages the logic when the chest is opened by the player. /// Activates the dialog and re-arranges the player's inventory, for that, it raises a signal /// to the player and set the chest to already open (<see cref="persistenceOpen"/>). /// </summary> private void OpenChest() { // Set up dialogue dialogBox.SetActive(true); dialogText.text = content.itemDescription; AudioManager.Instance.PlayEffectClip(AudioManager.PickUpItem); // Set up player inventory and notify player for animation. playerInventory.AddItem(content); playerInventory.currentItem = content; receiveItem.Notify(); // Disable context clue on top of player. context.Notify(); persistenceOpen.runtimeValue = true; _chestAnimator.SetBool(AnimatorOpen, true); }
/// <summary> /// Handle the logic events that happen when an enemy dies. /// </summary> private void OnEnemyDeath() { if (killedSignal != null) { killedSignal.Notify(); } AudioManager.Instance.PlayEffectClip(AudioManager.EnemyDead); // If a death effect has been defined... if (deathEffect != null) { GameObject enemyDeathEffect = Instantiate(deathEffect, transform.position, Quaternion.identity); // Destroy effect after a sec. Destroy(enemyDeathEffect, 1f); } }
protected override void Update() { if (PlayerInRange && Input.GetButtonDown("Interact")) { if (playerInventory.currentKeysValue.runtimeValue > 0) { playerInventory.SubtractKey(); context.Notify(); keyUsedSignal.Notify(); Open(); } else { AudioManager.Instance.PlayEffectClip(AudioManager.Error); } } }
/// <summary> /// Checks for user controller input either on the joystick or the D-PAD to manage future player operations. /// </summary> private void CheckPlayerInput() { // Check remote terminal input if (Input.GetButtonDown("RemoteTerminal") && hasTerminal.runtimeValue && currentState != PlayerState.Attack) { currentState = currentState != PlayerState.RemoteTerminal ? PlayerState.RemoteTerminal : PlayerState.Walk; playerRemoteTerminalSignal.Notify(); } // If in remote terminal mode, do not check for movement or attack. if (currentState == PlayerState.RemoteTerminal) { return; } // Check movement input _positionChange.x = Input.GetAxisRaw("Horizontal"); if (Math.Abs(_positionChange.x) < JoystickTolerance) { _positionChange.x = Input.GetAxisRaw("HorizontalPAD"); } _positionChange.y = Input.GetAxisRaw("Vertical"); if (Math.Abs(_positionChange.y) < JoystickTolerance) { _positionChange.y = Input.GetAxisRaw("VerticalPAD"); } // Check attack input if (Input.GetButtonDown("Attack") && currentState != PlayerState.Attack && currentState != PlayerState.Staggered) { if (hasSword.runtimeValue) { StartCoroutine(Attack()); } } else if (currentState == PlayerState.Idle || currentState == PlayerState.Walk) { UpdateAnimationAndMove(); } }
/// <summary> /// Logic for activation of the pause menu. Shows or hides the menu on screen /// along with the player cursor. Freezes the game timescale while on pause. /// </summary> public void TogglePause() { _isPaused = !_isPaused; mainPanel.SetActive(_isPaused); manualPanel.SetActive(false); Cursor.visible = !Cursor.visible; pauseSignal.Notify(); if (_isPaused) { Time.timeScale = 0; } else { Time.timeScale = 1f; IsShowingHelp = false; } AudioManager.Instance.PlayEffectClip(AudioManager.Pause); }
/// <summary> /// Applies damage to player and arranges the end of knockback logic if the player has /// health left. /// </summary> /// <param name="knockTime"></param> /// <param name="damage">Damage inflicted to the player when knocked back.</param> public void Knock(float knockTime, float damage) { // Reduce life no more than 0. currentHealth.runtimeValue = Mathf.Max(0, currentHealth.runtimeValue - damage); playerHealthSignal.Notify(); if (currentHealth.runtimeValue > 0) { // Camera kick playerDamageSignal.Notify(); // Sound effect AudioManager.Instance.PlayEffectClip(AudioManager.PlayerHit); // End knock back StartCoroutine(EndKnock(knockTime)); } // Player death else { playerDeathSignal.Notify(); } }