예제 #1
0
 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
     {
     }
 }
예제 #2
0
        private static Thought_SituationalSocial TryCreateSocialThought(SituationalThoughtHandler __instance,
                                                                        ThoughtDef def,
                                                                        Pawn otherPawn)
        {
            Thought_SituationalSocial situationalSocial = null;

            try
            {
                if (!ThoughtUtility.CanGetThought_NewTemp(__instance.pawn, def, false) || !def.Worker.CurrentSocialState(__instance.pawn, otherPawn).ActiveFor(def))
                {
                    return(null);
                }
                situationalSocial           = (Thought_SituationalSocial)ThoughtMaker.MakeThought(def);
                situationalSocial.pawn      = __instance.pawn;
                situationalSocial.otherPawn = otherPawn;
                situationalSocial.RecalculateState();
            }
            catch (Exception ex)
            {
                Log.Error("Exception while recalculating " + def + " thought state for pawn " + __instance.pawn + ": " + ex, false);
            }
            return(situationalSocial);
        }
 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);
 }