/// <summary> /// This function grabs events when the menu changes to handle dialogue replace /// </summary> /// <param name="sender">Sender object</param> /// <param name="e">paramaters</param> private void MenuEvents_MenuChanged(object sender, EventArgsClickableMenuChanged e) { if (GameClimate is null) { Monitor.Log("GameClimate is null"); } if (e.NewMenu is null) { Monitor.Log("e.NewMenu is null"); } if (e.NewMenu is DialogueBox box) { bool stormDialogue = false; double odds = Dice.NextDoublePositive(), stormOdds = GameClimate.GetStormOdds(SDate.Now().AddDays(1), Dice, DebugOutput); List <string> lines = Helper.Reflection.GetField <List <string> >(box, "dialogues").GetValue(); if (lines.FirstOrDefault() == Game1.content.LoadString("Strings\\StringsFromCSFiles:Object.cs.12822")) { if (WeatherOpt.Verbose) { Monitor.Log($"Rain totem interception firing with roll {odds.ToString("N3")} vs. odds {stormOdds.ToString("N3")}"); } // rain totem used, do your thing if (WeatherOpt.StormTotemChange) { if (odds <= stormOdds) { if (WeatherOpt.Verbose) { Monitor.Log("Replacing rain with storm.."); } Game1.weatherForTomorrow = Game1.weather_lightning; stormDialogue = true; } } // change dialogue text lines.Clear(); if (stormDialogue) { lines.Add(Helper.Translation.Get("hud-text.desc_stormtotem")); } else { lines.Add(Game1.content.LoadString("Strings\\StringsFromCSFiles:Object.cs.12822")); } } } }
/// <summary>Raised after a game menu is opened, closed, or replaced.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnMenuChanged(object sender, MenuChangedEventArgs e) { if (!Context.IsMainPlayer) { return; } // restore previous menu on close if (e.OldMenu is WeatherMenu && this.PreviousMenu != null) { Game1.activeClickableMenu = this.PreviousMenu; this.PreviousMenu = null; } // bandle new dialogue box else if (e.NewMenu is DialogueBox box) { bool stormDialogue = false; double odds = Dice.NextDoublePositive(), stormOdds = GameClimate.GetStormOdds(SDate.Now().AddDays(1), Dice); List <string> lines = Helper.Reflection.GetField <List <string> >(box, "dialogues").GetValue(); if (lines.FirstOrDefault() == Game1.content.LoadString("Strings\\StringsFromCSFiles:Object.cs.12822")) { if (WeatherOpt.Verbose) { Monitor.Log($"Rain totem interception firing with roll {odds:N3} vs. odds {stormOdds:N3}"); } // rain totem used, do your thing if (WeatherOpt.StormTotemChange) { if (odds <= stormOdds) { if (WeatherOpt.Verbose) { Monitor.Log("Replacing rain with storm.."); } Game1.netWorldState.Value.WeatherForTomorrow = Game1.weatherForTomorrow = Game1.weather_lightning; stormDialogue = true; } } // change dialogue text lines.Clear(); lines.Add(stormDialogue ? Helper.Translation.Get("hud-text.desc_stormtotem") : Game1.content.LoadString("Strings\\StringsFromCSFiles:Object.cs.12822")); } } }
/// <summary>Raised after a game menu is opened, closed, or replaced.</summary> /// <param name="sender">The event sender.</param> /// <param name="e">The event arguments.</param> private void OnMenuChanged(object sender, MenuChangedEventArgs e) { if (!Context.IsMainPlayer) { return; } // restore previous menu on close if (e.OldMenu is WeatherMenu && this.PreviousMenu != null) { Game1.activeClickableMenu = this.PreviousMenu; this.PreviousMenu = null; } // handle new dialogue box else if (e.NewMenu is DialogueBox box) { double odds = Dice.NextDouble(), stormOdds = GameClimate.GetStormOdds(SDate.Now().AddDays(1), Dice); WeatherProcessing.HandleStormTotemInterception(box, odds, stormOdds); } }