public void RemoveDirectRelation(PawnRelationDef def, Pawn otherPawn)
 {
     if (!TryRemoveDirectRelation(def, otherPawn))
     {
         Log.Warning(string.Concat("Could not remove relation ", def, " because it's not here. pawn=", pawn, ", otherPawn=", otherPawn));
     }
 }
Exemplo n.º 2
0
        private static string GetRelationsString(SocialCardUtility.CachedSocialTabEntry entry, Pawn selPawnForSocialInfo)
        {
            string text = string.Empty;

            if (entry.relations.Count != 0)
            {
                for (int i = 0; i < entry.relations.Count; i++)
                {
                    PawnRelationDef pawnRelationDef = entry.relations[i];
                    if (!text.NullOrEmpty())
                    {
                        text = text + ", " + pawnRelationDef.GetGenderSpecificLabel(entry.otherPawn);
                    }
                    else
                    {
                        text = pawnRelationDef.GetGenderSpecificLabelCap(entry.otherPawn);
                    }
                }
                return(text);
            }
            if (entry.opinionOfOtherPawn < -20)
            {
                return("Rival".Translate());
            }
            if (entry.opinionOfOtherPawn > 20)
            {
                return("Friend".Translate());
            }
            return("Acquaintance".Translate());
        }
 public bool TryRemoveDirectRelation(PawnRelationDef def, Pawn otherPawn)
 {
     if (def.implied)
     {
         Log.Warning("Tried to remove implied pawn relation " + def + ", pawn=" + this.pawn + ", otherPawn=" + otherPawn);
         return(false);
     }
     for (int i = 0; i < this.directRelations.Count; i++)
     {
         if (this.directRelations[i].def == def && this.directRelations[i].otherPawn == otherPawn)
         {
             if (def.reflexive)
             {
                 List <DirectPawnRelation> list = otherPawn.relations.directRelations;
                 DirectPawnRelation        item = list.Find((DirectPawnRelation x) => x.def == def && x.otherPawn == this.pawn);
                 list.Remove(item);
                 if (list.Find((DirectPawnRelation x) => x.otherPawn == this.pawn) == null)
                 {
                     this.pawnsWithDirectRelationsWithMe.Remove(otherPawn);
                 }
             }
             this.directRelations.RemoveAt(i);
             if (this.directRelations.Find((DirectPawnRelation x) => x.otherPawn == otherPawn) == null)
             {
                 otherPawn.relations.pawnsWithDirectRelationsWithMe.Remove(this.pawn);
             }
             this.GainedOrLostDirectRelation();
             otherPawn.relations.GainedOrLostDirectRelation();
             return(true);
         }
     }
     return(false);
 }
