public override void Execute(Session session, CommandContext context) { if (string.IsNullOrWhiteSpace(context.ArgumentString)) { PrintSyntax(session); return; } // confirm room doesn't exist // todo: there will inevitably be rooms with similar names, so they'll need to be key'ed different var room = RoomHelper.GetRoom(context.ArgumentString); if (room != null) { session.WriteLine(string.Format("Room already exists: {0}", context.ArgumentString)); return; } // get player area var playerRoom = RoomHelper.GetRoom(session.Player.Location); var areaKey = string.Empty; Area area = null; if (playerRoom != null) { areaKey = playerRoom.Area; if (!string.IsNullOrEmpty(areaKey)) { area = RoomHelper.GetArea(areaKey); } } // create room room = new Room() { Key = context.ArgumentString.ToLower(), Title = context.ArgumentString, Description = RoomHelper.GetDefaultRoomDescription(), Area = areaKey, }; // save room Server.Current.Database.Save <Room>(room); if (area != null) { area.Rooms.Add(room.Key); Server.Current.Database.Save <Area>(area); } // tell the admin player what the id is, so they can get to it session.WriteLine(string.Format("Room created: {0}", context.ArgumentString)); }
private void TryExecuteCommand(string input) { if (input.ToLower() == "exitmapping") { Session.PopState(); return; } var room = RoomHelper.GetPlayerRoom(Session.Player); if (_status == MappingStatus.Walking) { var direction = DirectionHelper.GetDirectionWord(input); if (string.IsNullOrEmpty(direction)) { Session.WriteLine("That's not a direction."); return; } if (room.HasExit(direction)) { var commandInfo = Server.Current.CommandLookup.FindCommand(direction, Session.Player); commandInfo.Command.Execute(Session, CommandContext.Create(direction)); return; } // set mode to request title Session.WriteLine("`RCreating exit, Please enter a title..."); _status = MappingStatus.NeedsTitle; _direction = direction; } else { // user is inputting a title var checkRoom = Server.Current.Database.Get <Room>(input.ToLower()); var calculatedKey = input.ToLower(); if (checkRoom != null) { calculatedKey = RoomHelper.GenerateKey(input); Session.WriteLine("`RRoom already exists. Using title: `G{0}`R.", calculatedKey); } var newRoom = new Room() { Area = room.Area, Description = RoomHelper.GetDefaultRoomDescription(), Key = calculatedKey.ToLower(), Title = input, }; newRoom.Exits.Add(DirectionHelper.GetOppositeDirection(_direction), new RoomExit() { IsDoor = false, IsOpen = true, LeadsTo = room.Key }); Server.Current.Database.Save(newRoom); room.Exits.Add(_direction, new RoomExit() { IsDoor = false, IsOpen = true, LeadsTo = newRoom.Key }); Server.Current.Database.Save(room); var commandInfo = Server.Current.CommandLookup.FindCommand(_direction, Session.Player); commandInfo.Command.Execute(Session, CommandContext.Create(_direction)); _status = MappingStatus.Walking; } }