public SPlayer AddPlayer(SPlayer newPlayer) { using (var cli = new DBGContext()) { Player NP = new Player() { DateRegistration = DateTime.Now, DateLastAction = DateTime.Now, DeviceId = newPlayer.DeviceId, GoogleId = newPlayer.GoogleId, Name = newPlayer.Name, Password = GeneratePassword(), Ip = GetIpClient(), }; cli.Players.Add(NP); PlayerInfoStatistic NPIS = new PlayerInfoStatistic() { AllStep = 0, Coins = 0, Distance = 0f, Donat = 0, LinkPlayer = NP, MaxCombo = 0, PerfectSteps = 0, PlayedGames = 0, QuestComplete = 0 }; cli.PlayerInfoStatistics.Add(NPIS); cli.SaveChanges(); newPlayer.PlayerId = NP.PlayerId; newPlayer.Password = NP.Password; return(newPlayer); } }
public SQuestResponse GenerateQuest(SPlayer whoRequesting) { SQuestResponse questResponse = new SQuestResponse() { SCanGenerate = false }; try { using (var cli = new DBGContext()) { var checkPlayer = cli.Players.FirstOrDefault(x => x.PlayerId == whoRequesting.PlayerId); if (checkPlayer.DateLastAction.Subtract(checkPlayer.DateLastAction.TimeOfDay) < DateTime.Now.Subtract(DateTime.Now.TimeOfDay)) { checkPlayer.DateLastAction = DateTime.Now; cli.SaveChanges(); questResponse.SCanGenerate = true; questResponse.SleftTime = DateTime.Now.AddDays(1).Subtract(DateTime.Now.TimeOfDay).Subtract(DateTime.Today); return(questResponse); } } } catch { } return(questResponse); }
public void UpdateRecord(SRecord sRecord) { try { using (var cli = new DBGContext()) { Record UR; UR = cli.Records.Include(x => x.LinkPlayer).FirstOrDefault(x => x.LinkPlayer.PlayerId == sRecord.LinkPlayer.PlayerId && x.Mode == sRecord.Mode); if (UR == null) { UR = new Record() { LinkPlayer = cli.Players.FirstOrDefault(x => x.PlayerId == sRecord.LinkPlayer.PlayerId), Mode = sRecord.Mode }; cli.Records.Add(UR); } if (UR.Score < sRecord.Score) { UR.Score = sRecord.Score; } if (UR.MaxSpeed < sRecord.MaxSpeed) { UR.MaxSpeed = sRecord.MaxSpeed; } if (UR.MaxTime < sRecord.MaxTime) { UR.MaxTime = sRecord.MaxTime; } cli.SaveChanges(); } } catch { } }
public void UpdateAchievement(SAchievement sAchievement) { try { using (var cli = new DBGContext()) { Achievement upAch; upAch = cli.Achievements.Include(x => x.LinkPlayer).FirstOrDefault(x => x.LinkPlayer.PlayerId == sAchievement.LinkPlayer.PlayerId && x.NameAchievement == sAchievement.NameAchievement); if (upAch == null) { upAch = new Achievement() { LinkPlayer = cli.Players.FirstOrDefault(x => x.PlayerId == sAchievement.LinkPlayer.PlayerId), NameAchievement = sAchievement.NameAchievement, NumberRewards = sAchievement.NumberRewards, }; cli.Achievements.Add(upAch); } else { upAch.NumberRewards = sAchievement.NumberRewards; } cli.SaveChanges(); } } catch { } }
public SPlayer CheckPlayer(SPlayer newPlayer) { using (var cli = new DBGContext()) { var CP = cli.Players.FirstOrDefault(x => x.PlayerId == newPlayer.PlayerId); CP.Ip = GetIpClient(); // CP.DateLastAction = DateTime.Now; cli.SaveChanges(); // нужно сделать проблемные варианты... return(newPlayer); }/**/ }
public void UpdateStatistic(SPlayerInfoStatistic sPISC) { try { using (var cli = new DBGContext()) { var pisc = cli.PlayerInfoStatistics.Include(x => x.LinkPlayer).FirstOrDefault(x => x.LinkPlayer.PlayerId == sPISC.LinkPlayer.PlayerId); pisc.AllStep = sPISC.AllStep; pisc.Coins = sPISC.Coins; pisc.Distance = sPISC.Distance; pisc.Donat = sPISC.Donat; pisc.MaxCombo = sPISC.MaxCombo; pisc.PerfectSteps = sPISC.PerfectSteps; pisc.PlayedGames = sPISC.PlayedGames; pisc.QuestComplete = sPISC.QuestComplete; cli.SaveChanges(); } } catch { } }