Exemplo n.º 4
0
 public static IEnumerable <PawnRelationDef> GetRelations(this Pawn me, Pawn other)
 {
     if (me != other && me.RaceProps.IsFlesh && other.RaceProps.IsFlesh && me.relations.RelatedToAnyoneOrAnyoneRelatedToMe && other.relations.RelatedToAnyoneOrAnyoneRelatedToMe)
     {
         try
         {
             bool anyNonKinFamilyByBloodRelation = false;
             List <PawnRelationDef> defs         = DefDatabase <PawnRelationDef> .AllDefsListForReading;
             int i = 0;
             for (int count = defs.Count; i < count; i++)
             {
                 PawnRelationDef pawnRelationDef = defs[i];
                 if (pawnRelationDef != PawnRelationDefOf.Kin && pawnRelationDef.Worker.InRelation(me, other))
                 {
                     if (pawnRelationDef.familyByBloodRelation)
                     {
                         anyNonKinFamilyByBloodRelation = true;
                     }
                     yield return(pawnRelationDef);
                 }
             }
             if (!anyNonKinFamilyByBloodRelation && PawnRelationDefOf.Kin.Worker.InRelation(me, other))
             {
                 yield return(PawnRelationDefOf.Kin);
             }
         }
         finally
         {
         }
     }
 }
 public void RemoveDirectRelation(PawnRelationDef def, Pawn otherPawn)
 {
     if (!this.TryRemoveDirectRelation(def, otherPawn))
     {
         Log.Warning("Could not remove relation " + def + " because it's not here. pawn=" + this.pawn + ", otherPawn=" + otherPawn);
     }
 }
 public void AddDirectRelation(PawnRelationDef def, Pawn otherPawn)
 {
     if (def.implied)
     {
         Log.Warning("Tried to directly add implied pawn relation " + def + ", pawn=" + this.pawn + ", otherPawn=" + otherPawn);
     }
     else if (otherPawn == this.pawn)
     {
         Log.Warning("Tried to add pawn relation " + def + " with self, pawn=" + this.pawn);
     }
     else if (this.DirectRelationExists(def, otherPawn))
     {
         Log.Warning("Tried to add the same relation twice: " + def + ", pawn=" + this.pawn + ", otherPawn=" + otherPawn);
     }
     else
     {
         int startTicks = (Current.ProgramState == ProgramState.Playing) ? Find.TickManager.TicksGame : 0;
         this.directRelations.Add(new DirectPawnRelation(def, otherPawn, startTicks));
         otherPawn.relations.pawnsWithDirectRelationsWithMe.Add(this.pawn);
         if (def.reflexive)
         {
             otherPawn.relations.directRelations.Add(new DirectPawnRelation(def, this.pawn, startTicks));
             this.pawnsWithDirectRelationsWithMe.Add(otherPawn);
         }
         this.GainedOrLostDirectRelation();
         otherPawn.relations.GainedOrLostDirectRelation();
     }
 }
        public static Pawn GetMostImportantColonyRelative(Pawn pawn)
        {
            if (pawn.relations == null || !pawn.relations.RelatedToAnyoneOrAnyoneRelatedToMe)
            {
                return(null);
            }
            IEnumerable <Pawn> enumerable = from x in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonistsAndPrisoners
                                            where x.relations.everSeenByPlayer
                                            select x;
            float num   = 0f;
            Pawn  pawn2 = null;

            foreach (Pawn current in enumerable)
            {
                PawnRelationDef mostImportantRelation = pawn.GetMostImportantRelation(current);
                if (mostImportantRelation != null)
                {
                    if (pawn2 == null || mostImportantRelation.importance > num)
                    {
                        num   = mostImportantRelation.importance;
                        pawn2 = current;
                    }
                }
            }
            return(pawn2);
        }
 public bool TryRemoveDirectRelation(PawnRelationDef def, Pawn otherPawn)
 {
     if (def.implied)
     {
         Log.Warning(string.Concat("Tried to remove implied pawn relation ", def, ", pawn=", pawn, ", otherPawn=", otherPawn));
         return(false);
     }
     for (int i = 0; i < directRelations.Count; i++)
     {
         if (directRelations[i].def != def || directRelations[i].otherPawn != otherPawn)
         {
             continue;
         }
         if (def.reflexive)
         {
             List <DirectPawnRelation> list = otherPawn.relations.directRelations;
             DirectPawnRelation        item = list.Find((DirectPawnRelation x) => x.def == def && x.otherPawn == pawn);
             list.Remove(item);
             if (list.Find((DirectPawnRelation x) => x.otherPawn == pawn) == null)
             {
                 pawnsWithDirectRelationsWithMe.Remove(otherPawn);
             }
         }
         directRelations.RemoveAt(i);
         if (directRelations.Find((DirectPawnRelation x) => x.otherPawn == otherPawn) == null)
         {
             otherPawn.relations.pawnsWithDirectRelationsWithMe.Remove(pawn);
         }
         GainedOrLostDirectRelation();
         otherPawn.relations.GainedOrLostDirectRelation();
         return(true);
     }
     return(false);
 }
Exemplo n.º 9
0
 public static bool IsExLovePartnerRelation(PawnRelationDef relation)
 {
     if (relation != PawnRelationDefOf.ExLover)
     {
         return(relation == PawnRelationDefOf.ExSpouse);
     }
     return(true);
 }
Exemplo n.º 10
0
 public static bool IsLovePartnerRelation(PawnRelationDef relation)
 {
     if (relation != PawnRelationDefOf.Lover && relation != PawnRelationDefOf.Fiance)
     {
         return(relation == PawnRelationDefOf.Spouse);
     }
     return(true);
 }
 public DirectPawnRelation GetDirectRelation(PawnRelationDef def, Pawn otherPawn)
 {
     if (def.implied)
     {
         Log.Warning(def + " is not a direct relation.");
         return(null);
     }
     return(this.directRelations.Find((DirectPawnRelation x) => x.def == def && x.otherPawn == otherPawn));
 }
