Esempio n. 1
0
            public static bool CreateRoom(CommandContext ctx)
            {
                if (openRooms.ContainsKey(ctx.User.Id))
                {
                    return(false);
                }
                if (BotHandler.GetUserState(ctx.User.Id) != UserState.Idle)
                {
                    return(false);
                }

                Room newRoom = new Room();

                newRoom.SetDefaultName(ctx, BotHandler.openRooms);


                openRooms.Add(ctx.User.Id, newRoom);
                openRooms[ctx.User.Id].AddPlayer(ctx.User.Id);
                openRooms[ctx.User.Id].hostId = ctx.User.Id;
                openRooms[ctx.User.Id].guild  = ctx.Guild;

                BotHandler.SetUserState(ctx.User.Id, UserState.HostingARoom);

                return(true);
            }
Esempio n. 2
0
            public static async Task DisbandRoom(CommandContext ctx, ulong hostId)
            {
                if (!BotHandler.openRooms.ContainsKey(hostId))
                {
                    await ctx.RespondAsync(new DiscordEmbedBuilder
                    {
                        Title       = "You're Not Hosting a Room",
                        Description = "You shouldn't be seeing this message normally. This is a bug.",
                        Color       = DiscordColor.Violet
                    }).ConfigureAwait(false);

                    return;
                }

                foreach (var player in BotHandler.openRooms[hostId].players)
                {
                    BotHandler.SetUserState(player, UserState.Idle);
                }

                BotHandler.openRooms.Remove(hostId);

                await ctx.RespondAsync(new DiscordEmbedBuilder {
                    Title = "Room Disbanded Successfully",
                    Color = DiscordColor.Green
                }).ConfigureAwait(false);
            }
Esempio n. 3
0
        public bool AddPlayer(ulong id)
        {
            if (this.players.Contains(id))
            {
                return(false);
            }

            this.players.Add(id);
            if (BotHandler.GetUserState(id) != UserState.HostingARoom)
            {
                BotHandler.SetUserState(id, UserState.WaitingInRoom);
            }
            return(true);
        }
Esempio n. 4
0
        public async Task <bool> StartGame(CommandContext ctx)
        {
            if (this.gameHandler.outputChannel == null || !ctx.Guild.Channels.ContainsKey(this.gameHandler.outputChannel.Id))
            {
                await ctx.RespondAsync(new DiscordEmbedBuilder {
                    Title       = "There's No Output Channel",
                    Description = "You need to bind the room to a channel for output, use the command \"room bind\".",
                    Color       = DiscordColor.Red
                }).ConfigureAwait(false);

                return(false);
            }

            this.roomState = RoomState.InGame;
            foreach (var id in this.players)
            {
                BotHandler.SetUserState(id, UserState.InGame);
            }

            //calls the GameHandler's Method to start a game
            await this.gameHandler.StartNewGame(this, ctx);

            return(true);
        }
Esempio n. 5
0
 public override Task <bool> ExecuteCheckAsync(CommandContext ctx, bool help)
 {
     return(Task.FromResult(this.States.Contains(BotHandler.GetUserState(ctx.User.Id))));
 }