public void AddInitialHybridHediffs(DefExtension_HybridChanceAlterer extension, Pawn pawn)
 {
     foreach (HediffToBodyparts hediffToBodyParts in extension.addedHediffs)
     {
         foreach (BodyPartDef part in hediffToBodyParts.bodyparts)
         {
             if (!pawn.RaceProps.body.GetPartsWithDef(part).EnumerableNullOrEmpty())
             {
                 pawn.health.AddHediff(hediffToBodyParts.hediff, pawn.RaceProps.body.GetPartsWithDef(part).RandomElement());
             }
         }
     }
 }
Beispiel #2
0
        public static PawnKindDef GetHybrid(ThingDef genomeDominant, ThingDef genomeSecondary, ThingDef genoframe, ThingDef booster,
                                            out float swapChance, out float failureChance, out PawnKindDef swapResult, out PawnKindDef failureResult)
        {
            if (genomeDominant == null || genomeSecondary == null)
            {
                swapChance    = 0;
                failureChance = 1;
                swapResult    = null;
                failureResult = null;
                return(null);
            }


            DefExtension_HybridChanceAlterer frameExtension   = genoframe?.GetModExtension <DefExtension_HybridChanceAlterer>();
            DefExtension_HybridChanceAlterer boosterExtension = booster?.GetModExtension <DefExtension_HybridChanceAlterer>();

            if ((genomeDominant.thingCategories?.Contains(InternalDefOf.GR_GeneticMaterialTierTwoOrThree) == true) || genomeDominant == genomeSecondary)
            {
                swapChance = 0f;
            }
            else
            {
                swapChance = (10f - (frameExtension?.stability ?? 0f) - (boosterExtension?.stability ?? 0f)) / 100f;
            }

            if (swapChance < 0f)
            {
                swapChance = 0f;
            }

            float paragonFailureFactor = 0f;

            if (genomeDominant == genomeSecondary)
            {
                paragonFailureFactor = 0.15f;
            }

            float failure = (GeneticRim_Mod.settings.GR_FailureRate - (frameExtension?.safety ?? 0f) - (boosterExtension?.safety ?? 0f));

            failureChance = (failure / 100f) + paragonFailureFactor;
            if (failureChance < 0f)
            {
                failureChance = 0f;
                failure       = 0f;
            }


            if (!hybrids.TryGetValue(genomeSecondary, out Dictionary <ThingDef, PawnKindDef> secondaryChain) || !secondaryChain.TryGetValue(genomeDominant, out swapResult))
            {
                swapResult = null;
                swapChance = 0f;
            }

            failureResult = failures.FirstOrDefault(td => td.GetModExtension <DefExtension_HybridFailure>().InRange(failure + paragonFailureFactor * 100)) ?? failures.RandomElement();

            PawnKindDef resultGlobal = null;

            if (hybrids.TryGetValue(genomeDominant, out secondaryChain))
            {
                if (secondaryChain.TryGetValue(genomeSecondary, out PawnKindDef result))
                {
                    resultGlobal = result;
                    return(result);
                }
            }

            if (resultGlobal == null && swapResult != null)
            {
                resultGlobal = swapResult;
                swapResult   = null;
                swapChance   = 0f;
                return(resultGlobal);
            }



            return(null);
        }
        public override void CompTick()
        {
            base.CompTick();

            if (this.growingResult != null)
            {
                if (compPowerTrader?.PowerOn == true)
                {
                    this.progress += 1f / hoursProcess; // (GenDate.TicksPerDay * 7f);

                    if (this.progress > 1)
                    {
                        Pawn pawn = null;
                        if (failure)
                        {
                            pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(this.failureResult, null, fixedBiologicalAge: 1, fixedChronologicalAge: 1,
                                                                                        newborn: false, forceGenerateNewPawn: true));
                            if (!GeneticRim_Mod.settings.GR_DisableWombAlerts)
                            {
                                Messages.Message("GR_ElectroWomb_Finished_Failure".Translate(), this.parent, MessageTypeDefOf.NegativeEvent, true);
                            }
                        }
                        else
                        {
                            pawn = PawnGenerator.GeneratePawn(new PawnGenerationRequest(this.growingResult, Faction.OfPlayer, fixedBiologicalAge: 1, fixedChronologicalAge: 1,
                                                                                        newborn: false, forceGenerateNewPawn: true));
                            if (!GeneticRim_Mod.settings.GR_DisableWombAlerts)
                            {
                                Messages.Message("GR_ElectroWomb_Finished".Translate(), this.parent, MessageTypeDefOf.PositiveEvent, true);
                            }
                        }

                        this.progress      = 0;
                        this.growingResult = null;

                        IntVec3 near = CellFinder.StandableCellNear(this.parent.Position, this.parent.Map, 5f);
                        GenSpawn.Spawn(pawn, near, this.parent.Map);
                        pawn.health.AddHediff(InternalDefOf.GR_RecentlyHatched);


                        if (!failure)
                        {
                            DefExtension_HybridChanceAlterer extension = this.booster?.GetModExtension <DefExtension_HybridChanceAlterer>();

                            if (extension?.isFertilityUnblocker != true && !GeneticRim_Mod.settings.GR_MakeAllHybridsFertile)
                            {
                                pawn.health.AddHediff(HediffDefOf.Sterilized);
                            }

                            if (extension?.isController == true || GeneticRim_Mod.settings.GR_MakeAllHybridsControllable)
                            {
                                pawn.health.AddHediff(InternalDefOf.GR_AnimalControlHediff);
                            }

                            if (extension?.addedHediffs != null)
                            {
                                AddInitialHybridHediffs(extension, pawn);
                            }

                            if (extension?.forceFemale != false)
                            {
                                pawn.gender = Gender.Female;
                            }

                            if (extension?.forceMale != false)
                            {
                                pawn.gender = Gender.Male;
                            }
                        }


                        CompHybrid compHybrid = pawn.TryGetComp <CompHybrid>();
                        if (compHybrid != null)
                        {
                            compHybrid.quality = this.genoframe?.GetModExtension <DefExtension_Quality>()?.quality ?? QualityCategory.Awful;
                        }
                        if (failureResult == InternalDefOf.GR_FleshGrowth && failure)
                        {
                            this.parent.Destroy();
                        }
                    }
                }
            }
        }