Exemplo n.º 12
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            int tile;

            if (!this.TryFindTile(out tile))
            {
                return(false);
            }
            Site site = SiteMaker.TryMakeSite_SingleSitePart(SiteCoreDefOf.DownedRefugee, (!Rand.Chance(0.3f)) ? "DownedRefugeeQuestThreat" : null, tile, null, true, null, true, null);

            if (site == null)
            {
                return(false);
            }
            site.sitePartsKnown = true;
            Pawn pawn = DownedRefugeeQuestUtility.GenerateRefugee(tile);

            site.GetComponent <DownedRefugeeComp>().pawn.TryAdd(pawn, true);
            int randomInRange = SiteTuning.QuestSiteRefugeeTimeoutDaysRange.RandomInRange;

            site.GetComponent <TimeoutComp>().StartTimeout(randomInRange * 60000);
            Find.WorldObjects.Add(site);
            string text  = this.def.letterLabel;
            string text2 = string.Format(this.def.letterText.AdjustedFor(pawn, "PAWN"), new object[]
            {
                randomInRange,
                pawn.ageTracker.AgeBiologicalYears,
                pawn.story.Title,
                SitePartUtility.GetDescriptionDialogue(site, site.parts.FirstOrDefault <SitePart>())
            }).CapitalizeFirst();
            Pawn mostImportantColonyRelative = PawnRelationUtility.GetMostImportantColonyRelative(pawn);

            if (mostImportantColonyRelative != null)
            {
                PawnRelationDef mostImportantRelation = mostImportantColonyRelative.GetMostImportantRelation(pawn);
                if (mostImportantRelation != null && mostImportantRelation.opinionOffset > 0)
                {
                    pawn.relations.relativeInvolvedInRescueQuest = mostImportantColonyRelative;
                    text2 = text2 + "\n\n" + "RelatedPawnInvolvedInQuest".Translate(new object[]
                    {
                        mostImportantColonyRelative.LabelShort,
                        mostImportantRelation.GetGenderSpecificLabel(pawn)
                    }).AdjustedFor(pawn, "PAWN");
                }
                else
                {
                    PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text2, pawn);
                }
                text = text + " " + "RelationshipAppendedLetterSuffix".Translate();
            }
            if (pawn.relations != null)
            {
                pawn.relations.everSeenByPlayer = true;
            }
            Find.LetterStack.ReceiveLetter(text, text2, this.def.letterDef, site, null, null);
            return(true);
        }
Exemplo n.º 13
0
        public static void Notify_PawnsSeenByPlayer(IEnumerable <Pawn> seenPawns, out string pawnRelationsInfo, bool informEvenIfSeenBefore = false, bool writeSeenPawnsNames = true)
        {
            StringBuilder      stringBuilder = new StringBuilder();
            IEnumerable <Pawn> enumerable    = from x in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonistsAndPrisoners
                                               where x.relations.everSeenByPlayer
                                               select x;
            bool flag = false;

            foreach (Pawn pawn in seenPawns)
            {
                if (pawn.RaceProps.IsFlesh)
                {
                    if (informEvenIfSeenBefore || !pawn.relations.everSeenByPlayer)
                    {
                        pawn.relations.everSeenByPlayer = true;
                        bool flag2 = false;
                        foreach (Pawn pawn2 in enumerable)
                        {
                            if (pawn != pawn2)
                            {
                                PawnRelationDef mostImportantRelation = pawn2.GetMostImportantRelation(pawn);
                                if (mostImportantRelation != null)
                                {
                                    if (!flag2)
                                    {
                                        flag2 = true;
                                        if (flag)
                                        {
                                            stringBuilder.AppendLine();
                                        }
                                        if (writeSeenPawnsNames)
                                        {
                                            stringBuilder.AppendLine(pawn.KindLabel.CapitalizeFirst() + " " + pawn.LabelShort + ":");
                                        }
                                    }
                                    flag = true;
                                    stringBuilder.AppendLine("  " + "Relationship".Translate(new object[]
                                    {
                                        mostImportantRelation.GetGenderSpecificLabelCap(pawn),
                                        pawn2.KindLabel + " " + pawn2.LabelShort
                                    }));
                                }
                            }
                        }
                    }
                }
            }
            if (flag)
            {
                pawnRelationsInfo = stringBuilder.ToString().TrimEndNewlines();
            }
            else
            {
                pawnRelationsInfo = null;
            }
        }
        public static PawnRelationDef GetMostImportantRelation(this Pawn me, Pawn other)
        {
            PawnRelationDef pawnRelationDef = null;

            foreach (PawnRelationDef relation in me.GetRelations(other))
            {
                if (pawnRelationDef == null || relation.importance > pawnRelationDef.importance)
                {
                    pawnRelationDef = relation;
                }
            }
            return(pawnRelationDef);
        }
