Пример #1
0
            static public void Postfix(ref int __result, CompMilkable __instance)
            {
                if (!Genes.EffectsThing(__instance.parent))
                {
                    return;
                }

                __result = (int)(__result * Genes.GetGene((Pawn)__instance.parent, AnimalGenetics.GatherYield));
            }
Пример #2
0
        public static void ForceMilk(Pawn p)
        {
            CompMilkable compMilkable = p.TryGetComp <CompMilkable>();

            if (compMilkable != null)
            {
                while (compMilkable.Fullness < 1)
                {
                    compMilkable.CompTick();
                }
                DebugActionsUtility.DustPuffFrom(p);
            }
        }
Пример #3
0
        public static void DrawMilkBars(this Pawn pawn, Rect rect)
        {
            //List<ThingComp> milkcomp = pawn.AllComps.FindAll(x => x is CompMilkable || x.GetType().ToString().ToLower().Contains("milkable"));
            ThingComp milkcomp = null;
            float     res      = 0;

            if (VariousDefOf.Hediff_Heavy_Lactating_Permanent != null)
            {
                if (pawn.health.hediffSet.HasHediff(VariousDefOf.Hediff_Heavy_Lactating_Permanent))
                {
                    milkcomp = pawn.AllComps.FirstOrDefault(x => x.GetType().ToString().ToLower().Contains("hypermilkable"));
                }
                else
                {
                    milkcomp = pawn.AllComps.FirstOrDefault(x => x.GetType().ToString().ToLower().Contains("milkable"));
                }
            }
            else
            {
                milkcomp = pawn.GetComp <CompMilkable>();
            }

            if (milkcomp != null)
            {
                if (milkcomp is CompMilkable)
                {
                    bool active = (bool)milkcomp.GetPropertyValue("Active");
                    if (active)
                    {
                        CompMilkable m = (CompMilkable)milkcomp;
                        res = Math.Max(m.Fullness, res);
                        Widgets.FillableBar(rect, Math.Min(res, 1.0f), TextureCache.milkTexture, Texture2D.blackTexture, true);
                        DrawMilkBottle(rect, pawn, VariousDefOf.Job_LactateSelf, m.Fullness);
                    }
                }
                else
                {
                    bool active = (bool)milkcomp.GetPropertyValue("Active");
                    if (active)
                    {
                        float fullness = (float)milkcomp.GetMemberValue("fullness");
                        res = Math.Max(fullness, res);
                        Widgets.FillableBar(rect, Math.Min(res, 1.0f), TextureCache.milkTexture, Texture2D.blackTexture, true);
                        DrawMilkBottle(rect, pawn, VariousDefOf.Job_LactateSelf_MC, fullness);
                    }
                }
            }
        }
 public bool Active(CompMilkable comp)
 {
     if (!Active())
     {
         return(false);
     }
     if (Pawn.gender != Gender.Female && comp.Props.milkFemaleOnly)
     {
         return(false);
     }
     if (!Pawn.ageTracker.CurLifeStage.milkable)
     {
         return(false);
     }
     return(true);
 }
