コード例 #1
0
        private Thought_SituationalSocial TryCreateSocialThought(ThoughtDef def, Pawn otherPawn)
        {
            Thought_SituationalSocial thought_SituationalSocial = null;

            try
            {
                if (!ThoughtUtility.CanGetThought(this.pawn, def))
                {
                    return(null);
                }
                if (!def.Worker.CurrentSocialState(this.pawn, otherPawn).Active)
                {
                    return(null);
                }
                thought_SituationalSocial           = (Thought_SituationalSocial)ThoughtMaker.MakeThought(def);
                thought_SituationalSocial.pawn      = this.pawn;
                thought_SituationalSocial.otherPawn = otherPawn;
                thought_SituationalSocial.RecalculateState();
                return(thought_SituationalSocial);
            }
            catch (Exception ex)
            {
                Log.Error("Exception while recalculating " + def + " thought state for pawn " + this.pawn + ": " + ex);
                return(thought_SituationalSocial);
            }
        }
コード例 #2
0
        private Thought_SituationalSocial TryCreateSocialThought(ThoughtDef def, Pawn otherPawn)
        {
            Thought_SituationalSocial thought_SituationalSocial = null;

            try
            {
                if (!ThoughtUtility.CanGetThought_NewTemp(pawn, def))
                {
                    return(null);
                }
                if (!def.Worker.CurrentSocialState(pawn, otherPawn).ActiveFor(def))
                {
                    return(null);
                }
                thought_SituationalSocial           = (Thought_SituationalSocial)ThoughtMaker.MakeThought(def);
                thought_SituationalSocial.pawn      = pawn;
                thought_SituationalSocial.otherPawn = otherPawn;
                thought_SituationalSocial.RecalculateState();
                return(thought_SituationalSocial);
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat("Exception while recalculating ", def, " thought state for pawn ", pawn, ": ", ex));
                return(thought_SituationalSocial);
            }
        }
コード例 #3
0
        private Thought_SituationalSocial TryCreateSocialThought(ThoughtDef def, Pawn otherPawn)
        {
            Thought_SituationalSocial thought_SituationalSocial = null;

            try
            {
                if (!ThoughtUtility.CanGetThought(this.pawn, def))
                {
                    Thought_SituationalSocial result = null;
                    return(result);
                }
                if (!def.Worker.CurrentSocialState(this.pawn, otherPawn).Active)
                {
                    Thought_SituationalSocial result = null;
                    return(result);
                }
                thought_SituationalSocial           = (Thought_SituationalSocial)ThoughtMaker.MakeThought(def);
                thought_SituationalSocial.pawn      = this.pawn;
                thought_SituationalSocial.otherPawn = otherPawn;
                thought_SituationalSocial.RecalculateState();
            }
            catch (Exception ex)
            {
                Log.Error(string.Concat(new object[]
                {
                    "Exception while recalculating ",
                    def,
                    " thought state for pawn ",
                    this.pawn,
                    ": ",
                    ex
                }));
            }
            return(thought_SituationalSocial);
        }
コード例 #4
0
        public override bool GroupsWith(Thought other)
        {
            Thought_SituationalSocial thought_SituationalSocial = other as Thought_SituationalSocial;

            if (thought_SituationalSocial == null)
            {
                return(false);
            }
            return(base.GroupsWith(other) && otherPawn == thought_SituationalSocial.otherPawn);
        }
コード例 #5
0
 private void CheckRecalculateSocialThoughts(Pawn otherPawn)
 {
     try
     {
         SituationalThoughtHandler.CachedSocialThoughts cachedSocialThoughts;
         if (!this.cachedSocialThoughts.TryGetValue(otherPawn, out cachedSocialThoughts))
         {
             cachedSocialThoughts = new SituationalThoughtHandler.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;
             while (j < count)
             {
                 if (!this.tmpCachedSocialThoughts.Contains(situationalSocialThoughtDefs[j]))
                 {
                     Thought_SituationalSocial thought_SituationalSocial2 = this.TryCreateSocialThought(situationalSocialThoughtDefs[j], otherPawn);
                     if (thought_SituationalSocial2 != null)
                     {
                         cachedSocialThoughts.thoughts.Add(thought_SituationalSocial2);
                     }
                 }
                 j++;
             }
             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
     {
     }
 }
コード例 #6
0
 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
     {
     }
 }
コード例 #7
0
        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
            {
            }
        }
