void SaveActionInDatabase() { if (player.ServerPlayerGameState == ClientGameState.Playing || player.ServerPlayerGameState == ClientGameState.PlayingTutorial) { int teamId = player.ServerTeamId; Teams.TeamResource team = teamList.GetScriptableTeamWithId(player.ServerTeamId); string teamName = team.TeamName; string teamColor = team.TeamColor.ToString(); int courseId = player.ServerCourseId; int labyrithId = player.serverLabyrinthId; int algorithmId = (int)player.serverAlgorithm; SQLiteUtilities.InsertPlayerAction( teamId, teamName, teamColor, courseId, labyrithId, algorithmId, (int)player.ServerPlayerGameAction, player.ServerPlayerGameActionDateTimeString, player.ServerPlayerGameActionValue); } }
public void Awake() { Persist(); if (settings == null) { settings = new ServerSettings(); } settings.LoadFromPlayerPrefs(); // Randomize seed UnityEngine.Random.InitState((int)Time.time); // Store all the teams in the DB // TODO remove, replace with 'Resources' asset foreach (Teams.TeamResource team in Teams.Resources.Instance.Teams) { SQLiteUtilities.InsertTeam( team.TeamId, team.TeamName, team.TeamColor.ToString(), DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff")); } State.OnValueChangedHandler += OnStateValueChanged; }
public void StartNextLevel( ILabyrinth labyrinth, Algorithms.Id algorithmId) { currentLevel = new Level { Number = NextLevelNumber, Labyrinth = labyrinth, Algorithm = Algorithms.Resources.Instance.GetAlgorithm(algorithmId) }; levels.Add(currentLevel); SQLiteUtilities.InsertLevel( SQLiteUtilities.GetNextLevelID(), currentLevel.Number, Id, labyrinth.Id ); baseAlgorithmId = algorithmId; for (int i = 0; i < PlayerList.instance.list.Count; i++) { Player player = PlayerList.instance.GetPlayerWithId(i); switch (player.ServerPlayerGameState) { case ClientGameState.Ready: case ClientGameState.PlayingTutorial: case ClientGameState.Playing: case ClientGameState.ViewingGlobalReplay: case ClientGameState.ViewingLocalReplay: case ClientGameState.WaitingForNextLevel: Debug.Log(player); player.serverAlgorithm = baseAlgorithmId; player.serverLabyrinthId = currentLevel.Labyrinth.Id; AssignCourse(player); player.TargetSetGame( player.connectionToClient, currentLevel.Labyrinth.Json, player.serverAlgorithm, currentLevel.Number); break; } } Server.Instance.State.Set(LevelState); }
private void Pairing() { if (!TabletId.IsNullOrEmpty() && !HeadsetId.IsNullOrEmpty()) { #if UNITY_EDITOR || UNITY_STANDALONE_WIN SQLiteUtilities.InsertPairing(TabletId, HeadsetId); #endif PairingState.Value = ServerPairingState.Both; SendPairingResult(true); } }
public CourseExecution(Course course, ILabyrinth labyrinth) { this.course = course; Queue <int> steps; Queue <string> stepValues; SQLiteUtilities.GetPlayerStepsForCourse(course.Id, out steps, out stepValues); Actions = steps.ToArray(); ActionValues = stepValues.ToArray(); }
// Use these events instead //public Cirrus.Event<Game> OnGameCreatedHandler; //public Cirrus.Event<Game> OnGameEndedHandler; public void StartQuickplay() { // When new game starts set all previous courses to innactive foreach (Course c in SQLiteUtilities.GetSessionCourses()) { SQLiteUtilities.SetCourseFinished(c.Id); } currentGame = new Quickplay(SQLiteUtilities.GetNextGameID()); SQLiteUtilities.InsertGame(currentGame.Id); currentGame.Start(); //OnGameCreatedHandler?.Invoke(currentGame); }
public void OnSave() { Debug.Log(Labyrinth.Name + " saved!"); Labyrinth.PopulateStartAndEndPositions(); // Save session //TODO improve var sessionLab = LabyrinthManager.Instance.GetLabyrinth(Labyrinth.Id); var idx = LabyrinthManager.Instance.Labyrinths.IndexOf(sessionLab);// Instance.GetLabyrinth(Labyrinth.Id); LabyrinthManager.Instance.Labyrinths[idx] = Labyrinth; // Save persistent SQLiteUtilities.UpdateLabyrinth(Labyrinth); }
public void generate() { int lo = int.Parse(longueur.text); int la = int.Parse(largeur.text); int er = int.Parse(erreur.text); int resol = getResolution(); int id = getId(); int st = getStyle(); int cy = 0; if (cycle.isOn) { cy = 1; } LabyrinthTranslator lab = new LabyrinthTranslator(lo, la, resol, er, st, cy); SQLiteUtilities.InsertOrReplaceLabyrinth(id, lo * 2 + 1, la * 2 + 1, lab.translate()); Debug.Log("Insert done"); }
public void StartNewGame() { // When new game starts set all previous courses to innactive foreach (Course c in SQLiteUtilities.GetSessionCourses()) { SQLiteUtilities.SetCourseFinished(c.Id); } currentGame = Server.Instance.Settings.IsLevelOrderPredefined.Value ? new Game( SQLiteUtilities.GetNextGameID(), predefinedLevels) : new Game( SQLiteUtilities.GetNextGameID()); SQLiteUtilities.InsertGame(currentGame.Id); currentGame.Start(); }
public void AddLabyrinth() { var data = SQLiteUtilities.CreateSampleLabyrinth(); LabyrinthManager.Instance.Labyrinths.Add(data); LabyrinthObject labyrinth = Labyrinths.Resources.Instance .GetLabyrinthObject(data) .Create(data); labyrinths.Add(labyrinth); labyrinth.GenerateLabyrinthVisual(); labyrinth.Init(enableCamera: true); labyrinth.Camera.OutputToTexture = true; labyrinth.transform.position = Vector3.right * Utils.SelectionOffset * (labyrinths.Count - 1); AddSection().AddButton(labyrinth); OnContentChangedHandler?.Invoke(); }
// Try find course ID initiated by a team member // Otherwise assign new course // // Returns true if created a course // Assumes ServerTeamId is set // BUG public void AssignCourse(Player player)//, out Course course) { Course course = null; int courseId = -1; SQLiteUtilities.SetCourseInactive(player.ServerCourseId); // Try to get an active course if (SQLiteUtilities.TryGetActiveCourseId(player.ServerTeamId, out courseId)) { player.ServerCourseId = courseId; } else { course = new Course { Id = SQLiteUtilities.GetNextCourseID(), Team = Teams.Resources.Instance.GetScriptableTeamWithId(player.ServerTeamId), Labyrinth = currentLevel.Labyrinth, Algorithm = Algorithms.Resources.Instance.GetAlgorithm(player.serverAlgorithm), //AlgorithmSteps = algorithm.GetAlgorithmSteps(currentRound.Labyrinth) // labyrinth) }; currentLevel.Courses.Add(course); player.ServerCourseId = course.Id; SQLiteUtilities.InsertPlayerCourse( player.ServerTeamId, player.serverLabyrinthId, (int)player.serverAlgorithm, player.ServerCourseId, player.ServerLevelNumber, Id); } }
private static void ShowRowUser(SQLiteUtilities.TableRow row) { Console.WriteLine(String.Format("\t Nick: {0}", row["Nick"])); Console.WriteLine(String.Format("\t Email: {0}", row["Email"])); Console.WriteLine(String.Format("\t FirstName: {0}", row["FirstName"])); Console.WriteLine(String.Format("\t LastName: {0}", row["LastName"])); Console.WriteLine(); }
private void OnPlayerStatusChanged() { if (player.ServerPlayerGameState == ClientGameState.Connecting) { serverPlayerInformation.AddPlayerOrReconnect(player); } else if (player.ServerPlayerGameState == ClientGameState.Pairing) { pairedId = SQLiteUtilities.GetPairing(player.deviceUniqueIdentifier, player.serverDeviceType); if (pairedId == null) { player.TargetSetGameState(player.connectionToClient, ClientGameState.NoAssociatedPair); } else { // BUG FIX?? // Team Id not assigned to tablet on reconnect if (player.serverDeviceType == Promoscience.DeviceType.Headset) { InitializeHeadsetInformation(); } else { StartCoroutine(PairingDeviceCoroutine()); } } } else if (player.ServerPlayerGameState == ClientGameState.WaitingReplay) { // TODO // Steps to recover Queue <int> steps; Queue <string> stepValues; //jsons SQLiteUtilities.GetPlayerStepsForCourse(player.ServerCourseId, out steps, out stepValues); // Use the steps for playback player.TargetSetViewingLocalPlayback( player.connectionToClient, GameManager.Instance.CurrentGame.CurrentLevel.Labyrinth.Id, steps.ToArray(), stepValues.ToArray()); } else if (player.serverDeviceType == Promoscience.DeviceType.Headset && player.ServerPlayerGameState == ClientGameState.Reconnecting) { pairedId = SQLiteUtilities.GetPairing(player.deviceUniqueIdentifier, player.serverDeviceType); if (pairedId == null) { player.TargetSetGameState(player.connectionToClient, ClientGameState.ReconnectingNoAssociatedPair); } else { if (Server.Instance.State.Value == ServerState.Level && player.ServerCourseId != -1) { #if UNITY_EDITOR || UNITY_STANDALONE_WIN int courseLabyrinthId = SQLiteUtilities.GetPlayerCourseLabyrinthId(player.ServerCourseId); #endif if (courseLabyrinthId == GameManager.Instance.CurrentGame.CurrentLevel.Labyrinth.Id) { #if UNITY_EDITOR || UNITY_STANDALONE_WIN Queue <int> steps; steps = SQLiteUtilities.GetPlayerStepsForCourse(player.ServerCourseId); if (SQLiteUtilities.HasPlayerAlreadyCompletedTheRound(player.ServerCourseId)) { // Use the steps for playback player.TargetSetPairedIpAdress( player.connectionToClient, ""); player.TargetSetLevelCompleted( player.connectionToClient, GameManager.Instance.CurrentGame.CurrentLevel.Labyrinth.Id, steps.ToArray()); } else { if (steps.Count > 0) { // Connection drop, used the steps to resume where you were GameManager.Instance.CurrentGame.JoinGameLevelWithSteps(player, steps.ToArray()); player.TargetSetPairedIpAdress(player.connectionToClient, ""); } else { player.TargetSetPairedIpAdress(player.connectionToClient, ""); player.TargetSetGameState(player.connectionToClient, ClientGameState.Ready); } } #endif } else { player.TargetSetPairedIpAdress(player.connectionToClient, ""); player.TargetSetGameState(player.connectionToClient, ClientGameState.Ready); } } else { player.TargetSetPairedIpAdress(player.connectionToClient, ""); player.TargetSetGameState(player.connectionToClient, ClientGameState.Ready); } } } else if (player.ServerPlayerGameState == ClientGameState.Ready) { if ( Server.Instance.State.Value == ServerState.Level || Server.Instance.State.Value == ServerState.Quickplay) { GameManager.Instance.CurrentGame.JoinGameLevel(player); } else if (Server.Instance.State.Value == ServerState.Intermission) { player.TargetSetGameState(player.connectionToClient, ClientGameState.WaitingForNextLevel); } } }
public void OnApplicationQuit() { // TODO remove from here SQLiteUtilities.ResetServerPlayerInformation(); }
public void ClearPlayerInformation() { SQLiteUtilities.ResetServerPlayerInformation(); }
public void SavePlayerInformationToDatabase() { SQLiteUtilities.InsertServerPlayerInformation(this); }
public void LoadPlayerInformationFromDatabase() { SQLiteUtilities.SetServerPlayerInformation(this); }
void Start() { SQLiteUtilities.CreateDatabaseIfItDoesntExist(); }