Exemplo n.º 15
0
        public void AddDirectRelation(PawnRelationDef def, Pawn otherPawn)
        {
            if (def.implied)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Tried to directly add implied pawn relation ",
                    def,
                    ", pawn=",
                    this.pawn,
                    ", otherPawn=",
                    otherPawn
                }), false);
                return;
            }
            if (otherPawn == this.pawn)
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Tried to add pawn relation ",
                    def,
                    " with self, pawn=",
                    this.pawn
                }), false);
                return;
            }
            if (this.DirectRelationExists(def, otherPawn))
            {
                Log.Warning(string.Concat(new object[]
                {
                    "Tried to add the same relation twice: ",
                    def,
                    ", pawn=",
                    this.pawn,
                    ", otherPawn=",
                    otherPawn
                }), false);
                return;
            }
            int startTicks = (Current.ProgramState != ProgramState.Playing) ? 0 : Find.TickManager.TicksGame;

            this.directRelations.Add(new DirectPawnRelation(def, otherPawn, startTicks));
            otherPawn.relations.pawnsWithDirectRelationsWithMe.Add(this.pawn);
            if (def.reflexive)
            {
                otherPawn.relations.directRelations.Add(new DirectPawnRelation(def, this.pawn, startTicks));
                this.pawnsWithDirectRelationsWithMe.Add(otherPawn);
            }
            this.GainedOrLostDirectRelation();
            otherPawn.relations.GainedOrLostDirectRelation();
        }
        public static void Notify_PawnsSeenByPlayer(IEnumerable <Pawn> seenPawns, out string pawnRelationsInfo, bool informEvenIfSeenBefore = false, bool writeSeenPawnsNames = true)
        {
            StringBuilder      stringBuilder = new StringBuilder();
            IEnumerable <Pawn> enumerable    = PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonistsAndPrisoners.Where((Pawn x) => x.relations.everSeenByPlayer);
            bool flag = false;

            foreach (Pawn seenPawn in seenPawns)
            {
                if (!seenPawn.RaceProps.IsFlesh || (!informEvenIfSeenBefore && seenPawn.relations.everSeenByPlayer))
                {
                    continue;
                }
                seenPawn.relations.everSeenByPlayer = true;
                bool flag2 = false;
                foreach (Pawn item in enumerable)
                {
                    if (seenPawn == item)
                    {
                        continue;
                    }
                    PawnRelationDef mostImportantRelation = item.GetMostImportantRelation(seenPawn);
                    if (mostImportantRelation == null)
                    {
                        continue;
                    }
                    if (!flag2)
                    {
                        flag2 = true;
                        if (flag)
                        {
                            stringBuilder.AppendLine();
                        }
                        if (writeSeenPawnsNames)
                        {
                            stringBuilder.AppendLine(seenPawn.KindLabel.CapitalizeFirst() + " " + seenPawn.NameShortColored.Resolve() + ":");
                        }
                    }
                    flag = true;
                    stringBuilder.AppendLine("  - " + "Relationship".Translate(mostImportantRelation.GetGenderSpecificLabelCap(seenPawn), item.KindLabel + " " + item.NameShortColored.Resolve(), item));
                }
            }
            if (flag)
            {
                pawnRelationsInfo = stringBuilder.ToString().TrimEndNewlines();
            }
            else
            {
                pawnRelationsInfo = null;
            }
        }
