Example #1
0
        public async Task <Result <Bets, ErrorCode> > GetBets(RequestContext <GetBetsArgs> requestContext)
        {
            using (logger.BeginScope(new Dictionary <string, object>
            {
                ["SessionKey"] = requestContext.UserSession.SessionKey,
                ["UserId"] = requestContext.UserSession.UserId,
                ["GameKey"] = requestContext.GameKey
            }))
            {
                logger.LogInformation("User call getbets");

                var userGameKey = requestContext.UserGameKey;

                var module = gameModules.GetModule(requestContext.GameKey);

                var lastSpinData = await userService.GetLastSpinData(requestContext.UserSession, requestContext.Game);

                var gameSetting = requestContext.GameSetting;

                var level = await userService.GetLevel(userGameKey);

                var extraSettings = module.GetExtraSettings(level, lastSpinData);

                var bets = new Bets
                {
                    Wheel             = module.InitialRandomWheel(),
                    FunPlayDemo       = requestContext.UserSession.IsFunPlay && requestContext.Operator.FunPlayDemo,
                    Coins             = gameSetting.CoinsDenomination.Split(';').Select(decimal.Parse).ToList(),
                    Multipliers       = gameSetting.CoinsMultiplier.Split(';').Select(int.Parse).ToList(),
                    ExtraGameSettings = extraSettings,
                    ServerTime        = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds()
                };

                if (!requestContext.UserSession.IsFunPlay)
                {
                    var userGameData = await userService.GetUserGameData(requestContext.UserSession.UserId, requestContext.Game.Id);

                    if (userGameData != null)
                    {
                        bets.Bet = userGameData.Bet;
                    }
                    var bonus = await bonusService.GetUnfinishBonus(requestContext.UserSession, requestContext.Game.Id);

                    bets.Bonus = bonus == null ? null : module.ConvertToBonus(bonus);
                }

                return(bets);
            }
        }