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)));
                        }
                    }
                    if (rec.Bleeding)
                    {
                        totalBleedRate += rec.BleedRate;
                    }
                }
                if (totalBleedRate != 0)
                {
                    HealthUtility.AdjustSeverity(pawn, HediffDefOf.BloodLoss, (totalBleedRate * 60 * this.parent.Severity) / (24 * 2500));
                }
            }
        }
        private void AntibioticEffect(Pawn pawn, List <HediffDef> extraHediffs, float minEffect = 0.025f)
        {
            List <Hediff> hediffs = (from x in pawn.health.hediffSet.hediffs
                                     where x.def.makesSickThought || extraHediffs.Contains(x.def)
                                     select x).ToList();

            for (int i = hediffs.Count - 1; i >= 0; i--)
            {
                if (hediffs[i].TendableNow())
                {
                    hediffs[i].Tended(0.8f);
                }
                float num = 0f;
                HediffComp_Immunizable hediffComp_Immunizable = hediffs[i].TryGetComp <HediffComp_Immunizable>();
                if (hediffComp_Immunizable != null)
                {
                    num += Mathf.Abs(hediffComp_Immunizable.Props.severityPerDayNotImmune / GenDate.TicksPerDay * 1.2f * GenDate.TicksPerHour);
                }
                HediffComp_GrowthMode hediffComp_GrowthMode = hediffs[i].TryGetComp <HediffComp_GrowthMode>();
                if (hediffComp_GrowthMode != null)
                {
                    num += Mathf.Abs(hediffComp_GrowthMode.Props.severityPerDayGrowing / GenDate.TicksPerDay * 1.5f * GenDate.TicksPerHour);
                }
                HediffComp_SeverityPerDay hediffComp_SeverityPerDay = hediffs[i].TryGetComp <HediffComp_SeverityPerDay>();
                if (hediffComp_SeverityPerDay != null)
                {
                    //num += Mathf.Abs(((HediffCompProperties_SeverityPerDay)hediffComp_SeverityPerDay.props).severityPerDay / GenDate.TicksPerDay * 2f * GenDate.TicksPerHour);
                    if (hediffComp_SeverityPerDay.props is HediffCompProperties_SeverityPerDay prop)
                    {
                        num += Mathf.Abs(prop.severityPerDay / GenDate.TicksPerDay * 2f * GenDate.TicksPerHour);
                    }
                }
                if (num < minEffect)
                {
                    num = minEffect;
                }
                if (hediffs[i].Severity < num)
                {
                    pawn.health.RemoveHediff(hediffs[i]);
                    continue;
                }
                hediffs[i].Severity -= num;
                if (!hediffs[i].Visible)
                {
                    pawn.health.RemoveHediff(hediffs[i]);
                }
            }
        }
Ejemplo n.º 3
0
        private void AntagonistEffect(Pawn pawn, List <HediffDef> extraHediffs, List <HediffDef> exceptHediffs, float minEffect = 0.025f)
        {
            List <Hediff> hediffs = (from x in pawn.health.hediffSet.hediffs
                                     where !exceptHediffs.Contains(x.def) && (ReceptorAntagonistDatabase.addictionHediffs.Contains(x.def) || ReceptorAntagonistDatabase.toleranceHediffs.Contains(x.def) || extraHediffs.Contains(x.def))
                                     select x).ToList();

            for (int i = hediffs.Count - 1; i >= 0; i--)
            {
                float num = 0f;
                HediffComp_SeverityPerDay hediffComp_SeverityPerDay = hediffs[i].TryGetComp <HediffComp_SeverityPerDay>();
                if (hediffComp_SeverityPerDay != null)
                {
                    if (hediffComp_SeverityPerDay.props is HediffCompProperties_SeverityPerDay prop)
                    {
                        num += Mathf.Abs(prop.severityPerDay / GenDate.TicksPerDay * 4f * GenDate.TicksPerHour);
                    }
                }
                if (num < minEffect)
                {
                    num = minEffect;
                }
                if (hediffs[i].Severity < num)
                {
                    pawn.health.RemoveHediff(hediffs[i]);
                    continue;
                }
                hediffs[i].Severity -= num;
                if (!hediffs[i].Visible)
                {
                    pawn.health.RemoveHediff(hediffs[i]);
                }
            }
            foreach (Need n in pawn.needs.AllNeeds)
            {
                if (n is Need_Chemical)
                {
                    n.CurLevel = n.MaxLevel;
                }
            }
        }
