Пример #1
0
 public static void HealNonPermanentInjuriesAndRestoreLegs(Pawn p)
 {
     if (p.Dead)
     {
         return;
     }
     HealthUtility.tmpHediffs.Clear();
     HealthUtility.tmpHediffs.AddRange(p.health.hediffSet.hediffs);
     for (int i = 0; i < HealthUtility.tmpHediffs.Count; i++)
     {
         Hediff_Injury hediff_Injury = HealthUtility.tmpHediffs[i] as Hediff_Injury;
         if (hediff_Injury != null && !hediff_Injury.IsPermanent())
         {
             p.health.RemoveHediff(hediff_Injury);
         }
         else
         {
             Hediff_MissingPart hediff_MissingPart = HealthUtility.tmpHediffs[i] as Hediff_MissingPart;
             if (hediff_MissingPart != null && hediff_MissingPart.Part.def.tags.Contains(BodyPartTagDefOf.MovingLimbCore) && (hediff_MissingPart.Part.parent == null || p.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null).Contains(hediff_MissingPart.Part.parent)))
             {
                 p.health.RestorePart(hediff_MissingPart.Part, null, true);
             }
         }
     }
     HealthUtility.tmpHediffs.Clear();
 }
Пример #2
0
 private void CacheMissingPartsCommonAncestors()
 {
     if (cachedMissingPartsCommonAncestors == null)
     {
         cachedMissingPartsCommonAncestors = new List <Hediff_MissingPart>();
     }
     else
     {
         cachedMissingPartsCommonAncestors.Clear();
     }
     missingPartsCommonAncestorsQueue.Clear();
     missingPartsCommonAncestorsQueue.Enqueue(pawn.def.race.body.corePart);
     while (missingPartsCommonAncestorsQueue.Count != 0)
     {
         BodyPartRecord node = missingPartsCommonAncestorsQueue.Dequeue();
         if (!PartOrAnyAncestorHasDirectlyAddedParts(node))
         {
             Hediff_MissingPart hediff_MissingPart = (from x in GetHediffs <Hediff_MissingPart>()
                                                      where x.Part == node
                                                      select x).FirstOrDefault();
             if (hediff_MissingPart != null)
             {
                 cachedMissingPartsCommonAncestors.Add(hediff_MissingPart);
             }
             else
             {
                 for (int i = 0; i < node.parts.Count; i++)
                 {
                     missingPartsCommonAncestorsQueue.Enqueue(node.parts[i]);
                 }
             }
         }
     }
 }
Пример #3
0
 public void Notify_Resurrected()
 {
     healthState = PawnHealthState.Mobile;
     hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x.TryGetComp <HediffComp_Immunizable>() != null);
     hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x is Hediff_Injury && !x.IsPermanent());
     hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && (x.def.lethalSeverity >= 0f || (x.def.stages != null && x.def.stages.Any((HediffStage y) => y.lifeThreatening))));
     hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x is Hediff_Injury && x.IsPermanent() && hediffSet.GetPartHealth(x.Part) <= 0f);
     while (true)
     {
         Hediff_MissingPart hediff_MissingPart = (from x in hediffSet.GetMissingPartsCommonAncestors()
                                                  where !hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x.Part)
                                                  select x).FirstOrDefault();
         if (hediff_MissingPart == null)
         {
             break;
         }
         RestorePart(hediff_MissingPart.Part, null, checkStateChange: false);
     }
     hediffSet.DirtyCache();
     if (ShouldBeDead())
     {
         hediffSet.hediffs.Clear();
     }
     Notify_HediffChanged(null);
 }
