/// <summary> /// Sets the "beaten" flag for a level. /// </summary> /// <param name="pillarConfig">Pillar config.</param> /// <param name="difficulty">Difficulty.</param> /// <param name="hitsTaken">Hits taken.</param> public static void SetLevelBeaten(PillarConfig pillarConfig, int difficulty = 1, int hitsTaken = 0) { PersistentDataStorage data = new PersistentDataStorage(Game.ForceVision); ProgressionData progressionData = GetProgressionData(data); progressionData.LevelsBeat.Add(new ProgressionLevel(pillarConfig, difficulty, hitsTaken)); data.SaveSerialized(ProgressionFile, progressionData); }
public void FinishLevel(bool victory) { // Clear Triggers ArchivistInterstitialController.Triggers.Clear(); MenuAudioController.Triggers.Clear(); // If this is the first time you won this level bool firstTimeBeat = false; bool earnedInsight = false; bool earnedLeadership = false; bool earnedAdvancedCombat = false; // Level we just played PillarConfig lastPlayedLevel = MenuController.ConfigToLoad; Difficulty lastPlayedDifficulty = MenuController.DifficultyToLoad; PersistentDataStorage data = new PersistentDataStorage(Game.ForceVision); ProgressionData progressionData = GetProgressionData(data); // Did not come from a game if (lastPlayedLevel == null || progressionData == null) { LoadNextScene(false, false); return; } // Just earned a medal if (!progressionData.InsightMedalUnlocked && IsMedalUnlocked(MedalType.Insight)) { earnedInsight = true; progressionData.InsightMedalUnlocked = true; } if (!progressionData.LeadershipMedalUnlocked && IsMedalUnlocked(MedalType.Leadership)) { earnedLeadership = true; progressionData.LeadershipMedalUnlocked = true; } if (!progressionData.CombatUnlocked && IsMedalUnlocked(MedalType.Combat)) { progressionData.CombatUnlocked = true; } if (!progressionData.AdvancedCombatUnlocked && IsMedalUnlocked(MedalType.AdvancedCombat)) { earnedAdvancedCombat = true; progressionData.AdvancedCombatUnlocked = true; } if (!progressionData.MasteryUnlocked && IsMedalUnlocked(MedalType.Mastery)) { progressionData.MasteryUnlocked = true; } data.SaveSerialized(ProgressionFile, progressionData); // Check for first time. if (victory) { ProgressionLevel level = progressionData.LevelsBeat.Find(check => (check.LevelHash == lastPlayedLevel.GetHashCode() && (int)lastPlayedDifficulty == check.Difficulty)); int hitsTaken = 0; if (lastPlayedLevel.Game == Game.Duel && GetDuelApi().LastResult != null) { hitsTaken = GetDuelApi().LastResult.HitsTaken; Log.Debug("LastResult found. Setting hitsTaken to " + hitsTaken.ToString()); } else { Log.Debug("LastResult NOT found. Setting hitsTaken to zero"); } if (level == null) { SetLevelBeaten(lastPlayedLevel, (int)lastPlayedDifficulty, hitsTaken); firstTimeBeat = true; if (lastPlayedLevel.IsBonusPlanet) { PlanetLineController.BeatFirstTime = false; MenuController.UnlockedPillar = true; } else { PlanetLineController.BeatFirstTime = true; } } // You did better this time (DUEL only) else if (level.HitsTaken > hitsTaken) { progressionData.LevelsBeat.First(item => item == level).HitsTaken = hitsTaken; data.SaveSerialized(ProgressionFile, progressionData); } } #region LOSS TRIGGERS // Defeat Archivist and strike down (loss) if (lastPlayedDifficulty == Difficulty.Hard && lastPlayedLevel.Duelist == DuelAPI.Duelist.Archivist && !victory) { ProgressionLevel level = progressionData.LevelsLost.Find(check => (check.LevelHash == lastPlayedLevel.GetHashCode() && (int)lastPlayedDifficulty == check.Difficulty)); if (GetDuelApi().LastResult != null && GetDuelApi().LastResult.DuelEnd == DuelAPI.DuelEndCondition.ObjectiveFail && level == null) { progressionData.LevelsLost.Add(new ProgressionLevel(lastPlayedLevel, (int)lastPlayedDifficulty)); data.SaveSerialized(ProgressionFile, progressionData); // Animation Trigger: Defeat Archivist on hard and strike down MenuAudioController.Triggers.Add(Constants.LoseCoreDuelHard); LoadNextScene(true, victory); return; } } // First Loss based on Config Values if (!victory && !string.IsNullOrEmpty(lastPlayedLevel.LostVOTrigger[(int)lastPlayedDifficulty - 1])) { ProgressionLevel level = progressionData.LevelsLost.Find(check => (check.LevelHash == lastPlayedLevel.GetHashCode() && (int)lastPlayedDifficulty == check.Difficulty)); // First Time Loss if (level == null) { // Save it progressionData.LevelsLost.Add(new ProgressionLevel(lastPlayedLevel, (int)lastPlayedDifficulty)); data.SaveSerialized(ProgressionFile, progressionData); // Audio Trigger: /* * Config: first loss on pillar 1 of assault (easy, medium, and hard), chess, tower for all planets * Config: First Time win first Strategy battle on Naboo * Config: First time win first Holochess match on Naboo * Config: First time defeat last assault mode on each planet (easy and medium) */ MenuAudioController.Triggers.Add(lastPlayedLevel.LostVOTrigger[(int)lastPlayedDifficulty - 1]); LoadNextScene(true, victory); return; } } #endregion // Always go back to where you came if you lose if (!victory) { LoadNextScene(true, victory); return; } // Not first time, either go back to where you came, or the next planet if (!firstTimeBeat) { LoadNextScene(true, victory); return; } // Error.. if (lastPlayedLevel.Interstitial.Length < (int)lastPlayedDifficulty) { LoadNextScene(false, victory); return; } // They unlocked green for the first time if (lastPlayedLevel.Game == Game.Duel && lastPlayedDifficulty == Difficulty.Easy && lastPlayedLevel.Duelist == DuelAPI.Duelist.KyloRen) { SetSavedSaberColorID((int)ColorID.GREEN); } // Hard Archivist Let Live if (lastPlayedDifficulty == Difficulty.Hard && lastPlayedLevel.Duelist == DuelAPI.Duelist.Archivist) { SetSavedSaberColorID((int)ColorID.PURPLE); // Animation Trigger: Defeat Archivist on hard and let live ArchivistInterstitialController.Triggers.Add(Constants.WinCoreDuelHard); LoadNextScene(false, victory); return; } bool earnAllTrailMedals = false; // Beat the LAST duelist on Hard if (earnedAdvancedCombat) { // Animation Trigger: Config: Defeat Naboo, Garal, Lothel, Hoth, Takodana Duelist on hard string audioEvent = lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1]; ArchivistInterstitialController.Triggers.Add(audioEvent); // Animation Trigger: Earn Advanced Combat Medal ArchivistInterstitialController.Triggers.Add(Constants.EarnAdvancedCombat); // This will always stack 2, 3 if 2 other medals are unlocked already if (IsMedalUnlocked(MedalType.Insight) && IsMedalUnlocked(MedalType.Leadership)) { // Animation Trigger: Earned advanced combat, leadership, Insight medals ArchivistInterstitialController.Triggers.Add(Constants.EarnAllTrailMedals); // Stack 3 animations, Duelist Beat, Medal Earned, Dark Archivist Unlocked progressionData.DarkArchivistUnlocked = true; data.SaveSerialized(ProgressionFile, progressionData); } LoadNextScene(false, victory); return; } // Unlocked Dark Archivist if ((earnedLeadership || earnedInsight) && !progressionData.DarkArchivistUnlocked) { if (IsMedalUnlocked(MedalType.Insight) && IsMedalUnlocked(MedalType.Leadership) && IsMedalUnlocked(MedalType.AdvancedCombat)) { // Animation Trigger: Earned advanced combat, leadership, Insight medals earnAllTrailMedals = true; progressionData.DarkArchivistUnlocked = true; data.SaveSerialized(ProgressionFile, progressionData); } } // Animation Trigger /* * Config: Defeat Ren on easy * Config: Defeat Archivist on med * Config: Defeat Core Holochess * Config: Defeat Core Tower Defense * Config: Defeat Naboo, Garal, Lothel, Hoth, Takodana Duelist on hard */ if (lastPlayedLevel.Interstitial[(int)lastPlayedDifficulty - 1]) { string audioEvent = lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1]; ArchivistInterstitialController.Triggers.Add(audioEvent); } // Audio Trigger /* * Config: Defeat Maul Easy * Config: Win Naboo Holochess Trial * Config: Win Naboo Strategy Trial * Config: Defeat Sister on easy * Config: Win Garel Holochess Trial * Config: Win Garel Strategy Trial * Config: Defeat Inquisitor on easy * Config: Win Lothal Holochess Trial * Config: Win Lothal Strategy Trial * Config: Defeat Vader on easy * Config: Win Hoth Holochess Trial * Config: Win Hoth Strategy Trial * Config: Win Takodana Holochess * Config: Win Takodana Strategy * Config: Defeat Maul on Med * Config: Defeat Sister on Med * Config: Defeat Inquisitor on med * Config: Defeat Vader on med * Config: Defeat Ren on med */ else if (!string.IsNullOrEmpty(lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1])) { // checking for duel games on bonus planet if (lastPlayedLevel.IsBonusPlanet) { bool hasWonStrategy = towerApi.HasWonBattle(TDAPI.Battles.Crait_3); if (lastPlayedLevel.Game == Game.Duel) { // player has not completed strategy if (!hasWonStrategy) { if (lastPlayedDifficulty == Difficulty.Easy) { MenuAudioController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistAndNotCompleteStrategy); } else if (lastPlayedDifficulty == Difficulty.Medium) { MenuAudioController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistMedium); } else if (lastPlayedDifficulty == Difficulty.Hard) { MenuAudioController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistHard); } } // player has completed strategy else { if (lastPlayedDifficulty == Difficulty.Easy) { ArchivistInterstitialController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistAndCompleteStrategy); } } } else if (lastPlayedLevel.Game == Game.TowerDefense) { // checking if duelist complete (easy) bool hasWonDuelist = duelApi.Progress.HasCompleted(DuelAPI.Duelist.PraetorianGuards, 1); if (hasWonStrategy && !hasWonDuelist) { MenuAudioController.Triggers.Add(AudioEventName.Progression.CompleteCraitStrategyAndNotCompleteDuelist); } else if (hasWonStrategy && hasWonDuelist) { ArchivistInterstitialController.Triggers.Add(AudioEventName.Progression.CompleteCraitDuelistAndCompleteStrategy); } } else if (lastPlayedLevel.Game == Game.Assault && lastPlayedLevel.PillarNumber == 2) { MenuAudioController.Triggers.Add(lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1]); } } else { string audioEvent = lastPlayedLevel.InterstitialTrigger[(int)lastPlayedDifficulty - 1]; MenuAudioController.Triggers.Add(audioEvent); } } // Make it last if (earnAllTrailMedals) { ArchivistInterstitialController.Triggers.Add(Constants.EarnAllTrailMedals); } if (lastPlayedLevel.IsBonusPlanet && lastPlayedLevel.Game == Game.Duel) { LoadNextScene(true, victory); } else { LoadNextScene((lastPlayedLevel.PillarNumber < 3), victory); } }