コード例 #1
0
        public async Task Move([Remainder] string args = "")
        {
            Adventure.Rank adventureRank;
            args = (args ?? "").ToString().ToLower().Trim();
            if (args.StartsWith('f'))
            {
                adventureRank = Adventure.Rank.Frontline;
            }
            else if (args.StartsWith('m'))
            {
                adventureRank = Adventure.Rank.Midline;
            }
            else if (args.StartsWith('b'))
            {
                adventureRank = Adventure.Rank.Backline;
            }
            else
            {
                await Context.User.SendMessageAsync("Invalid input! You need to specify a rank! front, mid, or back!");

                return;
            }

            Player player = await PlayersRepository.Get(Context.User.Id.ToString());

            if (!(await ModuleLibrary.PlayerExists(player, Context.User)))
            {
                return;
            }
            if (!(await ModuleLibrary.PlayerSetup(player, Context.User)))
            {
                return;
            }
            if (!(await ModuleLibrary.PlayerHasAdventure(player, Context.User)))
            {
                return;
            }

            Adventure.Rank?oldRank = player.AdventureRank;

            bool success = await PlayersRepository.ChangePlayerAdventureRank
                           (
                playerId : Context.User.Id.ToString(),
                adventureRank : adventureRank
                           );

            if (!success)
            {
                await Context.User.SendMessageAsync("Failed to move! Most likely, you've been removed from the adventure!");

                return;
            }

            await AdventuresRepository.AddLogToAdventure
            (
                adventureId : Context.Channel.Id.ToString(),
                logEntry : $"<@{player.Id}> moved from the {oldRank} to the {adventureRank}!"
            );
        }
コード例 #2
0
        public async Task Start([Remainder] string args = "")
        {
            Adventure.Rank adventureRank;
            args = (args ?? "").ToString().ToLower().Trim();
            if (args.StartsWith('f'))
            {
                adventureRank = Adventure.Rank.Frontline;
            }
            else if (args.StartsWith('m'))
            {
                adventureRank = Adventure.Rank.Midline;
            }
            else if (args.StartsWith('b'))
            {
                adventureRank = Adventure.Rank.Backline;
            }
            else
            {
                await Context.User.SendMessageAsync("Invalid input! You need to specify a rank! front, mid, or back!");

                return;
            }

            Player player = await PlayersRepository.Get(Context.User.Id.ToString());

            if (!(await ModuleLibrary.PlayerExists(player, Context.User)))
            {
                return;
            }
            if (!(await ModuleLibrary.PlayerSetup(player, Context.User)))
            {
                return;
            }
            if (!(await ModuleLibrary.PlayerHasNoAdventure(player, Context.User)))
            {
                return;
            }

            // Create an adventure if it doesn't already exist.
            await AdventuresRepository.Create
            (
                new Adventure()
            {
                Id                = Context.Channel.Id.ToString(),
                Channel           = Context.Channel.Id,
                Guild             = Context.Guild.Id,
                StartTime         = DateTime.UtcNow,
                RegenerateMessage = true
            }
            );

            await PlayersRepository.AddPlayerToAdventure
            (
                playerId : Context.User.Id.ToString(),
                adventureId : Context.Channel.Id.ToString(),
                adventureRank : adventureRank
            );

            await AdventuresRepository.AddLogToAdventure
            (
                adventureId : Context.Channel.Id.ToString(),
                logEntry : $"<@{player.Id}> joined the Adventure at the {adventureRank}!"
            );
        }