예제 #1
0
        public static void SetFieldsToAlienComp(Pawn pawn, GenomeSequence genomeSequence)
        {
            AlienComp alienComp = pawn.TryGetComp <AlienComp>();

            if (alienComp != null)
            {
                alienComp.skinColor       = genomeSequence.skinColor;
                alienComp.skinColorSecond = genomeSequence.skinColorSecond;
                alienComp.hairColorSecond = genomeSequence.hairColorSecond;
                alienComp.crownType       = genomeSequence.crownTypeAlien;
            }
        }
예제 #2
0
        public static void GetFieldsFromAlienComp(Pawn pawn, GenomeSequence genomeSequence)
        {
            AlienComp alienComp = pawn.TryGetComp <AlienComp>();

            if (alienComp != null)
            {
                genomeSequence.isAlien         = true;
                genomeSequence.skinColor       = alienComp.skinColor;
                genomeSequence.skinColorSecond = alienComp.skinColorSecond;
                genomeSequence.hairColorSecond = alienComp.hairColorSecond;
                genomeSequence.crownTypeAlien  = alienComp.crownType;
            }
        }
예제 #3
0
        public static Thing MakeGenomeSequence(Pawn pawn, ThingDef genomeDef)
        {
            Thing          genomeThing    = ThingMaker.MakeThing(genomeDef);
            GenomeSequence genomeSequence = genomeThing as GenomeSequence;

            if (genomeSequence != null)
            {
                //Standard.
                genomeSequence.sourceName = pawn?.Name?.ToStringFull ?? null;

                genomeSequence.pawnName = pawn.Name as NameTriple;

                if (genomeSequence.sourceName == null)
                {
                    genomeSequence.sourceName = pawn.def.LabelCap;
                }
                genomeSequence.pawnKindDef = pawn.kindDef;
                genomeSequence.gender      = pawn.gender;

                //Humanoid only.
                Pawn_StoryTracker story = pawn.story;
                if (story != null)
                {
                    genomeSequence.bodyType    = story.bodyType;
                    genomeSequence.crownType   = story.crownType;
                    genomeSequence.hairColor   = story.hairColor;
                    genomeSequence.skinMelanin = story.melanin;

                    foreach (Trait trait in story.traits.allTraits)
                    {
                        genomeSequence.traits.Add(new ExposedTraitEntry(trait));
                    }
                }

                //Alien Races compatibility.
                if (CompatibilityTracker.AlienRacesActive)
                {
                    AlienRaceCompat.GetFieldsFromAlienComp(pawn, genomeSequence);
                }
            }

            return(genomeThing);
        }
예제 #4
0
        public static void Notify_PawnDiedPostfix(Pawn victim)
        {
            RaceProperties raceProps       = victim.RaceProps;
            var            pawnIsImplanted = victim.health?.hediffSet?.GetFirstHediffOfDef(QEHediffDefOf.Clonebay_Implant);

            if (raceProps.Humanlike && victim.IsColonist && pawnIsImplanted != null)
            {
                Thing genomeSequence = GenomeUtility.MakeGenomeSequence(victim, QEThingDefOf.Clonebay_GenomeSequencerFilled);
                if (genomeSequence == null)
                {
                    Log.Warning("CloneBay: Failed to create a new genomesequence");
                    return;
                }
                GenomeSequence genome = genomeSequence as GenomeSequence;

                IntVec3 cell = victim.Position;

                victim.equipment.DropAllEquipment(cell);
                victim.apparel.DropAll(cell);
                victim.inventory.DropAllNearPawn(cell);

                Pawn prevPawn = victim as Pawn;

                foreach (Building_PawnVatGrower vatToUse in victim.Map.listerBuildings.AllBuildingsColonistOfClass <Building_PawnVatGrower>())
                {
                    if (vatToUse.status != CrafterStatus.Crafting)
                    {
                        float fuel = vatToUse.TryGetComp <CompRefuelable>().Fuel;
                        if (fuel > 99)
                        {
                            vatToUse.Notify_CraftingStarted(genome, prevPawn, cell);
                            vatToUse.TryGetComp <CompRefuelable>().ConsumeFuel(100);
                        }
                        break;
                    }
                }
            }
        }
