Esempio n. 1
0
        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));
        }
Esempio n. 2
0
        public override void Execute(Session session, CommandContext context)
        {
            // get room
            var room = RoomHelper.GetPlayerRoom(session.Player.Location);

            if (room == null)
            {
                Server.Current.Log(LogType.Error, "WhereCommand: couldn't find room");
                return;
            }

            // get area
            var area = RoomHelper.GetArea(room.Area);

            if (area == null)
            {
                Server.Current.Log(LogType.Error, "WhereCommand: couldn't find area");
                return;
            }

            Dictionary <string, string> players = new Dictionary <string, string>();

            // for each room in area, add players to list
            foreach (var roomKey in area.Rooms)
            {
                var theRoom = RoomHelper.GetRoom(roomKey);
                foreach (var playerInRoom in theRoom.GetPlayers())
                {
                    if (!players.ContainsKey(playerInRoom.Forename))
                    {
                        // get proper room name
                        var playerRoomName = RoomHelper.GetRoom(playerInRoom.Location);
                        players.Add(playerInRoom.Forename, playerRoomName.Title);
                    }
                }
            }

            session.WriteLine("Players in {0}:", area.Name);

            foreach (var player in players)
            {
                session.WriteLine(string.Format("{0,-20}{1}", player.Key, player.Value));
            }
        }