Пример #5
0
        public override void CompPostTick(ref float severityAdjustment)
        {
            base.CompPostTick(ref severityAdjustment);
            bool flag = base.Pawn != null;

            if (flag)
            {
                if (!initialized)
                {
                    initialized = true;
                    this.Initialize();
                }
            }

            if (Find.TickManager.TicksGame % 16 == 0)
            {
                IEnumerable <Hediff> hdEnum = this.Pawn.health.hediffSet.GetHediffs <Hediff>();
                foreach (Hediff hd in hdEnum)
                {
                    if (hd.def.defName == "SpaceHypoxia")
                    {
                        this.Pawn.health.RemoveHediff(hd);
                        break;
                    }
                }
            }

            if (Find.TickManager.TicksGame % 6000 == 0)
            {
                TM_Action.UpdateAnimalTraining(base.Pawn);
            }
            bool flag4 = Find.TickManager.TicksGame % 600 == 0 && this.Pawn.def != TorannMagicDefOf.TM_SkeletonR && this.Pawn.def != TorannMagicDefOf.TM_GiantSkeletonR;

            if (flag4)
            {
                UpdateHediff();
                necroValid = false;
                if (base.Pawn != null && !linkedPawn.DestroyedOrNull())
                {
                    necroValid = true;
                    lichStrike = 0;
                }
                else
                {
                    lichStrike++;
                }

                if (!necroValid && lichStrike > 2)
                {
                    if (base.Pawn.Map != null)
                    {
                        TM_MoteMaker.ThrowScreamMote(base.Pawn.Position.ToVector3(), base.Pawn.Map, .8f, 255, 255, 255);
                        base.Pawn.Kill(null, null);
                    }
                    else
                    {
                        base.Pawn.Kill(null, null);
                    }
                }
                else
                {
                    List <Need> needs = base.Pawn.needs.AllNeeds;
                    for (int i = 0; i < needs.Count; i++)
                    {
                        if (needs[i].def == NeedDefOf.Food || needs[i].def == NeedDefOf.Joy || needs[i].def == NeedDefOf.Rest || needs[i].def.defName == "Mood" || needs[i].def.defName == "Beauty" ||
                            needs[i].def.defName == "Comfort" || needs[i].def.defName == "Outdoors" || needs[i].def.defName == "RoomSize")
                        {
                            needs[i].CurLevel = needs[i].MaxLevel;
                        }
                    }
                    //if (base.Pawn.needs.food != null)
                    //{
                    //    base.Pawn.needs.food.CurLevel = base.Pawn.needs.food.MaxLevel;
                    //}
                    //if (base.Pawn.needs.rest != null)
                    //{
                    //    base.Pawn.needs.rest.CurLevel = base.Pawn.needs.rest.MaxLevel;
                    //}

                    //if (base.Pawn.IsColonist)
                    //{
                    //    base.Pawn.needs.beauty.CurLevel = .5f;
                    //    base.Pawn.needs.comfort.CurLevel = .5f;
                    //    base.Pawn.needs.joy.CurLevel = .5f;
                    //    base.Pawn.needs.mood.CurLevel = .5f;
                    //    base.Pawn.needs.space.CurLevel = .5f;
                    //}
                    Pawn pawn = base.Pawn;
                    int  num  = 1;
                    int  num2 = 1;

                    using (IEnumerator <BodyPartRecord> enumerator = pawn.health.hediffSet.GetInjuredParts().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            BodyPartRecord rec   = enumerator.Current;
                            bool           flag2 = num > 0;

                            if (flag2)
                            {
                                IEnumerable <Hediff_Injury> arg_BB_0 = pawn.health.hediffSet.GetHediffs <Hediff_Injury>();
                                Func <Hediff_Injury, bool>  arg_BB_1;

                                arg_BB_1 = ((Hediff_Injury injury) => injury.Part == rec);

                                foreach (Hediff_Injury current in arg_BB_0.Where(arg_BB_1))
                                {
                                    bool flag3 = num2 > 0;
                                    if (flag3)
                                    {
                                        bool flag5 = current.CanHealNaturally() && !current.IsPermanent();
                                        if (flag5)
                                        {
                                            current.Heal(2.0f);
                                            num--;
                                            num2--;
                                        }
                                        else
                                        {
                                            current.Heal(1.0f);
                                            num--;
                                            num2--;
                                        }
                                    }
                                }
                            }
                        }
                    }

                    using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffsTendable().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Hediff rec = enumerator.Current;
                            if (rec.TendableNow()) // && !currentTendable.IsPermanent()
                            {
                                rec.Tended(1, 1);
                            }
                        }
                    }

                    using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
                    {
                        while (enumerator.MoveNext())
                        {
                            Hediff rec = enumerator.Current;
                            if (!rec.IsPermanent())
                            {
                                if (rec.def.defName == "Cataract" || rec.def.defName == "HearingLoss" || rec.def.defName.Contains("ToxicBuildup") || rec.def.defName == "Abasia" || rec.def.defName == "BloodRot")
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                                if ((rec.def.defName == "Blindness" || rec.def.defName.Contains("Asthma") || rec.def.defName == "Cirrhosis" || rec.def.defName == "ChemicalDamageModerate") || rec.def.defName == "Scaria")
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                                if ((rec.def.defName == "Frail" || rec.def.defName == "BadBack" || rec.def.defName.Contains("Carcinoma") || rec.def.defName == "ChemicalDamageSevere"))
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                                if ((rec.def.defName.Contains("Alzheimers") || rec.def.defName == "Dementia" || rec.def.defName.Contains("HeartArteryBlockage") || rec.def.defName == "CatatonicBreakdown"))
                                {
                                    pawn.health.RemoveHediff(rec);
                                }
                            }
                            if (rec.def.makesSickThought)
                            {
                                pawn.health.RemoveHediff(rec);
                            }
                            if (rec.def.defName.Contains("Pregnant") || rec.def.defName == "DrugOverdose")
                            {
                                pawn.health.RemoveHediff(rec);
                            }
                        }
                    }
                    CompHatcher cp_h = this.Pawn.TryGetComp <CompHatcher>();
                    if (cp_h != null)
                    {
                        Traverse.Create(root: cp_h).Field(name: "gestateProgress").SetValue(0);
                    }
                    CompMilkable cp_m = this.Pawn.TryGetComp <CompMilkable>();
                    if (cp_m != null)
                    {
                        Traverse.Create(root: cp_m).Field(name: "fullness").SetValue(0);
                    }
                }
            }
        }
        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));
                }
            }
        }
 protected virtual void PreMakeNewToils()
 {
     comp = pawn.GetComp <CompMilkable>();
 }