Exemplo n.º 17
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            int tile;

            if (!this.TryFindTile(out tile))
            {
                return(false);
            }
            Site site = SiteMaker.TryMakeSite_SingleSitePart(SiteCoreDefOf.DownedRefugee, (!Rand.Chance(0.3f)) ? IncidentWorker_QuestDownedRefugee.DownedRefugeeQuestThreatTag : null, null, true, null);

            if (site == null)
            {
                return(false);
            }
            site.Tile = tile;
            Pawn pawn = DownedRefugeeQuestUtility.GenerateRefugee(tile);

            site.GetComponent <DownedRefugeeComp>().pawn.TryAdd(pawn, true);
            int randomInRange = IncidentWorker_QuestDownedRefugee.TimeoutDaysRange.RandomInRange;

            site.GetComponent <TimeoutComp>().StartTimeout(randomInRange * 60000);
            Find.WorldObjects.Add(site);
            string text = string.Format(this.def.letterText.AdjustedFor(pawn), pawn.Label, randomInRange).CapitalizeFirst();
            Pawn   mostImportantColonyRelative = PawnRelationUtility.GetMostImportantColonyRelative(pawn);

            if (mostImportantColonyRelative != null)
            {
                PawnRelationDef mostImportantRelation = mostImportantColonyRelative.GetMostImportantRelation(pawn);
                if (mostImportantRelation != null && mostImportantRelation.opinionOffset > 0)
                {
                    pawn.relations.relativeInvolvedInRescueQuest = mostImportantColonyRelative;
                    text = text + "\n\n" + "RelatedPawnInvolvedInQuest".Translate(new object[]
                    {
                        mostImportantColonyRelative.LabelShort,
                        mostImportantRelation.GetGenderSpecificLabel(pawn)
                    }).AdjustedFor(pawn);
                }
                else
                {
                    PawnRelationUtility.TryAppendRelationsWithColonistsInfo(ref text, pawn);
                }
            }
            if (pawn.relations != null)
            {
                pawn.relations.everSeenByPlayer = true;
            }
            Find.LetterStack.ReceiveLetter(this.def.letterLabel, text, this.def.letterDef, site, null);
            return(true);
        }
Exemplo n.º 18
0
 public void RemoveDirectRelation(PawnRelationDef def, Pawn otherPawn)
 {
     if (!this.TryRemoveDirectRelation(def, otherPawn))
     {
         Log.Warning(string.Concat(new object[]
         {
             "Could not remove relation ",
             def,
             " because it's not here. pawn=",
             this.pawn,
             ", otherPawn=",
             otherPawn
         }), false);
     }
 }
 public void Notify_PawnSold(Pawn playerNegotiator)
 {
     foreach (Pawn potentiallyRelatedPawn in this.PotentiallyRelatedPawns)
     {
         if (!potentiallyRelatedPawn.Dead && potentiallyRelatedPawn.needs.mood != null)
         {
             PawnRelationDef mostImportantRelation = potentiallyRelatedPawn.GetMostImportantRelation(this.pawn);
             if (mostImportantRelation != null && mostImportantRelation.soldThought != null)
             {
                 potentiallyRelatedPawn.needs.mood.thoughts.memories.TryGainMemory(mostImportantRelation.soldThought, playerNegotiator);
             }
         }
     }
     this.RemoveMySpouseMarriageRelatedThoughts();
 }
        public void AddDirectRelation(PawnRelationDef def, Pawn otherPawn)
        {
            if (def.implied)
            {
                Log.Warning(string.Concat("Tried to directly add implied pawn relation ", def, ", pawn=", pawn, ", otherPawn=", otherPawn));
                return;
            }
            if (otherPawn == pawn)
            {
                Log.Warning(string.Concat("Tried to add pawn relation ", def, " with self, pawn=", pawn));
                return;
            }
            if (DirectRelationExists(def, otherPawn))
            {
                Log.Warning(string.Concat("Tried to add the same relation twice: ", def, ", pawn=", pawn, ", otherPawn=", otherPawn));
                return;
            }
            int startTicks = ((Current.ProgramState == ProgramState.Playing) ? Find.TickManager.TicksGame : 0);

            def.Worker.OnRelationCreated(pawn, otherPawn);
            directRelations.Add(new DirectPawnRelation(def, otherPawn, startTicks));
            otherPawn.relations.pawnsWithDirectRelationsWithMe.Add(pawn);
            if (def.reflexive)
            {
                otherPawn.relations.directRelations.Add(new DirectPawnRelation(def, pawn, startTicks));
                pawnsWithDirectRelationsWithMe.Add(otherPawn);
            }
            GainedOrLostDirectRelation();
            otherPawn.relations.GainedOrLostDirectRelation();
            if (Current.ProgramState != ProgramState.Playing)
            {
                return;
            }
            if (!pawn.Dead && pawn.health != null)
            {
                for (int num = pawn.health.hediffSet.hediffs.Count - 1; num >= 0; num--)
                {
                    pawn.health.hediffSet.hediffs[num].Notify_RelationAdded(otherPawn, def);
                }
            }
            if (!otherPawn.Dead && otherPawn.health != null)
            {
                for (int num2 = otherPawn.health.hediffSet.hediffs.Count - 1; num2 >= 0; num2--)
                {
                    otherPawn.health.hediffSet.hediffs[num2].Notify_RelationAdded(pawn, def);
                }
            }
        }
 public bool DirectRelationExists(PawnRelationDef def, Pawn otherPawn)
 {
     if (def.implied)
     {
         Log.Warning(def + " is not a direct relation.");
         return(false);
     }
     for (int i = 0; i < this.directRelations.Count; i++)
     {
         DirectPawnRelation directPawnRelation = this.directRelations[i];
         if (directPawnRelation.def == def && directPawnRelation.otherPawn == otherPawn)
         {
             return(true);
         }
     }
     return(false);
 }
 public Pawn GetFirstDirectRelationPawn(PawnRelationDef def, Predicate <Pawn> predicate = null)
 {
     if (def.implied)
     {
         Log.Warning(def + " is not a direct relation.");
         return(null);
     }
     for (int i = 0; i < this.directRelations.Count; i++)
     {
         DirectPawnRelation directPawnRelation = this.directRelations[i];
         if (directPawnRelation.def == def && (predicate == null || predicate(directPawnRelation.otherPawn)))
         {
             return(directPawnRelation.otherPawn);
         }
     }
     return(null);
 }
