Ejemplo n.º 1
0
 public OutputSpinData Spin(InputSpinData inputData)
 {
     try
     {
         string s         = "[tamquoc] SpinInfo: " + JsonConvert.SerializeObject(inputData);
         var    ipAddress = "";
         var    db        = new DBHelper(Config.Game25LinesConnectionString);
         var    pars      = new SqlParameter[18];
         pars[0]  = new SqlParameter("@_AccountId", inputData.AccountId);
         pars[1]  = new SqlParameter("@_AccountName", inputData.AccountName);
         pars[2]  = new SqlParameter("@_RoomID", inputData.RoomId);
         pars[3]  = new SqlParameter("@_MoneyType", inputData.MoneyType);
         pars[4]  = new SqlParameter("@_LineData", inputData.LineData);
         pars[5]  = new SqlParameter("@_ClientIP", ipAddress);
         pars[6]  = new SqlParameter("@_TotalBetValue", inputData.TotalBetValue);
         pars[7]  = new SqlParameter("@_SlotsData", inputData.SlotsData);
         pars[8]  = new SqlParameter("@_IsJackpot", inputData.IsJackpot);
         pars[9]  = new SqlParameter("@_AddFreeSpins", inputData.AddFreeSpins);
         pars[10] = new SqlParameter("@_TotalPrizeValue", inputData.TotalPrizeValue);
         pars[11] = new SqlParameter("@_TotalBonusValue", inputData.TotalBonusValue);
         pars[12] = new SqlParameter("@_SpinId", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         pars[13] = new SqlParameter("@_TotalJackpotValue", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         pars[14] = new SqlParameter("@_FreeSpins", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         pars[15] = new SqlParameter("@_Jackpot", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         pars[16] = new SqlParameter("@_Balance", SqlDbType.BigInt)
         {
             Direction = ParameterDirection.Output
         };
         pars[17] = new SqlParameter("@_ResponseStatus", SqlDbType.Int)
         {
             Direction = ParameterDirection.Output
         };
         var spName = inputData.MoneyType == MoneyType.Gold ? "[dbo].[SP_Spins_CreateTransaction]" : "[dbo].[SP_Spins_CreateTransaction_Coin]";
         db.ExecuteNonQuerySP(spName, pars);
         var outPutData = new OutputSpinData()
         {
             SpinId            = pars[12].Value != DBNull.Value ? int.Parse(pars[12].Value.ToString()) : 0,
             TotalJackpotValue = pars[13].Value != DBNull.Value ? int.Parse(pars[13].Value.ToString()) : 0,
             FreeSpins         = pars[14].Value != DBNull.Value ? int.Parse(pars[14].Value.ToString()) : 0,
             Jackpot           = pars[15].Value != DBNull.Value ? int.Parse(pars[15].Value.ToString()) : 0,
             Balance           = pars[16].Value != DBNull.Value ? long.Parse(pars[16].Value.ToString()) : 0,
             ResponseStatus    = pars[17].Value != DBNull.Value ? int.Parse(pars[17].Value.ToString()) : -98
         };
         s += "\r\nResult spin: " + JsonConvert.SerializeObject(pars) +
              "\r\n" + JsonConvert.SerializeObject(pars.Select(x => x.Value).ToArray());
         //NLogManager.LogMessage($"Spin => AccountId:{inputData.AccountId}|AccountName:{inputData.AccountName}|RoomId:{inputData.RoomId}|MoneyType:{inputData.MoneyType}|LineData:{inputData.LineData}|Ip:{ipAddress}" +
         //                       $"ToTalBetValue:{inputData.TotalBetValue}|SlotsData:{inputData.SlotsData}|IsJackpot:{inputData.IsJackpot}|AddFreeSpins:{inputData.AddFreeSpins}|TotalPrizeValue:{inputData.TotalPrizeValue}" +
         //                       $"TotalBonusValue:{inputData.TotalBonusValue}|SpinId:{pars[12].Value}|TotalJackpotValue:{pars[13].Value}|FreeSpins:{pars[14].Value}|Jackpot:{pars[15].Value}|Balance:{pars[16].Value}|Response:{pars[17].Value}");
         s += "\r\nResponse data: " + JsonConvert.SerializeObject(outPutData);
         NLogManager.LogMessage(s);
         return(outPutData);
     }
     catch (Exception ex)
     {
         NLogManager.PublishException(ex);
         return(null);
     }
 }
        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
            });
        }
Ejemplo n.º 3
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);
        }