private void UpdateLeaderboard(int gameIdentID) { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { using (DataAccess.CSSStatsDataContext statsDB = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext()) { var game = statsDB.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID); if (game == null) throw new Exception("Couldn't get game for ID: " + gameIdentID); if (IsGameEligibleForLogging(game) == false) return; bool isDrawGame = IsDrawGame(game); foreach (DataAccess.GameTeam team in game.GameTeams) { var commanderAlias = DataAccess.Alias.GetAliasByCallsign(db, team.GameTeamCommander); foreach (DataAccess.GameTeamMember teamMember in team.GameTeamMembers) { int shipKills = 0; int stationKills = 0; int stationCaptures = 0; int droneKills = 0; int ejects = 0; int defection = 0; int score = 0; var alias = DataAccess.Alias.GetAliasByCallsign(db, teamMember.GameTeamMemberCallsign); if (alias == null) continue; // Check current team member for defections. foreach (DataAccess.GameTeam otherTeam in game.GameTeams) { if (otherTeam.GameTeamID == team.GameTeamID) continue; foreach (DataAccess.GameTeamMember otherTeamMember in otherTeam.GameTeamMembers) { var otherLogin = DataAccess.Alias.GetAliasByCallsign(db, otherTeamMember.GameTeamMemberCallsign); if (otherLogin != null && otherLogin.LoginId == alias.LoginId) { defection = 1; break; } } if (defection != 0) break; } var primaryMemberEvents = game.GameEvents.Where ( p => p.GameEventPerformerID != 1 && ( p.GameEventPerformerLoginID == alias.Login.Id && ( p.EventID == (int)AllegianceEventIDs.StationDestroyed || p.EventID == (int)AllegianceEventIDs.StationCaptured || p.EventID == (int)AllegianceEventIDs.ShipKilled ) ) || ( p.GameEventTargetLoginID == alias.Login.Id && p.EventID == (int)AllegianceEventIDs.ShipKilled ) ); foreach (var primaryMemberEvent in primaryMemberEvents) { switch (primaryMemberEvent.EventID) { case (int)Common.Enumerations.AllegianceEventIDs.ShipKilled: if (primaryMemberEvent.GameEventPerformerName.StartsWith(".") == true) { droneKills++; score += DroneKillPoints; } else { if (primaryMemberEvent.GameEventPerformerLoginID == teamMember.GameTeamMemberLoginID) { ejects++; } else { shipKills++; score += ShipKillPoints; } } break; case (int)Common.Enumerations.AllegianceEventIDs.StationCaptured: { stationCaptures++; score += StationCapturePoints; } break; case (int)Common.Enumerations.AllegianceEventIDs.StationDestroyed: { stationKills++; score += StationKillPoints; } break; } } if (alias != null) { var leaderboard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == alias.Login.Id); if (leaderboard == null) { leaderboard = new Allegiance.CommunitySecuritySystem.DataAccess.StatsLeaderboard() { CommandDraws = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. CommandLosses = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. CommandMu = 25D, CommandRank = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. CommandSigma = 25D / 3D, CommandWins = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Defects = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Draws = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. DroneKills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Ejects = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. HoursPlayed = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Kills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. LoginUsername = alias.Login.Username, LoginID = alias.Login.Id, Losses = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Mu = 25D, Rank = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Sigma = 25D / 3D, StackRating = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. StationCaptures = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. StationKills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Wins = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. DateModified = DateTime.Now //CommandDraws = commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0, //CommandLosses = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0, //CommandMu = 25D, //CommandRank = 0, //CommandSigma = 25D / 3D, //CommandWins = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0, //Defects = defection, //Draws = isDrawGame == true && defection == 0 ? 1 : 0, //DroneKills = droneKills, //Ejects = ejects, //HoursPlayed = teamMember.GameTeamMemberDuration / 60.0 / 60.0, //Kills = shipKills, //LoginUsername = alias.Login.Username, //LoginID = alias.Login.Id, //Losses = team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0, //Mu = 25D, //Rank = 0, //Sigma = 25D / 3D, //StackRating = 0, //StationCaptures = stationCaptures, //StationKills = stationKills, //Wins = team.GameTeamWinner == true && defection == 0 ? 1 : 0, //DateModified = DateTime.Now }; statsDB.StatsLeaderboards.InsertOnSubmit(leaderboard); } else { // These values are all set by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. //leaderboard.CommandDraws += commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0; //leaderboard.CommandLosses += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0; //leaderboard.CommandWins += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0; //leaderboard.Defects += defection; //leaderboard.Draws += isDrawGame == true && defection == 0 ? 1 : 0; //leaderboard.DroneKills += droneKills; //leaderboard.Ejects += ejects; //leaderboard.HoursPlayed += teamMember.GameTeamMemberDuration / 60.0 / 60.0; //leaderboard.Kills += shipKills; //leaderboard.Losses += team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0; //leaderboard.StationCaptures += stationCaptures; //leaderboard.StationKills += stationKills; //leaderboard.Wins += team.GameTeamWinner == true && defection == 0 ? 1 : 0; //leaderboard.DateModified = DateTime.Now; } teamMember.Score = score; statsDB.SubmitChanges(); db.SubmitChanges(); } } } } } }
private void UpdateLeaderboard(int gameIdentID) { using (DataAccess.CSSDataContext db = new Allegiance.CommunitySecuritySystem.DataAccess.CSSDataContext()) { using (DataAccess.CSSStatsDataContext statsDB = new Allegiance.CommunitySecuritySystem.DataAccess.CSSStatsDataContext()) { var game = statsDB.Games.FirstOrDefault(p => p.GameIdentID == gameIdentID); if (game == null) { throw new Exception("Couldn't get game for ID: " + gameIdentID); } if (IsGameEligibleForLogging(game) == false) { return; } bool isDrawGame = IsDrawGame(game); foreach (DataAccess.GameTeam team in game.GameTeams) { var commanderAlias = DataAccess.Alias.GetAliasByCallsign(db, team.GameTeamCommander); foreach (DataAccess.GameTeamMember teamMember in team.GameTeamMembers) { int shipKills = 0; int stationKills = 0; int stationCaptures = 0; int droneKills = 0; int ejects = 0; int defection = 0; int score = 0; var alias = DataAccess.Alias.GetAliasByCallsign(db, teamMember.GameTeamMemberCallsign); if (alias == null) { continue; } // Check current team member for defections. foreach (DataAccess.GameTeam otherTeam in game.GameTeams) { if (otherTeam.GameTeamID == team.GameTeamID) { continue; } foreach (DataAccess.GameTeamMember otherTeamMember in otherTeam.GameTeamMembers) { var otherLogin = DataAccess.Alias.GetAliasByCallsign(db, otherTeamMember.GameTeamMemberCallsign); if (otherLogin != null && otherLogin.LoginId == alias.LoginId) { defection = 1; break; } } if (defection != 0) { break; } } var primaryMemberEvents = game.GameEvents.Where ( p => p.GameEventPerformerID != 1 && ( p.GameEventPerformerLoginID == alias.Login.Id && ( p.EventID == (int)AllegianceEventIDs.StationDestroyed || p.EventID == (int)AllegianceEventIDs.StationCaptured || p.EventID == (int)AllegianceEventIDs.ShipKilled ) ) || ( p.GameEventTargetLoginID == alias.Login.Id && p.EventID == (int)AllegianceEventIDs.ShipKilled ) ); foreach (var primaryMemberEvent in primaryMemberEvents) { switch (primaryMemberEvent.EventID) { case (int)Common.Enumerations.AllegianceEventIDs.ShipKilled: if (primaryMemberEvent.GameEventPerformerName.StartsWith(".") == true) { droneKills++; score += DroneKillPoints; } else { if (primaryMemberEvent.GameEventPerformerLoginID == teamMember.GameTeamMemberLoginID) { ejects++; } else { shipKills++; score += ShipKillPoints; } } break; case (int)Common.Enumerations.AllegianceEventIDs.StationCaptured: { stationCaptures++; score += StationCapturePoints; } break; case (int)Common.Enumerations.AllegianceEventIDs.StationDestroyed: { stationKills++; score += StationKillPoints; } break; } } if (alias != null) { var leaderboard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == alias.Login.Id); if (leaderboard == null) { leaderboard = new Allegiance.CommunitySecuritySystem.DataAccess.StatsLeaderboard() { CommandDraws = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. CommandLosses = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. CommandMu = 25D, CommandRank = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. CommandSigma = 25D / 3D, CommandWins = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Defects = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Draws = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. DroneKills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Ejects = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. HoursPlayed = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Kills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. LoginUsername = alias.Login.Username, LoginID = alias.Login.Id, Losses = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Mu = 25D, Rank = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Sigma = 25D / 3D, StackRating = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. StationCaptures = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. StationKills = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. Wins = 0, // Value filled in by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. DateModified = DateTime.Now //CommandDraws = commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0, //CommandLosses = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0, //CommandMu = 25D, //CommandRank = 0, //CommandSigma = 25D / 3D, //CommandWins = commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0, //Defects = defection, //Draws = isDrawGame == true && defection == 0 ? 1 : 0, //DroneKills = droneKills, //Ejects = ejects, //HoursPlayed = teamMember.GameTeamMemberDuration / 60.0 / 60.0, //Kills = shipKills, //LoginUsername = alias.Login.Username, //LoginID = alias.Login.Id, //Losses = team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0, //Mu = 25D, //Rank = 0, //Sigma = 25D / 3D, //StackRating = 0, //StationCaptures = stationCaptures, //StationKills = stationKills, //Wins = team.GameTeamWinner == true && defection == 0 ? 1 : 0, //DateModified = DateTime.Now }; statsDB.StatsLeaderboards.InsertOnSubmit(leaderboard); } else { // These values are all set by ASGSServiceUpdateASRankings stored proc during AllegSkill calculation. //leaderboard.CommandDraws += commanderAlias.LoginId == alias.LoginId && isDrawGame == true && defection == 0 ? 1 : 0; //leaderboard.CommandLosses += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0; //leaderboard.CommandWins += commanderAlias.LoginId == alias.LoginId && team.GameTeamWinner == true && defection == 0 ? 1 : 0; //leaderboard.Defects += defection; //leaderboard.Draws += isDrawGame == true && defection == 0 ? 1 : 0; //leaderboard.DroneKills += droneKills; //leaderboard.Ejects += ejects; //leaderboard.HoursPlayed += teamMember.GameTeamMemberDuration / 60.0 / 60.0; //leaderboard.Kills += shipKills; //leaderboard.Losses += team.GameTeamWinner == false && isDrawGame == false && defection == 0 ? 1 : 0; //leaderboard.StationCaptures += stationCaptures; //leaderboard.StationKills += stationKills; //leaderboard.Wins += team.GameTeamWinner == true && defection == 0 ? 1 : 0; //leaderboard.DateModified = DateTime.Now; } teamMember.Score = score; statsDB.SubmitChanges(); db.SubmitChanges(); } } } } } }
public CommitPlayerDataResponse(CommitPlayerDataRequest request) { ErrorMessage = String.Empty; Succeeded = true; using (CSSStatsDataContext statsDB = new CSSStatsDataContext()) { using(CSSDataContext db = new CSSDataContext()) { foreach (var scoreQueue in statsDB.ScoreQueues.Where(p => p.GameGuid == request.GameGuid)) { var login = db.Logins.FirstOrDefault(p => p.Id == scoreQueue.LoginId); if(login == null) { Succeeded = false; ErrorMessage += "Couldn't find login for login id: " + scoreQueue.LoginId; continue; } string callsign = login.Username; var primaryAlias = login.Aliases.FirstOrDefault(p => p.IsDefault == true); if(primaryAlias == null) primaryAlias = login.Aliases.FirstOrDefault(); if(primaryAlias != null) callsign = primaryAlias.Callsign; StatsLeaderboard leaderBoard = statsDB.StatsLeaderboards.FirstOrDefault(p => p.LoginID == scoreQueue.LoginId); if (leaderBoard == null) { leaderBoard = new StatsLeaderboard() { CommandDraws = 0, CommandLosses = 0, CommandMu = 0, CommandRank = 0, CommandSigma = 0, CommandWins = 0, DateModified = DateTime.Now, Defects = 0, Draws = 0, DroneKills = 0, Ejects = 0, HoursPlayed = 0, Kills = 0, LoginID = scoreQueue.LoginId, LoginUsername = login.Username, Losses = 0, Mu = 0, PRank = 0, Rank = 0, Sigma = 0, StationCaptures = 0, StationKills = 0, Wins = 0, Xp = 0 }; statsDB.StatsLeaderboards.InsertOnSubmit(leaderBoard); } // Add in the new values. leaderBoard.CommandDraws += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == false && scoreQueue.CommandLose == false) ? 1 : 0; leaderBoard.CommandLosses += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == false && scoreQueue.CommandLose == true) ? 1 : 0; //leaderBoard.CommandMu = 0; //leaderBoard.CommandRank = 0; //leaderBoard.CommandSigma = 0; //leaderBoard.Mu = 0; //leaderBoard.Sigma = 0; leaderBoard.CommandWins += (scoreQueue.CommandCredit == true && scoreQueue.CommandWin == true && scoreQueue.CommandLose == false) ? 1 : 0; leaderBoard.DateModified = DateTime.Now; //leaderBoard.Defects = 0; leaderBoard.Draws += (scoreQueue.Win == false && scoreQueue.Lose == false) ? 1 : 0; leaderBoard.DroneKills += (int) Math.Round(scoreQueue.BuilderKills + scoreQueue.CarrierKills + scoreQueue.LayerKills + scoreQueue.MinerKills); leaderBoard.Ejects += scoreQueue.Deaths; leaderBoard.HoursPlayed += scoreQueue.TimePlayed.GetValueOrDefault(0) / 3600D; leaderBoard.Kills += (int) Math.Round(scoreQueue.PlayerKills); leaderBoard.Losses += (scoreQueue.Win == false && scoreQueue.Lose == true) ? 1 : 0; leaderBoard.StationCaptures += scoreQueue.PilotBaseCaptures + (int) Math.Round(scoreQueue.BaseCaptures); leaderBoard.StationKills += scoreQueue.PilotBaseKills + (int) Math.Round(scoreQueue.BaseKills); leaderBoard.Wins += (scoreQueue.Win == true && scoreQueue.Lose == false) ? 1 : 0; leaderBoard.Xp += (int) Math.Round(scoreQueue.Score); leaderBoard.PRank = 0; leaderBoard.Rank = GetLevel(statsDB, leaderBoard.Xp); statsDB.ScoreQueues.DeleteOnSubmit(scoreQueue); statsDB.SubmitChanges(); } } } this.Succeeded = true; }