예제 #1
0
 public static bool CanGetThought(Pawn pawn, ThoughtDef def)
 {
     try
     {
         if (!def.validWhileDespawned && !pawn.Spawned && !def.IsMemory)
         {
             bool result = false;
             return(result);
         }
         if (def.nullifyingTraits != null)
         {
             for (int i = 0; i < def.nullifyingTraits.Count; i++)
             {
                 if (pawn.story.traits.HasTrait(def.nullifyingTraits[i]))
                 {
                     bool result = false;
                     return(result);
                 }
             }
         }
         if (!def.requiredTraits.NullOrEmpty <TraitDef>())
         {
             bool flag = false;
             for (int j = 0; j < def.requiredTraits.Count; j++)
             {
                 if (pawn.story.traits.HasTrait(def.requiredTraits[j]))
                 {
                     if (!def.RequiresSpecificTraitsDegree || def.requiredTraitsDegree == pawn.story.traits.DegreeOfTrait(def.requiredTraits[j]))
                     {
                         flag = true;
                         break;
                     }
                 }
             }
             if (!flag)
             {
                 bool result = false;
                 return(result);
             }
         }
         if (def.nullifiedIfNotColonist && !pawn.IsColonist)
         {
             bool result = false;
             return(result);
         }
         if (ThoughtUtility.IsSituationalThoughtNullifiedByHediffs(def, pawn))
         {
             bool result = false;
             return(result);
         }
         if (ThoughtUtility.IsThoughtNullifiedByOwnTales(def, pawn))
         {
             bool result = false;
             return(result);
         }
     }
     finally
     {
     }
     return(true);
 }
 public override void AssignDebugData()
 {
     base.AssignDebugData();
     def  = ThoughtDefOf.DecreeMet ?? ThoughtDefOf.DebugGood;
     pawn = PawnsFinder.AllMaps_FreeColonists.FirstOrDefault();
 }
 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
     {
     }
 }
예제 #4
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
            {
            }
        }
        private static bool <TryGetRandomSocialFightProvokingThought> m__0(ISocialThought x)
        {
            ThoughtDef def = ((Thought)x).def;

            return(def != ThoughtDefOf.HadAngeringFight && def != ThoughtDefOf.HadCatharticFight && x.OpinionOffset() < 0f);
        }
