예제 #1
0
 public async Task PlaceBetOnCoinFlipMatch
 (
     DatabaseModel.CoinFlip match,
     JackpotMatchSetting setting,
     DatabaseModel.GameMode gameMode,
     List <AssetAndDescriptionId> assetAndDescriptionIds,
     string userSteamId
 )
 {
     await PlaceBetOnMatch(match.Id, setting, gameMode, assetAndDescriptionIds, userSteamId);
 }
예제 #2
0
 public async Task PlaceBetOnCoinFlipMatch
 (
     DatabaseModel.CoinFlip match,
     JackpotMatchSetting setting,
     DatabaseModel.GameMode gameMode,
     int assetAndDescriptionIdsCount,
     List <DatabaseModel.Item> items,
     DatabaseModel.User user,
     List <DatabaseModel.ItemDescription> uniqueItemDescriptions
 )
 {
     await PlaceBetOnMatch(match.Id, setting, gameMode, assetAndDescriptionIdsCount, items, user, uniqueItemDescriptions);
 }
예제 #3
0
        private async Task <DatabaseModel.CoinFlip> InsertedMatchAndBetWithTransaction
        (
            List <AssetAndDescriptionId> assetAndDescriptionIds,
            DatabaseModel.CoinFlip match,
            DatabaseModel.JackpotSetting jackpotSetting,
            DatabaseModel.GameMode gameMode,
            List <DatabaseModel.Item> items,
            DatabaseModel.User user,
            List <DatabaseModel.ItemDescription> itemDescription,
            JackpotMatchSetting jackpotMatchSetting
        )
        {
            DatabaseModel.CoinFlip       insertedMatch;
            DatabaseModel.JackpotSetting insertedJackpotSetting;

            using (var transaction = _transactionFactory.BeginTransaction())
            {
                try
                {
                    insertedJackpotSetting = await _repoServiceFactory.JackpotSettingRepo.InsertAsync(jackpotSetting, transaction);

                    match.SettingId = insertedJackpotSetting.Id;
                    insertedMatch   = await _repoServiceFactory.CoinFlipMatchRepoService.InsertAsync(match, transaction);
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw;
                }

                transaction.Commit();
            }

            try
            {
                var count = assetAndDescriptionIds.Count;
                await _betService.PlaceBetOnCoinFlipMatch(insertedMatch, jackpotMatchSetting, gameMode, count, items, user, itemDescription);
            }
            catch (Exception)
            {
                await _repoServiceFactory.CoinFlipMatchRepoService.RemoveAsync(insertedMatch);

                await _repoServiceFactory.JackpotSettingRepo.RemoveAsync(insertedJackpotSetting);

                throw;
            }

            return(insertedMatch);
        }
예제 #4
0
        private async Task PlaceBetOnMatch(int matchId, JackpotMatchSetting setting, DatabaseModel.GameMode gameMode,
                                           List <AssetAndDescriptionId> assetAndDescriptionIds, string userSteamId)
        {
            var itemDescs = assetAndDescriptionIds.Select(item => item.DescriptionId).Distinct().ToList();

            var itemsTask           = _repoServiceFactory.ItemRepoService.FindAsync(assetAndDescriptionIds);
            var userTask            = _repoServiceFactory.UserRepoService.FindAsync(userSteamId);
            var itemDescriptionTask = _repoServiceFactory.ItemDescriptionRepoService.FindAsync(itemDescs);

            await Task.WhenAll(itemsTask, userTask, itemDescriptionTask);

            var items            = itemsTask.Result;
            var user             = userTask.Result;
            var itemDescriptions = itemDescriptionTask.Result;

            await PlaceBetOnMatch(matchId, setting, gameMode, assetAndDescriptionIds.Count, items, user, itemDescriptions);
        }
예제 #5
0
        private async Task <MongoDbModels.JackpotMatch> InsertIntoMongoDb
        (
            DatabaseModel.CoinFlip insertedMatch,
            List <DatabaseModel.Item> items,
            List <DatabaseModel.ItemDescription> itemDescription,
            JackpotMatchSetting jackpotMatchSetting,
            DatabaseModel.User user
        )
        {
            var mapedItems         = items.MapItemsToItemsDescription(itemDescription);
            var coinFlipMatchModel = new MongoDbModels.JackpotMatch
            {
                LookUpId     = insertedMatch.Id,
                RoundId      = insertedMatch.RoundId,
                Hash         = insertedMatch.Hash,
                Salt         = insertedMatch.Salt,
                Percentage   = insertedMatch.Percentage,
                Status       = insertedMatch.Status,
                TimerStarted = insertedMatch.TimerStarted,
                Bets         = new List <CoinFlipBet>
                {
                    new CoinFlipBet
                    {
                        User = new User
                        {
                            ImageUrl = user.ImageUrl,
                            Name     = user.Name,
                            SteamId  = user.SteamId,
                        },
                        DateTime = DateTime.Now,
                        Items    = mapedItems,
                        Tickets  = new RoundTicket
                        {
                            Start = 1,
                            End   = (int)(mapedItems.Sum(item => item.Value) * 100)
                        },
                        IsHead = insertedMatch.CreatorIsHead
                    }
                },
                Setting = jackpotMatchSetting
            };

            await _mongoJackpotRepoService.InsertAsync(coinFlipMatchModel);

            return(coinFlipMatchModel);
        }
