public void OnDoorStay(OpenableDoor door)
 {
     if (!_isHandlingDoor)
     {
         StartCoroutine(DelayedDoorHandler(door));
     }
 }
    private IEnumerator IgnoreCollisionsUntilOpen(OpenableDoor door)
    {
        var enemy = transform.parent;

        if (enemy == null)
        {
            yield break;
        }

        Physics.IgnoreCollision(enemy.collider, door.collider, true);

        yield return(new WaitForSeconds(1f));

        if (enemy == null)
        {
            yield break;
        }

        // Restore collisions if the door is open or if the enemy has already moved away from the door
        if (door.IsOpen || enemy.gameObject.layer != LayerMaskStorage.EnemyAtDoorLayer)
        {
            Physics.IgnoreCollision(enemy.collider, door.collider, false);
        }
        else
        {
            // If door is still open or opening, keep ignoring collisions
            StartCoroutine(IgnoreCollisionsUntilOpen(door));
        }
    }
    protected override void Start()
    {
        base.Start();

        door = transform.parent.GetComponent <OpenableDoor>();
        Type.Set(InteractableType.Interactable);
    }
 private void Update()
 {
     if (medRoomNumberEntered && bathRoomNumberEntered && paintingNumberEntered)
     {
         oDoor         = safeDoor.GetComponent <OpenableDoor>();
         oDoor.enabled = true;
     }
 }
    private IEnumerator DelayedDoorHandler(OpenableDoor door)
    {
        _isHandlingDoor = true;

        yield return(new WaitForSeconds(_doorHandlerInterval));

        _isHandlingDoor = false;

        HandleDoor(door);
    }
Esempio n. 6
0
    private void SetCabinetReference(CallbackData data)
    {
        CabinetBase cabinet = (CabinetBase)data.DataObject;

        if (cabinet.type == CabinetBase.CabinetType.PassThrough)
        {
            this.cabinet = cabinet;
            door         = cabinet.transform.Find("Door").GetComponent <OpenableDoor>();
            base.UnsubscribeEvent(SetCabinetReference, EventType.ItemPlacedForReference);
        }
    }
Esempio n. 7
0
 protected override void HandleDoor(OpenableDoor door)
 {
     // Only open the door if we are is facing it. This somewhat simulates if the door is in our path.
     if (door.IsClosed && PathFinder.IsOnPath(door.transform))
     {
         var success = OpenDoor(door);
         if (!success)
         {
             Debug.LogWarning("Failed to open door.");
         }
     }
 }
    public void OnDoorStay(OpenableDoor door)
    {
        if (!enabled)
        {
            return;
        }

        if (_activeAi != null)
        {
            _activeAi.OnDoorStay(door);
        }
    }
    protected bool OpenDoor(OpenableDoor door)
    {
        var success = door.Open();

        if (success)
        {
            Wait(0.5f);

            // NOTE: Tried to disable collisions between layers DoorUnlocked and EnemyAtDoor
            // instead, but this caused the enemies to move through doors to reach the player.

            StartCoroutine(IgnoreCollisionsWith(door.collider, 5.0f));
            //StartCoroutine(IgnoreCollisionsUntilOpen(door)); // Doesn't work as well
        }

        return(success);
    }
    protected override void HandleDoor(OpenableDoor door)
    {
        // If enemy can see player, do nothing since most probably this door is not in the enemy's path
        if (LineOfSight.CanSeePlayer)
        {
            return;
        }

        // If door is being locked, do nothing
        if (door.IsBeingLocked)
        {
            return;
        }

        // TODO: Handle player locking himself in a room; how to detect and what actions to take?
        //       What if the player manages to lock an enemy inside a room? (More of a path manager problem)
        // NOTE: Above do not necessary only happen when pursuing! (Do not restrict to this behaviour)

        if (door.IsLocked)
        {
            Debug.Log("Door is locked.");

            if (!PathFinder.HasPath || (!PathFinder.IsCurrentTarget(_lastHeardPlayerPosition) &&
                                        !PathFinder.HasSearchedTarget(_lastHeardPlayerPosition)))
            {
                PathFinder.FindPathTo(_lastHeardPlayerPosition);

                Debug.Log("Trying to get around by finding path to last heard position " + _lastHeardPlayerPosition);
            }
        }
        // If door is closing or closed, attempt to open it
        else if (door.IsClosing || door.IsClosed)
        {
            var success = OpenDoor(door);

            if (!success)
            {
                Debug.LogWarning("Failed to open door.");
            }
        }
    }
 protected abstract void HandleDoor(OpenableDoor door);