Beispiel #1
0
        /// Cross-matrix now! uses world positions
        private void InteractDoor(Vector3Int currentPos, Vector3Int targetPos)
        {
            // Make sure there is a door controller
            DoorTrigger door = MatrixManager.Instance.GetFirst <DoorTrigger>(targetPos);

            if (!door)
            {
                door = MatrixManager.Instance.GetFirst <DoorTrigger>(Vector3Int.RoundToInt(currentPos));

                if (door)
                {
                    RegisterDoor registerDoor = door.GetComponent <RegisterDoor>();

                    Vector3Int localPos = MatrixManager.Instance.WorldToLocalInt(targetPos, matrix);
                    if (registerDoor.IsPassable(localPos))
                    {
                        door = null;
                    }
                }
            }

            // Attempt to open door
            if (door != null && allowInput)
            {
                door.Interact(gameObject, TransformState.HiddenPos);
            }
        }
    /// <summary>
    /// Gets the closest door to worldOrigin on the path from worldOrigin to targetPos (if there is one)
    /// Assumes that
    /// </summary>
    /// <param name="worldOrigin">Origin World position to check from. This is required because e.g. Windoors may not appear closed from certain positions.</param>
    /// <param name="targetPos">target world position to check</param>
    /// <returns>The DoorTrigger of the closed door object specified in the summary, null if no such object
    /// exists at that location</returns>
    public static DoorTrigger GetClosedDoorAt(Vector3Int worldOrigin, Vector3Int targetPos, bool isServer)
    {
        // Check door on the local tile first
        Vector3Int  localTarget = Instance.WorldToLocalInt(targetPos, AtPoint(targetPos, isServer).Matrix);
        DoorTrigger originDoor  = Instance.GetFirst <DoorTrigger>(worldOrigin, isServer);

        if (originDoor && !originDoor.GetComponent <RegisterDoor>().IsPassableTo(localTarget, isServer))
        {
            return(originDoor);
        }

        // No closed door on local tile, check target tile
        Vector3Int  localOrigin = Instance.WorldToLocalInt(worldOrigin, AtPoint(worldOrigin, isServer).Matrix);
        DoorTrigger targetDoor  = Instance.GetFirst <DoorTrigger>(targetPos, isServer);

        if (targetDoor && !targetDoor.GetComponent <RegisterDoor>().IsPassable(localOrigin, isServer))
        {
            return(targetDoor);
        }

        // No closed doors on either tile
        return(null);
    }