예제 #6
0
        private static List <Drug> GetFromHeddifStages(ThingDef def, HediffDef hediff, float doerSeverity, RimWorld.ThoughtDef thought)
        {
            var result         = new List <Drug>();
            var hasThought     = thought != null;
            var severityPerDay = hediff.CompProps <HediffCompProperties_SeverityPerDay>()?.severityPerDay;

            for (int i = 0; i < hediff.stages.Count; ++i)
            {
                var stage = hediff.stages[i];

                var row = new Drug {
                    DrugName = def.LabelCap
                };

                float severity;
                if (hediff.stages.Count == 1)
                {
                    severity         = doerSeverity;
                    row.BaseSeverity = severity.ToString("F2");
                    row.Label        = $"   {(string.IsNullOrEmpty(stage.label) ? hediff.label : stage.label)}(> {stage.minSeverity})";
                    row.Description  = $"Это единственное состояние";
                }
                else
                {
                    int count = 1;
                    severity         = stage.minSeverity == 0f ? doerSeverity : CalcSeverityLevelByMin(doerSeverity, stage.minSeverity, out count);
                    row.BaseSeverity = severity.ToString("F2");
                    row.Label        = $"   {(string.IsNullOrEmpty(stage.label) ? hediff.label : stage.label)}(> {stage.minSeverity}) x{count}";
                    row.Description  = $"Это состояние начинается после: {stage.minSeverity}\r\nДля этого состояния нужно принять раз: x{count}";
                }

                if (hasThought)
                {
                    var thoughtStages = thought.stages;
                    row.BaseMoodEffect = i < thoughtStages.Count ? thoughtStages[i].baseMoodEffect : thoughtStages.Last().baseMoodEffect;
                }

                if (severityPerDay != null)
                {
                    row.SeverityPerDay = ((float)severityPerDay).ToString("F2");
                    row.SeverityDays   = GetSeverityDays(severity, (float)severityPerDay).ToString("F2");
                }

                row.PainFactor = stage.painFactor.ToPercent();

                FillCapMods(ref row, /*hediff.stages[0]*/ stage); // why was [0] wtf?

                result.Add(row);
            }

            return(result);
        }
 private static void AppendThoughts_Relations(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind, List <IndividualThoughtToAdd> outIndividualThoughts, List <ThoughtDef> outAllColonistsThoughts)
 {
     if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Banished && victim.RaceProps.Animal)
     {
         List <DirectPawnRelation> directRelations = victim.relations.DirectRelations;
         for (int i = 0; i < directRelations.Count; i++)
         {
             if (!directRelations[i].otherPawn.Dead && directRelations[i].otherPawn.needs.mood != null && PawnUtility.ShouldGetThoughtAbout(directRelations[i].otherPawn, victim) && directRelations[i].def == PawnRelationDefOf.Bond)
             {
                 outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.BondedAnimalBanished, directRelations[i].otherPawn, victim, 1f, 1f));
             }
         }
     }
     if (thoughtsKind != 0 && thoughtsKind != PawnDiedOrDownedThoughtsKind.BanishedToDie)
     {
         return;
     }
     foreach (Pawn potentiallyRelatedPawn in victim.relations.PotentiallyRelatedPawns)
     {
         if (!potentiallyRelatedPawn.Dead && potentiallyRelatedPawn.needs.mood != null && PawnUtility.ShouldGetThoughtAbout(potentiallyRelatedPawn, victim))
         {
             PawnRelationDef mostImportantRelation = potentiallyRelatedPawn.GetMostImportantRelation(victim);
             if (mostImportantRelation != null)
             {
                 ThoughtDef genderSpecificDiedThought = mostImportantRelation.GetGenderSpecificDiedThought(victim);
                 if (genderSpecificDiedThought != null)
                 {
                     outIndividualThoughts.Add(new IndividualThoughtToAdd(genderSpecificDiedThought, potentiallyRelatedPawn, victim, 1f, 1f));
                 }
             }
         }
     }
     if (dinfo.HasValue)
     {
         Pawn pawn = dinfo.Value.Instigator as Pawn;
         if (pawn != null && pawn != victim)
         {
             foreach (Pawn potentiallyRelatedPawn2 in victim.relations.PotentiallyRelatedPawns)
             {
                 if (pawn != potentiallyRelatedPawn2 && !potentiallyRelatedPawn2.Dead && potentiallyRelatedPawn2.needs.mood != null)
                 {
                     PawnRelationDef mostImportantRelation2 = potentiallyRelatedPawn2.GetMostImportantRelation(victim);
                     if (mostImportantRelation2 != null)
                     {
                         ThoughtDef genderSpecificKilledThought = mostImportantRelation2.GetGenderSpecificKilledThought(victim);
                         if (genderSpecificKilledThought != null)
                         {
                             outIndividualThoughts.Add(new IndividualThoughtToAdd(genderSpecificKilledThought, potentiallyRelatedPawn2, pawn, 1f, 1f));
                         }
                     }
                     if (potentiallyRelatedPawn2.RaceProps.IsFlesh)
                     {
                         int num = potentiallyRelatedPawn2.relations.OpinionOf(victim);
                         if (num >= 20)
                         {
                             ThoughtDef killedMyFriend = ThoughtDefOf.KilledMyFriend;
                             Pawn       addTo          = potentiallyRelatedPawn2;
                             Pawn       otherPawn      = pawn;
                             float      friendDiedThoughtPowerFactor = victim.relations.GetFriendDiedThoughtPowerFactor(num);
                             outIndividualThoughts.Add(new IndividualThoughtToAdd(killedMyFriend, addTo, otherPawn, 1f, friendDiedThoughtPowerFactor));
                         }
                         else if (num <= -20)
                         {
                             ThoughtDef killedMyFriend = ThoughtDefOf.KilledMyRival;
                             Pawn       otherPawn      = potentiallyRelatedPawn2;
                             Pawn       addTo          = pawn;
                             float      friendDiedThoughtPowerFactor = victim.relations.GetRivalDiedThoughtPowerFactor(num);
                             outIndividualThoughts.Add(new IndividualThoughtToAdd(killedMyFriend, otherPawn, addTo, 1f, friendDiedThoughtPowerFactor));
                         }
                     }
                 }
             }
         }
     }
     if (victim.RaceProps.Humanlike)
     {
         foreach (Pawn allMapsCaravansAndTravelingTransportPod in PawnsFinder.AllMapsCaravansAndTravelingTransportPods)
         {
             if (!allMapsCaravansAndTravelingTransportPod.Dead && allMapsCaravansAndTravelingTransportPod.RaceProps.IsFlesh && allMapsCaravansAndTravelingTransportPod.needs.mood != null && PawnUtility.ShouldGetThoughtAbout(allMapsCaravansAndTravelingTransportPod, victim))
             {
                 int num2 = allMapsCaravansAndTravelingTransportPod.relations.OpinionOf(victim);
                 if (num2 >= 20)
                 {
                     outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.PawnWithGoodOpinionDied, allMapsCaravansAndTravelingTransportPod, victim, victim.relations.GetFriendDiedThoughtPowerFactor(num2), 1f));
                 }
                 else if (num2 <= -20)
                 {
                     outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.PawnWithBadOpinionDied, allMapsCaravansAndTravelingTransportPod, victim, victim.relations.GetRivalDiedThoughtPowerFactor(num2), 1f));
                 }
             }
         }
     }
 }
 public static bool CanGetThought(Pawn pawn, ThoughtDef def)
 {
     return(CanGetThought_NewTemp(pawn, def));
 }
 private static bool <Reset> m__1(ThoughtDef x)
 {
     return(x.IsSituational && !x.IsSocial);
 }