public override bool TryMergeWithExistingMemory(out bool showBubble) { ThoughtHandler thoughts = this.pawn.needs.mood.thoughts; if (thoughts.memories.NumMemoriesInGroup(this) >= 1) { Thought_MealTemp thought_Memory = thoughts.memories.OldestMemoryInGroup(this) as Thought_MealTemp; if (thought_Memory != null) { int moodVal = this.GetMoodValue(); if (moodVal == 0) // this has 0 value, don't add it { showBubble = false; } else if (thought_Memory.GetMoodValue() == moodVal) // other value is not 0 and equals this value { showBubble = (thought_Memory.age > thought_Memory.def.DurationTicks / 2); thought_Memory.Renew(); } else // different values, this one is non-zero { thoughts.memories.RemoveMemory(thought_Memory); thoughts.memories.Memories.Add(this); showBubble = true; } return(true); } } showBubble = true; return(false); }
public static bool MoodOffsetOfGroup(ThoughtHandler __instance, ref float __result, Thought group) { List <Thought> tmpThoughts = new List <Thought>(); __instance.GetMoodThoughts(group, tmpThoughts); if (!tmpThoughts.Any <Thought>()) { __result = 0.0f; return(false); } float num1 = 0.0f; float num2 = 1f; float num3 = 0.0f; for (int index = 0; index < tmpThoughts.Count; ++index) { Thought tmpThought = tmpThoughts[index]; if (null != tmpThought) { num1 += tmpThought.MoodOffset(); num3 += num2; num2 *= tmpThought.def.stackedEffectMultiplier; } } double num4 = (double)num1 / (double)tmpThoughts.Count; tmpThoughts.Clear(); double num5 = (double)num3; __result = (float)(num4 * num5); return(false); }
/// <summary> /// Thread-safe version for vanilla. /// </summary> /// <param name="group"></param> /// <param name="handler"></param> /// <returns></returns> private float MoodOffsetOfGroup(Thought group, ThoughtHandler handler) { List <Thought> tmpThoughts = _thoughts.Value; handler.GetMoodThoughts(group, tmpThoughts); if (!tmpThoughts.Any()) { return(0f); } float totalMoodOffset = 0f; float effectMultiplier = 1f; float totalEffectMultiplier = 0f; foreach (Thought thought in tmpThoughts) { totalMoodOffset += thought.MoodOffset(); totalEffectMultiplier += effectMultiplier; effectMultiplier *= thought.def.stackedEffectMultiplier; } float num4 = totalMoodOffset / (float)tmpThoughts.Count; tmpThoughts.Clear(); return(num4 * totalEffectMultiplier); }
/// <summary> /// Thread-safe version for vanilla. /// </summary> /// <returns></returns> private float TotalMoodOffsetThreadSafe() { List <Thought> curThoughts = _moodOffsetThoughts.Value; ThoughtHandler handler = _backingField.Pawn.needs?.mood?.thoughts; if (handler is null) { return(0f); } handler.GetDistinctMoodThoughtGroups(curThoughts); return(curThoughts.Sum(t => MoodOffsetOfGroup(t, handler))); }
public static bool TotalMoodOffset(ThoughtHandler __instance, ref float __result) { List <Thought> tmpThoughts = new List <Thought>(); __instance.GetDistinctMoodThoughtGroups(tmpThoughts); float num = 0.0f; float moodOffset = 0f; for (int index = 0; index < tmpThoughts.Count; ++index) { MoodOffsetOfGroup(__instance, ref moodOffset, tmpThoughts[index]); num += moodOffset; } tmpThoughts.Clear(); __result = num; return(false); }
public static bool TotalOpinionOffset(ThoughtHandler __instance, ref int __result, Pawn otherPawn) { List <ISocialThought> tmpTotalOpinionOffsetThoughts = new List <ISocialThought>(); __instance.GetDistinctSocialThoughtGroups(otherPawn, tmpTotalOpinionOffsetThoughts); int num = 0; int opinionOffset = 0; for (int index = 0; index < tmpTotalOpinionOffsetThoughts.Count; ++index) { OpinionOffsetOfGroup(__instance, ref opinionOffset, tmpTotalOpinionOffsetThoughts[index], otherPawn); num += opinionOffset; } tmpTotalOpinionOffsetThoughts.Clear(); __result = num; return(false); }
public static bool OpinionOffsetOfGroup(ThoughtHandler __instance, ref int __result, ISocialThought group, Pawn otherPawn) { List <ISocialThought> tmpSocialThoughts = new List <ISocialThought>(); __instance.GetSocialThoughts(otherPawn, group, tmpSocialThoughts); for (int index = tmpSocialThoughts.Count - 1; index >= 0; --index) { if ((double)tmpSocialThoughts[index].OpinionOffset() == 0.0) { tmpSocialThoughts.RemoveAt(index); } } if (!tmpSocialThoughts.Any <ISocialThought>()) { __result = 0; return(false); } ThoughtDef def = ((Thought)group).def; if (def.IsMemory && (double)def.stackedEffectMultiplier != 1.0) { tmpSocialThoughts.Sort((Comparison <ISocialThought>)((a, b) => ((Thought_Memory)a).age.CompareTo(((Thought_Memory)b).age))); } float f = 0.0f; float num = 1f; for (int index = 0; index < tmpSocialThoughts.Count; ++index) { f += tmpSocialThoughts[index].OpinionOffset() * num; num *= ((Thought)tmpSocialThoughts[index]).def.stackedEffectMultiplier; } tmpSocialThoughts.Clear(); if ((double)f == 0.0) { __result = 0; return(false); } __result = (double)f > 0.0 ? Mathf.Max(Mathf.RoundToInt(f), 1) : Mathf.Min(Mathf.RoundToInt(f), -1); return(false); }
internal static void CreateThoughtList(List <Pawn> pawns) { // for each pawn... ThoughtsAbout = new Dictionary <Pawn, List <string> >(); foreach (Pawn pawn in pawns) { // add list for this pawn ThoughtsAbout.Add(pawn, new List <string>()); // get thoughts targeted at the pawn by all other pawns... foreach (Pawn other in pawns.Where(p => p != pawn)) { ThoughtHandler thoughts = other.needs?.mood?.thoughts; if (thoughts == null) { continue; } // get distinct social thoughts var DistinctSocialThoughtGroups = new List <ISocialThought>(); thoughts.GetDistinctSocialThoughtGroups(pawn, DistinctSocialThoughtGroups); foreach (ISocialThought t in DistinctSocialThoughtGroups) { var thought = (Thought)t; if (t.OpinionOffset() != 0) { ThoughtsAbout[pawn].Add(thought.LabelCapSocial); } } } // remove duplicates if (!ThoughtsAbout[pawn].NullOrEmpty()) { ThoughtsAbout[pawn] = ThoughtsAbout[pawn].Distinct().ToList(); } } }
private void TryAddMemory(Pawn pawn, ThoughtDef memory) { ThoughtHandler thoughts = pawn.needs?.mood?.thoughts; if (thoughts == null) { return; } if (!ThoughtUtility.CanGetThought(pawn, memory)) { return; } var counter = 0; int max = PMUtilities.GetSettings().maxMutationThoughts; if (!ignoreThoughtLimit) { foreach (Thought_Memory thought in thoughts.memories.Memories) { if (MutationUtilities.AllMutationMemories.Contains(thought.def)) { counter++; } counter++; if (counter >= max) { return; //make sure to only add so many thoughts at once } } } pawn.TryGainMemory(memory); }