コード例 #1
0
        private async Task ManagePoints(IEnumerable <string> winners, BlackjackGame game)
        {
            // Add points to winners
            if (winners.Count() == 1)
            {
                await _usersPointsRepository.AddBalanceToUserAccount(winners.First(), game.MoneyToWin);
            }
            else
            {
                var splittedAmount = Math.Floor(game.MoneyToWin / winners.Count());
                foreach (var winner in winners)
                {
                    await _usersPointsRepository.AddBalanceToUserAccount(winner, (float)splittedAmount);
                }
            }

            // Remove points from loosers
            var losers = game.Members.Where(x => !winners.ToList().Contains(x.UserId))
                         .Select(x => x.UserId);

            foreach (var loser in losers)
            {
                await _usersPointsRepository.SubtractBalanceFromUserAccount(loser, game.BetAmount);
            }
        }
コード例 #2
0
        public async Task HandleAsync(Command command)
        {
            await _userPointsRepository.AddBalanceToUserAccount(command.Author.Id, 1000);

            await _userPointsRepository.UpdateDailyPoints(command.Author.Id);

            await _discordRestClient.PostMessage(command.CalledFromChannel,
                                                 new Rest.Models.Message {
                Content = $"Added 1000 points to user **{command.Author.Username}**"
            });
        }
コード例 #3
0
        private async Task ManagePoints(bool attackerWon)
        {
            var oppenentId = _command.Arguments[0].Substring(3, _command.Arguments[0].Length - 4);

            if (attackerWon)
            {
                attackerBalance += gameBounty;
                defenderBalance -= gameBounty;

                await _userPointsRepository.AddBalanceToUserAccount(_command.Author.Id, gameBounty);

                await _userPointsRepository.SubtractBalanceFromUserAccount(oppenentId, gameBounty);
            }
            else
            {
                attackerBalance -= gameBounty;
                defenderBalance += gameBounty;

                await _userPointsRepository.AddBalanceToUserAccount(oppenentId, gameBounty);

                await _userPointsRepository.SubtractBalanceFromUserAccount(_command.Author.Id, gameBounty);
            }
        }