public static void UpdateScore(UCGameTeamStat stat, int quarter, int scoreDelta) { if (scoreDelta == 0) { return; } switch (quarter) { case 1: stat.Q1 += scoreDelta; break; case 2: stat.Q2 += scoreDelta; break; case 3: stat.Q3 += scoreDelta; break; default: stat.Q4 += scoreDelta; break; } }
private void SetupTeamStat() { var item = Db.UCGameTeamStats.SingleOrDefault(i => i.TeamId == TeamId && i.GameId == Gameplay.GameId); if (item == null) { item = new UCGameTeamStat(); item.GameId = Gameplay.GameId; item.TeamId = TeamId; Db.UCGameTeamStats.Add(item); Db.SaveChanges(); } }
public static int GetTotalPoints(UCGameTeamStat stat) { return(stat.Q1 + stat.Q2 + stat.Q3 + stat.Q4); }
public static int GetScore(UCGameTeamStat stat) { return(stat.Q1 + stat.Q2 + stat.Q3 + stat.Q4); }
public static int UpdateGame(int gameId, int quarter, bool updateScores, UCGameTeamStat ts0, UCGameTeamStat ts1, bool updateTime, DateTime timeLeft, DateTime timerLastModified, GameplayModel gp = null) { var gameplay = gp ?? GameplayModel.Create(gameId); var game = gameplay.Game; var now = DateTime.UtcNow; bool hasGameUpdates = false; if (updateScores) { for (int i = 0; i < 2; i++) { var t = i == 0 ? ts0 : ts1; var ts = gameplay.TeamModels[i].Stat; ts.Q1 = t.Q1; ts.Q2 = t.Q2; ts.Q3 = t.Q3; ts.Q4 = t.Q4; ts.LastUpdate = DateTime.UtcNow; } } if (updateTime) { game.TimeLeft = timeLeft; //GameHelper.ComputeTimeRemaining(game); game.TimeLastModified = timerLastModified; hasGameUpdates = true; } if (game.CurrentQuarter != quarter) { // Create player stats stats game.CurrentQuarter = quarter; var q = quarter > 4 ? 4 : quarter; for (int i = 0; i < 2; i++) { var teamModel = gameplay.TeamModels[i]; var stats = teamModel.QuarterPlayerStats; var players = teamModel.Players; foreach (var player in players) { var stat = stats.SingleOrDefault(item => item.PlayerId == player.Id); if (stat == null) { stat = new UCGamePlayerStat(); stat.PlayerId = player.Id; stat.TeamId = player.TeamId; stat.GameId = gameplay.GameId; stat.Quarter = q; gameplay.Db.UCGamePlayerStats.Add(stat); } } } hasGameUpdates = true; } if (hasGameUpdates) { game.LastUpdate = now; } if (hasGameUpdates || updateScores) { game.LastActivityDate = now; gameplay.Db.SaveChanges(); } return(0); }