/**
     * Randomly locks descendant rooms of the given {@link MZRoom} with
     * {@link MZEdge}s that require the switch to be in the given state.
     * <p>
     * If the given state is Either, the required states will be random.
     *
     * @param room          the room whose child to lock
     * @param givenState    the state to require the switch to be in for the
     *                      child rooms to be accessible
     * @return              true if any locks were Added, false if none were
     *                      Added (which can happen due to the way the random
     *                      decisions are made)
     * @see MZCondition.SwitchState
     */
    protected bool SwitchLockChildRooms(MZRoom room,
                                        MZCondition.SwitchState givenState)
    {
        bool anyLocks = false;

        MZCondition.SwitchState state = givenState != MZCondition.SwitchState.Either
                ? givenState
                : (UnityEngine.Random.Range(0, 2) == 0
                    ? MZCondition.SwitchState.On
                    : MZCondition.SwitchState.Off);

        foreach (MZEdge edge in room.GetEdges())
        {
            int    neighborId = edge.GetTargetRoomId();
            MZRoom nextRoom   = dungeon.Get(neighborId);
            if (room.GetChildren().Contains(nextRoom))
            {
                if (room.GetEdge(neighborId).GetSymbol() == null &&
                    UnityEngine.Random.Range(0, 4) != 0)
                {
                    dungeon.Link(room, nextRoom, state.ToSymbol());
                    AddPrecond(nextRoom, new MZCondition(state.ToSymbol()));
                    anyLocks = true;
                }
                else
                {
                    anyLocks |= SwitchLockChildRooms(nextRoom, state);
                }

                if (givenState == MZCondition.SwitchState.Either)
                {
                    state = state.Invert();
                }
            }
        }
        return(anyLocks);
    }
Example #2
0
 public bool RoomsAreLinked(MZRoom room1, MZRoom room2)
 {
     return(room1.GetEdge(room2.id) != null || room2.GetEdge(room1.id) != null);
 }