예제 #6
0
        private async Task PlaceBetOnMatch
        (
            int matchId,
            JackpotMatchSetting setting,
            DatabaseModel.GameMode gameMode,
            int assetAndDescriptionIdsCount,
            List <DatabaseModel.Item> items,
            DatabaseModel.User user,
            List <DatabaseModel.ItemDescription> uniqueItemDescriptions
        )
        {
            if (!gameMode.IsEnabled)
            {
                throw new GameModeIsNotEnabledException($"The current gamemode {gameMode.Type} is not enabled");
            }

            if ((setting.AllowCsgo && setting.AllowPubg) == false)
            {
                var oneOrMoreItemsIsPubg = uniqueItemDescriptions.Any(AppIdToGameConverterHelper.IsPubgItem);
                var oneOrMoreItemsIsCsgo = uniqueItemDescriptions.Any(AppIdToGameConverterHelper.IsCsgoItem);

                if (setting.AllowCsgo && oneOrMoreItemsIsPubg)
                {
                    throw new NotAllowedAppIdOnMatchException("You tried to bet a PUBG item on a match that only accepts CSGO");
                }

                if (setting.AllowPubg && oneOrMoreItemsIsCsgo)
                {
                    throw new NotAllowedAppIdOnMatchException("You tried to bet a CSGO item on a match that only accepts PUBG");
                }
            }

            if (uniqueItemDescriptions.Any(description => !description.Valid))
            {
                throw new InvalidItemException("One or more items is not allowed to be used for betting at the moment, refresh the page and try again");
            }

            if (user == null)
            {
                throw new UserDoesNotExistException("Can't find a user");
            }

            if (items.Any(item => item.OwnerId != user.Id))
            {
                throw new UserDoesNotOwnThisItemsException("The user does not own this item!");
            }

            if (items.Count == 0)
            {
                throw new InvalidAssetAndDecriptionIdException("No items with that assetId or descriptionId was found");
            }

            if (items.Count != assetAndDescriptionIdsCount)
            {
                throw new NotSameCountAsExpectedException("assetAndDescriptionIds count != avalibleItems");
            }

            if (items.Count > setting.MaxItemAUserCanBet)
            {
                throw new ToManyItemsOnBetException($"You can max bet {setting.MaxItemAUserCanBet} items, you tried to bet {items.Count}");
            }

            if (items.Count < setting.MinItemAUserCanBet)
            {
                throw new ToFewItemsOnBetException($"You can min bet {setting.MinItemAUserCanBet} items, you tried to bet {items.Count}");
            }

            var sumOfBet = await _itemService.GetSumOfItems(items);

            if (sumOfBet > setting.MaxValueAUserCanBet)
            {
                throw new ToMuchValueOnBetException($"You can max bet {setting.MaxValueAUserCanBet} value, you tried to bet {sumOfBet}");
            }

            if (sumOfBet < setting.MinValueAUserCanBet)
            {
                throw new ToLittleValueOnBetException($"You can min bet {setting.MinValueAUserCanBet} value, you tried to bet {sumOfBet}");
            }


            var avalibleItems = await _itemService.GetAvalibleItemsForUser(user);

            if (avalibleItems.Count == 0)
            {
                throw new NoAvalibleItemsForBettingException("No avalible item for betting");
            }

            if (IsSameItemsInAvalibleItemsAsInItem(items, avalibleItems))
            {
                throw new ItemNotAvalibleException("This item can not be betted now! Is this items already betted on an open match?)");
            }

            await InsertBetWithTransaction(user, matchId, items, gameMode, uniqueItemDescriptions);

            //we have now successfully placed a bet

            if (gameMode.Type == GameModeHelper.GetStringFromType(GameModeType.JackpotCsgo))
            {
                _discordService.JackpotBetAsync(matchId, user.SteamId, sumOfBet);
            }
        }