示例#1
0
        public async Task Duel(SocketGuildUser target)
        {
            var fromUser = UserHandler.GetUser(Context.User.Id);
            var toUser   = UserHandler.GetUser(target.Id);

            ContextIds idList = new ContextIds(Context);

            //Tests each case to make sure all circumstances for the execution of this command are valid (character exists, in correct location)
            try
            {
                await UserHandler.UserInCombat(idList);

                await UserHandler.OtherUserInCombat(idList, toUser);

                await UserHandler.UserHasNoCards(idList, fromUser);

                await UserHandler.OtherUserHasNoCards(idList, fromUser, toUser);
            }
            catch (InvalidUserStateException)
            {
                return;
            }

            //Check that the user did not target themself with the command
            if (fromUser.UserId != toUser.UserId)
            {
                //Set the current user's combat request ID to the user specified
                fromUser.CombatRequest = toUser.UserId;

                //Check if the specified user has a combat request ID that is the current user's ID
                if (toUser.CombatRequest == fromUser.UserId)
                {
                    //Start duel
                    CombatInstance combat = new CombatInstance(idList);

                    combat.IsDuel = true;
                    var combatId = CombatHandler.NumberOfInstances();
                    combat.CombatId = combatId;

                    fromUser.CombatRequest = 0;
                    fromUser.CombatID      = combatId;
                    await combat.AddPlayerToCombat(fromUser, combat.CreateNewTeam());

                    toUser.CombatRequest = 0;
                    toUser.CombatID      = combatId;
                    await combat.AddPlayerToCombat(toUser, combat.CreateNewTeam());

                    CombatHandler.StoreInstance(combatId, combat);

                    await CombatHandler.InitiateDuel(combat);
                }
                else
                {
                    //Challenge the specified user
                    await Context.Channel.SendMessageAsync($"{target.Mention}, you have been challenged to a duel by {Context.User.Mention}\nUse the \"0.duel [mention target]\" command to accept.");
                }
            }
            else
            {
                //Tell the current user they have are a dum dum
                await Context.Channel.SendMessageAsync($"{Context.User.Mention}, stop hitting yourself!");
            }
        }