Пример #4
0
        protected override void IngestedCalculateAmounts(Pawn ingester, float nutritionWanted, out int numTaken, out float nutritionIngested)
        {
            BodyPartRecord bodyPartRecord = this.GetBestBodyPartToEat(ingester, nutritionWanted);

            if (bodyPartRecord == null)
            {
                Log.Error(ingester + " ate " + this + " but no body part was found. Replacing with core part.");
                bodyPartRecord = this.InnerPawn.RaceProps.body.corePart;
            }
            float bodyPartNutrition = FoodUtility.GetBodyPartNutrition(this.InnerPawn, bodyPartRecord);

            if (bodyPartRecord == this.InnerPawn.RaceProps.body.corePart)
            {
                if (PawnUtility.ShouldSendNotificationAbout(this.InnerPawn) && this.InnerPawn.RaceProps.Humanlike)
                {
                    Messages.Message("MessageEatenByPredator".Translate(this.InnerPawn.LabelShort, ingester.LabelIndefinite()).CapitalizeFirst(), ingester, MessageTypeDefOf.NegativeEvent);
                }
                numTaken = 1;
            }
            else
            {
                Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, this.InnerPawn, bodyPartRecord);
                hediff_MissingPart.lastInjury = HediffDefOf.Bite;
                hediff_MissingPart.IsFresh    = true;
                this.InnerPawn.health.AddHediff(hediff_MissingPart, null, null);
                numTaken = 0;
            }
            if (ingester.RaceProps.Humanlike && Rand.Value < 0.05000000074505806)
            {
                FoodUtility.AddFoodPoisoningHediff(ingester, this);
            }
            nutritionIngested = bodyPartNutrition;
        }
Пример #5
0
 public static void HealNonPermanentInjuriesAndRestoreLegs(Pawn p)
 {
     if (!p.Dead)
     {
         tmpHediffs.Clear();
         tmpHediffs.AddRange(p.health.hediffSet.hediffs);
         for (int i = 0; i < tmpHediffs.Count; i++)
         {
             Hediff_Injury hediff_Injury = tmpHediffs[i] as Hediff_Injury;
             if (hediff_Injury != null && !hediff_Injury.IsPermanent())
             {
                 p.health.RemoveHediff(hediff_Injury);
             }
             else
             {
                 Hediff_MissingPart hediff_MissingPart = tmpHediffs[i] as Hediff_MissingPart;
                 if (hediff_MissingPart != null && hediff_MissingPart.Part.def.tags.Contains(BodyPartTagDefOf.MovingLimbCore) && (hediff_MissingPart.Part.parent == null || p.health.hediffSet.GetNotMissingParts().Contains(hediff_MissingPart.Part.parent)))
                 {
                     p.health.RestorePart(hediff_MissingPart.Part);
                 }
             }
         }
         tmpHediffs.Clear();
     }
 }
Пример #6
0
        protected override void IngestedCalculateAmounts(Pawn ingester, float nutritionWanted, out int numTaken, out float nutritionIngested)
        {
            BodyPartRecord bodyPartRecord = GetBestBodyPartToEat(ingester, nutritionWanted);

            if (bodyPartRecord == null)
            {
                Log.Error(string.Concat(ingester, " ate ", this, " but no body part was found. Replacing with core part."));
                bodyPartRecord = InnerPawn.RaceProps.body.corePart;
            }
            float bodyPartNutrition = FoodUtility.GetBodyPartNutrition(this, bodyPartRecord);

            if (bodyPartRecord == InnerPawn.RaceProps.body.corePart)
            {
                if (PawnUtility.ShouldSendNotificationAbout(InnerPawn) && InnerPawn.RaceProps.Humanlike)
                {
                    Messages.Message("MessageEatenByPredator".Translate(InnerPawn.LabelShort, ingester.Named("PREDATOR"), InnerPawn.Named("EATEN")).CapitalizeFirst(), ingester, MessageTypeDefOf.NegativeEvent);
                }
                numTaken = 1;
            }
            else
            {
                Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, InnerPawn, bodyPartRecord);
                hediff_MissingPart.lastInjury = HediffDefOf.Bite;
                hediff_MissingPart.IsFresh    = true;
                InnerPawn.health.AddHediff(hediff_MissingPart);
                numTaken = 0;
            }
            nutritionIngested = bodyPartNutrition;
        }
