public SpinResult Spin(long accountId, string accountName, int roomId, MoneyType moneyType, string lineData)
        {
            var roomValue     = GetBetValueByRoom(roomId);
            var totalBetValue = lineData.Split(',').Length *roomValue;
            var slotsData     = _testService.IsTestAccount(accountName) ? _testService.GetTestData() : _slotsGeneService.GenerateSlotsData();

            //var newSlotsData = _slotsGeneService.HandleSlotsData(slotsData);
            var slotMachine  = new ThatTruyenSlotMachine();
            var prizeLines   = slotMachine.GetLinesPrize(slotsData, roomValue, lineData, out var isJackpot, out var payLinePrizeValue);
            var countBonus   = slotsData.Count(x => x == 3); // Đếm biểu tượng bonus
            var countScatter = slotsData.Count(x => x == 2); // đếm biểu tượng freeSpins
            //if (payLinePrizeValue == 0 && countBonus < 3 && countScatter < 3 && !isJackpot)
            //{
            //    if (CacheHandler.AddAccountAction(accountName, "MissSpin", 300) > 10)
            //    {
            //        do
            //        {
            //            slotsData = _slotsGeneService.GenerateSlotsData();
            //            prizeLines = slotMachine.GetLinesPrize(slotsData, roomValue, lineData, out isJackpot, out payLinePrizeValue);
            //            countBonus = slotsData.Count(x => x == 3); // Đếm biểu tượng bonus
            //            countScatter = slotsData.Count(x => x == 2); // đếm biểu tượng freeSpins
            //        } while (payLinePrizeValue == 0 && countBonus < 3 && countScatter < 3 && !isJackpot);
            //    }
            //}
            //else
            //{
            //    CacheHandler.RemoveAccountAction(accountName, "MissSpin");
            //}

            BonusGame bonusGame = null;

            // Tạo Bonus Game nếu có
            if (countBonus >= 3)
            {
                bonusGame = _bonusGeneService.GenerateBonusGame(totalBetValue, countBonus - 2);
            }

            var addFreeSpins = 0;

            if (countScatter >= 3)
            {
                addFreeSpins = (countScatter - 2) * 4;  // Thêm lượt FreeSpins
            }
            var inputSpinData = new InputSpinData()
            {
                AccountId       = accountId,
                AccountName     = accountName,
                MoneyType       = moneyType,
                AddFreeSpins    = addFreeSpins,
                RoomId          = roomId,
                IsJackpot       = isJackpot,
                SlotsData       = string.Join(",", slotsData.Select(x => x.ToString())),
                TotalBonusValue = countBonus >= 3 ? bonusGame.TotalPrizeValue : 0,
                TotalPrizeValue = payLinePrizeValue,
                LineData        = lineData,
                TotalBetValue   = totalBetValue
            };
            var outputSpinData = _dbService.Spin(inputSpinData);

            if (outputSpinData.ResponseStatus < 0)
            {
                if (outputSpinData.ResponseStatus == -90) // Limit Fund
                {
                    var missData = _missData[RandomUtil.NextInt(0, _missData.Length)];
                    _dbService.UpdateSlotsData(outputSpinData.SpinId, string.Join(",", missData.Select(x => x.ToString()))); // cap nhat kq tap truot
                    return(new SpinResult()
                    {
                        SpinId = outputSpinData.SpinId,
                        SlotsData = missData,
                        AddFreeSpin = 0,
                        PrizeLines = new List <PrizeLine>(),
                        Balance = outputSpinData.Balance,
                        FreeSpins = outputSpinData.FreeSpins,
                        Jackpot = outputSpinData.Jackpot,
                        ResponseStatus = 1
                    });
                }
                return(new SpinResult()
                {
                    ResponseStatus = outputSpinData.ResponseStatus
                });
            }

            if (countBonus >= 3)
            {
                _dbService.CreateBonusGame(moneyType, outputSpinData.SpinId, roomId, accountId, accountName, totalBetValue, bonusGame.BonusData, bonusGame.Mutiplier, bonusGame.TotalPrizeValue, out var bonusResponse);
            }

            UpdateCacheJackpot(roomId, outputSpinData.Jackpot, moneyType); // Cập nhật jackpot cho cache
            var totalPrizeValue = payLinePrizeValue + outputSpinData.TotalJackpotValue;

            HonorHandler.Instance.SaveHonor(accountName, roomId, totalPrizeValue, inputSpinData.IsJackpot ? 1 : 2); // Luu vinh danh

            return(new SpinResult()
            {
                SpinId = outputSpinData.SpinId,
                SlotsData = slotsData,
                AddFreeSpin = addFreeSpins,
                IsJackpot = isJackpot,
                PrizeLines = prizeLines,
                BonusGame = bonusGame,
                TotalPrizeValue = payLinePrizeValue + outputSpinData.TotalJackpotValue,
                TotalPaylinePrizeValue = payLinePrizeValue,
                TotalJackpotValue = outputSpinData.TotalJackpotValue,
                Balance = outputSpinData.Balance,
                FreeSpins = outputSpinData.FreeSpins,
                Jackpot = outputSpinData.Jackpot,
                ResponseStatus = outputSpinData.ResponseStatus
            });
        }
