Exemple #1
0
 protected bool FindPlace(Property.Room roomProp, out IntVector3 position, out IntVector3 entry)
 {
     foreach (Room room in dicRoomList.Values)
     {
         if (room.ConnectorList != null)
         {
             foreach (Connector conn in room.ConnectorList)
             {
                 if (conn.otherConnector == null && !conn.connectorProp.IsDynamic)
                 {
                     Property.ConnectorSocket connSocket = conn.socket as Property.ConnectorSocket;
                     if (connSocket.socketType == Property.ConnectorSocket.TYPE.TYPE_RELATIVE)
                     {
                         position = conn.ConnectToPos;
                         if (roomProp.CanPlaceAt(position))
                         {
                             entry = conn.LogicPosition;
                             return(true);
                         }
                     }
                 }
             }
         }
     }
     position = entry = IntVector3.Zero;
     return(false);
 }
Exemple #2
0
        private void OnPawnEnter(CharacterPawn pawn)
        {
            if (PawnsInRoom == null)
            {
                PawnsInRoom = new HashSet <CharacterPawn>();
            }
            PawnsInRoom.Add(pawn);

            if (!bExplored)
            {
                UIManager.Instance.QuestLog(string.Format("You found a new room at {0},{1},{2}", LogicPosition.x, LogicPosition.y, LogicPosition.z));
                bExplored = true;
            }
            else
            {
                UIManager.Instance.QuestLog(string.Format("You entered a room which located at {0},{1},{2}", LogicPosition.x, LogicPosition.y, LogicPosition.z));
            }

            if (pawn.controller != null)
            {
                UIManager.Instance.SetRoomName(RoomProp.roomName);
            }

            Property.Room prop = RoomProp;
            if (prop.EntryEvent != null)
            {
                prop.EntryEvent.CheckAndExecute(pawn, this);
            }
            //this.Show(true);
            pawn.curRoom = this;
        }
Exemple #3
0
 public bool TryExit(CharacterPawn pawn)
 {
     Property.Room prop = RoomProp;
     if (prop.ExitEvent != null)
     {
         return(prop.ExitEvent.CheckAndExecute(pawn, this));
     }
     return(true);
 }
Exemple #4
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);
    }
Exemple #5
0
    // Use this for initialization
    void Start()
    {
        FillRoomStack();
        //PickRoomMethod = PickRoomRandomly;

        Property.Room lobbyProp = Resources.Load <Property.Room>("Room/EntranceHall");
        if (lobbyProp)
        {
            lobby = new Room(lobbyProp);
            lobby.Init(IntVector3.Zero, Rotation2D.Identity, Vector3.zero, Quaternion.identity);
            lobby.Show(true);

            Property.Room upperLanding = Resources.Load <Property.Room>("Room/UpperLanding");
            if (upperLanding)
            {
                Room room = new Room(upperLanding);
                room.Init(new IntVector3(0, 1, 3), Rotation2D.Identity, Vector3.zero, Quaternion.identity);
            }
            else
            {
                Debug.LogError("Find UpperLanding fail!!");
            }

            Property.Room basementLanding = Resources.Load <Property.Room>("Room/BasementLanding");
            if (basementLanding)
            {
                Room room = new Room(basementLanding);
                room.Init(new IntVector3(0, -1, 0), Rotation2D.Identity, Vector3.zero, Quaternion.identity);
            }
            else
            {
                Debug.LogError("Find BasementLanding fail!!");
            }

            GameObject               charPrefab = Resources.Load <GameObject>("Models/Characters/Ethan");
            GameObject               charGO     = Instantiate <GameObject>(charPrefab);
            CharacterPawn            pawn       = charGO.GetComponent <CharacterPawn>();
            Property.CharacterDefine charDef    = Resources.Load <Property.CharacterDefine>("Character/TestChar");
            pawn.Setup(charDef);
        }
        else
        {
            Debug.LogError("Find Lobby fail!!");
        }
    }
Exemple #6
0
 private Rotation2D TurnRot(IntVector3 point, bool bInvert)
 {
     Property.Room prop = RoomProp;
     if (point.x < prop.ExtentMin.x)//left
     {
         return(bInvert ? Rotation2D.East : Rotation2D.West);
     }
     else if (point.x > prop.ExtentMax.x)//right
     {
         return(bInvert ? Rotation2D.West : Rotation2D.East);
     }
     else if (point.z < prop.ExtentMin.z) //back
     {
         return(Rotation2D.South);        //always turn 180
     }
     else if (point.z > prop.ExtentMax.z) //front
     {
         return(Rotation2D.North);        //always stay still
     }
     return(Rotation2D.Identity);
 }
Exemple #7
0
 public Room(Property.Room prop) : base(prop)
 {
     mono.OnEnter = OnTriggerEnter;
     mono.OnExit  = OnTriggerExit;
 }