Пример #7
0
        public static Pair <string, Color> GetPartConditionLabel(Pawn pawn, BodyPartRecord part)
        {
            float  partHealth = pawn.health.hediffSet.GetPartHealth(part);
            float  maxHealth  = part.def.GetMaxHealth(pawn);
            float  num        = partHealth / maxHealth;
            string text       = "";
            Color  white      = Color.white;

            if (partHealth <= 0f)
            {
                Hediff_MissingPart        hediff_MissingPart          = null;
                List <Hediff_MissingPart> missingPartsCommonAncestors = pawn.health.hediffSet.GetMissingPartsCommonAncestors();
                for (int i = 0; i < missingPartsCommonAncestors.Count; i++)
                {
                    if (missingPartsCommonAncestors[i].Part == part)
                    {
                        hediff_MissingPart = missingPartsCommonAncestors[i];
                        break;
                    }
                }
                if (hediff_MissingPart == null)
                {
                    bool fresh = false;
                    if (hediff_MissingPart != null && hediff_MissingPart.IsFreshNonSolidExtremity)
                    {
                        fresh = true;
                    }
                    bool solid = part.def.IsSolid(part, pawn.health.hediffSet.hediffs);
                    text  = GetGeneralDestroyedPartLabel(part, fresh, solid);
                    white = Color.gray;
                }
                else
                {
                    text  = hediff_MissingPart.LabelCap;
                    white = hediff_MissingPart.LabelColor;
                }
            }
            else if (num < 0.4f)
            {
                text  = "SeriouslyImpaired".Translate();
                white = RedColor;
            }
            else if (num < 0.7f)
            {
                text  = "Impaired".Translate();
                white = ImpairedColor;
            }
            else if (num < 0.999f)
            {
                text  = "SlightlyImpaired".Translate();
                white = SlightlyImpairedColor;
            }
            else
            {
                text  = "GoodCondition".Translate();
                white = GoodConditionColor;
            }
            return(new Pair <string, Color>(text, white));
        }
Пример #8
0
 public override void PostAdd(DamageInfo?dinfo)
 {
     this.pawn.health.RestorePart(base.Part, this, false);
     for (int i = 0; i < base.Part.parts.Count; i++)
     {
         Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(this.def, this.pawn, null);
         hediff_MissingPart.IsFresh    = false;
         hediff_MissingPart.lastInjury = this.lastInjury;
         hediff_MissingPart.Part       = base.Part.parts[i];
         this.pawn.health.hediffSet.AddDirect(hediff_MissingPart, null);
     }
 }
Пример #9
0
 public override void PostAdd(DamageInfo?dinfo)
 {
     base.PostAdd(dinfo);
     pawn.health.RestorePart(base.Part, this, checkStateChange: false);
     for (int i = 0; i < base.Part.parts.Count; i++)
     {
         Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn);
         hediff_MissingPart.IsFresh    = true;
         hediff_MissingPart.lastInjury = HediffDefOf.SurgicalCut;
         hediff_MissingPart.Part       = base.Part.parts[i];
         pawn.health.hediffSet.AddDirect(hediff_MissingPart);
     }
 }
 public void Notify_Resurrected()
 {
     this.healthState = PawnHealthState.Mobile;
     this.hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x.TryGetComp <HediffComp_Immunizable>() != null);
     this.hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x is Hediff_Injury && !x.IsPermanent());
     this.hediffSet.hediffs.RemoveAll(delegate(Hediff x)
     {
         bool result;
         if (x.def.everCurableByItem)
         {
             if (x.def.lethalSeverity < 0f)
             {
                 if (x.def.stages != null)
                 {
                     result = x.def.stages.Any((HediffStage y) => y.lifeThreatening);
                 }
                 else
                 {
                     result = false;
                 }
             }
             else
             {
                 result = true;
             }
         }
         else
         {
             result = false;
         }
         return(result);
     });
     this.hediffSet.hediffs.RemoveAll((Hediff x) => x.def.everCurableByItem && x is Hediff_Injury && x.IsPermanent() && this.hediffSet.GetPartHealth(x.Part) <= 0f);
     for (;;)
     {
         Hediff_MissingPart hediff_MissingPart = (from x in this.hediffSet.GetMissingPartsCommonAncestors()
                                                  where !this.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x.Part)
                                                  select x).FirstOrDefault <Hediff_MissingPart>();
         if (hediff_MissingPart == null)
         {
             break;
         }
         this.RestorePart(hediff_MissingPart.Part, null, false);
     }
     this.hediffSet.DirtyCache();
     if (this.ShouldBeDead())
     {
         this.hediffSet.hediffs.Clear();
     }
     this.Notify_HediffChanged(null);
 }
 public override void PostAdd(DamageInfo?dinfo)
 {
     if (Current.ProgramState != ProgramState.Playing || PawnGenerator.IsBeingGenerated(this.pawn))
     {
         this.IsFresh = false;
     }
     this.pawn.health.RestorePart(base.Part, this, false);
     for (int i = 0; i < base.Part.parts.Count; i++)
     {
         Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(this.def, this.pawn, null);
         hediff_MissingPart.IsFresh    = false;
         hediff_MissingPart.lastInjury = this.lastInjury;
         hediff_MissingPart.Part       = base.Part.parts[i];
         this.pawn.health.hediffSet.AddDirect(hediff_MissingPart, null, null);
     }
 }
