Esempio n. 1
0
        public static bool RemoveExpiredThoughtsFromCache(SituationalThoughtHandler __instance)
        {
            if (!this_cachedSocialThoughts.ContainsKey(__instance))
            {
                this_cachedSocialThoughts.Add(__instance, new Dictionary <Pawn, CachedSocialThoughts>());
            }
            Dictionary <Pawn, CachedSocialThoughts> this_cachedSocialThoughtsInstance = this_cachedSocialThoughts[__instance];
            //this_cachedSocialThoughtsInstance.RemoveAll(x => x.Value.Expired || x.Key.Discarded);
            List <Pawn> RemoveList = new List <Pawn>();

            lock (this_cachedSocialThoughtsInstance) {
                foreach (KeyValuePair <Pawn, CachedSocialThoughts> x in this_cachedSocialThoughtsInstance)
                {
                    if ((x.Value != null && x.Value.Expired) || (x.Key != null && x.Key.Discarded))
                    {
                        RemoveList.Add(x.Key);
                        continue;
                    }
                }
                foreach (Pawn r in RemoveList)
                {
                    this_cachedSocialThoughtsInstance.Remove(r);
                }
            }

            return(false);
        }
 public static bool Notify_SituationalThoughtsDirty(SituationalThoughtHandler __instance)
 {
     lock (__instance)
     {
         __instance.cachedThoughts       = new List <Thought_Situational>();
         __instance.cachedSocialThoughts = new Dictionary <Pawn, CachedSocialThoughts>();
     }
     __instance.lastMoodThoughtsRecalculationTick = -99999;
     return(false);
 }
 public static bool RemoveExpiredThoughtsFromCache(SituationalThoughtHandler __instance)
 {
     lock (__instance)
     {
         Dictionary <Pawn, CachedSocialThoughts> newCachedSocialThoughts = new Dictionary <Pawn, CachedSocialThoughts>(__instance.cachedSocialThoughts);
         newCachedSocialThoughts.RemoveAll(x => x.Value.Expired || x.Key.Discarded);
         __instance.cachedSocialThoughts = newCachedSocialThoughts;
     }
     return(false);
 }
Esempio n. 4
0
 public static bool Notify_SituationalThoughtsDirty(SituationalThoughtHandler __instance)
 {
     cachedThoughts(__instance).Clear();
     if (!this_cachedSocialThoughts.ContainsKey(__instance))
     {
         this_cachedSocialThoughts.Add(__instance, new Dictionary <Pawn, CachedSocialThoughts>());
     }
     this_cachedSocialThoughts[__instance].Clear();
     lastMoodThoughtsRecalculationTick(__instance) = -99999;
     return(false);
 }
        public static bool RemoveExpiredThoughtsFromCache(SituationalThoughtHandler __instance)
        {
            if (!this_cachedSocialThoughts.ContainsKey(__instance))
            {
                this_cachedSocialThoughts.Add(__instance, new Dictionary <Pawn, CachedSocialThoughts>());
            }
            Dictionary <Pawn, CachedSocialThoughts> this_cachedSocialThoughtsInstance = this_cachedSocialThoughts[__instance];

            this_cachedSocialThoughtsInstance.RemoveAll(x => x.Value.Expired || x.Key.Discarded);
            return(false);
        }
Esempio n. 6
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
     {
     }
 }
Esempio n. 7
0
        static void Postfix(Pawn_NeedsTracker __instance)
        {
            MultiplayerPawnComp comp = __instance.pawn.GetComp <MultiplayerPawnComp>();

            if (__instance.mood == null)
            {
                comp.thoughtsForInterface = null;
            }
            else
            {
                SituationalThoughtHandler thoughts = new SituationalThoughtHandler(__instance.pawn);
                comp.thoughtsForInterface = thoughts;
            }
        }
 public static bool AppendSocialThoughts(SituationalThoughtHandler __instance, Pawn otherPawn, List <ISocialThought> outThoughts)
 {
     __instance.CheckRecalculateSocialThoughts(otherPawn);
     if (__instance.cachedSocialThoughts.TryGetValue(otherPawn, out CachedSocialThoughts cachedSocialThought))
     {
         cachedSocialThought.lastQueryTick = Find.TickManager.TicksGame;
         List <Thought_SituationalSocial> activeThoughts = cachedSocialThought.activeThoughts;
         for (int index = 0; index < activeThoughts.Count; ++index)
         {
             outThoughts.Add((ISocialThought)activeThoughts[index]);
         }
     }
     return(false);
 }
