private void OnEnable() { Singleton <KeyListener> .Instance.GrabFocus(this); KeyListener.keyReleased += this.HandleKeyListenerkeyReleased; if (WPFMonoBehaviour.levelManager.gameState != LevelManager.GameState.MechanicGiftScreen) { return; } this.superGlueButton.SetActive(false); this.turboChargeButton.SetActive(false); this.superMagnetButton.SetActive(false); Texture2D rewardNativeTexture = AdvertisementHandler.GetRewardNativeTexture(); if (!WPFMonoBehaviour.levelManager.m_SuperGlueAllowed && !WPFMonoBehaviour.levelManager.m_SuperMagnetAllowed && !WPFMonoBehaviour.levelManager.m_TurboChargeAllowed) { this.SendClose(); } else if (rewardNativeTexture != null) { this.GiveGift(); this.SetTexture(rewardNativeTexture); } else { this.SendClose(); } }
public override LevelManager.GameState SetGameState(LevelManager.GameState currentState, LevelManager.GameState newState) { LevelManager.GameState gameState = currentState; switch (newState) { case LevelManager.GameState.Building: if (GameTime.IsPaused()) { GameTime.Pause(false); } if (currentState == LevelManager.GameState.Running || currentState == LevelManager.GameState.PausedWhileRunning) { base.StopRunningContraption(); this.retries++; if (this.retries == 3 && !this.levelManager.m_sandbox && !this.tutorialBookOpened) { int num = GameProgress.GetInt("Tutorial_Promotion_Count", 0, GameProgress.Location.Local, null); if (num < 3 && !GameProgress.IsLevelCompleted(Singleton <GameManager> .Instance.CurrentSceneName) && GameProgress.GetInt(this.TutorialPromotionCount, 0, GameProgress.Location.Local, null) == 0) { this.openTutorial = true; num++; GameProgress.SetInt("Tutorial_Promotion_Count", num, GameProgress.Location.Local); GameProgress.SetInt(this.TutorialPromotionCount, 1, GameProgress.Location.Local); } } bool @bool = GameProgress.GetBool(Singleton <GameManager> .Instance.CurrentSceneName + "_autobuild_available", false, GameProgress.Location.Local, null); bool bool2 = GameProgress.GetBool("PermanentBlueprint", false, GameProgress.Location.Local, null); if (!this.levelManager.m_sandbox && this.retries % 5 == 0 && AdvertisementHandler.GetRewardNativeTexture() != null) { int @int = GameProgress.GetInt("branded_reward_gifts_today", 0, GameProgress.Location.Local, null); int num2 = 2; if (Singleton <GameConfigurationManager> .IsInstantiated() && Singleton <GameConfigurationManager> .Instance.HasValue("branded_reward_gift_count", "count")) { num2 = Singleton <GameConfigurationManager> .Instance.GetValue <int>("branded_reward_gift_count", "count"); } if (@int < num2) { if (!GameProgress.HasKey("branded_reward_gift_time", GameProgress.Location.Local, null)) { GameProgress.SetInt("branded_reward_gift_time", Singleton <TimeManager> .Instance.CurrentEpochTime, GameProgress.Location.Local); } GameProgress.SetInt("branded_reward_gifts_today", @int + 1, GameProgress.Location.Local); this.openMechanicGift = true; } } } if (this.levelManager.m_toolboxOpenUponShopActivation) { this.levelManager.InGameGUI.BuildMenu.ToolboxButton.OnPressed(); } this.levelManager.SetupDynamicObjects(); base.ContraptionProto.SetVisible(true); if (this.levelManager.ConstructionUI) { this.levelManager.ConstructionUI.SetEnabled(true, true); } if (GameProgress.GetString("REPLAY_LEVEL", string.Empty, GameProgress.Location.Local, null) == SceneManager.GetActiveScene().name&& LightManager.enabledLightPositions != null && LightManager.enabledLightPositions.Count > 0) { PointLightSource[] array = UnityEngine.Object.FindObjectsOfType <PointLightSource>(); for (int i = 0; i < array.Length; i++) { if (LightManager.enabledLightPositions.Contains(array[i].transform.position)) { array[i].isEnabled = true; } } GameProgress.SetString("REPLAY_LEVEL", string.Empty, GameProgress.Location.Local); } break; case LevelManager.GameState.Preview: this.levelManager.m_previewSpeed = 1f; this.levelManager.m_previewTime = 0f; base.ContraptionProto.SetVisible(false); if (this.levelManager.ConstructionUI) { this.levelManager.ConstructionUI.SetEnabled(false, true); } break; case LevelManager.GameState.PreviewMoving: this.levelManager.m_previewTime = 0f; base.ContraptionProto.SetVisible(false); if (this.levelManager.ConstructionUI) { this.levelManager.ConstructionUI.SetEnabled(false, true); } this.levelManager.SetupDynamicObjects(); break; case LevelManager.GameState.PreviewWhileBuilding: if (this.levelManager.EggRequired) { this.levelManager.InGameGUI.PreviewMenu.SetGoal(base.gameData.m_eggTransportGoal); } else if (this.levelManager.PumpkinRequired) { this.levelManager.InGameGUI.PreviewMenu.SetGoal(base.gameData.m_pumpkinTransportGoal); } else { this.levelManager.InGameGUI.PreviewMenu.SetGoal(base.gameData.m_basicGoal); } this.levelManager.InGameGUI.PreviewMenu.SetChallenges(this.levelManager.Challenges); if (this.levelManager.ConstructionUI) { this.levelManager.ConstructionUI.SetEnabled(false, true); } this.levelManager.PreviewCenter = base.ContraptionProto.transform.position; this.levelManager.m_previewDragging = false; break; case LevelManager.GameState.PreviewWhileRunning: this.levelManager.PreviewCenter = base.ContraptionRunning.transform.position; GameTime.Pause(true); this.levelManager.m_previewDragging = false; break; case LevelManager.GameState.Running: if (GameTime.IsPaused()) { GameTime.Pause(false); } this.levelManager.TimeElapsed = 0f; this.levelManager.PartsInGoal.Clear(); this.levelManager.TimeStarted = false; this.levelManager.PigStartPosition = base.ContraptionProto.FindPig().transform.position; if (this.levelManager.ConstructionUI) { this.levelManager.ConstructionUI.SetEnabled(false, false); } base.ContraptionRunning = base.ContraptionProto.Clone(); base.ContraptionProto.SetVisible(false); if (base.ContraptionProto.HasRegularGlue) { if (!base.ContraptionProto.HasGluedParts) { GameProgress.AddSuperGlue(1); } base.ContraptionProto.RemoveSuperGlue(); } if (base.ContraptionProto.HasSuperMagnet) { base.ContraptionProto.HasSuperMagnet = false; } if (base.ContraptionProto.HasNightVision) { this.levelManager.LightManager.ToggleNightVision(); base.ContraptionProto.HasNightVision = false; } base.ContraptionRunning.StartContraption(); if (base.ContraptionProto.HasTurboCharge) { base.ContraptionProto.HasTurboCharge = false; } base.ContraptionRunning.SaveContraption(base.GetCurrentContraptionName()); break; case LevelManager.GameState.Continue: if (GameTime.IsPaused()) { GameTime.Pause(false); } if (gameState == LevelManager.GameState.Building || gameState == LevelManager.GameState.PausedWhileBuilding) { newState = LevelManager.GameState.Building; } else if (gameState == LevelManager.GameState.CustomizingPart) { newState = LevelManager.GameState.CustomizingPart; } else if (!this.levelManager.HasCompleted && gameState == LevelManager.GameState.LootCrateOpening) { newState = LevelManager.GameState.Running; } else { newState = ((!this.levelManager.HasCompleted) ? LevelManager.GameState.Running : LevelManager.GameState.Completed); } break; case LevelManager.GameState.Completed: this.levelManager.InGameGUI.ShowCurrentMenu(false); base.ContraptionRunning.TurnOffAllPoweredParts(); this.levelManager.PlayVictorySound(); if (this.levelManager.EggRequired) { this.levelManager.InGameGUI.LevelCompleteMenu.SetGoal(base.gameData.m_eggTransportGoal); } else if (this.levelManager.PumpkinRequired) { this.levelManager.InGameGUI.LevelCompleteMenu.SetGoal(base.gameData.m_pumpkinTransportGoal); } else { this.levelManager.InGameGUI.LevelCompleteMenu.SetGoal(base.gameData.m_basicGoal); } this.levelManager.InGameGUI.LevelCompleteMenu.SetChallenges(this.levelManager.Challenges); break; case LevelManager.GameState.PausedWhileRunning: GameTime.Pause(true); break; case LevelManager.GameState.PausedWhileBuilding: GameTime.Pause(true); break; case LevelManager.GameState.AutoBuilding: this.levelManager.StartAutoBuild(this.levelManager.m_oneStarContraption); break; case LevelManager.GameState.ShowingUnlockedParts: GameTime.Pause(false); this.levelManager.UnlockedParts = new List <ConstructionUI.PartDesc>(this.levelManager.ConstructionUI.UnlockedParts); this.levelManager.UnlockedPartIndex = -1; this.levelManager.PartShowTimer = 0f; break; case LevelManager.GameState.Snapshot: GameTime.Pause(true); this.levelManager.InGameGUI.ShowCurrentMenu(false); WPFMonoBehaviour.ingameCamera.TakeSnapshot(new Action(this.levelManager.HandleSnapshotFinished)); break; case LevelManager.GameState.SuperAutoBuilding: this.levelManager.StartAutoBuild(this.levelManager.m_threeStarContraption[this.levelManager.CurrentSuperBluePrint]); if (Singleton <SocialGameManager> .IsInstantiated()) { Singleton <SocialGameManager> .Instance.ReportAchievementProgress("grp.CHIPS_FOR_WHIPS", 100.0); } break; } currentState = newState; return(currentState); }