Пример #12
0
 public override void PostAdd(DamageInfo?dinfo)
 {
     base.PostAdd(dinfo);
     if (Current.ProgramState != ProgramState.Playing || PawnGenerator.IsBeingGenerated(pawn))
     {
         IsFresh = false;
     }
     pawn.health.RestorePart(base.Part, this, checkStateChange: false);
     for (int i = 0; i < base.Part.parts.Count; i++)
     {
         Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(def, pawn);
         hediff_MissingPart.IsFresh    = false;
         hediff_MissingPart.lastInjury = lastInjury;
         hediff_MissingPart.Part       = base.Part.parts[i];
         pawn.health.hediffSet.AddDirect(hediff_MissingPart);
     }
 }
Пример #13
0
 public override void PostAdd(DamageInfo?dinfo)
 {
     if (base.Part == null)
     {
         Log.Error("Part is null. It should be set before PostAdd for " + this.def + ".", false);
         return;
     }
     this.pawn.health.RestorePart(base.Part, this, false);
     for (int i = 0; i < base.Part.parts.Count; i++)
     {
         Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, this.pawn, null);
         hediff_MissingPart.IsFresh    = true;
         hediff_MissingPart.lastInjury = HediffDefOf.SurgicalCut;
         hediff_MissingPart.Part       = base.Part.parts[i];
         this.pawn.health.hediffSet.AddDirect(hediff_MissingPart, null, null);
     }
 }
        private HashSet <Hediff> CalculateMissingPartHediffsFromInjury(Hediff hediff)
        {
            HashSet <Hediff> missing = null;

            if (hediff.Part != null && hediff.Part != pawn.RaceProps.body.corePart && hediff.Severity >= hediffSet.GetPartHealth(hediff.Part))
            {
                missing = new HashSet <Hediff>();
                AddAllParts(hediff.Part);
            }
            return(missing);

            void AddAllParts(BodyPartRecord part)
            {
                Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn);

                hediff_MissingPart.lastInjury = hediff.def;
                hediff_MissingPart.Part       = part;
                missing.Add(hediff_MissingPart);
                foreach (BodyPartRecord part in part.parts)
                {
                    AddAllParts(part);
                }
            }
        }