예제 #5
0
        public static Pawn MakePawnFromGenomeSequence(GenomeSequence genomeSequence)
        {
            //int adultAge = (int)genome.pawnKindDef.RaceProps.lifeStageAges.Last().minAge;

            PawnGenerationRequest request = new PawnGenerationRequest(
                genomeSequence.pawnKindDef,
                faction: null,
                forceGenerateNewPawn: true,
                canGeneratePawnRelations: false,
                fixedGender: genomeSequence.gender,
                fixedBiologicalAge: 0,
                fixedChronologicalAge: 0,
                allowFood: false);
            Pawn pawn = PawnGenerator.GeneratePawn(request);

            //No pregenerated equipment.
            pawn?.equipment?.DestroyAllEquipment();
            pawn?.apparel?.DestroyAll();
            pawn?.inventory?.DestroyAll();

            //No pregenerated hediffs.
            pawn.health.hediffSet.Clear();

            //Set name
            pawn.Name = genomeSequence.pawnName;

            //Set everything else.
            if (pawn.story is Pawn_StoryTracker storyTracker)
            {
                storyTracker.hairDef = DefDatabase <HairDef> .GetNamed("Shaved");

                storyTracker.bodyType  = genomeSequence.bodyType;
                storyTracker.crownType = genomeSequence.crownType;
                storyTracker.hairColor = genomeSequence.hairColor;
                storyTracker.melanin   = genomeSequence.skinMelanin;

                storyTracker.traits.allTraits.Clear();
                foreach (ExposedTraitEntry trait in genomeSequence.traits)
                {
                    //storyTracker.traits.GainTrait(new Trait(trait.def, trait.degree));
                    storyTracker.traits.allTraits.Add(new Trait(trait.def, trait.degree));
                    if (pawn.workSettings != null)
                    {
                        pawn.workSettings.Notify_UseWorkPrioritiesChanged();
                    }
                    if (pawn.skills != null)
                    {
                        pawn.skills.Notify_SkillDisablesChanged();
                    }
                    if (!pawn.Dead && pawn.RaceProps.Humanlike)
                    {
                        pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
                    }
                }

                //Give random vatgrown backstory.
                storyTracker.childhood = DefDatabase <BackstoryDef> .GetNamed("Backstory_ColonyVatgrown_Clonebay").GetFromDatabase();

                storyTracker.adulthood = null;

                //Dirty hack ahoy! - No longer needed 1.1
                //AccessTools.Field(typeof(Pawn_StoryTracker), "cachedDisabledWorkTypes").SetValue(storyTracker, null);
                //typeof(Pawn_StoryTracker).GetField("cachedDisabledWorkTypes", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(storyTracker, null);
                //typeof(PawnGenerator).GetMethod("GenerateSkills", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.InvokeMethod).Invoke(null, new object[] { pawn });
            }

            if (pawn.skills is Pawn_SkillTracker skillsTracker)
            {
                foreach (SkillRecord skill in skillsTracker.skills)
                {
                    skill.Level   = 0;
                    skill.passion = Passion.None;
                    skill.Notify_SkillDisablesChanged();
                }


                List <SkillRecord> skillPassions = new List <SkillRecord>();
                int skillsPicked = 0;
                int iterations   = 0;
                //Pick 4 random skills to give minor passions to.
                while (skillsPicked < 4 && iterations < 1000)
                {
                    SkillRecord randomSkill = skillsTracker.skills.RandomElement();
                    if (!skillPassions.Contains(randomSkill))
                    {
                        skillPassions.Add(randomSkill);
                        randomSkill.passion = Passion.Minor;
                        skillsPicked++;
                    }

                    iterations++;
                }

                skillsPicked = 0;
                iterations   = 0;
                //Pick 2 random skills to give major passions to.
                while (skillsPicked < 2 && iterations < 1000)
                {
                    SkillRecord randomSkill = skillsTracker.skills.RandomElement();
                    if (!skillPassions.Contains(randomSkill))
                    {
                        skillPassions.Add(randomSkill);
                        randomSkill.passion = Passion.Major;
                        skillsPicked++;
                    }

                    iterations++;
                }
            }

            if (pawn.workSettings is Pawn_WorkSettings workSettings)
            {
                workSettings.EnableAndInitialize();
            }

            //Alien Races compatibility.
            if (CompatibilityTracker.AlienRacesActive)
            {
                AlienRaceCompat.SetFieldsToAlienComp(pawn, genomeSequence);
            }


            PortraitsCache.SetDirty(pawn);
            PortraitsCache.PortraitsCacheUpdate();

            //Add Hediff marking them as a clone.
            Log.Message("CloneBay: add hediffs");
            pawn.health.AddHediff(QEHediffDefOf.QE_CloneStatus);
            pawn.health.AddHediff(QEHediffDefOf.Clonebay_Implant);
            return(pawn);
        }