Exemplo n.º 1
0
    private IEnumerator StealKeyAnimation()
    {
        // Do animation procedure towards guard to steal key.
        while (true)
        {
            // TODO replace this dummy animation.
            yield return(new WaitForSeconds(1.0f));

            break;
        }
        // TODO; like above, seems inefficient.
        // Steal the first available key.
        foreach (DoorKey key in gameObject.GetComponents <DoorKey>())
        {
            if (key.IsStealable)
            {
                // Grant the key to the player.
                audioSource.PlayOneShot(keySteal);
                nearbyPlayer.GrantKey(key.KeyIdentity);
                Destroy(key);
                break;
            }
        }
        // Release interaction state.
        InteractionComplete?.Invoke();
    }
Exemplo n.º 2
0
 private IEnumerator ExitHiding()
 {
     animatedPosition  = transform.position;
     animatedDirection = transform.forward;
     while (true)
     {
         float travel = Time.deltaTime * enterExitHideSpeed;
         if (travel < Vector3.Distance(animatedPosition, transform.position + transform.forward * exitDistance))
         {
             animatedPosition += travel * animatedDirection;
             nearbyPlayer.transform.position = animatedPosition;
         }
         else
         {
             animatedPosition = transform.position + transform.forward * exitDistance;
             nearbyPlayer.transform.position = animatedPosition;
             break;
         }
         yield return(null);
     }
     PromptVisible         = true;
     PromptMessage         = "Hide";
     nearbyPlayer.IsHiding = false;
     InteractionComplete?.Invoke();
 }
Exemplo n.º 3
0
 // This is called when the player
 // pressed the interact button
 public override void Interact()
 {
     // If the player is currently in the prompt range,
     // then start stealing the key.
     if (PromptVisible)
     {
         StartCoroutine(StealKeyAnimation());
     }
     // Otherwise reject this interaction attempt.
     else
     {
         InteractionComplete?.Invoke();
     }
 }
Exemplo n.º 4
0
    private IEnumerator WhileStealing()
    {
        // TODO: this string should be made
        // into an inspector field. Maybe
        // inherit this from Interaction class.
        PromptMessage = "Stealing...";
        float timeRemaining = stealTime;

        while (true)
        {
            // If the player releases the interact key
            // they can abort this stealing.
            if (!Input.GetKey(interactKey))
            {
                PromptProgress = 0f;
                PromptMessage  = "Steal";
                break;
            }

            // Check the remaining time.
            timeRemaining -= Time.deltaTime;
            PromptProgress = Mathf.Clamp((stealTime - timeRemaining) / stealTime, 0f, 1f);
            if (timeRemaining < 0.2)
            {
                if (audioSource.isPlaying == false)
                {
                    audioSource.PlayOneShot(artStealing);
                }
            }
            if (timeRemaining < 0f)
            {
                // TODO this is a hot fix. Player state needs to be
                // better stolen. Perhaps an objective singleton to handle
                // objective event routing.
                FindObjectOfType <PlayerInteractor>().TriggerArtStolen();
                InteractionComplete?.Invoke();
                Destroy(gameObject);
                break;
            }
            yield return(null);
        }
        nearbyPlayer.IsMovementLocked = false;
        InteractionComplete?.Invoke();
    }
Exemplo n.º 5
0
    public void Interact()
    {
        if (userOpeningDoor.CheckKey(this))
        {
            isLocked = !isLocked;
            if (isLocked)
            {
                PromptMessage         = $"Unlock door";
                playerBlocker.enabled = true;
            }
            else
            {
                PromptMessage         = $"Lock door";
                playerBlocker.enabled = false;
            }
        }

        InteractionComplete?.Invoke();
    }