Ejemplo n.º 1
0
 public Room FindRoom(Property.RoomFilter filter)
 {
     foreach (Room room in dicRoomList.Values)
     {
         if (filter.Check(room.RoomProp))
         {
             return(room);
         }
     }
     return(null);
 }
Ejemplo n.º 2
0
    private Room CreateRoomFromStack(Property.RoomFilter filter, bool specified, IntVector3 position, IntVector3 entry)
    {
        if (specified)
        {
            Debug.LogFormat("create room at {0},{1},{2}", position.x, position.y, position.z);
            Room result = null;
            if (dicRoomList.TryGetValue(position, out result) && result != null)
            {
                return(null);
            }
        }

        if (roomQueue.Count == 0)
        {
            RefillRoomQueue(15);
        }

        Property.Room roomProp = null;
        bool          isRoomGood;
        int           count = roomQueue.Count;

        do
        {
            if (--count < 0)
            {
                break;
            }

            roomProp   = roomQueue.Dequeue();
            isRoomGood = filter == null || filter.Check(roomProp);
            isRoomGood = isRoomGood && (specified ? roomProp.CanPlaceAt(position) : FindPlace(roomProp, out position, out entry));
            if (!isRoomGood)
            {
                roomQueue.Enqueue(roomProp);
                roomProp = null;
            }
        } while(!isRoomGood);

        Room roomInst = null;

        if (roomProp != null)
        {
            roomInst = new Room(roomProp);
            //make sure room has a connector to entry
            Rotation2D roomRot = roomInst.FaceTo(entry - position);
            //TODO: after we have position & rotation, check if this room can be placed in scene
            roomInst.Init(position, roomRot, Vector3.zero, Quaternion.identity);
        }

        return(roomInst);
    }
Ejemplo n.º 3
0
    public static void TransportToRoom(CharacterPawn pawn, ActorBase actor, string roomFilter)
    {
        Connector from = actor as Connector;

        if (from == null)
        {
            Debug.LogError("TransportToRoom: from null connector!");
        }

        Property.RoomFilter filter = Resources.Load <Property.RoomFilter>(string.Format("Room/RoomFilter/{0}", roomFilter));

        Room destRoom = GameLoader.Instance.FindRoom(filter);

        if (destRoom == null)
        {
            destRoom = GameLoader.Instance.CreateRoomByFilter(filter);
        }
        if (destRoom != null)
        {
            foreach (Connector conn in destRoom.ConnectorList)
            {
                if (conn.connectorProp.IsDynamic)
                {
                    if (conn.TryGetThrough(pawn, from.LogicPosition))
                    {
                        from.parentRoom.Show(false);
                        return;
                    }
                }
            }
            Debug.LogErrorFormat("Transport to {0} fail!  Cannot connect to dest room!", roomFilter);
        }
        else
        {
            Debug.LogErrorFormat("Transport to {0} fail! No dest room", roomFilter);
        }
    }
Ejemplo n.º 4
0
 public Room CreateRoomByFilter(Property.RoomFilter filter)
 {
     return(CreateRoomFromStack(filter, false, IntVector3.Zero, IntVector3.Zero));
 }