Exemplo n.º 23
0
 public static IEnumerable <PawnRelationDef> GetRelations(this Pawn me, Pawn other)
 {
     if (me == other)
     {
         yield break;
     }
     if (!me.RaceProps.IsFlesh || !other.RaceProps.IsFlesh)
     {
         yield break;
     }
     if (!me.relations.RelatedToAnyoneOrAnyoneRelatedToMe || !other.relations.RelatedToAnyoneOrAnyoneRelatedToMe)
     {
         yield break;
     }
     try
     {
         bool anyNonKinFamilyByBloodRelation = false;
         List <PawnRelationDef> defs         = DefDatabase <PawnRelationDef> .AllDefsListForReading;
         int i     = 0;
         int count = defs.Count;
         while (i < count)
         {
             PawnRelationDef def = defs[i];
             if (def != PawnRelationDefOf.Kin)
             {
                 if (def.Worker.InRelation(me, other))
                 {
                     if (def.familyByBloodRelation)
                     {
                         anyNonKinFamilyByBloodRelation = true;
                     }
                     yield return(def);
                 }
             }
             i++;
         }
         if (!anyNonKinFamilyByBloodRelation && PawnRelationDefOf.Kin.Worker.InRelation(me, other))
         {
             yield return(PawnRelationDefOf.Kin);
         }
     }
     finally
     {
     }
     yield break;
 }
        public static Pawn GetMostImportantColonyRelative(Pawn pawn)
        {
            IEnumerable <Pawn> enumerable = from x in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_FreeColonistsAndPrisoners
                                            where x.relations.everSeenByPlayer
                                            select x;
            float num   = 0f;
            Pawn  pawn2 = null;

            foreach (Pawn item in enumerable)
            {
                PawnRelationDef mostImportantRelation = pawn.GetMostImportantRelation(item);
                if (mostImportantRelation != null && (pawn2 == null || mostImportantRelation.importance > num))
                {
                    num   = mostImportantRelation.importance;
                    pawn2 = item;
                }
            }
            return(pawn2);
        }
Exemplo n.º 25
0
        public static Pawn GetMostImportantColonyRelative(Pawn pawn)
        {
            if (pawn.relations == null || !pawn.relations.RelatedToAnyoneOrAnyoneRelatedToMe)
            {
                return(null);
            }
            IEnumerable <Pawn> enumerable = PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive_FreeColonistsAndPrisoners.Where((Pawn x) => x.relations.everSeenByPlayer);
            float num   = 0f;
            Pawn  pawn2 = null;

            foreach (Pawn item in enumerable)
            {
                PawnRelationDef mostImportantRelation = pawn.GetMostImportantRelation(item);
                if (mostImportantRelation != null && (pawn2 == null || mostImportantRelation.importance > num))
                {
                    num   = mostImportantRelation.importance;
                    pawn2 = item;
                }
            }
            return(pawn2);
        }
        public static IEnumerable <PawnRelationDef> GetRelations(this Pawn me, Pawn other)
        {
            if (me != other && me.RaceProps.IsFlesh && other.RaceProps.IsFlesh && me.relations.RelatedToAnyoneOrAnyoneRelatedToMe && other.relations.RelatedToAnyoneOrAnyoneRelatedToMe)
            {
                try
                {
                    bool anyNonKinFamilyByBloodRelation = false;
                    List <PawnRelationDef> defs         = DefDatabase <PawnRelationDef> .AllDefsListForReading;
                    int i     = 0;
                    int count = defs.Count;
                    for (; i < count; i++)
                    {
                        PawnRelationDef def = defs[i];
                        if (def != PawnRelationDefOf.Kin && def.Worker.InRelation(me, other))
                        {
                            if (!def.familyByBloodRelation)
                            {
                                ;
                            }
                            yield return(def);

                            /*Error: Unable to find new state assignment for yield return*/;
                        }
                    }
                    if (!anyNonKinFamilyByBloodRelation && PawnRelationDefOf.Kin.Worker.InRelation(me, other))
                    {
                        yield return(PawnRelationDefOf.Kin);

                        /*Error: Unable to find new state assignment for yield return*/;
                    }
                }
                finally
                {
                    ((_003CGetRelations_003Ec__Iterator0) /*Error near IL_01d7: stateMachine*/)._003C_003E__Finally0();
                }
            }
            yield break;
IL_01e7:
            /*Error near IL_01e8: Unexpected return in MoveNext()*/;
        }