Exemple #2
0
        public SpinResult Spin(long accountId, string accountName, int roomId, MoneyType moneyType, string lineData)
        {
            String s = "[tamquoc] Spin play: " +
                       "\r\naccountId: " + accountId +
                       "\r\naccountName: " + accountName +
                       "\r\nroomId: " + roomId +
                       "\r\nmoneyType: " + moneyType +
                       "\r\nlineData: " + lineData;
            var roomValue     = GetBetValueByRoom(roomId);
            var totalBetValue = lineData.Split(',').Length *roomValue;
            var slotsData     = _testService.IsTestAccount(accountName) ? _testService.GetTestData() : _slotsGeneService.GenerateSlotsData();

            var       newSlotsData = _slotsGeneService.HandleSlotsData(slotsData);
            var       slotMachine  = new SlotMachine();
            var       prizeLines   = slotMachine.GetLinesPrize(newSlotsData, roomValue, lineData, out var isJackpot, out var payLinePrizeValue);
            var       countBonus   = slotsData.Count(x => x == 3); // Đếm biểu tượng bonus
            var       countScatter = slotsData.Count(x => x == 2); // đếm biểu tượng freeSpins
            BonusGame bonusGame    = null;

            // Tạo Bonus Game nếu có
            if (countBonus >= 3)
            {
                bonusGame = _bonusGeneService.GenerateBonusGame(totalBetValue, countBonus - 2);
                s        += "\r\nWin bonus: " + JsonConvert.SerializeObject(bonusGame);
            }

            var addFreeSpins = 0;

            if (countScatter >= 3)
            {
                addFreeSpins = (countScatter - 2) * 4;  // Thêm lượt FreeSpins
                s           += "\r\nWin Free spin: " + addFreeSpins;
            }
            var inputSpinData = new InputSpinData()
            {
                AccountId       = accountId,
                AccountName     = accountName,
                MoneyType       = moneyType,
                AddFreeSpins    = addFreeSpins,
                RoomId          = roomId,
                IsJackpot       = isJackpot,
                SlotsData       = string.Join(",", slotsData.Select(x => x.ToString())),
                TotalBonusValue = countBonus > 3 ? bonusGame.TotalPrizeValue : 0,
                TotalPrizeValue = payLinePrizeValue,
                LineData        = lineData,
                TotalBetValue   = totalBetValue
            };
            var outputSpinData = _dbService.Spin(inputSpinData);

            if (outputSpinData.ResponseStatus < 0)
            {
                if (outputSpinData.ResponseStatus == -90) // Limit Fund
                {
                    return(new SpinResult()
                    {
                        SpinId = outputSpinData.SpinId,
                        SlotsData = _missData[RandomUtil.NextInt(0, _missData.Length)],
                        AddFreeSpin = 0,
                        PrizeLines = new List <PrizeLine>(),
                        Balance = outputSpinData.Balance,
                        FreeSpins = outputSpinData.FreeSpins,
                        Jackpot = outputSpinData.Jackpot,
                        ResponseStatus = 1
                    });
                }
                return(new SpinResult()
                {
                    ResponseStatus = outputSpinData.ResponseStatus
                });
            }

            if (countBonus >= 3)
            {
                _dbService.CreateBonusGame(moneyType, outputSpinData.SpinId, roomId, accountId, accountName, totalBetValue, bonusGame.BonusData, bonusGame.Mutiplier, bonusGame.TotalPrizeValue, out var bonusResponse);
            }

            UpdateCacheJackpot(roomId, outputSpinData.Jackpot, moneyType); // Cập nhật jackpot cho cache
            var totalPrizeValue = payLinePrizeValue + outputSpinData.TotalJackpotValue;

            HonorHandler.Instance.SaveHonor(accountName, roomId, totalPrizeValue, inputSpinData.IsJackpot ? 1 : 2); // Luu vinh danh

            var d = new SpinResult()
            {
                SpinId                 = outputSpinData.SpinId,
                SlotsData              = slotsData,
                AddFreeSpin            = addFreeSpins,
                IsJackpot              = isJackpot,
                PrizeLines             = prizeLines,
                BonusGame              = bonusGame,
                TotalPrizeValue        = payLinePrizeValue + outputSpinData.TotalJackpotValue,
                TotalPaylinePrizeValue = payLinePrizeValue,
                TotalJackpotValue      = outputSpinData.TotalJackpotValue,
                Balance                = outputSpinData.Balance,
                FreeSpins              = outputSpinData.FreeSpins,
                Jackpot                = outputSpinData.Jackpot,
                ResponseStatus         = outputSpinData.ResponseStatus
            };

            s += "\r\nResponse: " + JsonConvert.SerializeObject(d);
            NLogManager.LogMessage(s);
            return(d);
        }