public async Task UpdateLastSpinData(UserSession userSession, Game game, SpinResult spinResult) { var user = userSession.User; var spinData = new UserGameSpinData() { UserId = user.Id, GameId = game.Id, Data = spinResult.ToByteArray() }; if (userSession.IsFunPlay) { var key = userSession.SessionKey + "_" + game.Id.ToString(); await cache.SetAsync(key, spinData, new DistributedCacheEntryOptions { SlidingExpiration = TimeSpan.FromMinutes(5) }); } else { using (var db = databaseManager.GetWritableDatabase()) { var lastSpin = await db.UserGameSpinDatas .Where(x => x.UserId == user.Id) .Where(x => x.GameId == game.Id) .AsNoTracking() .FirstOrDefaultAsync(); if (lastSpin == null) { db.UserGameSpinDatas.Add(spinData); } else { lastSpin.Data = spinData.Data; db.UserGameSpinDatas.Update(lastSpin); } await db.SaveChangesAsync(); } } }
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 decimal CalculateTotalBet(UserGameSpinData userGameSpinData, RequestContext <SpinArgs> requestContext) { var args = requestContext.Parameters; return(args.LineBet * BullRushConfiguration.Credit); }
public Result <SpinResult, ErrorCode> UpdateUserLastSpinData(int level, UserGameSpinData userGameSpinData, RequestContext <BonusArgs> requestContext, BonusResult bonusResult) { throw new NotImplementedException(); }
public IExtraGameSettings GetExtraSettings(int level, UserGameSpinData userGameSpinData) { return(new EmptyExtraGameSettings()); }