Ejemplo n.º 4
0
        private void ReverseHediff(Pawn pawn, int ticks)
        {
            float totalBleedRate = 0;

            using (IEnumerator <Hediff> enumerator = pawn.health.hediffSet.GetHediffs <Hediff>().GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Hediff rec = enumerator.Current;
                    if (rec != null)
                    {
                        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) / (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)
                                {
                                    bool drugTolerance = false;
                                    HediffComp_DrugEffectFactor drugEffectComp = rec.TryGetComp <HediffComp_DrugEffectFactor>();
                                    if (drugEffectComp != null)
                                    {
                                        if (drugEffectComp.Def.CompProps <HediffCompProperties_DrugEffectFactor>().chemical != null)
                                        {
                                            drugTolerance = true;
                                        }
                                    }
                                    if (!drugTolerance)
                                    {
                                        rec.Severity -= ((sevDay * ticks * this.parent.Severity) / (1000));
                                    }
                                }
                            }
                        }
                        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(ticks * this.parent.Severity)));
                            }
                        }
                        if (rec.Bleeding)
                        {
                            totalBleedRate += rec.BleedRate;
                        }
                    }
                }
                if (totalBleedRate != 0)
                {
                    HealthUtility.AdjustSeverity(pawn, HediffDefOf.BloodLoss, -(totalBleedRate * ticks * this.parent.Severity) / (24 * 2500));
                }
            }
            List <Hediff> hediffList = pawn.health.hediffSet.GetHediffs <Hediff>().ToList();

            if (hediffList != null && hediffList.Count > 0)
            {
                for (int i = 0; i < hediffList.Count; i++)
                {
                    Hediff rec = hediffList[i];
                    if (rec != null && rec != this.parent)
                    {
                        if (rec.def.scenarioCanAdd || rec.def.isBad)
                        {
                            if ((rec.ageTicks - 1000) < 0)
                            {
                                if (rec.def.defName.Contains("TM_"))
                                {
                                    if (rec.def.isBad && rec.def != TorannMagicDefOf.TM_ResurrectionHD)
                                    {
                                        this.Pawn.health.RemoveHediff(rec);
                                        break;
                                    }
                                }
                                else
                                {
                                    List <BodyPartRecord> bpList          = pawn.RaceProps.body.AllParts;
                                    List <BodyPartRecord> replacementList = new List <BodyPartRecord>();
                                    replacementList.Clear();
                                    for (int j = 0; j < bpList.Count; j++)
                                    {
                                        BodyPartRecord record = bpList[j];
                                        if (pawn.health.hediffSet.hediffs.Any((Hediff x) => x.Part == record) && (record.parent == null || pawn.health.hediffSet.GetNotMissingParts().Contains(record.parent)) && (!pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(record) || pawn.health.hediffSet.HasDirectlyAddedPartFor(record)))
                                        {
                                            replacementList.Add(record);
                                        }
                                    }
                                    Hediff_MissingPart mphd = rec as Hediff_MissingPart;
                                    if (mphd != null && mphd.Part != null)
                                    {
                                        if (replacementList.Contains(mphd.Part))
                                        {
                                            if (RemoveChildParts(mphd))
                                            {
                                                break;
                                            }
                                            else
                                            {
                                                if (this.Pawn.needs != null && this.Pawn.needs.mood != null && this.Pawn.needs.mood.thoughts != null && this.Pawn.needs.mood.thoughts.memories != null)
                                                {
                                                    this.Pawn.needs.mood.thoughts.memories.TryGainMemory(TorannMagicDefOf.TM_PhantomLimb);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            goto IgnoreHediff;
                                        }
                                    }
                                    this.Pawn.health.RemoveHediff(rec);
                                    i = hediffList.Count;
                                    break;
                                    IgnoreHediff :;
                                }
                            }
                            else
                            {
                                rec.ageTicks -= 1000;
                            }
                        }
                    }
                }
            }
            //using (IEnumerator<Hediff> enumerator = pawn.health.hediffSet.GetHediffs<Hediff>().GetEnumerator())
            //{
            //    while (enumerator.MoveNext())
            //    {
            //        Hediff rec = enumerator.Current;
            //        if (rec != null && rec != this.parent)
            //        {
            //            if ((rec.ageTicks - 2500) < 0)
            //            {
            //                if (rec.def.defName.Contains("TM_"))
            //                {
            //                    if (rec.def.isBad)
            //                    {
            //                        this.Pawn.health.RemoveHediff(rec);
            //                    }
            //                }
            //                else
            //                {
            //                    this.Pawn.health.RemoveHediff(rec);
            //                }
            //            }
            //            else
            //            {
            //                rec.ageTicks -= 2500;
            //            }
            //        }
            //    }
            //}
        }
        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));
                }
            }
        }