private bool AcceptCurrentMission(string username) { Player player = _unitOfWork.PlayerRepository.DbSet.Include(x => x.CurrentMission).Include(p => p.Level).FirstOrDefault(x => x.User.UserName.Equals(username)); if (player?.CurrentMission == null) { return(false); } Mission mission = player.CurrentMission; player.Exp += mission.ExpReward; Level nextLevel = _unitOfWork.LevelRepository.DbSet.Where(l => l.ExpRequired <= player.Exp).ToList() .Aggregate((i1, i2) => i1.ExpRequired > i2.ExpRequired ? i1 : i2); if (player.Level != null && nextLevel != null && nextLevel.Id != player.Level.Id) { player.Level = nextLevel; } MissionHistory missionHistory = new MissionHistory() { Mission = mission, Player = player, FinishDate = DateTime.Now }; player.CurrentMission = null; _unitOfWork.MissionHistoryRepository.DbSet.Add(missionHistory); _unitOfWork.Save(); return(true); }
private void loadHistory() { if (initialized) { prepareHistoryFile(); if (!historyLoaded) { if (isHistory) { //showDebug ("Void loadHistory : History Loaded From JSON", true); missionHistory = MissionHistory.getMissionHistoryFromJSON(selectedMission, filePath); if (missionHistory.isFirstOH().Equals(MissionHistory.False)) { blocked = 2; } settled = false; } else { //showDebug ("Void loadHistory : History Created From Loaded Mission", true); missionHistory = MissionHistory.getLoadedMissionHistory(selectedMission, currentMission.getObjectives()); settled = true; } historyLoaded = true; } } }
public static MissionHistory getLoadedMissionHistory(string selectedMission, Objective[] loadedObjectives) { MissionHistory mh = new MissionHistory(); mh.name = selectedMission; mh.status = Active; mh.objectives = new List <ObjectiveHistory> (); for (int i = 0; i < loadedObjectives.Length; i++) { ObjectiveHistory oh = ObjectiveHistory.getLoadedObjectiveHistory(i, loadedObjectives [i]); mh.objectives.Add(oh); } return(mh); }
public static MissionHistory getMissionHistoryFromJSON(string selectedMission, string filePath) { LAJsonReader laJsonReader = new LAJsonReader(filePath); laJsonReader.setExternal(true); JSONNode node = laJsonReader.parsing(); MissionHistory mh = new MissionHistory(); //mh.name = selectedMission; mh.name = node ["historique"] ["mission"]; mh.status = node ["historique"] ["status"]; mh.objectives = ObjectiveHistory.getObjectiveHistoryFromJSON(node ["historique"]); return(mh); }