public Controller(int RoomSize) { for (int i = 0; i < RoomSize; i++) { RoomList.Add(new Room()); } }
public RandomRoom CreateRoom(WaitUser[] members) { string roomID; do { // create a random string of 8 characters string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; char[] stringChars = new char[8]; Random random = new Random(); for (int i = 0; i < stringChars.Length; i++) { stringChars[i] = chars[random.Next(chars.Length)]; } roomID = new String(stringChars); } while (SearchRoom(roomID) != null); RandomRoom room = new RandomRoom { ID = roomID, Members = members }; RoomList.Add(room); return(room); }
/// <summary> /// Start the Room system. /// </summary> public override void Start() { SystemHost.UpdateSystemHost(this, "Starting..."); RoomList.Add("main", new DefaultRoom()); var num = LoadUserOwnedRooms(); SystemHost.UpdateSystemHost(this, $"Loaded {num} user owned rooms"); SystemHost.UpdateSystemHost(this, "Started"); }
/// <summary> /// 更新部分 /// </summary> private void RefreshSome(List <long> RoomsId) { _element.Dispatcher.BeginInvoke(new Action(() => { foreach (var RoomId in RoomsId) { RoomModel item = Resources.GetRes().RoomsModel.Where(x => x.RoomId == RoomId).FirstOrDefault(); RoomStateModel model = RoomList.Where(x => x.RoomId == RoomId).FirstOrDefault(); if (null == model) { RoomStateModel newRoomStateModel = new RoomStateModel() { RoomId = item.RoomId, RoomNo = item.RoomNo, UseState = (null != item.PayOrder), OrderSession = item.OrderSession, PayOrder = item.PayOrder, OpenRoom = OpenRoom }; RoomList.Add(newRoomStateModel); } else { if (null != item && null != model && model.OrderSession != item.OrderSession) { RoomStateModel oldModel = RoomList.Where(x => null != x.OrderSession && x.OrderSession.Equals(model.OrderSession, StringComparison.Ordinal)).FirstOrDefault(); int no = RoomList.Count; if (null != oldModel) { no = RoomList.IndexOf(oldModel); RoomList.RemoveAt(no); } RoomStateModel newRoomStateModel = new RoomStateModel() { RoomId = item.RoomId, RoomNo = item.RoomNo, UseState = (null != item.PayOrder), OrderSession = item.OrderSession, PayOrder = item.PayOrder, OpenRoom = OpenRoom }; RoomList.Insert(no, newRoomStateModel); } else { if (null != model && item == null) { RoomStateModel oldModel = RoomList.Where(x => x.OrderSession.Equals(model.OrderSession, StringComparison.Ordinal)).FirstOrDefault(); if (null != oldModel) { int no = RoomList.IndexOf(oldModel); if (-1 != no) { RoomList.RemoveAt(no); } } } } } } RefreshAll(true); })); }
public bool RegisterCell(string serial, CellRoom cell) { if (RoomMap.ContainsKey(serial)) { string message = string.Format("Cell {0} is already exist", serial); ServerApp.Logger.Error(message); return(false); } RoomList.Add(cell); RoomMap[serial] = cell; return(true); }
private int LoadUserOwnedRooms() { var ret = 0; var rooms = Room.manager.GetAll(); foreach (var r in rooms) { var room = new UserOwnedRoom(r); RoomList.Add(room.Name.ToLower(), room); ret++; } return(ret); }
public async Task Init(Guid roomId) { try { _roomId = roomId; var roomModel = await _bookingService.GetRoomAsync(ApiPriority.UserInitiated, roomId); var roomReservations = await _bookingService.GetReservationsAsync(ApiPriority.UserInitiated, roomId); if (roomModel != null) { // Room info Title = roomModel.Name; AboutRoomTitle = $"About {roomModel.Name}"; AboutRoomText = roomModel.Description; AboutRoomVisible = !string.IsNullOrWhiteSpace(roomModel.Description); NumberOfPersons = $"{roomModel.NumberOfGuests} Persons"; // Room images var imageList = roomModel.Images.Select(roomModelImage => new BodySliderData(roomModelImage.Medium)).ToList(); foreach (var bodySliderData in imageList) { RoomList.Add(new BodySliderItemViewModel(bodySliderData, () => { ShowViewModel <ImageZoomViewModel>(new { url = bodySliderData.ImageUrl }); })); } ImageUrl = roomModel.Header == null ? Defaults.RoomHeaderDefault : roomModel.Header.Medium; // Check reservations at this current time IsAvailable = !roomReservations.Any(t => t.ReservationStart <DateTime.Now && t.ReservationEnd> DateTime.Now); var locationModel = await PlatformService.GetLocationAsync(ApiPriority.UserInitiated, roomModel.LocationId); if (locationModel != null) { LocationName = locationModel.Name; AboutLocationTitle = $"About {locationModel.Name}"; AboutLocationText = locationModel.AboutText; AboutLocationVisible = !string.IsNullOrWhiteSpace(locationModel.AboutText); } } } catch (Exception ex) { ExceptionService.HandleException(ex); } }
public async Task Init(Guid id) { try { _id = id; var myreservations = await _bookingService.GetMyReservationsAsync(); var reservation = myreservations?.Reservations?.FirstOrDefault(r => r.Id == id); if (reservation != null) { var roomModel = myreservations.Rooms?.FirstOrDefault(r => r.Id == reservation.RoomId); if (roomModel != null) { ImageUrl = roomModel.Header != null ? roomModel.Header.Large : Defaults.RoomHeaderDefault; ReservationCode = reservation.ReservationCode; Date = reservation.ReservationStart.ToString("D"); Checkin = reservation.ReservationStart.ToString("t"); Checkout = reservation.ReservationEnd.ToString("t"); Room = roomModel.Name; IsPrivate = reservation.IsPrivate; Message = reservation.Message; Title = reservation.Title; foreach (var roomModelImage in roomModel.Images) { RoomList.Add(new BodySliderItemViewModel(new BodySliderData(roomModelImage.Medium), () => { ShowViewModel <ImageZoomViewModel>(new { url = roomModelImage.Large }); })); } // Get location var locationmodel = await PlatformService.GetLocationAsync(ApiPriority.UserInitiated, roomModel.LocationId); Location = locationmodel?.Name; } } else { // TODO : Show some error? } } catch (Exception ex) { ExceptionService.HandleException(ex); } }
/// <summary> /// 第一次加载所有 /// </summary> private void FirstLoad() { RoomList.Clear(); foreach (var item in Resources.GetRes().RoomsModel.OrderByDescending(x => x.Order).ThenBy(x => x.RoomNo.Length).ThenBy(x => x.RoomNo)) { RoomList.Add(new RoomStateModel() { RoomId = item.RoomId, RoomNo = item.RoomNo, UseState = (null != item.PayOrder), OrderSession = item.OrderSession, PayOrder = item.PayOrder, OpenRoom = OpenRoom }); } RefreshAll(false); }
public JsonResult CreateRoom(PlayerRoom room) { bool flag = roomList.Add(new PlayerRoom { TotalLimit = room.TotalLimit, Name = room.Name, PlayerList = new List <Player>(), }); if (flag) { var query = roomList.FindAll(x => string.Equals(x.Name, room.Name)); var queryPlayer = playerList.FindAll(x => string.Equals(x.ConnectionId, Context.ConnectionId)); if (query != null && query.Count > 0) { if (queryPlayer != null && queryPlayer.Count > 0) { queryPlayer.FirstOrDefault().RoomName = room.Name; query.FirstOrDefault().PlayerList.Add(queryPlayer.FirstOrDefault()); Groups.Add(Context.ConnectionId, room.Name); CurrentRoomList(); return(new JsonResult { Data = new { result = true, data = JavaScriptObjectParser.Parse(roomList) } }); } else { return(new JsonResult { Data = new { result = false } }); } } else { return(new JsonResult { Data = new { result = false } }); } } else { return(new JsonResult { Data = new { result = false } }); } }
/// <summary> /// Create a new room if one with the provided name does not already exist. /// </summary> /// <param name="sender">Session of the user trying to create a room.</param> /// <param name="name">Name of the room to create.</param> /// <returns></returns> public static UserOwnedRoom CreateRoom(Session sender, string name) { var record = new Room() { Name = name, Description = "", OwnerUserID = sender.User.ID }; var room = RoomList.ContainsKey(name.ToLower()) ? null : new UserOwnedRoom(record); if (room != null) { var id = Room.manager.Create(room.Data); room.Data = Room.manager.Get(id); RoomList.Add(room.Name.ToLower(), room); } return(room); }
public IEnumerator CreateCorridors() { foreach (GeneratorRoom room in grid.RoomList) { roomList.Add(room); } while (roomList.Count > 0) { Vector2i room1Pos = roomList[0].location; Vector2i room2Pos = FindNearestInList(room1Pos); if (room2Pos.x != Vector2i.zero.x || room2Pos.y != Vector2i.zero.y) { grid.CreateCorridor(prefab, room1Pos, room2Pos); } yield return(0); } }
public GeneratorRoom CreateRoom(Vector2i chunkPos, GeneratorChunk groundPrefab, Vector2i roomSize, bool isSecure = false) { GeneratorRoom newRoom = new GeneratorRoom(); GameObject room = new GameObject(); room.transform.SetParent(parent.transform); Color testColor = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), 1.0f); room.name = "Room"; for (int i = 0; i < roomSize.y; i++) { for (int j = 0; j < roomSize.x; j++) { GeneratorChunk c = CreateChunk(chunkPos + new Vector2i(j, i), groundPrefab, testColor, room); newRoom.chunks.Add(c); } } if (isSecure) { newRoom.isSafe = true; room.name = "SecureRoom"; safeRoomList.Add(newRoom); } else { unSafeRoomList.Add(newRoom); } newRoom.location = chunkPos; newRoom.size = roomSize; roomList.Add(newRoom); return(newRoom); }
public async Task CreateRoom() { var room = await httpClient.PostJsonAsync <Room>(@"api/room", new Room()); RoomList.Add(room); }
public void AddSquareRoom(string IdSquareRoom, int posXInCompleteRoom, int posYInCompleteRoom) { RoomList.Add(new SquareRoom(this, IdSquareRoom, posXInCompleteRoom, posYInCompleteRoom)); }
private void Generate() { // create initial room point // always will be room 1 Room startRoom = new Room("Rooms/room1"); startRoom.MinimapRoomCoordinates = new Vector2((float)Math.Round((double)(maxWidth / 2)), (float)Math.Round((double)(maxHeight / 2))); // start in middle startRoom.Visited = true; RoomList.Add(startRoom); _currentAmtOfRooms++; // set some properties // tile size is 32x32. We need to adjust room width and height so we don't get the extra space around the room that holds // the collisions for the passages. RoomWidth = startRoom.GetRoomWidth() - (2 * tileSize); RoomHeight = startRoom.GetRoomHeight() - (2 * tileSize); while (true) { // out of rooms if (_maxRooms - _currentAmtOfRooms <= 0) { break; } if (_currentRoomIndex >= RoomList.Count) { break; } CurrentRoom = RoomList[_currentRoomIndex]; // randomly choose amount of directions to branch depending on which // is less: max rooms left to place or connections possible for room //int maxPossibleConnections = Math.Min(_maxRooms - _currentAmtOfRooms, CurrentRoom.GetPossibleConnectionCount(RoomList)); int maxPossibleConnections = Math.Min(_maxRooms - _currentAmtOfRooms, GetPossibleConnectionsCount()); // if we can't connect, go to next room if (maxPossibleConnections <= 0) { _currentRoomIndex++; continue; } // generated max amount of rooms if (maxPossibleConnections == 0) { break; } int todoConnections = XeldaGame.rand.Next(1, maxPossibleConnections + 1); // for each needed room, generate and connect the rooms for (int i = 0; i < todoConnections; i++) { Direction dir = GetRandomDirectionForConnection(CurrentRoom); int roomNumber = XeldaGame.rand.Next(1, _maxRoomTemplates + 1); Room room = new Room("Rooms/room" + roomNumber, dir, RoomList.IndexOf(CurrentRoom)); room.Visited = false; SetDebugRoomPosition(CurrentRoom, room, dir); RoomList.Add(room); _currentAmtOfRooms++; CurrentRoom.ConnectThisToNewRoom(dir, RoomList.IndexOf(room)); } // treat list like queue and go to next node and build off of that. _currentRoomIndex++; } // set CurrentRoom back to 0 so player starts at first node. CurrentRoom = RoomList[0]; // first room of dungeon should have no mobs CurrentRoom.ClearMobsFromRoom(); // tell each room to add walls to block passages that have no adjacent room to connect foreach (Room room in RoomList) { room.AddPassageWalls(); } }
public void RoomGen(int minRoomSize, int maxRoomSize) { bool failed = false; int width = rand.Next(minRoomSize, maxRoomSize); int heigth = rand.Next(minRoomSize, maxRoomSize); int x = rand.Next(1, mapWidth - width - 1); int y = rand.Next(1, mapHeight - heigth - 1); Room newRoom = new Room(x, y, width, heigth); //Debug.Log($"Room x:{x} Room y:{y}"); foreach (Room other in RoomList) { if (newRoom.Intercept(other)) { failed = true; //Debug.Log("intercept"); break; } } if (!failed) { RoomList.Add(newRoom); //Debug.Log($"room center:{newRoom.Center.x}, {newRoom.Center.y}"); for (int rX = newRoom.X1; rX <= newRoom.X2; rX++) { for (int rY = newRoom.Y1; rY <= newRoom.Y2; rY++) { int rando = rY % 5; MapArr[rY, rX] = "ground" + rando; } } } if (RoomList.Count > 1) { int x1 = RoomList[RoomList.Count - 1].Center.x; int y1 = RoomList[RoomList.Count - 1].Center.y; int x2 = RoomList[RoomList.Count - 2].Center.x; int y2 = RoomList[RoomList.Count - 2].Center.y; int coin_flip = rand.Next(0, 2); if (coin_flip == 0) { for (int i = Math.Min(x1, x2); i <= Math.Max(x1, x2); i++) { MapArr[y1, i] = "ground" + i % 5; } for (int j = Math.Min(y1, y2); j <= Math.Max(y1, y2); j++) { MapArr[j, x2] = "ground" + j % 5; } //MapArr[RoomList[RoomList.Count - 1].Center.y, RoomList[RoomList.Count - 1].Center.x] = "defaultWater"; } else if (coin_flip == 1) { for (int j = Math.Min(y1, y2); j <= Math.Max(y1, y2); j++) { MapArr[j, x1] = "ground" + j % 5; } for (int i = Math.Min(x1, x2); i <= Math.Max(x1, x2); i++) { MapArr[y2, i] = "ground" + i % 5; } //MapArr[RoomList[RoomList.Count - 1].Center.y, RoomList[RoomList.Count - 1].Center.x] = "defaultWater"; } foreach (Vector2Int vec in RoomList[RoomList.Count - 1].WaterList) { MapArr[vec.y, vec.x] = "defaultWater"; } } }
void _serverConnection_DataReceived(object sender, EventArgs e) { _context.Post(new SendOrPostCallback(delegate(object state) { try { if (_serverConnection != null) { byte[] data = _serverConnection.ReadData(); while (data != null) { //parse data ChatMessage msg = ChatMessage.Parse(data); if (msg != null) { //handle data if (msg.Name == "signinfailed") { closeConnection(); break; } else if (msg.Name == "signinsuccess") { _retryCount = 0; ChatConnectionStatus = ConnectionStatus.SignedIn; } else if (msg.Name == "txt") { if (NewTextMessage != null) { NewTextMessage(this, msg.ID, msg.Parameters["msg"], Color.FromArgb(int.Parse(msg.Parameters["color"]))); } if (Core.Settings.Default.ChatPlaySounds && _sndMessage != null) { _sndMessage.Play(); } } else if (msg.Name == "usersinroom") { bool newUser = false; int i = 0; foreach (var x in UsersInRoomList) { x.present = false; } bool wasempty = UsersInRoomList.Count == 0; while (msg.Parameters.ContainsKey(string.Format("name{0}", i))) { string id = msg.Parameters[string.Format("id{0}", i)]; UserInRoomInfo c = (from x in UsersInRoomList where x.ID == id select x).FirstOrDefault(); if (c == null) { c = new UserInRoomInfo(); c.ID = id; c.Username = msg.Parameters[string.Format("name{0}", i)]; c.present = true; c.FollowThisUser = false; c.SelectionCount = -1; if (msg.Parameters.ContainsKey(string.Format("sc{0}", i))) { string selCount = msg.Parameters[string.Format("sc{0}", i)]; if (!string.IsNullOrEmpty(selCount)) { c.SelectionCount = int.Parse(selCount); } } c.CanBeFollowed = bool.Parse(msg.Parameters[string.Format("cbf{0}", i)]); c.ActiveGeocache = msg.Parameters[string.Format("agc{0}", i)]; UsersInRoomList.Add(c); if (!wasempty) { if (NewTextMessage != null) { NewTextMessage(this, "-1", string.Format("{0} {1}", c.Username, Localization.TranslationManager.Instance.Translate("JoinedTheRoom") as string), Color.Black); } } newUser = true; } else { bool cbf = c.CanBeFollowed; string agc = c.ActiveGeocache; c.CanBeFollowed = bool.Parse(msg.Parameters[string.Format("cbf{0}", i)]); c.ActiveGeocache = msg.Parameters[string.Format("agc{0}", i)]; c.present = true; c.UpdateText(); if (cbf != c.CanBeFollowed || agc != c.ActiveGeocache) { if (UserInfoUpdate != null) { UserInfoUpdate(this, c); } } } i++; } var rmList = from a in UsersInRoomList where !a.present select a; foreach (var x in rmList) { UsersInRoomList.Remove(x); } if (newUser && Core.Settings.Default.ChatPlaySounds && _sndWelcome != null) { _sndWelcome.Play(); } } else if (msg.Name == "follow") { UserInRoomInfo[] curUsr = UsersInRoomList.ToArray(); UserInRoomInfo c = (from x in curUsr where x.ID == msg.ID select x).FirstOrDefault(); if (c != null) { c.CanBeFollowed = bool.Parse(msg.Parameters["canfollow"]); c.ActiveGeocache = msg.Parameters["cache"]; c.SelectionCount = -1; if (msg.Parameters.ContainsKey("selected")) { string selCount = msg.Parameters["selected"]; if (!string.IsNullOrEmpty(selCount)) { c.SelectionCount = int.Parse(selCount); } } if (c.FollowThisUser) { if (!c.CanBeFollowed) { c.FollowThisUser = false; } } c.UpdateText(); if (UserInfoUpdate != null) { UserInfoUpdate(this, c); } } } else if (msg.Name == "rooms") { RoomInfo[] curRms = RoomList.ToArray(); foreach (var x in curRms) { x.present = false; } int i = 0; while (msg.Parameters.ContainsKey(string.Format("name{0}", i))) { string name = msg.Parameters[string.Format("name{0}", i)]; RoomInfo c = (from x in curRms where x.Name == name select x).FirstOrDefault(); if (c == null) { c = new RoomInfo(); c.present = true; c.Name = name; RoomList.Add(c); } else { c.present = true; } i++; } var rmList = from a in RoomList where !a.present select a; foreach (var x in rmList) { RoomList.Remove(x); } } else if (msg.Name == "reqsel") { StringBuilder sb = new StringBuilder(); UserInRoomInfo[] curUsr = UsersInRoomList.ToArray(); UserInRoomInfo c = (from x in curUsr where x.ID == msg.ID select x).FirstOrDefault(); if (c != null) { if (NewTextMessage != null) { NewTextMessage(this, "-1", string.Format("{0} {1}", c.Username, Localization.TranslationManager.Instance.Translate("RequestedSelection") as string), Color.Black); } if (Core.ApplicationData.Instance.ActiveDatabase != null) { var gsel = from Core.Data.Geocache g in Core.ApplicationData.Instance.ActiveDatabase.GeocacheCollection where g.Selected select g; foreach (var g in gsel) { sb.AppendFormat("{0},", g.Code); } } } ChatMessage bmsg = new ChatMessage(); bmsg.Name = "reqselresp"; bmsg.Parameters.Add("reqid", msg.Parameters["reqid"]); bmsg.Parameters.Add("clientid", msg.ID); bmsg.Parameters.Add("selection", sb.ToString()); SendMessage(bmsg); } else if (msg.Name == "reqselresp") { if (msg.Parameters["reqid"] == _currentCopySelectionRequestID && _getGeocacheThread == null) { //handle response Core.Storage.Database db = Core.ApplicationData.Instance.ActiveDatabase; if (db != null) { string[] gcCodes = msg.Parameters["selection"].Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); using (Utils.DataUpdater upd = new Utils.DataUpdater(db)) { foreach (var g in db.GeocacheCollection) { g.Selected = gcCodes.Contains(g.Code); } } //are we missing geocaches? _importGeocaches.Clear(); if (Core.Settings.Default.LiveAPIMemberTypeId > 0) { foreach (string s in gcCodes) { if (db.GeocacheCollection.GetGeocache(s) == null && s.StartsWith("GC")) { _importGeocaches.Add(s); } } if (_importGeocaches.Count > 0) { _copySelectionDb = db; _dataUpdater = new Utils.DataUpdater(db); _getGeocacheThread = new Thread(new ThreadStart(getCopiedSelectionGeocacheInbackgroundMethod)); _getGeocacheThread.IsBackground = true; _getGeocacheThread.Start(); } } } } _currentCopySelectionRequestID = null; } } data = _serverConnection.ReadData(); } } } catch { closeConnection(); } }), null); }
protected override void CreateMap() { // Maintain a list of points bordering the current list of rooms so we can attach // more rooms. Also track of the facing of the wall the point comes from. IList <int> openPoints = new List <int>(); // Also keep track of the rooms and where they are. IList <Room> initialRooms = new List <Room>(); int[,] occupied = new int[Width, Height]; // Set up the initial placement of the map. Include special features, if any. int counter = InitialPlacement(initialRooms, openPoints, ref occupied); IList <Room> allRooms = new List <Room>(initialRooms); while (openPoints.Count > 0) { // Choose a random point to create a room around; int index = openPoints[Rand.Next(openPoints.Count)]; int availX = index % Width; int availY = index / Width; // Fit a room around the point as best as possible. AdjustRoom should avoid most // collisions between rooms. int width = (int)Rand.NextGamma(_ALPHA, _BETA); int height = (int)Rand.NextGamma(_ALPHA, _BETA); Room room = AdjustRoom(availX, availY, width, height, occupied); // Update the room list, the open point list, and the location grid. RemoveOpenPoints(room, openPoints); if (TrackRoom(room, allRooms, counter + 1, ref occupied)) { counter++; } AddOpenPoints(room, openPoints, occupied); } // Use the largest areas as rooms and triangulate them to calculate hallways. RoomList = allRooms .OrderByDescending(r => r.Area) .Take((int)(allRooms.Count * _FILL_PERCENT)) .ToList(); // Ensure that prefab elements are included foreach (Room initial in initialRooms) { if (!RoomList.Contains(initial)) { RoomList.Add(initial); } } // If we don't get enough rooms, we can't (and don't need to) triangulate, so just // draw in what we have. if (RoomList.Count == 1) { CreateRoomWithoutBorder(RoomList[0]); } else if (RoomList.Count == 2) { // Add the only hallway to the hall list Adjacency = new ICollection <int>[] { new[] { 1 }, new[] { 0 } }; ClearRoomsBetween(RoomList[0], RoomList[1], allRooms, occupied); } else { var polygon = new Polygon(); foreach (Room room in RoomList) { polygon.Add(new Vertex(room.Center.X, room.Center.Y)); } IMesh delaunay = polygon.Triangulate(); // Reduce the number of edges and clear out rooms along the remaining edges. ICollection <int>[] adj = BuildAdjacencyList(delaunay.Edges, RoomList.Count); var edges = TrimEdges(adj, RoomList).ToList(); // Restore some edges, so exploring is a bit more interesting RestoreEdges(edges, delaunay.Edges.ToList(), adj, _END_TYPE); Adjacency = BuildAdjacencyList(edges, RoomList.Count); foreach (Edge edge in edges) { ClearRoomsBetween(RoomList[edge.P0], RoomList[edge.P1], allRooms, occupied); } } PostProcess(); }
/* Methods */ public void AddRoom(HotelRoom r) { RoomList.Add(r); }