示例#1
0
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            string name        = e.Command.ChatMessage.DisplayName;
            string nameToLower = name.ToLower();

            if (DuelCommand.DuelRequests.ContainsKey(nameToLower) == true)
            {
                DuelCommand.DuelData data = DuelCommand.DuelRequests[nameToLower];
                DuelCommand.DuelRequests.Remove(nameToLower);

                TimeSpan diff = DateTime.Now - data.CurDuelTime;

                if (diff.TotalMinutes >= DuelCommand.DUEL_MINUTES)
                {
                    BotProgram.MsgHandler.QueueMessage("You are not in a duel or your duel has expired!");
                    return;
                }

                BotProgram.MsgHandler.QueueMessage($"{name} has denied to duel with {data.UserDueling} and miss out on a potential {data.BetAmount} credit(s)!");
            }
            else
            {
                BotProgram.MsgHandler.QueueMessage("You are not in a duel or your duel has expired!");
            }
        }
        public override void ExecuteCommand(EvtChatCommandArgs e)
        {
            string name        = e.Command.ChatMessage.DisplayName;
            string nameToLower = name.ToLower();

            if (DuelCommand.DuelRequests.ContainsKey(nameToLower) == true)
            {
                DuelCommand.DuelData data = DuelCommand.DuelRequests[nameToLower];
                DuelCommand.DuelRequests.Remove(nameToLower);

                TimeSpan diff = DateTime.Now - data.CurDuelTime;

                if (diff.TotalMinutes >= DuelCommand.DUEL_MINUTES)
                {
                    BotProgram.MsgHandler.QueueMessage("You are not in a duel or your duel has expired!");
                    return;
                }

                long   betAmount     = data.BetAmount;
                string dueled        = data.UserDueling;
                string dueledToLower = dueled.ToLower();

                User duelerUser = BotProgram.GetUser(nameToLower);
                User dueledUser = BotProgram.GetUser(dueledToLower);

                //First confirm both users have enough credits for the duel, as they could've lost some in that time
                if (duelerUser.Credits < betAmount || dueledUser.Credits < betAmount)
                {
                    BotProgram.MsgHandler.QueueMessage("At least one user involved in the duel no longer has enough points for the duel! The duel is off!");
                    return;
                }

                //50/50 chance of either user winning
                int val = Rand.Next(0, 2);

                string message = string.Empty;

                if (val == 0)
                {
                    duelerUser.AddCredits(betAmount);
                    dueledUser.SubtractCredits(betAmount);

                    message = $"{name} won the bet against {dueled} for {betAmount} credit(s)!";
                }
                else
                {
                    duelerUser.SubtractCredits(betAmount);
                    dueledUser.AddCredits(betAmount);

                    message = $"{dueled} won the bet against {name} for {betAmount} credit(s)!";
                }

                BotProgram.SaveBotData();

                BotProgram.MsgHandler.QueueMessage(message);
            }
            else
            {
                BotProgram.MsgHandler.QueueMessage("You are not in a duel or your duel has expired!");
            }
        }