コード例 #1
0
        public void OverwritePawn(Pawn pawn)
        {
            var extension = this.def.GetModExtension <StackSavingOptionsModExtension>();

            if (pawn.Faction != this.faction)
            {
                pawn.SetFaction(this.faction);
            }
            if (this.isFactionLeader)
            {
                pawn.Faction.leader = pawn;
            }

            pawn.Name = this.name;
            if (pawn.needs?.mood?.thoughts?.memories?.Memories != null)
            {
                for (int num = pawn.needs.mood.thoughts.memories.Memories.Count - 1; num >= 0; num--)
                {
                    pawn.needs.mood.thoughts.memories.RemoveMemory(pawn.needs.mood.thoughts.memories.Memories[num]);
                }
            }

            if (this.thoughts != null)
            {
                if (this.gender == pawn.gender)
                {
                    this.thoughts.RemoveAll(x => x.def == AlteredCarbonDefOf.AC_WrongGender);
                    this.thoughts.RemoveAll(x => x.def == AlteredCarbonDefOf.AC_WrongGenderDouble);
                }
                if (this.race == pawn.kindDef.race)
                {
                    this.thoughts.RemoveAll(x => x.def == AlteredCarbonDefOf.AC_WrongRace);
                }

                foreach (var thought in this.thoughts)
                {
                    if (thought is Thought_MemorySocial && thought.otherPawn == null)
                    {
                        continue;
                    }
                    pawn.needs.mood.thoughts.memories.TryGainMemory(thought, thought.otherPawn);
                }
            }
            pawn.story.traits.allTraits.RemoveAll(x => !extension.ignoresTraits.Contains(x.def.defName));
            if (this.traits != null)
            {
                foreach (var trait in this.traits)
                {
                    if (extension.ignoresTraits != null && extension.ignoresTraits.Contains(trait.def.defName))
                    {
                        continue;
                    }
                    pawn.story.traits.GainTrait(trait);
                }
            }

            pawn.relations.ClearAllRelations();

            var origPawn = GetOriginalPawn(pawn);

            foreach (var otherPawn in this.relatedPawns)
            {
                if (otherPawn != null)
                {
                    foreach (var rel in otherPawn.relations.DirectRelations)
                    {
                        if (this.name == rel.otherPawn?.Name)
                        {
                            rel.otherPawn = pawn;
                        }
                    }
                }
            }

            foreach (var otherPawn in this.relatedPawns)
            {
                if (otherPawn != null)
                {
                    foreach (var rel in this.relations)
                    {
                        foreach (var rel2 in otherPawn.relations.DirectRelations)
                        {
                            if (rel.def == rel2.def && rel2.otherPawn?.Name == pawn.Name)
                            {
                                rel2.otherPawn = pawn;
                            }
                        }
                    }
                }
            }

            foreach (var rel in this.relations)
            {
                if (rel.otherPawn != null)
                {
                    var oldRelation = rel.otherPawn.relations.DirectRelations.Where(r => r.def == rel.def && r.otherPawn.Name == pawn.Name).FirstOrDefault();
                    if (oldRelation != null)
                    {
                        oldRelation.otherPawn = pawn;
                    }
                }
                pawn.relations.AddDirectRelation(rel.def, rel.otherPawn);
            }

            if (origPawn != null)
            {
                origPawn.relations = new Pawn_RelationsTracker(origPawn);
            }

            pawn.skills.skills.Clear();
            if (this.skills != null)
            {
                foreach (var skill in this.skills)
                {
                    var newSkill = new SkillRecord(pawn, skill.def);
                    newSkill.passion          = skill.passion;
                    newSkill.levelInt         = skill.levelInt;
                    newSkill.xpSinceLastLevel = skill.xpSinceLastLevel;
                    newSkill.xpSinceMidnight  = skill.xpSinceMidnight;
                    pawn.skills.skills.Add(newSkill);
                }
            }
            if (pawn.playerSettings == null)
            {
                pawn.playerSettings = new Pawn_PlayerSettings(pawn);
            }
            pawn.playerSettings.hostilityResponse = (HostilityResponseMode)this.hostilityMode;

            Backstory newChildhood = null;

            BackstoryDatabase.TryGetWithIdentifier(this.childhood, out newChildhood, true);
            pawn.story.childhood = newChildhood;
            if (this.adulthood?.Length > 0)
            {
                Backstory newAdulthood = null;
                BackstoryDatabase.TryGetWithIdentifier(this.adulthood, out newAdulthood, true);
                pawn.story.adulthood = newAdulthood;
            }
            else
            {
                pawn.story.adulthood = null;
            }
            if (pawn.workSettings == null)
            {
                pawn.workSettings = new Pawn_WorkSettings();
            }
            pawn.Notify_DisabledWorkTypesChanged();
            if (priorities != null)
            {
                foreach (var priority in priorities)
                {
                    pawn.workSettings.SetPriority(priority.Key, priority.Value);
                }
            }
            pawn.playerSettings.AreaRestriction = this.areaRestriction;
            pawn.playerSettings.medCare         = this.medicalCareCategory;
            pawn.playerSettings.selfTend        = this.selfTend;
            if (pawn.foodRestriction == null)
            {
                pawn.foodRestriction = new Pawn_FoodRestrictionTracker();
            }
            pawn.foodRestriction.CurrentFoodRestriction = this.foodRestriction;
            if (pawn.outfits == null)
            {
                pawn.outfits = new Pawn_OutfitTracker();
            }
            pawn.outfits.CurrentOutfit = this.outfit;
            if (pawn.drugs == null)
            {
                pawn.drugs = new Pawn_DrugPolicyTracker();
            }
            pawn.drugs.CurrentPolicy = this.drugPolicy;
            pawn.ageTracker.AgeChronologicalTicks = this.ageChronologicalTicks;
            if (pawn.timetable == null)
            {
                pawn.timetable = new Pawn_TimetableTracker(pawn);
            }
            if (this.times != null)
            {
                pawn.timetable.times = this.times;
            }
            if (pawn.gender != this.gender)
            {
                if (pawn.story.traits.HasTrait(TraitDefOf.BodyPurist))
                {
                    pawn.needs.mood.thoughts.memories.TryGainMemory(AlteredCarbonDefOf.AC_WrongGenderDouble);
                }
                else
                {
                    pawn.needs.mood.thoughts.memories.TryGainMemory(AlteredCarbonDefOf.AC_WrongGender);
                }
            }

            if (pawn.kindDef.race != this.race)
            {
                pawn.needs.mood.thoughts.memories.TryGainMemory(AlteredCarbonDefOf.AC_WrongRace);
            }
            if (ModLister.RoyaltyInstalled)
            {
                if (pawn.royalty == null)
                {
                    pawn.royalty = new Pawn_RoyaltyTracker(pawn);
                }
                if (this.royalTitles != null)
                {
                    foreach (var title in this.royalTitles)
                    {
                        pawn.royalty.SetTitle(title.faction, title.def, false, false, false);
                    }
                }
                if (this.heirs != null)
                {
                    foreach (var heir in this.heirs)
                    {
                        pawn.royalty.SetHeir(heir.Value, heir.Key);
                    }
                }

                if (this.favor != null)
                {
                    foreach (var fav in this.favor)
                    {
                        pawn.royalty.SetFavor(fav.Key, fav.Value);
                    }
                }

                if (this.bondedThings != null)
                {
                    foreach (var bonded in this.bondedThings)
                    {
                        var comp = bonded.TryGetComp <CompBladelinkWeapon>();
                        if (comp != null)
                        {
                            comp.bondedPawn = pawn;
                        }
                    }
                }
                if (this.factionPermits != null)
                {
                    Traverse.Create(pawn.royalty).Field("factionPermits").SetValue(this.factionPermits);
                }
                if (this.permitPoints != null)
                {
                    Traverse.Create(pawn.royalty).Field("permitPoints").SetValue(this.permitPoints);
                }
            }
            if (ModCompatibility.IndividualityIsActive)
            {
                ModCompatibility.SetSyrTraitsSexuality(pawn, this.sexuality);
                ModCompatibility.SetSyrTraitsRomanceFactor(pawn, this.romanceFactor);
            }

            if (ModCompatibility.PsychologyIsActive)
            {
                ModCompatibility.SetPsychologyData(pawn, this.psychologyData);
            }
        }