Esempio n. 9
0
        static void Prefix(SituationalThoughtHandler __instance)
        {
            if (ignore)
            {
                return;
            }

            ignore = true;

            SituationalThoughtHandler thoughts = __instance.pawn.GetComp <MultiplayerPawnComp>().thoughtsForInterface;

            thoughts?.RemoveExpiredThoughtsFromCache();

            ignore = false;
        }
Esempio n. 10
0
        static void Prefix(SituationalThoughtHandler __instance)
        {
            if (ignore)
            {
                return;
            }

            ignore = true;

            SituationalThoughtHandler thoughts = __instance.pawn.GetComp <MultiplayerPawnComp>().thoughtsForInterface;

            thoughts?.Notify_SituationalThoughtsDirty();

            ignore = false;
        }
Esempio n. 11
0
        static bool Prefix(SituationalThoughtHandler __instance, List <Thought> outThoughts)
        {
            if (!Cancel || ignore)
            {
                return(true);
            }

            ignore = true;

            SituationalThoughtHandler thoughts = __instance.pawn.GetComp <MultiplayerPawnComp>().thoughtsForInterface;

            thoughts?.AppendMoodThoughts(outThoughts);

            ignore = false;

            return(false);
        }
Esempio n. 12
0
 public static void CanGetThoughtPostfix(ThoughtDef def, SituationalThoughtHandler __instance, ref bool __result)
 {
     if (__result)
     {
         try
         {
             Need_Soul soul;
             if (HarmonyPatches.HasSoulTraitNullyfyingTraits(def, __instance.pawn, out soul))
             {
                 __result = false;
                 return;
             }
             ThoughtDefCorruption Tdef = def as ThoughtDefCorruption;
             if (Tdef != null)
             {
                 if (IsAutomaton(__instance.pawn))
                 {
                     if (Tdef.IsAutomatonThought)
                     {
                         return;
                     }
                     else
                     {
                         __result = false;
                         return;
                     }
                 }
                 if (!Tdef.requiredSoulTraits.NullOrEmpty())
                 {
                     for (int i = 0; i < soul.SoulTraits.Count; i++)
                     {
                         if (!Tdef.requiredSoulTraits.Contains(soul.SoulTraits[i].SDef))
                         {
                             __result = false;
                         }
                     }
                 }
             }
         }
         finally
         {
             ProfilerThreadCheck.EndSample();
         }
     }
 }
            internal static bool TryCreateThoughtPrefix([NotNull] ref ThoughtDef def,
                                                        [NotNull] SituationalThoughtHandler __instance)
            {
                var tGroup = def.GetModExtension <ThoughtGroupDefExtension>();

                if (tGroup == null)
                {
                    return(true);                //quit early if there is no def extension
                }
                ThoughtDef nDef = def.GetSubstitute(__instance.pawn);

                if (nDef == def)
                {
                    return(true);
                }
                def = nDef;
                return(!Traverse.Create(__instance).Field("tmpCachedThoughts").GetValue <HashSet <ThoughtDef> >().Contains(def));
            }
Esempio n. 14
0
 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 CheckRecalculateMoodThoughts(SituationalThoughtHandler __instance)
        {
            int ticksGame = Find.TickManager.TicksGame;

            if (ticksGame - __instance.lastMoodThoughtsRecalculationTick < 100)
            {
                return(false);
            }
            __instance.lastMoodThoughtsRecalculationTick = ticksGame;
            try
            {
                tmpCachedThoughts.Clear();
                for (int index = 0; index < __instance.cachedThoughts.Count; ++index)
                {
                    __instance.cachedThoughts[index].RecalculateState();
                    tmpCachedThoughts.Add(__instance.cachedThoughts[index].def);
                }
                List <ThoughtDef> socialThoughtDefs = ThoughtUtility.situationalNonSocialThoughtDefs;
                int index1 = 0;
                for (int count = socialThoughtDefs.Count; index1 < count; ++index1)
                {
                    if (!tmpCachedThoughts.Contains(socialThoughtDefs[index1]))
                    {
                        Thought_Situational thought = __instance.TryCreateThought(socialThoughtDefs[index1]);
                        if (thought != null)
                        {
                            lock (__instance.cachedThoughts)
                            {
                                __instance.cachedThoughts.Add(thought);
                            }
                        }
                    }
                }
            }
            finally
            {
            }
            return(false);
        }
Esempio n. 16
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);
 }
Esempio n. 18
0
 public static void Postfix_Constructor(SituationalThoughtHandler __instance, Pawn pawn)
 {
     this_cachedSocialThoughts[__instance] = new Dictionary <Pawn, CachedSocialThoughts>();
 }