Exemplo n.º 1
0
        // original rebuilded
        public static bool CompTick(CompEggLayer __instance)
        {
            if (WorkRebalancerMod.Instance.Prof.RestoreWhenHostileDetected &&
                HostileHandler.HostileDetected)
            {
                return(true);
            }

            if ((bool)Active.Invoke(__instance, null))
            {
                float num  = 1f / (__instance.Props.eggLayIntervalDays * 60000f);
                Pawn  pawn = __instance.parent as Pawn;
                if (pawn != null)
                {
                    num *= PawnUtility.BodyResourceGrowthSpeed(pawn);
                }

                float _eggProgress = (float)eggProgress.GetValue(__instance);
                _eggProgress += num * WorkRebalancerMod.Instance.Prof.EggLayerSpeedMult;
                if (_eggProgress > 1f)
                {
                    _eggProgress = 1f;
                }
                if ((bool)ProgressStoppedBecauseUnfertilized.Invoke(__instance, null))
                {
                    _eggProgress = __instance.Props.eggProgressUnfertilizedMax;
                }
                eggProgress.SetValue(__instance, _eggProgress);
            }

            return(false);
        }
Exemplo n.º 2
0
 //Plant babies for human/bestiality pregnancy
 public static void PregnancyDecider(Pawn mother, Pawn father)
 {
     //human-human
     if (RJWPregnancySettings.humanlike_pregnancy_enabled && xxx.is_human(mother) && xxx.is_human(father))
     {
         Hediff_HumanlikePregnancy.Create(mother, father);
     }
     //human-animal
     //maybe make separate option for human males vs female animals???
     else if (RJWPregnancySettings.bestial_pregnancy_enabled && ((xxx.is_human(mother) && xxx.is_animal(father)) || (xxx.is_animal(mother) && xxx.is_human(father))))
     {
         Hediff_BestialPregnancy.Create(mother, father);
     }
     //animal-animal
     else if (xxx.is_animal(mother) && xxx.is_animal(father))
     {
         CompEggLayer compEggLayer = mother.TryGetComp <CompEggLayer>();
         // fertilize eggs of same species
         if (compEggLayer != null)
         {
             if (mother.kindDef == father.kindDef)
             {
                 compEggLayer.Fertilize(father);
             }
         }
         else if (RJWPregnancySettings.animal_pregnancy_enabled)
         {
             Hediff_BestialPregnancy.Create(mother, father);
         }
     }
 }
Exemplo n.º 3
0
            static void ProduceEggPatch([NotNull]  CompEggLayer __instance, ref Thing __result)
            {
                if (__result == null || __result.def != PMThingDefOf.EggChickenUnfertilized)
                {
                    return;
                }
                var isInfused = __instance.parent?.GetComp <AspectTracker>()?.Contains(AspectDefOf.MutagenInfused, 0) == true;

                if (isInfused)
                {
                    __result.def = PMThingDefOf.TFEgg;
                }
            }
 public bool Active(CompEggLayer comp)
 {
     if (!Active())
     {
         return(false);
     }
     if (Pawn.gender != Gender.Female && comp.Props.eggLayFemaleOnly)
     {
         return(false);
     }
     if (!Pawn.ageTracker.CurLifeStage.milkable)
     {
         return(false);
     }
     return(true);
 }
Exemplo n.º 5
0
            static Thing Postfix(Thing __result, Pawn ___fertilizedBy, CompEggLayer __instance)
            {
                if (__result.TryGetComp <Comp_OHFP_Hatcher>() is Comp_OHFP_Hatcher comp)
                {
                    comp.hatcheeFaction = __instance.parent.Faction;
                    if (__instance.parent is Pawn pawn)
                    {
                        comp.hatcheeParent = pawn;
                    }
                    if (___fertilizedBy != null)
                    {
                        comp.otherParent = ___fertilizedBy;
                    }
                }

                return(__result);
            }
    // RimWorld.CompEggLayer
    public static void ProduceEgg_PostFix(CompEggLayer __instance, ref Thing __result)
    {
        var compHatcher = __result.TryGetComp <CompMultiHatcher>();

        if (compHatcher == null)
        {
            return;
        }

        compHatcher.hatcheeFaction = __instance.parent.Faction;
        if (__instance.parent is Pawn pawn)
        {
            compHatcher.hatcheeParent = pawn;
        }

        if (Traverse.Create(__instance).Field("fertilizedBy").GetValue <Pawn>() is { } Fertilizer)
        {
            compHatcher.otherParent = Fertilizer;
        }
    }
