private static void CheckRecalculateSocialThoughts(SituationalThoughtHandler __instance, Pawn otherPawn) { try { CachedSocialThoughts cachedSocialThoughts; if (!this_cachedSocialThoughts.ContainsKey(__instance)) { this_cachedSocialThoughts.Add(__instance, new Dictionary <Pawn, CachedSocialThoughts>()); } if (!this_cachedSocialThoughts[__instance].TryGetValue(otherPawn, out cachedSocialThoughts)) { cachedSocialThoughts = new CachedSocialThoughts(); this_cachedSocialThoughts[__instance].SetOrAdd(otherPawn, cachedSocialThoughts); } if (!cachedSocialThoughts.ShouldRecalculateState) { return; } cachedSocialThoughts.lastRecalculationTick = Find.TickManager.TicksGame; //this.tmpCachedSocialThoughts.Clear(); HashSet <ThoughtDef> tmpCachedSocialThoughts = new HashSet <ThoughtDef>(); for (int index = 0; index < cachedSocialThoughts.thoughts.Count; ++index) { Thought_SituationalSocial thought = cachedSocialThoughts.thoughts[index]; thought.RecalculateState(); tmpCachedSocialThoughts.Add(thought.def); } List <ThoughtDef> socialThoughtDefs = ThoughtUtility.situationalSocialThoughtDefs; int index1 = 0; for (int count = socialThoughtDefs.Count; index1 < count; ++index1) { if (!tmpCachedSocialThoughts.Contains(socialThoughtDefs[index1])) { Thought_SituationalSocial socialThought = TryCreateSocialThought(__instance, socialThoughtDefs[index1], otherPawn); if (socialThought != null) { cachedSocialThoughts.thoughts.Add(socialThought); } } } cachedSocialThoughts.activeThoughts.Clear(); for (int index2 = 0; index2 < cachedSocialThoughts.thoughts.Count; ++index2) { Thought_SituationalSocial thought = cachedSocialThoughts.thoughts[index2]; if (thought.Active) { cachedSocialThoughts.activeThoughts.Add(thought); } } } finally { } }
public void AppendSocialThoughts(Pawn otherPawn, List <ISocialThought> outThoughts) { CheckRecalculateSocialThoughts(otherPawn); CachedSocialThoughts obj = cachedSocialThoughts[otherPawn]; obj.lastQueryTick = Find.TickManager.TicksGame; List <Thought_SituationalSocial> activeThoughts = obj.activeThoughts; for (int i = 0; i < activeThoughts.Count; i++) { outThoughts.Add(activeThoughts[i]); } }
private void CheckRecalculateSocialThoughts(Pawn otherPawn) { try { CachedSocialThoughts cachedSocialThoughts = default(CachedSocialThoughts); if (!this.cachedSocialThoughts.TryGetValue(otherPawn, out cachedSocialThoughts)) { cachedSocialThoughts = new CachedSocialThoughts(); this.cachedSocialThoughts.Add(otherPawn, cachedSocialThoughts); } if (cachedSocialThoughts.ShouldRecalculateState) { cachedSocialThoughts.lastRecalculationTick = Find.TickManager.TicksGame; this.tmpCachedSocialThoughts.Clear(); for (int i = 0; i < cachedSocialThoughts.thoughts.Count; i++) { Thought_SituationalSocial thought_SituationalSocial = cachedSocialThoughts.thoughts[i]; thought_SituationalSocial.RecalculateState(); this.tmpCachedSocialThoughts.Add(thought_SituationalSocial.def); } List <ThoughtDef> situationalSocialThoughtDefs = ThoughtUtility.situationalSocialThoughtDefs; int j = 0; int count = situationalSocialThoughtDefs.Count; for (; j < count; j++) { if (!this.tmpCachedSocialThoughts.Contains(situationalSocialThoughtDefs[j])) { Thought_SituationalSocial thought_SituationalSocial2 = this.TryCreateSocialThought(situationalSocialThoughtDefs[j], otherPawn); if (thought_SituationalSocial2 != null) { cachedSocialThoughts.thoughts.Add(thought_SituationalSocial2); } } } cachedSocialThoughts.activeThoughts.Clear(); for (int k = 0; k < cachedSocialThoughts.thoughts.Count; k++) { Thought_SituationalSocial thought_SituationalSocial3 = cachedSocialThoughts.thoughts[k]; if (thought_SituationalSocial3.Active) { cachedSocialThoughts.activeThoughts.Add(thought_SituationalSocial3); } } } } finally { } }
private void CheckRecalculateSocialThoughts(Pawn otherPawn) { try { if (!cachedSocialThoughts.TryGetValue(otherPawn, out var value)) { value = new CachedSocialThoughts(); cachedSocialThoughts.Add(otherPawn, value); } if (!value.ShouldRecalculateState) { return; } value.lastRecalculationTick = Find.TickManager.TicksGame; tmpCachedSocialThoughts.Clear(); for (int i = 0; i < value.thoughts.Count; i++) { Thought_SituationalSocial thought_SituationalSocial = value.thoughts[i]; thought_SituationalSocial.RecalculateState(); tmpCachedSocialThoughts.Add(thought_SituationalSocial.def); } List <ThoughtDef> situationalSocialThoughtDefs = ThoughtUtility.situationalSocialThoughtDefs; int j = 0; for (int count = situationalSocialThoughtDefs.Count; j < count; j++) { if (!tmpCachedSocialThoughts.Contains(situationalSocialThoughtDefs[j])) { Thought_SituationalSocial thought_SituationalSocial2 = TryCreateSocialThought(situationalSocialThoughtDefs[j], otherPawn); if (thought_SituationalSocial2 != null) { value.thoughts.Add(thought_SituationalSocial2); } } } value.activeThoughts.Clear(); for (int k = 0; k < value.thoughts.Count; k++) { Thought_SituationalSocial thought_SituationalSocial3 = value.thoughts[k]; if (thought_SituationalSocial3.Active) { value.activeThoughts.Add(thought_SituationalSocial3); } } } finally { } }
public static bool AppendSocialThoughts(SituationalThoughtHandler __instance, Pawn otherPawn, List <ISocialThought> outThoughts) { CheckRecalculateSocialThoughts(__instance, otherPawn); if (!this_cachedSocialThoughts.ContainsKey(__instance)) { this_cachedSocialThoughts.Add(__instance, new Dictionary <Pawn, CachedSocialThoughts>()); } try { CachedSocialThoughts cachedSocialThought = this_cachedSocialThoughts[__instance][otherPawn]; cachedSocialThought.lastQueryTick = Find.TickManager.TicksGame; List <Thought_SituationalSocial> activeThoughts = cachedSocialThought.activeThoughts; for (int index = 0; index < activeThoughts.Count; ++index) { outThoughts.Add(activeThoughts[index]); } } catch (KeyNotFoundException) { } return(false); }
public static bool CheckRecalculateSocialThoughts(SituationalThoughtHandler __instance, Pawn otherPawn) { try { if (!__instance.cachedSocialThoughts.TryGetValue(otherPawn, out CachedSocialThoughts cachedSocialThoughts)) { lock (__instance.cachedSocialThoughts) { if (!__instance.cachedSocialThoughts.TryGetValue(otherPawn, out CachedSocialThoughts cachedSocialThoughts2)) { cachedSocialThoughts2 = new CachedSocialThoughts(); __instance.cachedSocialThoughts.Add(otherPawn, cachedSocialThoughts2); } cachedSocialThoughts = cachedSocialThoughts2; } } if (!cachedSocialThoughts.ShouldRecalculateState) { return(false); } cachedSocialThoughts.lastRecalculationTick = Find.TickManager.TicksGame; tmpCachedSocialThoughts.Clear(); for (int index = 0; index < cachedSocialThoughts.thoughts.Count; ++index) { Thought_SituationalSocial thought = cachedSocialThoughts.thoughts[index]; thought.RecalculateState(); tmpCachedSocialThoughts.Add(thought.def); } List <ThoughtDef> socialThoughtDefs = ThoughtUtility.situationalSocialThoughtDefs; int index1 = 0; for (int count = socialThoughtDefs.Count; index1 < count; ++index1) { if (!tmpCachedSocialThoughts.Contains(socialThoughtDefs[index1])) { Thought_SituationalSocial socialThought = __instance.TryCreateSocialThought(socialThoughtDefs[index1], otherPawn); if (socialThought != null) { lock (__instance.cachedSocialThoughts) { cachedSocialThoughts.thoughts.Add(socialThought); } } } } lock (__instance.cachedSocialThoughts) { __instance.cachedSocialThoughts[otherPawn] = new CachedSocialThoughts(); } for (int index2 = 0; index2 < cachedSocialThoughts.thoughts.Count; ++index2) { Thought_SituationalSocial thought = cachedSocialThoughts.thoughts[index2]; if (thought.Active) { lock (__instance.cachedSocialThoughts) { cachedSocialThoughts.activeThoughts.Add(thought); } } } } finally { } return(false); }
private void RecalculateSocialThoughtsAffectingMood() { try { this.tmpToAdd.Clear(); List <ThoughtDef> situationalSocialThoughtDefs = ThoughtUtility.situationalSocialThoughtDefs; int i = 0; int count = situationalSocialThoughtDefs.Count; for (; i < count; i++) { if (situationalSocialThoughtDefs[i].socialThoughtAffectingMood) { foreach (Pawn item in situationalSocialThoughtDefs[i].Worker.PotentialPawnCandidates(this.pawn)) { if (item != this.pawn) { this.tmpToAdd.Add(new Pair <ThoughtDef, Pawn>(situationalSocialThoughtDefs[i], item)); } } } } foreach (KeyValuePair <Pawn, CachedSocialThoughts> item2 in this.cachedSocialThoughtsAffectingMood) { List <Thought_SituationalSocial> thoughts = item2.Value.thoughts; for (int num = thoughts.Count - 1; num >= 0; num--) { if (!this.tmpToAdd.Contains(new Pair <ThoughtDef, Pawn>(thoughts[num].def, item2.Key))) { thoughts.RemoveAt(num); } } } foreach (Pair <ThoughtDef, Pawn> item3 in this.tmpToAdd) { ThoughtDef first = item3.First; Pawn second = item3.Second; CachedSocialThoughts cachedSocialThoughts = default(CachedSocialThoughts); bool flag = this.cachedSocialThoughtsAffectingMood.TryGetValue(second, out cachedSocialThoughts); if (flag) { bool flag2 = false; int num2 = 0; while (num2 < cachedSocialThoughts.thoughts.Count) { if (cachedSocialThoughts.thoughts[num2].def != first) { num2++; continue; } flag2 = true; break; } if (!flag2) { goto IL_01e5; } continue; } goto IL_01e5; IL_01e5: Thought_SituationalSocial thought_SituationalSocial = this.TryCreateSocialThought(first, second); if (thought_SituationalSocial != null) { if (!flag) { cachedSocialThoughts = new CachedSocialThoughts(); this.cachedSocialThoughtsAffectingMood.Add(second, cachedSocialThoughts); } cachedSocialThoughts.thoughts.Add(thought_SituationalSocial); } } this.cachedSocialThoughtsAffectingMood.RemoveAll((KeyValuePair <Pawn, CachedSocialThoughts> x) => x.Value.thoughts.Count == 0); int ticksGame = Find.TickManager.TicksGame; foreach (KeyValuePair <Pawn, CachedSocialThoughts> item4 in this.cachedSocialThoughtsAffectingMood) { CachedSocialThoughts value = item4.Value; List <Thought_SituationalSocial> thoughts2 = value.thoughts; value.activeThoughts.Clear(); for (int j = 0; j < thoughts2.Count; j++) { thoughts2[j].RecalculateState(); value.lastRecalculationTick = ticksGame; if (thoughts2[j].Active) { value.activeThoughts.Add(thoughts2[j]); } } } } finally { } }