internal static bool TryDoRandomMoodCausedMentalBreak(this MentalBreaker _this) { if (!_this.GetCanDoRandomMentalBreaks() || _this.GetPawn().Downed || !_this.GetPawn().Awake()) { return(false); } if (_this.GetPawn().Faction != Faction.OfPlayer && _this.GetCurrentDesiredMoodBreakIntensity() != MentalBreakIntensity.Extreme) { return(false); } MentalBreakDef mentalBreakDef; if (!_this.GetCurrentPossibleMoodBreaks().TryRandomElementByWeight((MentalBreakDef d) => d.Worker.CommonalityFor(_this.GetPawn()), out mentalBreakDef)) { Log.Message(_this.GetCurrentDesiredMoodBreakIntensity().ToString()); foreach (MentalBreakDef def in _this.GetCurrentPossibleMoodBreaks()) { Log.Message(def.ToString()); } return(false); } MethodInfo method = typeof(MentalBreaker).GetMethod("RandomMentalBreakReason", BindingFlags.Instance | BindingFlags.NonPublic); Thought thought = null; if (method != null) { thought = (Thought)method.Invoke(_this, new object[] { }); } //if (temp != null) thought = (Thought)temp.GetValue(_this); string reason = (thought == null) ? null : thought.LabelCap; if (_this.IsWearingStraitJacket()) { if (Rand.Range(0, 100) < 95) //95% of the time { Cthulhu.Utility.DebugReport("StraitJacket :: Mental Break Triggered"); MentalStateDef stateDef = mentalBreakDef.mentalState; string label = "MentalBreakAvertedLetterLabel".Translate() + ": " + stateDef.beginLetterLabel; string text = string.Format(stateDef.beginLetter, _this.GetPawn().Label).AdjustedFor(_this.GetPawn()).CapitalizeFirst(); if (reason != null) { text = text + "\n\n" + "MentalBreakReason".Translate(new object[] { reason }); text = text + "\n\n" + "StraitjacketBenefit".Translate(new object[] { _this.GetPawn().gender.GetPossessive(), _this.GetPawn().gender.GetObjective(), _this.GetPawn().gender.GetObjective() + "self" }); } Find.LetterStack.ReceiveLetter(label, text, stateDef.beginLetterType, _this.GetPawn(), null); return(false); } _this.StripStraitJacket(); Messages.Message(_this.GetPawn().LabelCap + " has escaped out of their straitjacket!", MessageSound.SeriousAlert); } _this.GetPawn().mindState.mentalStateHandler.TryStartMentalState(mentalBreakDef.mentalState, reason, false, true, null); return(true); }