public static bool UpdateWhenCurrentLocation_Prefix(CommunityCenter __instance, GameTime time) { try { var index = ModEntry.Instance.Helper.Reflection.GetField <int>(__instance, "restoreAreaIndex").GetValue(); var timerField = ModEntry.Instance.Helper.Reflection.GetField <int>(__instance, "restoreAreaTimer"); var timer = timerField.GetValue(); var phaseField = ModEntry.Instance.Helper.Reflection.GetField <int>(__instance, "restoreAreaPhase"); var phase = phaseField.GetValue(); if (timer == 0 || !Bundles.IsCommunityCentreKitchenEnabledByHost()) { return(true); } if (index != Bundles.CommunityCentreAreaNumber) { // Reload the incomplete custom bundle area if the Pantry was just completed, as it overrides the area if (phase == 3 && timer == 2000 && Game1.IsMasterGame && Game1.currentLocation is CommunityCenter && index == 0 && __instance.areasComplete.Count > Bundles.CommunityCentreAreaNumber && !__instance.areasComplete[Bundles.CommunityCentreAreaNumber]) { Bundles.CheckAndTryToUnrenovateKitchen(); } return(true); } var messageAlphaField = ModEntry.Instance.Helper.Reflection.GetField <float>(__instance, "messageAlpha"); var messageAlpha = messageAlphaField.GetValue(); var buildUpSound = ModEntry.Instance.Helper.Reflection.GetField <ICue>(__instance, "buildUpSound").GetValue(); var junimoNotesViewportTargets = ModEntry.Instance.Helper.Reflection.GetField <List <int> >(__instance, "junimoNotesViewportTargets").GetValue(); __instance.missedRewardsChest.Value.updateWhenCurrentLocation(time, __instance); if (timer > 0) { var old = timer; timer -= time.ElapsedGameTime.Milliseconds; switch (phase) { case 0: if (timer <= 0) { timer = 3000; phase = 1; if (Game1.player.currentLocation == __instance) { Game1.player.faceDirection(2); Game1.player.jump(); Game1.player.jitterStrength = 1f; Game1.player.showFrame(94); // THIS IS AN IMPORTANT BIT: // Add some mail to flag this bundle as having been completed Log.D($"Sending mail for Cooking bundle completion ({ModEntry.MailKitchenCompleted})", ModEntry.Instance.Config.DebugMode); Game1.player.mailForTomorrow.Add(ModEntry.MailKitchenCompleted + "%&NL&%"); } } break; case 1: if (Game1.IsMasterGame && Game1.random.NextDouble() < 0.4) { var area = new Rectangle(Bundles.CommunityCentreArea.X, Bundles.CommunityCentreArea.Y, Bundles.CommunityCentreArea.Width + 12, Bundles.CommunityCentreArea.Height + 6); var v = Utility.getRandomPositionInThisRectangle(area, Game1.random); var i = new Junimo(v * 64f, index, temporary: true); if (!__instance.isCollidingPosition(i.GetBoundingBox(), Game1.viewport, i)) { __instance.characters.Add(i); ModEntry.Instance.Helper.Reflection.GetField <Multiplayer>( typeof(Game1), "multiplayer").GetValue().broadcastSprites(__instance, new TemporaryAnimatedSprite((Game1.random.NextDouble() < 0.5) ? 5 : 46, v * 64f + new Vector2(16f, 16f), Color.White) { layerDepth = 1f }); __instance.localSound("tinyWhip"); } } if (timer <= 0) { timer = 999999; phase = 2; if (Game1.player.currentLocation != __instance) { break; } Game1.screenGlowOnce(Color.White, hold: true, 0.005f, 1f); if (Game1.soundBank != null) { buildUpSound = Game1.soundBank.GetCue("wind"); buildUpSound.SetVariable("Volume", 0f); buildUpSound.SetVariable("Frequency", 0f); buildUpSound.Play(); } Game1.player.jitterStrength = 2f; Game1.player.stopShowingFrame(); } Game1.drawLighting = false; break; case 2: if (buildUpSound != null) { buildUpSound.SetVariable("Volume", Game1.screenGlowAlpha * 150f); buildUpSound.SetVariable("Frequency", Game1.screenGlowAlpha * 150f); } if (Game1.screenGlowAlpha >= Game1.screenGlowMax) { messageAlpha += 0.008f; messageAlpha = Math.Min(messageAlpha, 1f); } if ((Game1.screenGlowAlpha == Game1.screenGlowMax || Game1.currentLocation != __instance) && timer > 5200) { timer = 5200; } if (timer < 5200 && Game1.random.NextDouble() < (5200 - timer) / 10000f) { __instance.localSound((Game1.random.NextDouble() < 0.5) ? "dustMeep" : "junimoMeep1"); } if (timer > 0) { break; } timer = 2000; messageAlpha = 0f; phase = 3; if (Game1.IsMasterGame) { for (var j = __instance.characters.Count - 1; j >= 0; j--) { if (__instance.characters[j] is Junimo && (__instance.characters[j] as Junimo).temporaryJunimo.Value) { __instance.characters.RemoveAt(j); } } } if (Game1.player.currentLocation == __instance) { Game1.screenGlowHold = false; __instance.loadArea(index); if (buildUpSound != null) { buildUpSound.Stop(AudioStopOptions.Immediate); } __instance.localSound("wand"); Game1.changeMusicTrack("junimoStarSong"); __instance.localSound("woodyHit"); Game1.flashAlpha = 1f; Game1.player.stopJittering(); Game1.drawLighting = true; } break; case 3: if (old > 1000 && timer <= 1000) { var junimo = __instance.getJunimoForArea(index); if (junimo != null && Game1.IsMasterGame) { if (!junimo.holdingBundle.Value) { junimo.Position = Utility.getRandomAdjacentOpenTile(Utility.PointToVector2(Bundles.CommunityCentreNotePosition), __instance) * 64f; var iter = 0; while (__instance.isCollidingPosition(junimo.GetBoundingBox(), Game1.viewport, junimo) && iter < 20) { junimo.Position = Utility.getRandomPositionInThisRectangle(Bundles.CommunityCentreArea, Game1.random) * 64f; iter++; } if (iter < 20) { junimo.fadeBack(); } } junimo.returnToJunimoHutToFetchStar(__instance); } } if (timer <= 0 && !ModEntry.Instance.Helper.Reflection.GetField <bool>( __instance, "_isWatchingJunimoGoodbye").GetValue()) { Game1.freezeControls = false; } break; } } else if (Game1.activeClickableMenu == null && junimoNotesViewportTargets != null && junimoNotesViewportTargets.Count > 0 && !Game1.isViewportOnCustomPath()) { ModEntry.Instance.Helper.Reflection.GetMethod(__instance, "setViewportToNextJunimoNoteTarget").Invoke(); } timerField.SetValue(timer); phaseField.SetValue(phase); messageAlphaField.SetValue(messageAlpha); return(false); } catch (Exception e) { Log.E($"Error in {nameof(UpdateWhenCurrentLocation_Prefix)}:\n{e}"); } return(true); }