private bool IsDraftingDone(DatabaseModel.JackpotSetting currentMatchSetting, DatabaseModel.CoinFlip coinFlip) { var countdownTimeSpan = TimeSpan.FromMilliseconds(currentMatchSetting.TimmerInMilliSec); var draftingTimeSpan = TimeSpan.FromMilliseconds(currentMatchSetting.DraftingTimeInMilliSec); return((DateTime.Now - (coinFlip.TimerStarted.Value + countdownTimeSpan + draftingTimeSpan)).TotalMilliseconds > 0); }
public async Task RemoveAsync(DatabaseModel.JackpotSetting setting) { using (var cn = DatabaseConnection.GetNewOpenConnection()) { await cn.ExecuteAsync("DELETE FROM JackpotSetting WHERE Id = @id", new { Id = setting.Id }); cn.Close(); } }
public async Task <DatabaseModel.JackpotSetting> InsertAsync(DatabaseModel.JackpotSetting setting, ITransactionWrapper transactionWrapper) { var cn = transactionWrapper.SqlConnection; var transaction = transactionWrapper.Transaction; var insertedId = await cn.InsertAsync(setting, transaction); setting.Id = insertedId; return(setting); }
public async Task <DatabaseModel.JackpotSetting> InsertAsync(DatabaseModel.JackpotSetting setting) { using (var cn = DatabaseConnection.GetNewOpenConnection()) { await cn.InsertAsync <DatabaseModel.JackpotSetting>(setting); cn.Close(); return(setting); } }
private async Task SetUpGameModeAndSetting() { var currentMatch = await _repoServiceFactory.MatchRepoService.GetCurrentMatch(); if (currentMatch != null) //there is no matches, this is the first time we are starting the server. { _currentMatchSettings = (DatabaseModel.JackpotSetting) await _gameModeSettingService.Find(currentMatch.SettingId, GameModeType.JackpotCsgo); } _gameMode = await _repoServiceFactory.GameModeRepoService.Find(GameModeHelper.GetStringFromType(GameModeType.JackpotCsgo)); }
private async Task <DatabaseModel.CoinFlip> InsertedMatchAndBetWithTransaction ( List <AssetAndDescriptionId> assetAndDescriptionIds, DatabaseModel.CoinFlip match, DatabaseModel.JackpotSetting jackpotSetting, DatabaseModel.GameMode gameMode, List <DatabaseModel.Item> items, DatabaseModel.User user, List <DatabaseModel.ItemDescription> itemDescription, JackpotMatchSetting jackpotMatchSetting ) { DatabaseModel.CoinFlip insertedMatch; DatabaseModel.JackpotSetting insertedJackpotSetting; using (var transaction = _transactionFactory.BeginTransaction()) { try { insertedJackpotSetting = await _repoServiceFactory.JackpotSettingRepo.InsertAsync(jackpotSetting, transaction); match.SettingId = insertedJackpotSetting.Id; insertedMatch = await _repoServiceFactory.CoinFlipMatchRepoService.InsertAsync(match, transaction); } catch (Exception) { transaction.Rollback(); throw; } transaction.Commit(); } try { var count = assetAndDescriptionIds.Count; await _betService.PlaceBetOnCoinFlipMatch(insertedMatch, jackpotMatchSetting, gameMode, count, items, user, itemDescription); } catch (Exception) { await _repoServiceFactory.CoinFlipMatchRepoService.RemoveAsync(insertedMatch); await _repoServiceFactory.JackpotSettingRepo.RemoveAsync(insertedJackpotSetting); throw; } return(insertedMatch); }
private async Task <JackpotMatch> GetMatch(DatabaseModel.JackpotSetting settings, DatabaseModel.Match match, DatabaseModel.GameMode gameMode) { var items = await _betService.GetBettedItemsOnMatch(match.Id, gameMode.Id) ?? new List <Item>(); return(new JackpotMatch( match.RoundId.ToString(), match.Hash, match.Salt, match.Percentage, MatchStatusHelper.GetMatchStatusFromInt(match.Status), await GetBets(items, match.Id, gameMode), match.TimerStarted, settings.ToJackpotMatchSetting() )); }
public static JackpotMatchSetting ToJackpotMatchSetting(this DatabaseModel.JackpotSetting jackpotSetting) { return(new JackpotMatchSetting ( jackpotSetting.Rake, TimeSpan.FromMilliseconds(jackpotSetting.TimmerInMilliSec), jackpotSetting.ItemsLimit, jackpotSetting.MaxItemAUserCanBet, jackpotSetting.MinItemAUserCanBet, jackpotSetting.MaxValueAUserCanBet, jackpotSetting.MinValueAUserCanBet, jackpotSetting.AllowCsgo, jackpotSetting.AllowPubg, TimeSpan.FromMilliseconds(jackpotSetting.DraftingTimeInMilliSec), jackpotSetting.DraftingGraph )); }
private async Task DraftWinner(DatabaseModel.CoinFlip match, DatabaseModel.JackpotSetting matchSetting, List <DatabaseModel.Bet> betsOnMatch) { var itemBetsOnMatch = await _repoServiceFactory.ItemBettedRepoService.FindAsync(betsOnMatch); var percentage = Convert.ToDouble(match.Percentage, CultureInfo.InvariantCulture); var winningBet = _draftService.GetWinningBet(percentage, betsOnMatch, itemBetsOnMatch); var winningUser = await _repoServiceFactory.UserRepoService.FindAsync(winningBet.Bet.UserId); match.WinnerId = winningUser.Id; match.Status = (int)MatchStatus.Drafting; await _repoServiceFactory.CoinFlipMatchRepoService.UpdateAsync(match); await _jackpotRepoService.UpdateStatusForMatch(match, MatchStatus.Drafting); await _jackpotRepoService.SetWinnerForMatch(match, new UserWithQuote { ImageUrl = winningUser.ImageUrl, Name = winningUser.Name, SteamId = winningUser.SteamId, Quote = winningUser.Quote }); await _jackpotRepoService.SetWinnerTicketForMatch(match, winningBet.WinningTicket + 1); var potValue = itemBetsOnMatch.Sum(itemBet => itemBet.Value); await _coinFlipHubConnections.MatchDrafting(new CoinFlipWinnerSelected { Winner = new UserWithQuote { ImageUrl = winningUser.ImageUrl, Name = winningUser.Name, SteamId = winningUser.SteamId, Quote = winningUser.Quote, }, Percentage = match.Percentage, PotValue = potValue, RoundId = match.RoundId, WinningTicket = winningBet.WinningTicket + 1, Salt = match.Salt, }); await _draftService.ChangeOwnerOfItems(betsOnMatch, itemBetsOnMatch, winningUser, match.Id, matchSetting.Rake, _currentGamemode.Id); _discordService.CoinFlipWinnerAsync(match.RoundId, potValue); }
private DatabaseModel.JackpotSetting CreateJackpotSetting(CreateCoinFlipSettingModel setting, decimal totalValueOfItems) { var factor = ((setting.Diff / new decimal(100.0)) + 1); var maxDiff = (totalValueOfItems * factor); var minDiff = (totalValueOfItems / factor); var jackpotSetting = new DatabaseModel.JackpotSetting ( 5, 10 * 1000, setting.MaxItem * 2, setting.MaxItem, setting.MinItem, decimal.Round(maxDiff, 2), decimal.Round(minDiff, 2), 10 * 1000, setting.AllowCsgo, setting.AllowPubg, "drafting graph" ); return(jackpotSetting); }
public async Task <DatabaseModel.Match> CreateNewMatchAsync(int roundId) { var settingRes = await _gameModeSettingService.GetSettingForType(GameModeType.JackpotCsgo); _currentMatchSettings = (DatabaseModel.JackpotSetting)settingRes ?? throw new NullReferenceException("The match setting is NULL!"); _gameMode = await _repoServiceFactory.GameModeRepoService.Find(GameModeHelper.GetStringFromType(GameModeType.JackpotCsgo)); var res = await base.CreateNewMatchAsync(roundId, _gameMode); var jackpotMatch = new JackpotMatch( roundId.ToString(), res.Hash, res.Salt, res.Percentage, MatchStatusHelper.GetMatchStatusFromInt(res.Status), new List <Bet>(), res.TimerStarted, new JackpotMatchSetting( _currentMatchSettings.Rake, TimeSpan.FromMilliseconds(_currentMatchSettings.TimmerInMilliSec), _currentMatchSettings.ItemsLimit, _currentMatchSettings.MaxItemAUserCanBet, _currentMatchSettings.MinItemAUserCanBet, _currentMatchSettings.MaxValueAUserCanBet, _currentMatchSettings.MinValueAUserCanBet, _currentMatchSettings.AllowCsgo, _currentMatchSettings.AllowPubg, TimeSpan.FromMilliseconds(_currentMatchSettings.DraftingTimeInMilliSec), _currentMatchSettings.DraftingGraph ) ); await _matchHubConnections.NewMatchCreated(jackpotMatch); _isClosed = false; return(res); }
protected async Task <JackpotMatch> GetCurrentMatch(DatabaseModel.JackpotSetting settings, DatabaseModel.GameMode gameMode) { var match = await _matchRepoService.GetCurrentMatch(); return(await GetMatch(settings, match, gameMode)); }
protected async Task <JackpotMatch> GetMatchAsync(int id, DatabaseModel.JackpotSetting settings, DatabaseModel.GameMode gameMode) { var match = await _matchRepoService.FindAsync(id); return(await GetMatch(settings, match, gameMode)); }
private bool IsTimerDone(DatabaseModel.JackpotSetting currentMatchSetting, DatabaseModel.CoinFlip coinFlip) { var timeSpan = TimeSpan.FromMilliseconds(currentMatchSetting.TimmerInMilliSec); return((DateTime.Now - (coinFlip.TimerStarted.Value + timeSpan)).TotalMilliseconds > 0); }
private async Task SendWebSocketEventPlayerJoinedAndInsertCoinFlipBetToMongoDb ( DatabaseModel.CoinFlip coinFlip, DatabaseModel.JackpotSetting currentMatchSetting, List <DatabaseModel.Bet> bets ) { var creatorBet = bets.First(bet => bet.UserId == coinFlip.CreatorUserId); var creatorItemBetted = await _repoServiceFactory.ItemBettedRepoService.FindAsync(creatorBet); var creatorValueBet = creatorItemBetted.Sum(betted => betted.Value); var newBet = bets.First(bet => bet.UserId != coinFlip.CreatorUserId); var itemBetted = await _repoServiceFactory.ItemBettedRepoService.FindAsync(newBet); var valueBet = itemBetted.Sum(betted => betted.Value); var dbUser = await _repoServiceFactory.UserRepoService.FindAsync(newBet.UserId); var user = new User { ImageUrl = dbUser.ImageUrl, Name = dbUser.Name, SteamId = dbUser.SteamId }; var unquieItemDescriptions = itemBetted.Select(item => item.DescriptionId).Distinct().ToList(); var itemDescriptions = await _repoServiceFactory.ItemDescriptionRepoService.FindAsync(unquieItemDescriptions); var items = new List <Item>(); foreach (var itemDescription in itemDescriptions) { foreach (var betted in itemBetted) { if (betted.DescriptionId != itemDescription.Id) { continue; } items.Add(new Item { AssetId = betted.AssetId, DescriptionId = itemDescription.Id, IconUrl = itemDescription.ImageUrl, Name = itemDescription.Name, Value = itemDescription.Value, TookAsRake = false, Owner = user, }); } } var coinflipBet = new CoinFlipBet { IsHead = !coinFlip.CreatorIsHead, Items = items, User = user, DateTime = newBet.Created, Tickets = new RoundTicket { Start = ((int)(creatorValueBet * 100)) + 1, End = (int)((valueBet + creatorValueBet) * 100) } }; var websocketData = new TimerStartedWebsocketModel { RoundId = coinFlip.RoundId, Bet = coinflipBet, DraftingTimeInMilliSec = currentMatchSetting.DraftingTimeInMilliSec }; await _jackpotRepoService.AddBetToMatch(coinFlip, coinflipBet); await _coinFlipHubConnections.MatchTimmerStarted(websocketData); _discordService.CoinFlipJoinAsync(creatorValueBet, coinFlip.RoundId, user.SteamId); }