Exemplo n.º 27
0
 public void Notify_PawnSold(Pawn playerNegotiator)
 {
     foreach (Pawn potentiallyRelatedPawn in PotentiallyRelatedPawns)
     {
         if (!potentiallyRelatedPawn.Dead && potentiallyRelatedPawn.needs.mood != null)
         {
             PawnRelationDef mostImportantRelation = potentiallyRelatedPawn.GetMostImportantRelation(pawn);
             if (mostImportantRelation != null && mostImportantRelation.soldThoughts != null)
             {
                 if (mostImportantRelation == PawnRelationDefOf.Bond)
                 {
                     pawn.relations.RemoveDirectRelation(mostImportantRelation, potentiallyRelatedPawn);
                 }
                 foreach (ThoughtDef soldThought in mostImportantRelation.soldThoughts)
                 {
                     potentiallyRelatedPawn.needs.mood.thoughts.memories.TryGainMemory(soldThought, playerNegotiator);
                 }
             }
         }
     }
     RemoveMySpouseMarriageRelatedThoughts();
 }
Exemplo n.º 28
0
        private static string GetRelationsString(CachedSocialTabEntry entry, Pawn selPawnForSocialInfo)
        {
            string text = "";

            if (entry.relations.Count == 0)
            {
                if (entry.opinionOfOtherPawn < -20)
                {
                    return("Rival".Translate());
                }
                if (entry.opinionOfOtherPawn > 20)
                {
                    return("Friend".Translate());
                }
                return("Acquaintance".Translate());
            }
            for (int i = 0; i < entry.relations.Count; i++)
            {
                PawnRelationDef pawnRelationDef = entry.relations[i];
                text = (text.NullOrEmpty() ? pawnRelationDef.GetGenderSpecificLabelCap(entry.otherPawn) : (text + ", " + pawnRelationDef.GetGenderSpecificLabel(entry.otherPawn)));
            }
            return(text);
        }
