コード例 #1
0
 public void HealthTick()
 {
     if (!this.Dead)
     {
         for (int i = this.hediffSet.hediffs.Count - 1; i >= 0; i--)
         {
             Hediff hediff = this.hediffSet.hediffs[i];
             try
             {
                 hediff.Tick();
                 hediff.PostTick();
             }
             catch (Exception ex)
             {
                 Log.Error(string.Concat(new object[]
                 {
                     "Exception ticking hediff ",
                     hediff.ToStringSafe <Hediff>(),
                     " for pawn ",
                     this.pawn.ToStringSafe <Pawn>(),
                     ". Removing hediff... Exception: ",
                     ex
                 }), false);
                 try
                 {
                     this.RemoveHediff(hediff);
                 }
                 catch (Exception arg)
                 {
                     Log.Error("Error while removing hediff: " + arg, false);
                 }
             }
         }
         bool flag = false;
         for (int j = this.hediffSet.hediffs.Count - 1; j >= 0; j--)
         {
             Hediff hediff2 = this.hediffSet.hediffs[j];
             if (hediff2.ShouldRemove)
             {
                 this.hediffSet.hediffs.RemoveAt(j);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             this.Notify_HediffChanged(null);
         }
         if (!this.Dead)
         {
             this.immunity.ImmunityHandlerTick();
             if (this.pawn.RaceProps.IsFlesh && this.pawn.IsHashIntervalTick(600) && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (this.hediffSet.HasNaturallyHealingInjury())
                 {
                     float num = 8f;
                     if (this.pawn.GetPosture() != PawnPosture.Standing)
                     {
                         num += 4f;
                         Building_Bed building_Bed = this.pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = (from x in this.hediffSet.GetHediffs <Hediff_Injury>()
                                                    where x.CanHealNaturally()
                                                    select x).RandomElement <Hediff_Injury>();
                     hediff_Injury.Heal(num * this.pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (this.hediffSet.HasTendedAndHealingInjury() && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = (from x in this.hediffSet.GetHediffs <Hediff_Injury>()
                                                     where x.CanHealFromTending()
                                                     select x).RandomElement <Hediff_Injury>();
                     float tendQuality = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float num2        = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal(22f * num2 * this.pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (flag2 && !this.HasHediffsNeedingTendByPlayer(false) && !HealthAIUtility.ShouldSeekMedicalRest(this.pawn) && !this.hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(this.pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(new object[]
                     {
                         this.pawn.LabelCap
                     }), this.pawn, MessageTypeDefOf.PositiveEvent, true);
                 }
             }
             if (this.pawn.RaceProps.IsFlesh && this.hediffSet.BleedRateTotal >= 0.1f)
             {
                 float num3 = this.hediffSet.BleedRateTotal * this.pawn.BodySize;
                 if (this.pawn.GetPosture() == PawnPosture.Standing)
                 {
                     num3 *= 0.004f;
                 }
                 else
                 {
                     num3 *= 0.0004f;
                 }
                 if (Rand.Value < num3)
                 {
                     this.DropBloodFilth();
                 }
             }
             if (this.pawn.IsHashIntervalTick(60))
             {
                 List <HediffGiverSetDef> hediffGiverSets = this.pawn.RaceProps.hediffGiverSets;
                 if (hediffGiverSets != null)
                 {
                     for (int k = 0; k < hediffGiverSets.Count; k++)
                     {
                         List <HediffGiver> hediffGivers = hediffGiverSets[k].hediffGivers;
                         for (int l = 0; l < hediffGivers.Count; l++)
                         {
                             hediffGivers[l].OnIntervalPassed(this.pawn, null);
                             if (this.pawn.Dead)
                             {
                                 return;
                             }
                         }
                     }
                 }
                 if (this.pawn.story != null)
                 {
                     List <Trait> allTraits = this.pawn.story.traits.allTraits;
                     for (int m = 0; m < allTraits.Count; m++)
                     {
                         TraitDegreeData currentData = allTraits[m].CurrentData;
                         if (currentData.randomDiseaseMtbDays > 0f && Rand.MTBEventOccurs(currentData.randomDiseaseMtbDays, 60000f, 60f))
                         {
                             BiomeDef biome;
                             if (this.pawn.Tile != -1)
                             {
                                 biome = Find.WorldGrid[this.pawn.Tile].biome;
                             }
                             else
                             {
                                 biome = DefDatabase <BiomeDef> .GetRandom();
                             }
                             IncidentDef incidentDef = (from d in DefDatabase <IncidentDef> .AllDefs
                                                        where d.category == IncidentCategoryDefOf.DiseaseHuman
                                                        select d).RandomElementByWeightWithFallback((IncidentDef d) => biome.CommonalityOfDisease(d), null);
                             if (incidentDef != null)
                             {
                                 ((IncidentWorker_Disease)incidentDef.Worker).ApplyToPawns(Gen.YieldSingle <Pawn>(this.pawn));
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #2
0
ファイル: Pawn_HealthTracker.cs プロジェクト: potsh/RimWorld
 public void HealthTick()
 {
     if (!Dead)
     {
         for (int num = hediffSet.hediffs.Count - 1; num >= 0; num--)
         {
             Hediff hediff = hediffSet.hediffs[num];
             try
             {
                 hediff.Tick();
                 hediff.PostTick();
             }
             catch (Exception ex)
             {
                 Log.Error("Exception ticking hediff " + hediff.ToStringSafe() + " for pawn " + pawn.ToStringSafe() + ". Removing hediff... Exception: " + ex);
                 try
                 {
                     RemoveHediff(hediff);
                 }
                 catch (Exception arg)
                 {
                     Log.Error("Error while removing hediff: " + arg);
                 }
             }
         }
         bool flag = false;
         for (int num2 = hediffSet.hediffs.Count - 1; num2 >= 0; num2--)
         {
             Hediff hediff2 = hediffSet.hediffs[num2];
             if (hediff2.ShouldRemove)
             {
                 hediffSet.hediffs.RemoveAt(num2);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             Notify_HediffChanged(null);
         }
         if (!Dead)
         {
             immunity.ImmunityHandlerTick();
             if (pawn.RaceProps.IsFlesh && pawn.IsHashIntervalTick(600) && (pawn.needs.food == null || !pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (hediffSet.HasNaturallyHealingInjury())
                 {
                     float num3 = 8f;
                     if (pawn.GetPosture() != 0)
                     {
                         num3 += 4f;
                         Building_Bed building_Bed = pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num3 += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealNaturally).RandomElement();
                     hediff_Injury.Heal(num3 * pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (hediffSet.HasTendedAndHealingInjury() && (pawn.needs.food == null || !pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealFromTending).RandomElement();
                     float         tendQuality    = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float         num4           = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal(8f * num4 * pawn.HealthScale * 0.01f);
                     flag2 = true;
                 }
                 if (flag2 && !HasHediffsNeedingTendByPlayer() && !HealthAIUtility.ShouldSeekMedicalRest(pawn) && !hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(pawn.LabelCap, pawn), pawn, MessageTypeDefOf.PositiveEvent);
                 }
             }
             if (pawn.RaceProps.IsFlesh && hediffSet.BleedRateTotal >= 0.1f)
             {
                 float num5 = hediffSet.BleedRateTotal * pawn.BodySize;
                 num5 = ((pawn.GetPosture() != 0) ? (num5 * 0.0004f) : (num5 * 0.004f));
                 if (Rand.Value < num5)
                 {
                     DropBloodFilth();
                 }
             }
             if (pawn.IsHashIntervalTick(60))
             {
                 List <HediffGiverSetDef> hediffGiverSets = pawn.RaceProps.hediffGiverSets;
                 if (hediffGiverSets != null)
                 {
                     for (int i = 0; i < hediffGiverSets.Count; i++)
                     {
                         List <HediffGiver> hediffGivers = hediffGiverSets[i].hediffGivers;
                         for (int j = 0; j < hediffGivers.Count; j++)
                         {
                             hediffGivers[j].OnIntervalPassed(pawn, null);
                             if (pawn.Dead)
                             {
                                 return;
                             }
                         }
                     }
                 }
                 if (pawn.story != null)
                 {
                     List <Trait> allTraits = pawn.story.traits.allTraits;
                     for (int k = 0; k < allTraits.Count; k++)
                     {
                         TraitDegreeData currentData = allTraits[k].CurrentData;
                         if (currentData.randomDiseaseMtbDays > 0f && Rand.MTBEventOccurs(currentData.randomDiseaseMtbDays, 60000f, 60f))
                         {
                             BiomeDef biome;
                             if (pawn.Tile != -1)
                             {
                                 biome = Find.WorldGrid[pawn.Tile].biome;
                             }
                             else
                             {
                                 biome = DefDatabase <BiomeDef> .GetRandom();
                             }
                             IncidentDef incidentDef = (from d in DefDatabase <IncidentDef> .AllDefs
                                                        where d.category == IncidentCategoryDefOf.DiseaseHuman
                                                        select d).RandomElementByWeightWithFallback((IncidentDef d) => biome.CommonalityOfDisease(d));
                             if (incidentDef != null)
                             {
                                 string      blockedInfo;
                                 List <Pawn> list = ((IncidentWorker_Disease)incidentDef.Worker).ApplyToPawns(Gen.YieldSingle(pawn), out blockedInfo);
                                 if (PawnUtility.ShouldSendNotificationAbout(pawn))
                                 {
                                     if (list.Contains(pawn))
                                     {
                                         Find.LetterStack.ReceiveLetter("LetterLabelTraitDisease".Translate(incidentDef.diseaseIncident.label), "LetterTraitDisease".Translate(pawn.LabelCap, incidentDef.diseaseIncident.label, pawn.Named("PAWN")).AdjustedFor(pawn), LetterDefOf.NegativeEvent, pawn);
                                     }
                                     else if (!blockedInfo.NullOrEmpty())
                                     {
                                         Messages.Message(blockedInfo, pawn, MessageTypeDefOf.NeutralEvent);
                                     }
                                 }
                             }
                         }
                     }
                 }
             }
         }
     }
 }
コード例 #3
0
        public void HealthTick()
        {
            if (this.Dead)
            {
                return;
            }
            for (int i = this.hediffSet.hediffs.Count - 1; i >= 0; i--)
            {
                Hediff hediff = this.hediffSet.hediffs[i];
                hediff.Tick();
                hediff.PostTick();
            }
            bool flag = false;

            for (int j = this.hediffSet.hediffs.Count - 1; j >= 0; j--)
            {
                Hediff hediff2 = this.hediffSet.hediffs[j];
                if (hediff2.ShouldRemove)
                {
                    this.hediffSet.hediffs.RemoveAt(j);
                    hediff2.PostRemoved();
                    flag = true;
                }
            }
            if (flag)
            {
                this.Notify_HediffChanged(null);
            }
            if (this.Dead)
            {
                return;
            }
            this.immunity.ImmunityHandlerTick();
            if (this.pawn.RaceProps.IsFlesh && this.pawn.IsHashIntervalTick(600) && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
            {
                bool flag2 = false;
                if (this.hediffSet.HasNaturallyHealingInjury())
                {
                    float num = 8f;
                    if (this.pawn.GetPosture() != PawnPosture.Standing)
                    {
                        num += 4f;
                        Building_Bed building_Bed = this.pawn.CurrentBed();
                        if (building_Bed != null)
                        {
                            num += building_Bed.def.building.bed_healPerDay;
                        }
                    }
                    Hediff_Injury hediff_Injury = this.hediffSet.GetHediffs <Hediff_Injury>().Where(new Func <Hediff_Injury, bool>(HediffUtility.CanHealNaturally)).RandomElement <Hediff_Injury>();
                    hediff_Injury.Heal(num * this.pawn.HealthScale * 0.01f);
                    flag2 = true;
                }
                if (this.hediffSet.HasTendedAndHealingInjury() && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
                {
                    Hediff_Injury hediff_Injury2 = this.hediffSet.GetHediffs <Hediff_Injury>().Where(new Func <Hediff_Injury, bool>(HediffUtility.CanHealFromTending)).RandomElement <Hediff_Injury>();
                    float         tendQuality    = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                    float         num2           = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                    hediff_Injury2.Heal(22f * num2 * this.pawn.HealthScale * 0.01f);
                    flag2 = true;
                }
                if (flag2 && !this.HasHediffsNeedingTendByColony(false) && !HealthAIUtility.ShouldSeekMedicalRest(this.pawn) && !this.hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(this.pawn))
                {
                    Messages.Message("MessageFullyHealed".Translate(new object[]
                    {
                        this.pawn.LabelCap
                    }), this.pawn, MessageTypeDefOf.PositiveEvent);
                }
            }
            if (this.pawn.RaceProps.IsFlesh && this.hediffSet.BleedRateTotal >= 0.1f)
            {
                float num3 = this.hediffSet.BleedRateTotal * this.pawn.BodySize;
                if (this.pawn.GetPosture() == PawnPosture.Standing)
                {
                    num3 *= 0.008f;
                }
                else
                {
                    num3 *= 0.0008f;
                }
                if (Rand.Value < num3)
                {
                    this.TryDropBloodFilth();
                }
            }
            List <HediffGiverSetDef> hediffGiverSets = this.pawn.RaceProps.hediffGiverSets;

            if (hediffGiverSets != null && this.pawn.IsHashIntervalTick(60))
            {
                for (int k = 0; k < hediffGiverSets.Count; k++)
                {
                    List <HediffGiver> hediffGivers = hediffGiverSets[k].hediffGivers;
                    for (int l = 0; l < hediffGivers.Count; l++)
                    {
                        hediffGivers[l].OnIntervalPassed(this.pawn, null);
                        if (this.pawn.Dead)
                        {
                            return;
                        }
                    }
                }
            }
        }
コード例 #4
0
 public void HealthTick()
 {
     if (!this.Dead)
     {
         for (int num = this.hediffSet.hediffs.Count - 1; num >= 0; num--)
         {
             Hediff hediff = this.hediffSet.hediffs[num];
             hediff.Tick();
             hediff.PostTick();
         }
         bool flag = false;
         for (int num2 = this.hediffSet.hediffs.Count - 1; num2 >= 0; num2--)
         {
             Hediff hediff2 = this.hediffSet.hediffs[num2];
             if (hediff2.ShouldRemove)
             {
                 this.hediffSet.hediffs.RemoveAt(num2);
                 hediff2.PostRemoved();
                 flag = true;
             }
         }
         if (flag)
         {
             this.Notify_HediffChanged(null);
         }
         if (!this.Dead)
         {
             this.immunity.ImmunityHandlerTick();
             if (this.pawn.RaceProps.IsFlesh && this.pawn.IsHashIntervalTick(600) && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
             {
                 bool flag2 = false;
                 if (this.hediffSet.HasNaturallyHealingInjury())
                 {
                     float num3 = 8f;
                     if (this.pawn.GetPosture() != 0)
                     {
                         num3 = (float)(num3 + 4.0);
                         Building_Bed building_Bed = this.pawn.CurrentBed();
                         if (building_Bed != null)
                         {
                             num3 += building_Bed.def.building.bed_healPerDay;
                         }
                     }
                     Hediff_Injury hediff_Injury = this.hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealNaturally).RandomElement();
                     hediff_Injury.Heal((float)(num3 * this.pawn.HealthScale * 0.0099999997764825821));
                     flag2 = true;
                 }
                 if (this.hediffSet.HasTendedAndHealingInjury() && (this.pawn.needs.food == null || !this.pawn.needs.food.Starving))
                 {
                     Hediff_Injury hediff_Injury2 = this.hediffSet.GetHediffs <Hediff_Injury>().Where(HediffUtility.CanHealFromTending).RandomElement();
                     float         tendQuality    = hediff_Injury2.TryGetComp <HediffComp_TendDuration>().tendQuality;
                     float         num4           = GenMath.LerpDouble(0f, 1f, 0.5f, 1.5f, Mathf.Clamp01(tendQuality));
                     hediff_Injury2.Heal((float)(22.0 * num4 * this.pawn.HealthScale * 0.0099999997764825821));
                     flag2 = true;
                 }
                 if (flag2 && !this.HasHediffsNeedingTendByColony(false) && !HealthAIUtility.ShouldSeekMedicalRest(this.pawn) && !this.hediffSet.HasTendedAndHealingInjury() && PawnUtility.ShouldSendNotificationAbout(this.pawn))
                 {
                     Messages.Message("MessageFullyHealed".Translate(this.pawn.LabelCap), this.pawn, MessageTypeDefOf.PositiveEvent);
                 }
             }
             if (this.pawn.RaceProps.IsFlesh && this.hediffSet.BleedRateTotal >= 0.10000000149011612)
             {
                 float num5 = this.hediffSet.BleedRateTotal * this.pawn.BodySize;
                 num5 = (float)((this.pawn.GetPosture() != 0) ? (num5 * 0.00079999997979030013) : (num5 * 0.00800000037997961));
                 if (Rand.Value < num5)
                 {
                     this.TryDropBloodFilth();
                 }
             }
             List <HediffGiverSetDef> hediffGiverSets = this.pawn.RaceProps.hediffGiverSets;
             if (hediffGiverSets != null && this.pawn.IsHashIntervalTick(60))
             {
                 for (int i = 0; i < hediffGiverSets.Count; i++)
                 {
                     List <HediffGiver> hediffGivers = hediffGiverSets[i].hediffGivers;
                     int num6 = 0;
                     while (num6 < hediffGivers.Count)
                     {
                         hediffGivers[num6].OnIntervalPassed(this.pawn, null);
                         if (!this.pawn.Dead)
                         {
                             num6++;
                             continue;
                         }
                         return;
                     }
                 }
             }
         }
     }
 }