Esempio n. 1
0
        public string ResetIncapableOf()
        {
            CustomPawn.ClearCachedDisabledWorkTypes(this.pawn.story);
            List <string> incapableList = new List <string>();

            foreach (var tag in pawn.story.DisabledWorkTags)
            {
                incapableList.Add(WorkTypeDefsUtility.LabelTranslated(tag));
            }
            if (incapableList.Count > 0)
            {
                incapable = string.Join(", ", incapableList.ToArray());
            }
            else
            {
                incapable = null;
            }
            return(incapable);
        }
Esempio n. 2
0
        // Uses the customized settings within the CustomPawn to create a new Pawn.
        public Pawn ConvertToPawn(bool resolveGraphics)
        {
            Pawn result = new Randomizer().GenerateColonist();

            result.gender          = this.pawn.gender;
            result.story.adulthood = Adulthood;
            result.story.childhood = Childhood;
            TraitSet traitSet = new TraitSet(result);

            traitSet.allTraits.Clear();
            foreach (Trait trait in traits)
            {
                if (trait != null)
                {
                    traitSet.allTraits.Add(trait);
                }
            }
            result.story.traits        = traitSet;
            result.story.skinWhiteness = this.pawn.story.skinWhiteness;
            result.story.hairDef       = this.pawn.story.hairDef;
            result.story.hairColor     = colors[PawnLayers.Hair];
            // Need to use reflection to set the private graphic path method.
            typeof(Pawn_StoryTracker).GetField("headGraphicPath", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(result.story, HeadGraphicPath);
            // Clear cached values from the story tracker.
            // TODO: It might make more sense to create a new instance of Pawn_StoryTracker, but need
            // to make sure all of the details are filled in with that approach.
            CustomPawn.ClearCachedDisabledWorkTypes(result.story);

            result.Name = this.pawn.Name;

            result.ageTracker.BirthAbsTicks      = this.pawn.ageTracker.BirthAbsTicks;
            result.ageTracker.AgeBiologicalTicks = this.pawn.ageTracker.AgeBiologicalTicks;

            FieldInfo      wornApparelField = typeof(Pawn_ApparelTracker).GetField("wornApparel", BindingFlags.Instance | BindingFlags.NonPublic);
            List <Apparel> apparel          = (List <Apparel>)wornApparelField.GetValue(result.apparel);

            apparel.Clear();

            AddApparel(result, PawnLayers.Pants);
            AddApparel(result, PawnLayers.BottomClothingLayer);
            AddApparel(result, PawnLayers.MiddleClothingLayer);
            AddApparel(result, PawnLayers.TopClothingLayer);
            AddApparel(result, PawnLayers.Accessory);
            AddApparel(result, PawnLayers.Hat);

            foreach (SkillRecord skill in result.skills.skills)
            {
                int value = this.GetSkillLevel(skill.def);
                if (value < 0)
                {
                    value = 0;
                }
                if (value > 20)
                {
                    value = 20;
                }
                skill.level = value;
                if (!IsSkillDisabled(skill.def))
                {
                    skill.passion          = this.currentPassions[skill.def];
                    skill.xpSinceLastLevel = Rand.Range(skill.XpRequiredForLevelUp * 0.1f, skill.XpRequiredForLevelUp * 0.5f);
                }
                else
                {
                    skill.passion          = Passion.None;
                    skill.xpSinceLastLevel = 0;
                }
            }

            if (resolveGraphics)
            {
                result.Drawer.renderer.graphics.ResolveAllGraphics();
            }

            result.relations.ClearAllRelations();
            ClearCachedDisabledWorkTypes(result.story);

            return(result);
        }