コード例 #1
0
        public async Task <CoinFlipMatch> CreateMatch
        (
            string creatorSteamId,
            bool creatorIsHead,
            List <AssetAndDescriptionId> assetAndDescriptionIds,
            CreateCoinFlipSettingModel setting
        )
        {
            var user = await _repoServiceFactory.UserRepoService.FindAsync(creatorSteamId);

            if (user == null)
            {
                throw new UserDoesNotExistException($"The user does with steamId {creatorSteamId} not exist.");
            }

            if (assetAndDescriptionIds.Count == 0)
            {
                throw new InvalidBetException("No items selected");
            }

            var items = await _repoServiceFactory.ItemRepoService.FindAsync(assetAndDescriptionIds);

            var totalValueOfItems = await _itemService.GetSumOfItems(items);

            var jackpotSetting      = CreateJackpotSetting(setting, totalValueOfItems);
            var jackpotMatchSetting = jackpotSetting.ToJackpotMatchSetting();

            var itemDescsIds = assetAndDescriptionIds.Select(item => item.DescriptionId).Distinct().ToList();

            var itemDescriptionTask = _repoServiceFactory.ItemDescriptionRepoService.FindAsync(itemDescsIds);
            var gameModeTask        = _repoServiceFactory.GameModeRepoService.Find(GameModeHelper.GetStringFromType(GameModeType.CoinFlip));
            var getPreHashTask      = _preHashRepoService.Find(setting.PreHash, creatorSteamId);

            await Task.WhenAll(gameModeTask, itemDescriptionTask, getPreHashTask);

            if (!gameModeTask.Result.IsEnabled)
            {
                throw new GameModeIsNotEnabledException("The current gamemode CoinFlip is not enabled at the moment.");
            }

            var match = CreateCoinFlipMatch(creatorIsHead, user, gameModeTask.Result, getPreHashTask.Result);


            var insertedMatch = await InsertedMatchAndBetWithTransaction
                                (
                assetAndDescriptionIds,
                match,
                jackpotSetting,
                gameModeTask.Result,
                items,
                user,
                itemDescriptionTask.Result,
                jackpotMatchSetting
                                );

            var mongoDbMatch = await InsertIntoMongoDb(insertedMatch, items, itemDescriptionTask.Result, jackpotMatchSetting, user);

            var coinFlipMatch = new CoinFlipMatch(mongoDbMatch);

            await _coinFlipHubConnections.MatchCreated(coinFlipMatch);

            _discordService.CoinFlipCreateAsync(setting.AllowCsgo, setting.AllowPubg, totalValueOfItems, match.RoundId, user.SteamId);

            return(coinFlipMatch);
        }