Пример #15
0
        public static Pair <string, Color> GetPartConditionLabel(Pawn pawn, BodyPartRecord part)
        {
            float  partHealth = pawn.health.hediffSet.GetPartHealth(part);
            float  maxHealth  = part.def.GetMaxHealth(pawn);
            float  num        = partHealth / maxHealth;
            string empty      = string.Empty;
            Color  white      = Color.white;

            if (partHealth <= 0.0)
            {
                Hediff_MissingPart        hediff_MissingPart          = null;
                List <Hediff_MissingPart> missingPartsCommonAncestors = pawn.health.hediffSet.GetMissingPartsCommonAncestors();
                int num2 = 0;
                while (num2 < missingPartsCommonAncestors.Count)
                {
                    if (missingPartsCommonAncestors[num2].Part != part)
                    {
                        num2++;
                        continue;
                    }
                    hediff_MissingPart = missingPartsCommonAncestors[num2];
                    break;
                }
                if (hediff_MissingPart == null)
                {
                    bool fresh = false;
                    if (hediff_MissingPart != null && hediff_MissingPart.IsFreshNonSolidExtremity)
                    {
                        fresh = true;
                    }
                    bool solid = part.def.IsSolid(part, pawn.health.hediffSet.hediffs);
                    empty = HealthUtility.GetGeneralDestroyedPartLabel(part, fresh, solid);
                    white = Color.gray;
                }
                else
                {
                    empty = hediff_MissingPart.LabelCap;
                    white = hediff_MissingPart.LabelColor;
                }
            }
            else if (num < 0.40000000596046448)
            {
                empty = "SeriouslyImpaired".Translate();
                white = HealthUtility.DarkRedColor;
            }
            else if (num < 0.699999988079071)
            {
                empty = "Impaired".Translate();
                white = HealthUtility.ImpairedColor;
            }
            else if (num < 0.99900001287460327)
            {
                empty = "SlightlyImpaired".Translate();
                white = HealthUtility.SlightlyImpairedColor;
            }
            else
            {
                empty = "GoodCondition".Translate();
                white = HealthUtility.GoodConditionColor;
            }
            return(new Pair <string, Color>(empty, white));
        }
 private bool <Notify_Resurrected> m__4(Hediff_MissingPart x)
 {
     return(!this.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(x.Part));
 }
Пример #17
0
 public void AddDirect(Hediff hediff, DamageInfo?dinfo = default(DamageInfo?), DamageWorker.DamageResult damageResult = null)
 {
     if (hediff.def == null)
     {
         Log.Error("Tried to add health diff with null def. Canceling.");
     }
     else if (hediff.Part != null && !GetNotMissingParts().Contains(hediff.Part))
     {
         Log.Error("Tried to add health diff to missing part " + hediff.Part);
     }
     else
     {
         hediff.ageTicks = 0;
         hediff.pawn     = pawn;
         bool flag = false;
         for (int i = 0; i < hediffs.Count; i++)
         {
             if (hediffs[i].TryMergeWith(hediff))
             {
                 flag = true;
             }
         }
         if (!flag)
         {
             hediffs.Add(hediff);
             hediff.PostAdd(dinfo);
             if (pawn.needs != null && pawn.needs.mood != null)
             {
                 pawn.needs.mood.thoughts.situational.Notify_SituationalThoughtsDirty();
             }
         }
         bool flag2 = hediff is Hediff_MissingPart;
         if (!(hediff is Hediff_MissingPart) && hediff.Part != null && hediff.Part != pawn.RaceProps.body.corePart && GetPartHealth(hediff.Part) == 0f && hediff.Part != pawn.RaceProps.body.corePart)
         {
             bool flag3 = HasDirectlyAddedPartFor(hediff.Part);
             Hediff_MissingPart hediff_MissingPart = (Hediff_MissingPart)HediffMaker.MakeHediff(HediffDefOf.MissingBodyPart, pawn);
             hediff_MissingPart.IsFresh    = !flag3;
             hediff_MissingPart.lastInjury = hediff.def;
             pawn.health.AddHediff(hediff_MissingPart, hediff.Part, dinfo);
             damageResult?.AddHediff(hediff_MissingPart);
             if (flag3)
             {
                 if (dinfo.HasValue)
                 {
                     hediff_MissingPart.lastInjury = HealthUtility.GetHediffDefFromDamage(dinfo.Value.Def, pawn, hediff.Part);
                 }
                 else
                 {
                     hediff_MissingPart.lastInjury = null;
                 }
             }
             flag2 = true;
         }
         DirtyCache();
         if (flag2 && pawn.apparel != null)
         {
             pawn.apparel.Notify_LostBodyPart();
         }
         if (hediff.def.causesNeed != null && !pawn.Dead)
         {
             pawn.needs.AddOrRemoveNeedsAsAppropriate();
         }
     }
 }