// Reward any items gained from the level private static void RewardItems(LevelProgressData levelProgressData, LevelInfo levelInfo) { if (levelProgressData.Items == null) { return; } foreach (var reward in levelProgressData.Items) { // stars are always added to level progress, even though they may not be awarded to the player if (reward.Key == ItemType.Star1 || reward.Key == ItemType.Star2 || reward.Key == ItemType.Star3) { int newStarsGained = reward.Value - levelInfo.StarsAwarded; // only award the stars if they are more than what was already been awarded if (newStarsGained <= 0) { continue; } levelInfo.AddLevelCompletionStars(newStarsGained); ItemProgress.AddItem(ItemType.Star, newStarsGained); } else if (reward.Key != ItemType.Star) { ItemProgress.AddItem(reward.Key, reward.Value); // add any items gained } else { Debug.Log("Warning: ItemType.Star should not be used for level rewards. Use Star1, Star2, Star3 instead"); } } }
public GameplayData(string name, MapData mapData, LevelScenarioData scenarioData, LevelProgressData progressData) { this.name = name; this.mapData = mapData; this.scenarioData = scenarioData; this.progressData = progressData; }
public static void CompleteLevel(int index) { int prevBest = GetBestDifficultyForIndex(index); if (GameSettings.difficulty > prevBest) { string key = LevelManager.instance.levelData [index].name; if (progressData.ContainsKey(key)) { progressData.Remove(key); } LevelProgressData newData = new LevelProgressData(key, GameSettings.difficulty); progressData.Add(key, newData); string serializedData = ""; foreach (KeyValuePair <string, LevelProgressData> pair in progressData) { serializedData += pair.Value.Serialized(); serializedData += "/"; } serializedData = serializedData.Substring(0, serializedData.Length - 1); //cut off last slashs PlayerPrefs.SetString("ProgressData", serializedData); } }
public bool IsLevelLocked(string levelName) { LevelProgressData lpd = this.LevelProgress.FirstOrDefault(x => x.LevelName == levelName); if (lpd == null) { throw new Exception("The level name \"" + levelName + "\" was not found in the LevelProgress list."); } return(lpd.Locked); }
public void EndShift() { LevelScenarioData scenarioData = ScenarioProgressController.Singleton.scenarioData; LevelProgressData progressData = ScenarioProgressController.Singleton.progressData; progressData.shiftsPassed++; MapData mapData = new MapData(scenarioData.name, BlockGridController.Singleton.grid); GameplayData gameplayData = new GameplayData( "Saved Game - " + scenarioData.name + " - Shift #" + (progressData.shiftsPassed + 1) + " - " + DateTime.Now.ToString("MM-dd-yyyy--HH-mm-ss"), mapData, scenarioData, progressData ); SceneSwitcher.Singleton.ToResultsScene(new NextShiftLoaderData(gameplayData)); }
public static LevelProgress LoadOrCreate(string bundleId, string imageId) { if (string.IsNullOrEmpty(bundleId) || string.IsNullOrEmpty(imageId)) { return(null); } var path = GetFilePath(bundleId, imageId); var data = JsonLoader.LoadFromFile <LevelProgressData>(path); if (data == null) { data = new LevelProgressData(); } return(Create(bundleId, imageId, data)); }
public static void LoadProgressData() { if (progressData.Count > 0) { return; } string curData = PlayerPrefs.GetString("ProgressData"); if (!string.IsNullOrEmpty(curData)) { string[] dataList = curData.Split('/'); foreach (string levelData in dataList) { LevelProgressData newData = new LevelProgressData(levelData); progressData.Add(newData.levelName, newData); } } }
public static LevelProgress Create(string bundleId, string imageId, LevelProgressData data) { if (string.IsNullOrEmpty(bundleId) || string.IsNullOrEmpty(imageId)) { return(null); } var levelProgress = new LevelProgress(); levelProgress.BundleId = bundleId; levelProgress.ImageId = imageId; levelProgress.m_data = data; if (!string.IsNullOrEmpty(data.Steps)) { levelProgress.m_steps = new List <ImageStepTileCoords>(Base64Serializer.Decode <ImageStepTileCoords[]>(data.Steps)); } return(levelProgress); }
public void StopMatch() { bool isWin = !PlayerController.I.Player.Health.Hp.IsZero; bool allEnemies = this.killCount == this.preset.count; bool noDamage = PlayerController.I.Player.Health.Hp.IsMax; var progress = LevelProgressData.GetProgress(this.preset.id); progress.complete |= isWin; progress.allEnemies |= allEnemies; progress.noDamage |= noDamage; var popup = PopupManager.OpenPopup <EndLevelPopup>(); popup.SetWindow(isWin); if (isWin) { popup.SetStars(1 + (allEnemies ? 1 : 0) + (noDamage ? 1 : 0)); } popup.OnRemoving += GameManager.StopLevel; }
protected override void OnInit() { foreach (var btn in this.returnBtns) { btn.onClick.AddListener(() => Hide(null)); } this.cellReference.GO.SetActive(false); var points = this.levelPoints; var count = points.Length; for (int i = 0; i < count; ++i) { int id = i; var preset = LevelPresetData.GetPreset(id); var progress = LevelProgressData.GetProgress(id); var cell = Instantiate(this.cellReference, points[id]); cell.GO.SetActive(true); cell.Name.text = $"Level {id + 1}"; cell.SetStars(progress.Stars); bool active = id == 0 || LevelProgressData.GetProgress(id - 1).complete; cell.SetActive(active); if (active) { cell.StartBtn.onClick.AddListener(() => { var popup = PopupManager.OpenPopup <StartLevelPopup>(); popup.SetDescription($"Level {id + 1}\nasteroids: {preset.count}\ntime: {preset.duration}"); popup.SetStars(progress.Stars); popup.OnStart += () => { Hide(null); GameManager.StartLevel(id); }; }); } } }