コード例 #8
0
 private void RecalculateSocialThoughtsAffectingMood()
 {
     try
     {
         this.tmpToAdd.Clear();
         List <ThoughtDef> situationalSocialThoughtDefs = ThoughtUtility.situationalSocialThoughtDefs;
         int i     = 0;
         int count = situationalSocialThoughtDefs.Count;
         while (i < count)
         {
             if (situationalSocialThoughtDefs[i].socialThoughtAffectingMood)
             {
                 foreach (Pawn current in situationalSocialThoughtDefs[i].Worker.PotentialPawnCandidates(this.pawn))
                 {
                     if (current != this.pawn)
                     {
                         this.tmpToAdd.Add(new Pair <ThoughtDef, Pawn>(situationalSocialThoughtDefs[i], current));
                     }
                 }
             }
             i++;
         }
         foreach (KeyValuePair <Pawn, SituationalThoughtHandler.CachedSocialThoughts> current2 in this.cachedSocialThoughtsAffectingMood)
         {
             List <Thought_SituationalSocial> thoughts = current2.Value.thoughts;
             for (int j = thoughts.Count - 1; j >= 0; j--)
             {
                 if (!this.tmpToAdd.Contains(new Pair <ThoughtDef, Pawn>(thoughts[j].def, current2.Key)))
                 {
                     thoughts.RemoveAt(j);
                 }
             }
         }
         foreach (Pair <ThoughtDef, Pawn> current3 in this.tmpToAdd)
         {
             ThoughtDef first  = current3.First;
             Pawn       second = current3.Second;
             SituationalThoughtHandler.CachedSocialThoughts cachedSocialThoughts;
             bool flag = this.cachedSocialThoughtsAffectingMood.TryGetValue(second, out cachedSocialThoughts);
             if (flag)
             {
                 bool flag2 = false;
                 for (int k = 0; k < cachedSocialThoughts.thoughts.Count; k++)
                 {
                     if (cachedSocialThoughts.thoughts[k].def == first)
                     {
                         flag2 = true;
                         break;
                     }
                 }
                 if (flag2)
                 {
                     continue;
                 }
             }
             Thought_SituationalSocial thought_SituationalSocial = this.TryCreateSocialThought(first, second);
             if (thought_SituationalSocial != null)
             {
                 if (!flag)
                 {
                     cachedSocialThoughts = new SituationalThoughtHandler.CachedSocialThoughts();
                     this.cachedSocialThoughtsAffectingMood.Add(second, cachedSocialThoughts);
                 }
                 cachedSocialThoughts.thoughts.Add(thought_SituationalSocial);
             }
         }
         this.cachedSocialThoughtsAffectingMood.RemoveAll((KeyValuePair <Pawn, SituationalThoughtHandler.CachedSocialThoughts> x) => x.Value.thoughts.Count == 0);
         int ticksGame = Find.TickManager.TicksGame;
         foreach (KeyValuePair <Pawn, SituationalThoughtHandler.CachedSocialThoughts> current4 in this.cachedSocialThoughtsAffectingMood)
         {
             SituationalThoughtHandler.CachedSocialThoughts value = current4.Value;
             List <Thought_SituationalSocial> thoughts2           = value.thoughts;
             value.activeThoughts.Clear();
             for (int l = 0; l < thoughts2.Count; l++)
             {
                 thoughts2[l].RecalculateState();
                 value.lastRecalculationTick = ticksGame;
                 if (thoughts2[l].Active)
                 {
                     value.activeThoughts.Add(thoughts2[l]);
                 }
             }
         }
     }
     finally
     {
     }
 }
コード例 #9
0
        public override bool GroupsWith(Thought other)
        {
            Thought_SituationalSocial thought_SituationalSocial = other as Thought_SituationalSocial;

            return(thought_SituationalSocial != null && base.GroupsWith(other) && this.otherPawn == thought_SituationalSocial.otherPawn);
        }