/// <summary> /// Starts this <c>Level</c>. /// </summary> public bool Start() { if (State == LevelState.Running) { SoomlaUtils.LogError(TAG, "Can't start a level that is already running. state=" + State); return(false); } SoomlaUtils.LogDebug(TAG, "Starting level with world id: " + _id); if (!CanStart()) { return(false); } if (State != LevelState.Paused) { Elapsed = 0; LevelStorage.IncTimesStarted(this); } StartTime = this.UseTimeScaling ? Mathf.RoundToInt(Time.time * 1000) : DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond; State = LevelState.Running; return(true); }
/// <summary> /// Sets this <c>Level</c> as completed. /// </summary> /// <param name="completed">If set to <c>true</c> completed.</param> public override void SetCompleted(bool completed) { if (completed) { State = LevelState.Completed; LevelStorage.IncTimesCompleted(this); } else { State = LevelState.Idle; } base.SetCompleted(completed); }
/// <summary> /// Ends this <c>Level</c>. /// </summary> /// <param name="completed">If set to <c>true</c> completed.</param> public void End(bool completed) { // check end() called without matching start(), // i.e, the level is not running nor paused if (State != LevelState.Running && State != LevelState.Paused) { SoomlaUtils.LogError(TAG, "end() called without prior start()! ignoring."); return; } State = LevelState.Ended; long duration = GetPlayDurationMillis(); LevelStorage.SetLastDurationMillis(this, duration); if (completed) { // Calculate the slowest \ fastest durations of level play if (duration > GetSlowestDurationMillis()) { LevelStorage.SetSlowestDurationMillis(this, duration); } // We assume that levels' duration is never 0 long fastest = GetFastestDurationMillis(); if (fastest == 0 || duration < fastest) { LevelStorage.SetFastestDurationMillis(this, duration); } } if (completed) { foreach (Score score in Scores.Values) { score.Reset(true); // resetting scores } SetCompleted(true); } // Count number of times this level was played LevelStorage.IncTimesPlayed(this); }
void ClearCurrentState() { List <String> allKeys = KeyValueStorage.GetEncryptedKeys(); if (allKeys != null) { foreach (string key in allKeys) { if (key.StartsWith(GateStorage.getKeyGatePrefix()) || key.StartsWith(LevelStorage.getKeyLevelPrefix()) || key.StartsWith(MissionStorage.getKeyMissionPrefix()) || key.StartsWith(ScoreStorage.getKeyScorePrefix()) || key.StartsWith(WorldStorage.getKeyWorldPrefix())) { KeyValueStorage.DeleteKeyValue(key); } } } }
/// <summary> /// Gets the fastest duration in millis that this <c>Level</c> was played. /// </summary> /// <returns>The fastest duration in millis.</returns> public long GetFastestDurationMillis() { return(LevelStorage.GetFastestDurationMillis(this)); }
/// <summary> /// Gets the number of times this <c>Level</c> was played. /// </summary> /// <returns>The number of times played.</returns> public int GetTimesPlayed() { return(LevelStorage.GetTimesPlayed(this)); }
/// <summary> /// Gets the number of times this <c>Level</c> was started. /// </summary> /// <returns>The number of times started.</returns> public int GetTimesStarted() { return(LevelStorage.GetTimesStarted(this)); }