Beispiel #1
0
 /// <summary>
 /// Restores all of this guards stolen keys.
 /// </summary>
 public void RestoreKeys()
 {
     // Re-enable keys on this guard.
     foreach (KeyID key in stolenKeys)
     {
         DoorKey newKey = gameObject.AddComponent <DoorKey>();
         newKey.KeyIdentity = key;
         currentKeys.Add(key);
         // Update where the AI can navigate to.
         int maskBit = NavUtilities.NavAreaFromKeyID(key);
         navAgent.areaMask = navAgent.areaMask | maskBit;
     }
     stolenKeys.Clear();
 }
Beispiel #2
0
 private void Start()
 {
     audioSource = GetComponent <AudioSource>();
     // Populate the inital keys that this guard has.
     stolenKeys  = new List <KeyID>();
     currentKeys = new List <KeyID>();
     foreach (DoorKey key in gameObject.GetComponents <DoorKey>())
     {
         currentKeys.Add(key.KeyIdentity);
         int maskBit = NavUtilities.NavAreaFromKeyID(key.KeyIdentity);
         // Update where the AI can navigate to.
         navAgent.areaMask = navAgent.areaMask | maskBit;
     }
     investigationPoints = new Stack <Vector3>();
     // The stationary home is always the gaurds initial scene position and rotation.
     stationaryHome      = transform.position;
     stationaryDirection = transform.forward;
     // Set the initial state of this guard.
     Behavior = initialBehavior;
 }
Beispiel #3
0
    /// <summary>
    /// Makes the guard check if they have a given key to open a door.
    /// If the guard doesn't have the key they may become suspicious or look for the key.
    /// </summary>
    /// <param name="doorKey">The type of key.</param>
    /// <returns>True if the key is present.</returns>
    public bool CheckKey(KeyDoor door)
    {
        // Does the guard think they have the key?
        if (currentKeys.Contains(door.LockID))
        {
            KeyID requiredKey = door.LockID;
            // Make sure the key hasn't been stolen.
            foreach (DoorKey key in gameObject.GetComponents <DoorKey>())
            {
                if (key.KeyIdentity == requiredKey)
                {
                    return(true);
                }
            }
            // Otherwise the key has been stolen.
            currentKeys.Remove(requiredKey);
            stolenKeys.Add(requiredKey);
            // Update the pathing in navmesh.
            navAgent.areaMask -= NavUtilities.NavAreaFromKeyID(requiredKey);
            // React to the key loss with behavior:
            switch (Behavior)
            {
            case AIBehaviorState.Stationary:
            case AIBehaviorState.Patrolling:
                investigationPoints.Push(KeyRestock.RestockLocations[0].position);
                Behavior = AIBehaviorState.Investigating;
                break;

            case AIBehaviorState.Investigating:
                // Generate a cluster of suspicion points on the other side of the door.
                investigationPoints.Push(KeyRestock.RestockLocations[0].position);
                Behavior = AIBehaviorState.Investigating;
                break;
            }
        }
        return(false);
    }