public bool Contains(SmartCoin coin) { lock (StateLock) { return(WaitingList.ContainsKey(coin) || Rounds.Any(x => x.CoinsRegistered.Contains(coin))); } }
private void OnRoundsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { RaisePropertyChanged(() => MostDamageWeapon); RaisePropertyChanged(() => WinStatus); ClutchWonCount = Players.Sum(p => p.ClutchWonCount); ClutchCount = Players.Sum(p => p.ClutchCount); ClutchLostCount = Players.Sum(p => p.ClutchLostCount); if (Rounds.Any()) { KillPerRound = GetKillPerRound(); DeathPerRound = GetKillPerRound(); AssistPerRound = GetAssistPerRound(); MvpCount = Players.Sum(p => p.RoundMvpCount); DeathPerRound = Math.Round((double)DeathCount / Rounds.Count, 2); } if (Players.Any()) { float totalHltv = Players.Sum(player => player.RatingHltv); AverageHltvRating = totalHltv / Players.Count; decimal totalEseaRws = Players.Sum(player => player.EseaRws); AverageEseaRws = Math.Round(totalEseaRws / Players.Count, 2); } }
private void OnPlayersHurtedCollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { DamageArmorCount = PlayersHurted.Sum(h => h.ArmorDamage); DamageHealthCount = PlayersHurted.Sum(h => h.HealthDamage); HitCount = PlayersHurted.Count; if (Rounds.Any()) { AverageHealthDamage = GetAverageHealthDamage(); } }
public void AddCoinToWaitingList(SmartCoin coin) { lock (StateLock) { if (!(WaitingList.ContainsKey(coin) || Rounds.Any(x => x.CoinsRegistered.Contains(coin)))) { WaitingList.Add(coin, DateTimeOffset.UtcNow); Logger.LogInfo($"Coin added to the waiting list: {coin.Index}:{coin.TransactionId}."); } } }
public Core.Game.Entities.Round GetOrCreateRound(string roundId, Guid gameId, Guid playerId, Guid brandId) { if (Rounds.Any(x => x.ExternalRoundId == roundId)) { return(GetRound(roundId)); } var brand = Brands.Single(x => x.Id == brandId); return(new Core.Game.Entities.Round(roundId, gameId, playerId, brand)); }
public void CreateRounds(int holeCount) { if (Rounds.Any()) { throw new InvalidOperationException("Rounds have already been set."); } for (int i = 1; i <= holeCount; i++) { Rounds.Add(new Round(i, 3, this)); } }
private void DisableAllRounds() { if (!Rounds.Any(r => r.RoundEnabled)) { return; } Rounds.ToList().ForEach(async r => { r.RoundEnabled = false; await _roundService.EditRound(r.RoundId, r); }); }
public async Task <IActionResult> OnGetAsync([Range(0, 1000)] int round = 0) { if (!ModelState.IsValid) { return(NotFound()); } var now = DateTime.UtcNow; var date = new DateTime(2020, 1, 1); int offset = now.Month - date.Month + (now.Year - date.Year) * 12; Rounds = await _context.Challenges.Where(x => x.State == 3).Select(x => (x.ReleaseDate.Month - date.Month) + (x.ReleaseDate.Year - date.Year) * 12).Distinct().OrderBy(x => x).ToListAsync(); round--; if (!Rounds.Contains(round)) { if (Rounds.Any()) { round = Rounds.Last(); } else { round = offset; } } Index = round; int pageMonthOffset = round % 12; int pageYearOffset = round / 12; int month = date.Month + pageMonthOffset; int year = date.Year + pageYearOffset; if (month < 1) { month += 12; year -= 1; } Round = $"{new DateTime(2020, month, 1).ToString("MMMM", CultureInfo.InvariantCulture)} {year}"; Challenges = await _context.Challenges.Where(x => x.State == 3 && x.ReleaseDate.Month == month && x.ReleaseDate.Year == year).OrderBy(x => x.ReleaseDate).ToListAsync(); Categories = Challenges.Select(x => x.Category).Distinct().ToList(); return(Page()); }
public bool DoesRoundNoExist(int roundNo) { return(Rounds.Any(p => p.RoundNo == roundNo)); }
public void Start() { Interlocked.Exchange(ref _running, 1); // At start the client asks for status. // The client is asking for status periodically, randomly between every 0.2 * connConfTimeout and 0.8 * connConfTimeout. // - if the GUI is at the mixer tab -Activate(), DeactivateIfNotMixing(). // - if coins are queued to mix. // The client is asking for status periodically, randomly between every 2 to 7 seconds. // - if it is participating in a mix thats status >= connConf. // The client is triggered only when a status response arrives. The answer to the server is delayed randomly from 0 to 7 seconds. Task.Run(async() => { try { await ProcessStatusAsync(); while (IsRunning) { try { // If stop was requested return. if (IsRunning == false) { return; } var inputRegMixing = false; var activelyMixing = false; using (await MixLock.LockAsync()) { // if mixing >= connConf: delay = new Random().Next(2, 7); activelyMixing = Rounds.Any(x => x.AliceUniqueId != null && x.State.Phase >= CcjRoundPhase.ConnectionConfirmation); inputRegMixing = Rounds.Any(x => x.AliceUniqueId != null); } if (activelyMixing) { var delay = new Random().Next(2, 7); await Task.Delay(TimeSpan.FromSeconds(delay), Stop.Token); await ProcessStatusAsync(); } else if (Interlocked.Read(ref _frequentStatusProcessingIfNotMixing) == 1 || inputRegMixing) { double rand = double.Parse($"0.{new Random().Next(2, 8)}"); // randomly between every 0.2 * connConfTimeout and 0.8 * connConfTimeout int delay; using (await MixLock.LockAsync()) { delay = (int)(rand * Rounds.First(x => x.State.Phase == CcjRoundPhase.InputRegistration).State.RegistrationTimeout); } await Task.Delay(TimeSpan.FromSeconds(delay), Stop.Token); await ProcessStatusAsync(); } else { await Task.Delay(1000); // dormant } } catch (TaskCanceledException ex) { Logger.LogTrace <CcjClient>(ex); } catch (Exception ex) { Logger.LogError <CcjClient>(ex); } } } finally { if (IsStopping) { Interlocked.Exchange(ref _running, 3); } } }); }