Exemplo n.º 29
0
        private static void AppendThoughts_Relations(Pawn victim, DamageInfo?dinfo, PawnDiedOrDownedThoughtsKind thoughtsKind, List <IndividualThoughtToAdd> outIndividualThoughts, List <ThoughtToAddToAll> 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.needs != null && 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));
                    }
                }
            }
            if (thoughtsKind != 0 && thoughtsKind != PawnDiedOrDownedThoughtsKind.BanishedToDie && thoughtsKind != PawnDiedOrDownedThoughtsKind.Lost)
            {
                return;
            }
            bool flag = thoughtsKind == PawnDiedOrDownedThoughtsKind.Lost;

            foreach (Pawn potentiallyRelatedPawn in victim.relations.PotentiallyRelatedPawns)
            {
                if (potentiallyRelatedPawn.needs == null || potentiallyRelatedPawn.needs.mood == null || !PawnUtility.ShouldGetThoughtAbout(potentiallyRelatedPawn, victim))
                {
                    continue;
                }
                PawnRelationDef mostImportantRelation = potentiallyRelatedPawn.GetMostImportantRelation(victim);
                if (mostImportantRelation != null)
                {
                    ThoughtDef thoughtDef = (flag ? mostImportantRelation.GetGenderSpecificLostThought(victim) : mostImportantRelation.GetGenderSpecificDiedThought(victim));
                    if (thoughtDef != null)
                    {
                        outIndividualThoughts.Add(new IndividualThoughtToAdd(thoughtDef, potentiallyRelatedPawn, victim));
                    }
                }
            }
            if (dinfo.HasValue && thoughtsKind != PawnDiedOrDownedThoughtsKind.Lost)
            {
                Pawn pawn = dinfo.Value.Instigator as Pawn;
                if (pawn != null && pawn != victim)
                {
                    foreach (Pawn potentiallyRelatedPawn2 in victim.relations.PotentiallyRelatedPawns)
                    {
                        if (pawn == potentiallyRelatedPawn2 || potentiallyRelatedPawn2.needs == null || potentiallyRelatedPawn2.needs.mood == null)
                        {
                            continue;
                        }
                        PawnRelationDef mostImportantRelation2 = potentiallyRelatedPawn2.GetMostImportantRelation(victim);
                        if (mostImportantRelation2 != null)
                        {
                            ThoughtDef genderSpecificKilledThought = mostImportantRelation2.GetGenderSpecificKilledThought(victim);
                            if (genderSpecificKilledThought != null)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(genderSpecificKilledThought, potentiallyRelatedPawn2, pawn));
                            }
                        }
                        if (potentiallyRelatedPawn2.RaceProps.IsFlesh)
                        {
                            int num = potentiallyRelatedPawn2.relations.OpinionOf(victim);
                            if (num >= 20)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KilledMyFriend, potentiallyRelatedPawn2, pawn, 1f, victim.relations.GetFriendDiedThoughtPowerFactor(num)));
                            }
                            else if (num <= -20)
                            {
                                outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.KilledMyRival, potentiallyRelatedPawn2, pawn, 1f, victim.relations.GetRivalDiedThoughtPowerFactor(num)));
                            }
                        }
                    }
                }
            }
            ThoughtDef thoughtDef2 = ((thoughtsKind == PawnDiedOrDownedThoughtsKind.Lost) ? ThoughtDefOf.PawnWithGoodOpinionLost : ThoughtDefOf.PawnWithGoodOpinionDied);
            ThoughtDef thoughtDef3 = ((thoughtsKind == PawnDiedOrDownedThoughtsKind.Lost) ? ThoughtDefOf.PawnWithBadOpinionLost : ThoughtDefOf.PawnWithBadOpinionDied);

            if (!victim.RaceProps.Humanlike)
            {
                return;
            }
            foreach (Pawn item in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive)
            {
                if (item.needs != null && item.RaceProps.IsFlesh && item.needs.mood != null && PawnUtility.ShouldGetThoughtAbout(item, victim))
                {
                    int num2 = item.relations.OpinionOf(victim);
                    if (num2 >= 20)
                    {
                        outIndividualThoughts.Add(new IndividualThoughtToAdd(thoughtDef2, item, victim, victim.relations.GetFriendDiedThoughtPowerFactor(num2)));
                    }
                    else if (num2 <= -20)
                    {
                        outIndividualThoughts.Add(new IndividualThoughtToAdd(thoughtDef3, item, victim, victim.relations.GetRivalDiedThoughtPowerFactor(num2)));
                    }
                }
            }
        }
 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.needs != null && 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));
             }
         }
     }
     if (thoughtsKind == PawnDiedOrDownedThoughtsKind.Died || thoughtsKind == PawnDiedOrDownedThoughtsKind.BanishedToDie)
     {
         foreach (Pawn potentiallyRelatedPawn in victim.relations.PotentiallyRelatedPawns)
         {
             if (potentiallyRelatedPawn.needs != null && 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));
                     }
                 }
             }
         }
         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.needs != null && 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));
                             }
                         }
                         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 item in PawnsFinder.AllMapsCaravansAndTravelingTransportPods_Alive)
             {
                 if (item.needs != null && item.RaceProps.IsFlesh && item.needs.mood != null && PawnUtility.ShouldGetThoughtAbout(item, victim))
                 {
                     int num2 = item.relations.OpinionOf(victim);
                     if (num2 >= 20)
                     {
                         outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.PawnWithGoodOpinionDied, item, victim, victim.relations.GetFriendDiedThoughtPowerFactor(num2)));
                     }
                     else if (num2 <= -20)
                     {
                         outIndividualThoughts.Add(new IndividualThoughtToAdd(ThoughtDefOf.PawnWithBadOpinionDied, item, victim, victim.relations.GetRivalDiedThoughtPowerFactor(num2)));
                     }
                 }
             }
         }
     }
 }