private static void GenerateFreeSpinResult(int level, RequestContext <BonusArgs> requestContext, BullRushFreeSpinResult fsr, BullRushFreeSpinBonus bonus)
        {
            var bullRushSpinResult = new BullRushSpinResult()
            {
                Level                    = fsr.SpinResult.Level,
                SpinBet                  = fsr.SpinResult.SpinBet,
                DistributedAllRows       = fsr.SpinResult.DistributedAllRows,
                WinPositions             = new List <BullRushWinPosition>(),
                BonusPositions           = new List <BonusPosition>(),
                RowPositions             = new List <int>(),
                CurrentRacingCounter     = fsr.SpinResult.CurrentRacingCounter,
                IsRacing                 = fsr.SpinResult.IsRacing,
                IsBonusRacing            = fsr.SpinResult.IsBonusRacing,
                CurrentRacingStep        = fsr.SpinResult.CurrentRacingStep,
                PreviousPowerUp          = fsr.SpinResult.PreviousPowerUp,
                NumberOfMagnetActiveRows = fsr.SpinResult.NumberOfMagnetActiveRows,
                InventoryList            = fsr.SpinResult.InventoryList,
                SelectedBonusRacingPrize = fsr.SpinResult.SelectedBonusRacingPrize,
                CumulativeWin            = fsr.SpinResult.CumulativeWin,
                NumOfJackpot             = fsr.SpinResult.NumOfJackpot,
                Bet = 0,
                SpinTransactionId = fsr.SpinTransactionId.HasValue
                ? fsr.SpinTransactionId
                : fsr.TransactionId,
                PlatformType = requestContext.Platform,
                RoundId      = fsr.RoundId
            };


            //bullRushSpinResult.Wheel = MegaMoneyCommon.GenerateFreeSpin(level, variantWheel, bullRushSpinResult.InventoryList, chosenPowerUpItems, fsr.SpinResult.SpinBet.FunPlayDemoKey);

            fsr.SpinResult = bullRushSpinResult;
        }
        private static BullRushSpinResult GenerateJackpotResult(RequestContext <BonusArgs> requestContext, BullRushJackpotBonusResult br, BullRushJackpotBonus BullRushBonus)
        {
            var bullRushSpinResult = new BullRushSpinResult()
            {
                Level                   = br.SpinResult.Level,
                SpinBet                 = br.SpinResult.SpinBet,
                BonusPositions          = br.SpinResult.BonusPositions,
                IsRacing                = br.SpinResult.IsRacing,
                IsBonusRacing           = br.SpinResult.IsBonusRacing,
                SelectedOuterWheelValue = br.SpinResult.SelectedOuterWheelValue,
                SelectedOuterWheelIndex = br.SpinResult.SelectedOuterWheelIndex,
                CurrentRacingCounter    = br.SpinResult.CurrentRacingCounter,
                CurrentJackpotCounter   = br.SpinResult.CurrentJackpotCounter,
                NumOfJackpot            = br.SpinResult.NumOfJackpot,
                InventoryList           = br.SpinResult.InventoryList,
                CumulativeWin           = br.SpinResult.CumulativeWin,
                Bet = 0,
                SpinTransactionId = br.SpinTransactionId.HasValue
                ? br.SpinTransactionId
                : br.TransactionId,
                PlatformType       = requestContext.Platform,
                RoundId            = br.RoundId,
                CurrentRacingStep  = br.SpinResult.CurrentRacingStep,
                CurrentJackpotStep = br.SpinResult.CurrentJackpotStep,
                InnerWheel         = br.SpinResult.InnerWheel
            };

            var random = RandomNumberEngine.NextDouble();

            if (bullRushSpinResult.SpinBet.FunPlayDemoKey == 1)
            {
                random = 1;
            }

            var selectedCoinValue = BullRushConfiguration.InnerWheelWeight.FirstOrDefault(item => random <= item.Key).Value;

            bullRushSpinResult.SelectedInnerWheelIndex = BullRushConfiguration.InnerWheel.IndexOf(selectedCoinValue);

            bullRushSpinResult.SelectedInnerWheelValue = selectedCoinValue;

            br.SpinResult = bullRushSpinResult;

            return(bullRushSpinResult);
        }
        public static BullRushJackpotBonus CreateBonus(BullRushSpinResult sr)
        {
            var bonus = new BullRushJackpotBonus
            {
                BonusType          = BonusType.FreeSpin,
                Guid               = Guid.NewGuid(),
                UserGameKey        = sr.SpinBet.UserGameKey,
                SpinBet            = sr.SpinBet,
                CurrentRacingStep  = sr.CurrentRacingStep,
                CurrentJackpotStep = sr.CurrentJackpotStep,
                CurrentStep        = sr.CurrentJackpotStep,
                NumOfJackpot       = sr.NumOfJackpot,
                Counter            = sr.CurrentJackpotCounter,
                SpinTransactionId  = sr.SpinTransactionId ?? sr.TransactionId,
                CumulativeWin      = sr.CumulativeWin,
                IsFreeSpin         = sr.IsRacing,
                IsInnerWheelBonus  = sr.IsInnerWheelBonus,
                GameResult         = sr
            };

            return(bonus);
        }
        public static BullRushFreeSpinBonus CreateBonus(BullRushSpinResult bullRushSpinResult)
        {
            var bonus = new BullRushFreeSpinBonus
            {
                BonusType          = BonusType.FreeSpin,
                Guid               = Guid.NewGuid(),
                UserGameKey        = bullRushSpinResult.SpinBet.UserGameKey,
                SpinBet            = bullRushSpinResult.SpinBet,
                SpinTransactionId  = bullRushSpinResult.SpinTransactionId ?? bullRushSpinResult.TransactionId,
                CurrentStep        = bullRushSpinResult.CurrentRacingStep,
                NumOfFreeSpin      = bullRushSpinResult.NumOfJackpot,
                RacingCounter      = bullRushSpinResult.CurrentRacingCounter,
                BonusRacingCounter = bullRushSpinResult.CurrentBonusRacingCounter,
                CumulativeWin      = bullRushSpinResult.CumulativeWin,
                PreviousPowerUp    = bullRushSpinResult.PreviousPowerUp,
                Multiplier         = 1,
                IsFreeSpin         = bullRushSpinResult.IsRacing,
                GameResult         = bullRushSpinResult
            };

            return(bonus);
        }
        public Result <SpinResult, ErrorCode> ExecuteSpin(int level, UserGameSpinData userGameSpinData, RequestContext <SpinArgs> requestContext)
        {
            var lastSpin = userGameSpinData == null ? default : userGameSpinData.Data.FromByteArray <BullRushSpinResult>();

                           var result = new BullRushSpinResult()
                           {
                               Level   = level,
                               SpinBet = new SpinBet(requestContext.UserGameKey, requestContext.Platform)
                               {
                                   CurrencyId         = requestContext.Currency.Id,
                                   GameSettingGroupId = requestContext.GameSetting.GameSettingGroupId,
                                   LineBet            = requestContext.Parameters.LineBet,
                                   //Lines = BullRushConfiguration.Lines,
                                   //Multiplier = BullRushConfiguration.Multiplier,
                                   FunPlayDemoKey = requestContext.Parameters.FunPlayDemoKey,
                                   Credits        = BullRushConfiguration.Credit
                               },

                               PlatformType = requestContext.Platform
                           };

                           if (lastSpin != null)
                           {
                               var lastList = new List <int>(lastSpin.InventoryList);

                               result.InventoryList = lastList;
                           }

                           var random = RandomNumberEngine.NextDouble();

                           var selectedValue = BullRushConfiguration.OuterWheelWeight.FirstOrDefault(item => random <= item.Key).Value;

                           //result.Wheel = new Wheel(1, 8, "4,0,-1,1,4,3,-1,2");

                           result.SelectedOuterWheelIndex = BullRushConfiguration.OuterWheel.IndexOf(selectedValue);

                           result.SelectedOuterWheelValue = selectedValue;

                           if (selectedValue == BullRushConfiguration.RACE)
                           {
                               var inventoryOfThreePowerUps = new List <int>();

                               var magnetIndex = result.InventoryList.IndexOf(BullRushConfiguration.MAGNET);
                               if (magnetIndex != -1)
                               {
                                   inventoryOfThreePowerUps.Add(BullRushConfiguration.MAGNET);
                                   result.InventoryList.RemoveAt(magnetIndex);
                               }

                               var vacuumIndex = result.InventoryList.IndexOf(BullRushConfiguration.VACUUM);
                               if (vacuumIndex != -1)
                               {
                                   inventoryOfThreePowerUps.Add(BullRushConfiguration.VACUUM);
                                   result.InventoryList.RemoveAt(vacuumIndex);
                               }

                               var shieldIndex = result.InventoryList.IndexOf(BullRushConfiguration.SHIELD);
                               if (shieldIndex != -1)
                               {
                                   inventoryOfThreePowerUps.Add(BullRushConfiguration.SHIELD);
                                   result.InventoryList.RemoveAt(shieldIndex);
                               }

                               result.IsBonus                  = true;
                               result.IsInnerWheelBonus        = true;
                               result.InventoryOfThreePowerUps = new List <int>(inventoryOfThreePowerUps);
                               result.CurrentJackpotStep       = 1;
                           }
                           else if (selectedValue == BullRushConfiguration.SURPRISE)
                           {
                               var randomSuprise = RandomNumberEngine.NextDouble();

                               var supriseValue = BullRushConfiguration.SupriseWeight.FirstOrDefault(x => randomSuprise <= x.Key).Value;

                               if (supriseValue == BullRushConfiguration.BUNDLE)
                               {
                                   result.InventoryList.Add(BullRushConfiguration.MAGNET);
                                   result.InventoryList.Add(BullRushConfiguration.VACUUM);
                                   result.InventoryList.Add(BullRushConfiguration.SHIELD);
                               }
                               else if (supriseValue == BullRushConfiguration.COIN1)
                               {
                                   result.Win = 100 * result.SpinBet.LineBet;
                               }
                               else if (supriseValue == BullRushConfiguration.COIN2)
                               {
                                   result.Win = 200 * result.SpinBet.LineBet;
                               }
                           }
                           else if (selectedValue != BullRushConfiguration.RACE && selectedValue != BullRushConfiguration.LOSE)
                           {
                               result.InventoryList.Add(selectedValue);
                           }

                           return(result);
        }
        public static List <List <decimal> > GenerateRacing(Wheel variantWheel, List <int> chosenTreasureItems, BullRushSpinResult sr)
        {
            var lineBet                  = sr.SpinBet.LineBet;
            var funplayKey               = sr.SpinBet.FunPlayDemoKey;
            var w                        = new Wheel(BullRushConfiguration.Rows);
            var distributedAllRows       = new List <List <decimal> >();
            var inventoryOfThreePowerUps = new List <int>(sr.InventoryOfThreePowerUps);

            for (int row = 0; row < variantWheel.Height; row++)
            {
                var distributeListed = new List <decimal>();

                // Coin
                if (variantWheel[0][row] > 0)
                {
                    for (int j = 0; j < variantWheel[0][row]; j++)
                    {
                        distributeListed.Add(lineBet);
                    }
                }

                // Obstacle
                if (variantWheel[1][row] > 0)
                {
                    for (int j = 0; j < variantWheel[1][row]; j++)
                    {
                        distributeListed.Add(BullRushConfiguration.OBSTACLE);
                    }
                }

                // Power up
                if (variantWheel[2][row] > 0 && inventoryOfThreePowerUps.Count > 0)
                {
                    var randomIndex = RandomNumberEngine.Next(0, inventoryOfThreePowerUps.Count() - 1);

                    var powerUp = inventoryOfThreePowerUps[randomIndex];

                    inventoryOfThreePowerUps.RemoveAt(randomIndex);

                    distributeListed.Add(powerUp);
                }

                // Chest-Treasure
                if (variantWheel[3][row] > 0 && chosenTreasureItems.IndexOf(row) != -1)
                {
                    var indexChest = sr.InventoryList.FindIndex(x => x == BullRushConfiguration.TREASURE);

                    if (indexChest != -1)
                    {
                        for (int j = 0; j < variantWheel[3][row]; j++)
                        {
                            var random = RandomNumberEngine.NextDouble();

                            var valueOfTreasure = BullRushConfiguration.TreasureDrawing.FirstOrDefault(x => random <= x.Key).Value;

                            var chestValue = valueOfTreasure * lineBet;

                            sr.InventoryList.Remove(indexChest);

                            distributeListed.Add(chestValue);
                        }
                    }
                }

                var currentItemsOfDistributed = distributeListed.Count;

                for (int i = 0; i < BullRushConfiguration.WidthOfRace - currentItemsOfDistributed; i++)
                {
                    distributeListed.Add(-1);
                }

                var randomDistributed = distributeListed.Shuffle();

                distributedAllRows.Add(randomDistributed);
            }

            return(distributedAllRows);
        }