void rotateRoom() { RoomMono room = parentObject.GetComponent <RoomMono>(); if (room != null) { room.rotate90Deg(1); } }
public RoomMono CreateRoomObject(RoomData roomData, Transform parent, int roomNumber) { GameObject go = GameObject.Instantiate(prefabMap[roomData.Name], parent); go.name = roomNumber + " " + roomData.Index.ToString(); RoomMono roomMono = go.AddComponent <RoomMono>(); roomMono.init(RoomCollection.Instance.BaseSize, roomData.Name, roomData.RelativeChance, roomData.Rotation, roomData.Dimensions, roomData.LowerBounds, roomData.UpperBounds, roomData.Index); return(roomMono); }
public RoomData CreateRoomDataObject(RoomMono roomMono) { return(new RoomData(roomMono.name, roomMono.type, roomMono.relativeChance, roomMono.dimensions, roomMono.lowerBound, roomMono.upperBound, roomMono.doors)); }
private void OnInCommingData(ServerClient client, ServerObject so) { ServerObject serverObject = new ServerObject(); string cmd = so.GetString("cmd"); string[] msg = null; int roomID; RoomMono r; List <ServerClient> tempClients; List <Room> roomTemp = new List <Room>(); switch (cmd) { case ConstantData.WHO_CONNECTED: client.clientName = so.GetString("clientName"); int index = clients.Count; List <ServerClient> temp = new List <ServerClient>(); for (int i = 0; i < index - 1; i++) { temp.Add(clients[i]); } serverObject.PutString("cmd", ConstantData.ANNOUNCE_WHO_CONNECTED); serverObject.PutString("clientName", client.clientName); Broadcast(serverObject, temp); serverObject = new ServerObject(); serverObject.PutString("cmd", ConstantData.WELCOME_MESSAGE); serverObject.PutString("welcomemsg", "welcome {0}"); Broadcast(serverObject, clients[index - 1]); temp.Clear(); break; case ConstantData.CREATE_ROOM: //su7a3 GameObject Room = new GameObject(); Room.AddComponent <RoomMono>(); RoomMono newRoom = Room.GetComponent <RoomMono>(); listRoom.Add(newRoom); newRoom.room = new Room(); newRoom.room.roomID = listRoom.Count; serverObject.PutString("cmd", ConstantData.CREATE_ROOM); serverObject.PutString("msg", "success"); serverObject.PutInt("roomID", listRoom.Count); Broadcast(serverObject, clients); LogController.Log("Create new room success"); break; case ConstantData.JOIN_ROOM: roomID = so.GetInt("roomID"); r = listRoom[roomID - 1]; ServerClient sc = null; foreach (var item in clients) { if (item.clientName == so.GetString("clientName")) { sc = item; break; } } if (r.room.numberPlayer == 0) { r.room.client1 = sc; serverObject.PutString("cmd", ConstantData.JOIN_ROOM); serverObject.PutString("isHost", "1"); serverObject.PutInt("roomID", roomID); Broadcast(serverObject, sc); r.room.numberPlayer++; } else if (r.room.numberPlayer == 1) { r.room.client2 = sc; serverObject.PutString("cmd", ConstantData.JOIN_ROOM); serverObject.PutString("isHost", "0"); serverObject.PutInt("roomID", roomID); Broadcast(serverObject, sc); r.room.numberPlayer++; } else if (r.room.numberPlayer == 2) { LogController.Log("Room is full"); } break; case ConstantData.GET_LIST_ROOM: serverObject.PutString("cmd", ConstantData.GET_LIST_ROOM); foreach (var item in listRoom) { roomTemp.Add(item.room); } serverObject.PutList <Room>("listRoom", roomTemp); Broadcast(serverObject, client); roomTemp.Clear(); break; case ConstantData.GET_ROOM_INFO: roomID = so.GetInt("roomID"); r = listRoom[roomID - 1]; tempClients = new List <ServerClient> { r.room.client1, r.room.client2 }; serverObject.PutString("cmd", ConstantData.GET_ROOM_INFO); serverObject.PutString("client1", r.room.client1.clientName); serverObject.PutString("client2", r.room.client2.clientName); Broadcast(serverObject, tempClients); break; case ConstantData.GUEST_READY: roomID = so.GetInt("roomID"); r = listRoom[roomID - 1]; serverObject.PutString("cmd", ConstantData.GUEST_READY); Broadcast(serverObject, r.room.client1); break; case ConstantData.GUEST_CANCLE_READY: roomID = so.GetInt("roomID"); r = listRoom[roomID - 1]; serverObject.PutString("cmd", ConstantData.GUEST_CANCLE_READY); Broadcast(serverObject, r.room.client1); break; case ConstantData.START_GAME: roomID = so.GetInt("roomID"); r = listRoom[roomID - 1]; tempClients = new List <ServerClient> { r.room.client1, r.room.client2 }; serverObject.PutString("cmd", ConstantData.START_GAME); Broadcast(serverObject, tempClients); break; case ConstantData.UPDATE_PLAYER_ROTATION: roomID = so.GetInt("roomID"); r = listRoom[roomID - 1]; if (r.room.client1.clientName == client.clientName) { Broadcast(so, r.room.client2); } else { Broadcast(so, r.room.client1); } break; case ConstantData.UPDATE_PLAYER_SPEED: roomID = so.GetInt("roomID"); r = listRoom[roomID - 1]; if (r.room.client1.clientName == client.clientName) { Broadcast(so, r.room.client2); } else { Broadcast(so, r.room.client1); } break; case ConstantData.USER_MOVE_UP: roomID = so.GetInt("roomID"); r = listRoom[roomID - 1]; if (r.room.client1.clientName == client.clientName) { serverObject.PutString("cmd", ConstantData.USER_MOVE_UP); serverObject.PutFloat("speed", 1.0f); Broadcast(serverObject, r.room.client1); serverObject = new ServerObject(); serverObject.PutString("cmd", ConstantData.OPPONENT_MOVE_UP); serverObject.PutFloat("speed", 1.0f); Broadcast(serverObject, r.room.client2); } else { serverObject.PutString("cmd", ConstantData.USER_MOVE_UP); serverObject.PutFloat("speed", 1.0f); Broadcast(serverObject, r.room.client2); serverObject = new ServerObject(); serverObject.PutString("cmd", ConstantData.OPPONENT_MOVE_UP); serverObject.PutFloat("speed", 1.0f); Broadcast(serverObject, r.room.client1); } break; case ConstantData.GET_CARD: roomID = so.GetInt("roomID"); int numPlayer = so.GetInt("numPlayer"); r = listRoom[roomID - 1]; tempClients = new List <ServerClient> { r.room.client1, r.room.client2 }; if (listUsedCards.Count == 0) { for (int i = 0; i < 3 * numPlayer; i++) { int cardIndex = -1; do { cardIndex = UnityEngine.Random.Range(1, 53); } while (listUsedCards.Contains(cardIndex)); listUsedCards.Add(cardIndex); } } serverObject.PutString("cmd", ConstantData.GET_CARD); serverObject.PutList("listCardIndex", listUsedCards); Broadcast(serverObject, tempClients); break; } }
private void OnInCommingData(ServerClient client, string data) { LogController.Log(client.clientName + ": " + data); string[] msg = data.Split('|'); int roomID; RoomMono r; List <ServerClient> tempClients; switch (msg[0]) { case ConstantData.WHO_CONNECTED: client.clientName = msg[1]; int index = clients.Count; List <ServerClient> temp = new List <ServerClient>(); for (int i = 0; i < index - 1; i++) { temp.Add(clients[i]); } Broadcast(ConstantData.ANNOUNCE_WHO_CONNECTED + '|' + client.clientName, temp); Broadcast(ConstantData.WELCOME_MESSAGE + "|welcome {0}", clients[index - 1]); temp.Clear(); break; case ConstantData.CREATE_ROOM: //su7a3 GameObject Room = new GameObject(); Room.AddComponent <RoomMono>(); RoomMono newRoom = Room.GetComponent <RoomMono>(); listRoom.Add(newRoom); newRoom.room = new Room(); newRoom.room.roomID = listRoom.Count; Broadcast(ConstantData.CREATE_ROOM_RESPONSE + "|success|" + listRoom.Count, clients); LogController.Log("Create new room success"); break; case ConstantData.JOIN_ROOM: roomID = Convert.ToInt32(msg[2]); r = listRoom[roomID - 1]; ServerClient sc = null; foreach (var item in clients) { if (item.clientName == msg[1]) { sc = item; break; } } if (r.room.numberPlayer == 0) { r.room.client1 = sc; Broadcast(ConstantData.JOIN_ROOM_RESPONSE + "|1|" + roomID, sc); r.room.numberPlayer++; } else if (r.room.numberPlayer == 1) { r.room.client2 = sc; Broadcast(ConstantData.JOIN_ROOM_RESPONSE + "|0|" + roomID, sc); r.room.numberPlayer++; } else if (r.room.numberPlayer == 2) { LogController.Log("Room is full"); } break; case ConstantData.GET_ROOM_INFO: roomID = Convert.ToInt32(msg[1]); r = listRoom[roomID - 1]; tempClients = new List <ServerClient> { r.room.client1, r.room.client2 }; Broadcast(ConstantData.GET_ROOM_INFO + "|" + r.room.client1.clientName + "|" + r.room.client2.clientName, tempClients); break; case ConstantData.GUEST_READY: roomID = Convert.ToInt32(msg[1]); r = listRoom[roomID - 1]; Broadcast(ConstantData.GUEST_READY, r.room.client1); break; case ConstantData.GUEST_CANCLE_READY: roomID = Convert.ToInt32(msg[1]); r = listRoom[roomID - 1]; Broadcast(ConstantData.GUEST_CANCLE_READY, r.room.client1); break; case ConstantData.START_GAME: roomID = Convert.ToInt32(msg[1]); r = listRoom[roomID - 1]; tempClients = new List <ServerClient> { r.room.client1, r.room.client2 }; Broadcast(ConstantData.START_GAME, tempClients); break; } }