Exemplo n.º 7
0
        static bool Prefix(ref Job __result, Pawn pawn)
        {
            CompEggLayer compEggLayer = pawn.TryGetComp <CompEggLayer>();

            if (compEggLayer == null || !compEggLayer.CanLayNow)
            {
                return(false);
            }
            IntVec3      c;
            Building_Bed bed = RestUtility.FindBedFor(pawn);

            if (bed != null)
            {
                c = bed.Position;
            }
            else
            {
                c = RCellFinder.RandomWanderDestFor(pawn, pawn.Position, 5f, null, Danger.Some);
            }
            __result = new Job(JobDefOf.LayEgg, c);
            return(false);
        }
        private void AccelerateHediff(Pawn pawn, int ticks)
        {
            float totalBleedRate = 0;

            using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Hediff rec = enumerator.Current;
                    HediffComp_Immunizable immuneComp = rec.TryGetComp <HediffComp_Immunizable>();
                    if (immuneComp != null)
                    {
                        if (immuneComp.Def.CompProps <HediffCompProperties_Immunizable>() != null)
                        {
                            float immuneSevDay = immuneComp.Def.CompProps <HediffCompProperties_Immunizable>().severityPerDayNotImmune;
                            if (immuneSevDay != 0 && !rec.FullyImmune())
                            {
                                rec.Severity += immuneSevDay * ticks * this.parent.Severity / (24 * 2500);
                            }
                        }
                    }
                    HediffComp_SeverityPerDay sevDayComp = rec.TryGetComp <HediffComp_SeverityPerDay>();
                    if (sevDayComp != null)
                    {
                        if (sevDayComp.Def.CompProps <HediffCompProperties_SeverityPerDay>() != null)
                        {
                            float sevDay = sevDayComp.Def.CompProps <HediffCompProperties_SeverityPerDay>().severityPerDay;
                            if (sevDay != 0)
                            {
                                rec.Severity += sevDay * ticks * this.parent.Severity / (24 * 2500);
                            }
                        }
                    }
                    HediffComp_Disappears tickComp = rec.TryGetComp <HediffComp_Disappears>();
                    if (tickComp != null)
                    {
                        int ticksToDisappear = Traverse.Create(root: tickComp).Field(name: "ticksToDisappear").GetValue <int>();
                        if (ticksToDisappear != 0)
                        {
                            Traverse.Create(root: tickComp).Field(name: "ticksToDisappear").SetValue(ticksToDisappear - Mathf.RoundToInt(60 * this.parent.Severity));
                        }
                    }
                    Hediff_Pregnant hdp = this.Pawn.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("Pregnant")) as Hediff_Pregnant;
                    if (hdp != null)
                    {
                        hdp.Severity += 1f / (this.Pawn.RaceProps.gestationPeriodDays * (2500f / this.parent.Severity));
                    }
                    CompEggLayer eggComp = this.Pawn.TryGetComp <CompEggLayer>();
                    if (eggComp != null)
                    {
                        float eggProgress = Traverse.Create(root: eggComp).Field(name: "eggProgress").GetValue <float>();
                        bool  isActive    = Active(eggComp);
                        if (isActive)
                        {
                            eggProgress += 1f / (eggComp.Props.eggLayIntervalDays * (2500f / this.parent.Severity));
                            Traverse.Create(root: eggComp).Field(name: "eggProgress").SetValue(eggProgress);
                        }
                    }
                    //CompHasGatherableBodyResource gatherComp = this.Pawn.TryGetComp<CompHasGatherableBodyResource>();
                    //if (gatherComp != null)
                    //{
                    //    float gatherProgress = gatherComp.Fullness;

                    //    int rate = Traverse.Create(root: gatherComp).Field(name: "GatherResourcesIntervalDays").GetValue<int>();
                    //    bool isActive = Active();
                    //    if (isActive)
                    //    {
                    //        gatherProgress += (1f / ((float)(rate * (2500f / this.parent.Severity))));
                    //        Traverse.Create(root: gatherComp).Field(name: "fullness").SetValue(gatherProgress);
                    //    }
                    //}
                    CompMilkable milkComp = this.Pawn.TryGetComp <CompMilkable>();
                    if (milkComp != null)
                    {
                        float milkProgress = milkComp.Fullness;
                        int   rate         = milkComp.Props.milkIntervalDays;
                        bool  isActive     = Active(milkComp);
                        if (isActive)
                        {
                            milkProgress += 1f / ((float)(rate * (2500f / this.parent.Severity)));
                            Traverse.Create(root: milkComp).Field(name: "fullness").SetValue(milkProgress);
                        }
                    }
                    if (rec.Bleeding)
                    {
                        totalBleedRate += rec.BleedRate;
                    }
                }
                if (totalBleedRate != 0)
                {
                    HealthUtility.AdjustSeverity(pawn, HediffDefOf.BloodLoss, totalBleedRate * 60 * this.parent.Severity / (24 * 2500));
                }
            }
        }