public static InjurySeverity GetTendSeverity(this Pawn patient)
        {
            if (!HealthAIUtility.ShouldBeTendedNowByPlayer(patient))     //    .ShouldBeTendedNow( patient ) )
            {
                return(InjurySeverity.Minor);
            }

            var hediffs = patient.health.hediffSet.hediffs;
            var ticksToDeathDueToBloodLoss = HealthUtility.TicksUntilDeathDueToBloodLoss(patient);

            // going to die in <6 hours, or any tendable is life threathening
            if (ticksToDeathDueToBloodLoss <= GenDate.TicksPerHour * 6 ||
                hediffs.Any(h => h.CurStage?.lifeThreatening ?? false) ||
                hediffs.Any(NearLethalDisease))
            {
                return(InjurySeverity.LifeThreathening);
            }

            // going to die in <12 hours, or any immunity < severity and can be fatal, or death by a thousand cuts imminent
            if (ticksToDeathDueToBloodLoss <= GenDate.TicksPerHour * 12 ||
                hediffs.Any(PotentiallyLethalDisease) ||
                DeathByAThousandCuts(patient))
            {
                return(InjurySeverity.Major);
            }

            // otherwise
            return(InjurySeverity.Minor);
        }
Exemple #2
0
        private TextModel GetBleedWarning()
        {
            var bloodLossTicksRemaining = HealthUtility.TicksUntilDeathDueToBloodLoss(Model.Base);
            var text = bloodLossTicksRemaining < GenDate.TicksPerDay ? Lang.Get("Model.Health.Bleed", bloodLossTicksRemaining.ToStringTicksToPeriod()) : null;

            return(TextModel.Create(text, GetHealthTooltip(), Theme.CriticalColor.Value, OnClick));
        }
Exemple #3
0
        public static void DrawHediffListing(Rect rect, Pawn pawn, bool showBloodLoss)
        {
            GUI.color = Color.white;
            if (Prefs.DevMode && Current.ProgramState == ProgramState.Playing)
            {
                DoDebugOptions(rect, pawn);
            }
            GUI.BeginGroup(rect);
            float lineHeight = Text.LineHeight;
            Rect  outRect    = new Rect(0f, 0f, rect.width, rect.height - lineHeight);
            Rect  viewRect   = new Rect(0f, 0f, rect.width - 16f, scrollViewHeight);
            Rect  rect2      = rect;

            if (viewRect.height > outRect.height)
            {
                rect2.width -= 16f;
            }
            Widgets.BeginScrollView(outRect, ref scrollPosition, viewRect);
            GUI.color = Color.white;
            float curY = 0f;

            highlight = true;
            bool flag = false;

            if (Event.current.type == EventType.Layout)
            {
                lastMaxIconsTotalWidth = 0f;
            }
            foreach (IGrouping <BodyPartRecord, Hediff> item in VisibleHediffGroupsInOrder(pawn, showBloodLoss))
            {
                flag = true;
                DrawHediffRow(rect2, pawn, item, ref curY);
            }
            if (!flag)
            {
                Widgets.NoneLabelCenteredVertically(new Rect(0f, 0f, viewRect.width, outRect.height), "(" + "NoHealthConditions".Translate() + ")");
                curY = outRect.height - 1f;
            }
            if (Event.current.type == EventType.Repaint)
            {
                scrollViewHeight = curY;
            }
            else if (Event.current.type == EventType.Layout)
            {
                scrollViewHeight = Mathf.Max(scrollViewHeight, curY);
            }
            Widgets.EndScrollView();
            float bleedRateTotal = pawn.health.hediffSet.BleedRateTotal;

            if (bleedRateTotal > 0.01f)
            {
                Rect   rect3 = new Rect(0f, rect.height - lineHeight, rect.width, lineHeight);
                string t     = "BleedingRate".Translate() + ": " + bleedRateTotal.ToStringPercent() + "/" + "LetterDay".Translate();
                int    num   = HealthUtility.TicksUntilDeathDueToBloodLoss(pawn);
                t = ((num >= 60000) ? ((string)(t + (" (" + "WontBleedOutSoon".Translate() + ")"))) : ((string)(t + (" (" + "TimeToDeath".Translate(num.ToStringTicksToPeriod()) + ")"))));
                Widgets.Label(rect3, t);
            }
            GUI.EndGroup();
            GUI.color = Color.white;
        }
Exemple #4
0
        private static string GetHealthReport(Pawn subject)
        {
            var health  = subject.health;
            var payload = health.summaryHealth.SummaryHealthPercent.ToStringPercent() + " ";

            payload += health.State != PawnHealthState.Mobile
                ? GetHealthStateFriendly(health.State)
                : GetMoodFriendly(subject);

            if (health.hediffSet.BleedRateTotal > 0.01f)
            {
                var ticks = HealthUtility.TicksUntilDeathDueToBloodLoss(subject);

                payload += " | ";
                payload += ticks >= 60000 ? "⌛" : $"⏳ {ticks.ToStringTicksToPeriod(shortForm: true)}";
                payload += " | ";
            }

            var source = DefDatabase <PawnCapacityDef> .AllDefsListForReading;

            if (subject.def.race.Humanlike)
            {
                source = source.Where(c => c.showOnHumanlikes).ToList();
            }
            else if (subject.def.race.Animal)
            {
                source = source.Where(c => c.showOnAnimals).ToList();
            }
            else if (subject.def.race.IsMechanoid)
            {
                source = source.Where(c => c.showOnMechanoids).ToList();
            }
            else
            {
                source.Clear();
                payload += "Unsupported race";
            }

            if (!source.Any())
            {
                return(payload);
            }

            var container = "";

            foreach (var capacity in source.OrderBy(c => c.listOrder))
            {
                if (!PawnCapacityUtility.BodyCanEverDoCapacity(subject.RaceProps.body, capacity))
                {
                    continue;
                }

                container += $"{capacity.GetLabelFor(subject).CapitalizeFirst()}: ";
                container += HealthCardUtility.GetEfficiencyLabel(subject, capacity).First;
                container += ", ";
            }

            return(payload + container.Substring(0, container.Length - 2));
        }
Exemple #5
0
 public static bool ShouldBeTendedNowUrgent(Pawn pawn)
 {
     if (!HealthAIUtility.ShouldBeTendedNow(pawn))
     {
         return(false);
     }
     return(HealthUtility.TicksUntilDeathDueToBloodLoss(pawn) < 15000);
 }
Exemple #6
0
 public static bool ShouldBeTendedNowByPlayerUrgent(Pawn pawn)
 {
     if (ShouldBeTendedNowByPlayer(pawn))
     {
         return(HealthUtility.TicksUntilDeathDueToBloodLoss(pawn) < 45000);
     }
     return(false);
 }
        protected override string GetTip(Pawn pawn)
        {
            int ticksUntilDeathDueToBloodLoss = HealthUtility.TicksUntilDeathDueToBloodLoss(pawn);

            if (ticksUntilDeathDueToBloodLoss < GenDate.TicksPerDay)
                return "TimeToDeath".Translate(ticksUntilDeathDueToBloodLoss.ToStringTicksToPeriod());

            return "WontBleedOutSoon".Translate();
        }
Exemple #8
0
        public static void DrawHediffListing(Rect rect, Pawn pawn, bool showBloodLoss)
        {
            GUI.color = Color.white;
            if (Prefs.DevMode && Current.ProgramState == ProgramState.Playing)
            {
                HealthCardUtility.DoDebugOptions(rect, pawn);
            }
            GUI.BeginGroup(rect);
            float lineHeight = Text.LineHeight;
            Rect  outRect    = new Rect(0f, 0f, rect.width, rect.height - lineHeight);
            Rect  viewRect   = new Rect(0f, 0f, (float)(rect.width - 16.0), HealthCardUtility.scrollViewHeight);
            Rect  rect2      = rect;

            if (viewRect.height > outRect.height)
            {
                rect2.width -= 16f;
            }
            Widgets.BeginScrollView(outRect, ref HealthCardUtility.scrollPosition, viewRect, true);
            GUI.color = Color.white;
            float num = 0f;

            HealthCardUtility.highlight = true;
            bool flag = false;

            foreach (IGrouping <BodyPartRecord, Hediff> item in HealthCardUtility.VisibleHediffGroupsInOrder(pawn, showBloodLoss))
            {
                flag = true;
                HealthCardUtility.DrawHediffRow(rect2, pawn, item, ref num);
            }
            if (!flag)
            {
                GUI.color   = Color.gray;
                Text.Anchor = TextAnchor.UpperCenter;
                Rect rect3 = new Rect(0f, 0f, viewRect.width, 30f);
                Widgets.Label(rect3, "NoInjuries".Translate());
                Text.Anchor = TextAnchor.UpperLeft;
            }
            if (Event.current.type == EventType.Layout)
            {
                HealthCardUtility.scrollViewHeight = num;
            }
            Widgets.EndScrollView();
            float bleedRateTotal = pawn.health.hediffSet.BleedRateTotal;

            if (bleedRateTotal > 0.0099999997764825821)
            {
                Rect   rect4 = new Rect(0f, rect.height - lineHeight, rect.width, lineHeight);
                string str   = "BleedingRate".Translate() + ": " + bleedRateTotal.ToStringPercent() + "/" + "LetterDay".Translate();
                int    num2  = HealthUtility.TicksUntilDeathDueToBloodLoss(pawn);
                str = ((num2 >= 60000) ? (str + " (" + "WontBleedOutSoon".Translate() + ")") : (str + " (" + "TimeToDeath".Translate(num2.ToStringTicksToPeriod(true, false, true)) + ")"));
                Widgets.Label(rect4, str);
            }
            GUI.EndGroup();
            GUI.color = Color.white;
        }
        private static float GetTendPriority(Pawn patient)
        {
            int num = HealthUtility.TicksUntilDeathDueToBloodLoss(patient);

            if (num < 15000)
            {
                if (patient.RaceProps.Humanlike)
                {
                    return(GenMath.LerpDouble(0f, 15000f, 5f, 4f, (float)num));
                }
                return(GenMath.LerpDouble(0f, 15000f, 4f, 3f, (float)num));
            }
            else
            {
                int i = 0;
                while (i < patient.health.hediffSet.hediffs.Count)
                {
                    Hediff      hediff   = patient.health.hediffSet.hediffs[i];
                    HediffStage curStage = hediff.CurStage;
                    if (((curStage != null && curStage.lifeThreatening) || hediff.def.lethalSeverity >= 0f) && hediff.TendableNow(false))
                    {
                        if (patient.RaceProps.Humanlike)
                        {
                            return(2.5f);
                        }
                        return(2f);
                    }
                    else
                    {
                        i++;
                    }
                }
                if (patient.health.hediffSet.BleedRateTotal >= 0.0001f)
                {
                    if (patient.RaceProps.Humanlike)
                    {
                        return(1.5f);
                    }
                    return(1f);
                }
                else
                {
                    if (patient.RaceProps.Humanlike)
                    {
                        return(0.5f);
                    }
                    return(0f);
                }
            }
        }
        protected override string GetIconTip(Pawn pawn)
        {
            string text         = pawn.health.hediffSet.BleedRateTotal.ToStringPercent() + "/" + "LetterDay".Translate();
            int    ticksToDeath = HealthUtility.TicksUntilDeathDueToBloodLoss(pawn);

            if (ticksToDeath < 60000)
            {
                text += " (" + "TimeToDeath".Translate(ticksToDeath.ToStringTicksToPeriod()) + ")";
            }
            else
            {
                text = text + " (" + "WontBleedOutSoon".Translate() + ")";
            }
            return(text);
        }
        public static float computeTendPriority(Pawn worker, Pawn target)
        {
            bool  isSick          = target.health.hediffSet.HasImmunizableNotImmuneHediff();
            int   ticksToBleedOut = HealthUtility.TicksUntilDeathDueToBloodLoss(target);
            float delta           = float.MaxValue;
            float priority        = 0;

            if (isSick)
            {
                delta    = FindMostSevereHediffDelta(target);
                priority = ((float)Math.Pow(10, 20)) + delta;
            }
            else if (ticksToBleedOut < int.MaxValue)
            {
                priority = ((float)Math.Pow(10, 10)) - ticksToBleedOut;
            }
            //Log.Message("Hello from computeTendPriority with pawn: " + target.Name.ToStringShort + ", priority: " + priority);

            return(priority);
        }
Exemple #12
0
        protected override bool isPawnAffected(Pawn p)
        {
            /*
             * if (p.Faction != Faction.OfPlayer)
             * {
             *  return false;
             * }
             */
            int ticksToBleedDeath = HealthUtility.TicksUntilDeathDueToBloodLoss(p);

            if (ticksToBleedDeath < 60000)
            {
                bleeders[p] = ticksToBleedDeath;
                return(true);
            }
            else
            {
                bleeders.Remove(p);
                return(false);
            }
        }
Exemple #13
0
        public static void DoHediffTooltip(Rect rect, Pawn p, float bleedRate, float healthPercent)
        {
            var tooltip = new StringBuilder();

            tooltip.AppendLine("BleedingRate".Translate() + ": " + bleedRate.ToStringPercent() + "/" + "LetterDay".Translate());
            if (!Mathf.Approximately(bleedRate, 0f))
            {
                var ticksBloodLoss = HealthUtility.TicksUntilDeathDueToBloodLoss(p);
                tooltip.AppendLine(ticksBloodLoss < 60000 ? " (" + "TimeToDeath".Translate(ticksBloodLoss.ToStringTicksToPeriod(true)) + ")" : " (" + "WontBleedOutSoon".Translate() + ")");
            }
            tooltip.AppendLine();
            tooltip.AppendLine("FluffyMedical.HealthPoints".Translate() + ": " + healthPercent.ToStringPercent());
            if (Mathf.Approximately(healthPercent, 1f))
            {
                TooltipHandler.TipRegion(rect, tooltip.ToString());
                return;
            }

            try
            {
                var bodyPartRecords = p.RaceProps.body.AllParts;
                foreach (var bodyPartRecord in bodyPartRecords)
                {
                    var healthPoint = p.health.hediffSet.GetPartHealth(bodyPartRecord);
                    var hitPoint    = bodyPartRecord.def.GetMaxHealth(p);

                    if (Mathf.Approximately(healthPoint, hitPoint))
                    {
                        continue;
                    }

                    tooltip.AppendLine(bodyPartRecord.def.LabelCap + ": " + healthPoint.ToString() + " / " + bodyPartRecord.def.GetMaxHealth(p).ToString());
                }
            }
            catch (Exception)
            {
                Log.Message("Error getting tooltip for medical info.");
            }
            TooltipHandler.TipRegion(rect, tooltip.ToString());
        }
Exemple #14
0
        public override TaggedString GetExplanation()
        {
            StringBuilder stringBuilder = new StringBuilder();

            foreach (Pawn dyingAnimal in AnimalsNeedingRescue.OrderByDescending(a => a.health.hediffSet.BleedRateTotal))
            {
                int bloodLoss = HealthUtility.TicksUntilDeathDueToBloodLoss(dyingAnimal);
                stringBuilder.Append("    " + dyingAnimal.LabelShortCap);
                stringBuilder.Append(" (" + "TimeToDeath".Translate(bloodLoss.ToStringTicksToPeriod(true, false, true, true).Colorize(ColoredText.WarningColor)) + ")");
                stringBuilder.AppendLine();
            }

            var firstColonistWithAnimalRescue = ColonistsWithAnimalRescue.FirstOrFallback();

            Log.Message($"Druidlike: colonist: {firstColonistWithAnimalRescue?.NameShortColored}");

            if (AnimalsNeedingRescue.Count == 1)
            {
                return("AlertDownedAnimalDesc".Translate(firstColonistWithAnimalRescue?.NameShortColored ?? "", stringBuilder.ToString()));
            }
            return("AlertDownedAnimalsDesc".Translate(firstColonistWithAnimalRescue?.NameShortColored ?? "", stringBuilder.ToString()));
        }
Exemple #15
0
        // Token: 0x0600002F RID: 47 RVA: 0x00002870 File Offset: 0x00000A70
        public static void UseShard(Pawn doctor, Pawn patient, Cloakgen medkit)
        {
            bool flag = patient.health.HasHediffsNeedingTend(false);

            Log.Message(string.Format("UseShard flag: {0}, doctor: {1}, patient: {2}", flag, doctor, patient));
            if (flag)
            {
                Hediff hediff = HealthShardTendUtility.FindLifeThreateningHediff(patient);
                if (hediff != null)
                {
                    Log.Message(string.Format("hediff: {0}", hediff));
                    medkit.UseKit();
                    HealthShardTendUtility.Cure(hediff);
                    return;
                }
                if (HealthUtility.TicksUntilDeathDueToBloodLoss(patient) < 2500)
                {
                    Log.Message(string.Format("TicksUntilDeathDueToBloodLoss: {0}", HealthUtility.TicksUntilDeathDueToBloodLoss(patient)));
                    Hediff hediff2 = HealthShardTendUtility.FindMostBleedingHediff(patient);
                    if (hediff2 != null)
                    {
                        Log.Message(string.Format("hediff2: {0}", hediff2));
                        medkit.UseKit();
                        HealthShardTendUtility.Cure(hediff2);
                        return;
                    }
                }
                Hediff_Injury hediff_Injury3 = HealthShardTendUtility.FindInjury(patient, null);
                if (hediff_Injury3 != null)
                {
                    Log.Message(string.Format("hediff2: {0}", hediff_Injury3));
                    medkit.UseKit();
                    HealthShardTendUtility.Cure(hediff_Injury3);
                    return;
                }
            }
        }
        private bool UpdateInternal()
        {
            var entries = Find.ColonistBar.GetEntries();

            _entries = entries
                       .Where(t => t.pawn != null)
                       .OrderBy(t => t.@group)
                       .ThenBy(t => HealthUtility.TicksUntilDeathDueToBloodLoss(t.pawn))
                       .ToList();

            for (int i = 0; i < _entries.Count; i++)
            {
                if (_entries[i].pawn == entries[i].pawn)
                {
                    continue;
                }

                _cacheUsed = false;
                return(true);
            }

            _cacheUsed = false;
            return(false);
        }
Exemple #17
0
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);
            Hediff hediff = FindLifeThreateningHediff(usedBy);

            if (hediff != null)
            {
                Cure(hediff);
            }
            else
            {
                if (HealthUtility.TicksUntilDeathDueToBloodLoss(usedBy) < 2500)
                {
                    Hediff hediff2 = FindMostBleedingHediff(usedBy);
                    if (hediff2 != null)
                    {
                        Cure(hediff2);
                        return;
                    }
                }
                if (usedBy.health.hediffSet.GetBrain() != null)
                {
                    Hediff_Injury hediff_Injury = FindPermanentInjury(usedBy, Gen.YieldSingle(usedBy.health.hediffSet.GetBrain()));
                    if (hediff_Injury != null)
                    {
                        Cure(hediff_Injury);
                        return;
                    }
                }
                BodyPartRecord bodyPartRecord = FindBiggestMissingBodyPart(usedBy, HandCoverageAbsWithChildren);
                if (bodyPartRecord != null)
                {
                    Cure(bodyPartRecord, usedBy);
                }
                else
                {
                    Hediff_Injury hediff_Injury2 = FindPermanentInjury(usedBy, from x in usedBy.health.hediffSet.GetNotMissingParts()
                                                                       where x.def == BodyPartDefOf.Eye
                                                                       select x);
                    if (hediff_Injury2 != null)
                    {
                        Cure(hediff_Injury2);
                    }
                    else
                    {
                        Hediff hediff3 = FindImmunizableHediffWhichCanKill(usedBy);
                        if (hediff3 != null)
                        {
                            Cure(hediff3);
                        }
                        else
                        {
                            Hediff hediff4 = FindNonInjuryMiscBadHediff(usedBy, onlyIfCanKill: true);
                            if (hediff4 != null)
                            {
                                Cure(hediff4);
                            }
                            else
                            {
                                Hediff hediff5 = FindNonInjuryMiscBadHediff(usedBy, onlyIfCanKill: false);
                                if (hediff5 != null)
                                {
                                    Cure(hediff5);
                                }
                                else
                                {
                                    if (usedBy.health.hediffSet.GetBrain() != null)
                                    {
                                        Hediff_Injury hediff_Injury3 = FindInjury(usedBy, Gen.YieldSingle(usedBy.health.hediffSet.GetBrain()));
                                        if (hediff_Injury3 != null)
                                        {
                                            Cure(hediff_Injury3);
                                            return;
                                        }
                                    }
                                    BodyPartRecord bodyPartRecord2 = FindBiggestMissingBodyPart(usedBy);
                                    if (bodyPartRecord2 != null)
                                    {
                                        Cure(bodyPartRecord2, usedBy);
                                    }
                                    else
                                    {
                                        Hediff_Addiction hediff_Addiction = FindAddiction(usedBy);
                                        if (hediff_Addiction != null)
                                        {
                                            Cure(hediff_Addiction);
                                        }
                                        else
                                        {
                                            Hediff_Injury hediff_Injury4 = FindPermanentInjury(usedBy);
                                            if (hediff_Injury4 != null)
                                            {
                                                Cure(hediff_Injury4);
                                            }
                                            else
                                            {
                                                Hediff_Injury hediff_Injury5 = FindInjury(usedBy);
                                                if (hediff_Injury5 != null)
                                                {
                                                    Cure(hediff_Injury5);
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #18
0
            static bool Prefix(Pawn_JobTracker_Crutch __instance, JobCondition condition)
            {
                if (__instance == null || __instance._pawn == null || !__instance._pawn.IsColonistPlayerControlled || __instance.curJob == null)
                {
                    return(true);
                }

                if (Settings.fun_police && __instance._pawn.needs.joy != null && __instance._pawn.needs.joy.CurLevel > 0.95f)
                {
                    CompJoyToppedOff c = __instance._pawn.TryGetComp <CompJoyToppedOff>();
                    if (c != null)
                    {
                        c.JoyToppedOff = true;
                    }
                }

                Job job = null;

                if (Settings.clean_before_work && condition == JobCondition.Succeeded && __instance.jobQueue != null &&
                    __instance.jobQueue.Count == 0 && __instance.curJob != null && ProperJob(__instance.curJob, __instance._pawn, JobDefOf.DeliverFood))
                {
                    job = MakeCleaningJob(__instance._pawn, __instance.curJob.targetA, Settings.op_clean_num);
                }

                if (Settings.clean_after_tending && condition == JobCondition.Succeeded && __instance.jobQueue != null &&
                    __instance.jobQueue.Count == 0 && ProperJob(__instance.curJob, __instance._pawn, JobDefOf.TendPatient))
                {
                    ThinkTreeDef thinkTree   = null;
                    MethodInfo   mi          = AccessTools.Method(typeof(Pawn_JobTracker), "DetermineNextJob");
                    ThinkResult  thinkResult = (ThinkResult)mi.Invoke(__instance, new object[] { thinkTree });
                    if (ProperJob(thinkResult.Job, __instance._pawn, JobDefOf.TendPatient))
                    {
                        Pawn pawn = (Pawn)thinkResult.Job.targetA.Thing;
                        if (pawn.GetRoom() == __instance.curJob.targetA.Thing.GetRoom() || ((float)HealthUtility.TicksUntilDeathDueToBloodLoss(pawn) / 2500f) < 6)
                        {
                            return(true);
                        }
                    }

                    job = MakeCleaningJob(__instance._pawn, __instance.curJob.targetA, Settings.doc_clean_num);
                }
                //
                if (job != null)
                {
                    __instance.jobQueue.EnqueueFirst(job);
                }
                //
                return(true);
            }
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);
            Hediff hediff = this.FindLifeThreateningHediff(usedBy);

            if (hediff != null)
            {
                this.Cure(hediff);
            }
            else
            {
                if (HealthUtility.TicksUntilDeathDueToBloodLoss(usedBy) < 5000)
                {
                    Hediff hediff2 = this.FindMostBleedingHediff(usedBy);
                    if (hediff2 != null)
                    {
                        this.Cure(hediff2);
                        return;
                    }
                }
                Hediff hediff3 = this.FindImmunizableHediffWhichCanKill(usedBy);
                if (hediff3 != null)
                {
                    this.Cure(hediff3);
                }
                else
                {
                    Hediff hediff4 = this.FindCarcinoma(usedBy);
                    if (hediff4 != null)
                    {
                        this.Cure(hediff4);
                    }
                    else
                    {
                        Hediff hediff5 = this.FindNonInjuryMiscBadHediff(usedBy, true);
                        if (hediff5 != null)
                        {
                            this.Cure(hediff5);
                        }
                        else
                        {
                            Hediff hediff6 = this.FindNonInjuryMiscBadHediff(usedBy, false);
                            if (hediff6 != null)
                            {
                                this.Cure(hediff6);
                            }
                            else
                            {
                                BodyPartRecord bodyPartRecord = this.FindBiggestMissingBodyPart(usedBy, 0.01f);
                                if (bodyPartRecord != null)
                                {
                                    this.Cure(bodyPartRecord, usedBy);
                                }
                                else
                                {
                                    Hediff_Injury hediff_Injury = this.FindInjury(usedBy, usedBy.health.hediffSet.GetBrain());
                                    if (hediff_Injury != null)
                                    {
                                        this.Cure(hediff_Injury);
                                    }
                                    else
                                    {
                                        BodyPartRecord bodyPartRecord2 = this.FindBiggestMissingBodyPart(usedBy, 0f);
                                        if (bodyPartRecord2 != null)
                                        {
                                            this.Cure(bodyPartRecord2, usedBy);
                                        }
                                        else
                                        {
                                            Hediff_Addiction hediff_Addiction = this.FindAddiction(usedBy);
                                            if (hediff_Addiction != null)
                                            {
                                                this.Cure(hediff_Addiction);
                                            }
                                            else
                                            {
                                                Hediff_Injury hediff_Injury2 = this.FindOldInjury(usedBy);
                                                if (hediff_Injury2 != null)
                                                {
                                                    this.Cure(hediff_Injury2);
                                                }
                                                else
                                                {
                                                    Hediff_Injury hediff_Injury3 = this.FindInjury(usedBy, null);
                                                    if (hediff_Injury3 != null)
                                                    {
                                                        this.Cure(hediff_Injury3);
                                                    }
                                                }
                                            }
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
Exemple #20
0
        private static string HealthReport([NotNull] Pawn pawn)
        {
            var segments = new List <string>
            {
                ResponseHelper.JoinPair("TKUtils.PawnHealth.OverallHealth".Localize(), pawn.health.summaryHealth.SummaryHealthPercent.ToStringPercent())
            };

            if (pawn.health.State != PawnHealthState.Mobile)
            {
                segments[0] += $" {GetHealthStateFriendly(pawn.health.State)}";
            }
            else
            {
                segments[0] += $" {GetMoodFriendly(pawn)}";
            }

            if (pawn.health.hediffSet.BleedRateTotal > 0.01f)
            {
                int ticks = HealthUtility.TicksUntilDeathDueToBloodLoss(pawn);

                segments.Add(
                    ticks >= 60000
                        ? ResponseHelper.BleedingSafeGlyphs.AltText("WontBleedOutSoon".Localize().CapitalizeFirst())
                        : $"{ResponseHelper.BleedingBadGlyphs.AltText("BleedingRate".Localize())} ({ticks.ToStringTicksToPeriod(shortForm: true)})"
                    );
            }

            List <PawnCapacityDef> source = GetCapacitiesForPawn(pawn).ToList();

            if (source.Count > 0)
            {
                source = source.OrderBy(d => d.listOrder).ToList();

                string[] capacities = source.Where(capacity => PawnCapacityUtility.BodyCanEverDoCapacity(pawn.RaceProps.body, capacity))
                                      .Select(
                    capacity => ResponseHelper.JoinPair(
                        RichTextHelper.StripTags(capacity.GetLabelFor(pawn)).CapitalizeFirst(),
                        HealthCardUtility.GetEfficiencyLabel(pawn, capacity).First
                        )
                    )
                                      .ToArray();

                segments.Add(capacities.SectionJoin());
            }
            else
            {
                segments.Add("TKUtils.Responses.UnsupportedRace".LocalizeKeyed(pawn.kindDef.race.defName));
            }

            if (!TkSettings.ShowSurgeries)
            {
                return(segments.GroupedJoin());
            }

            BillStack surgeries = pawn.health.surgeryBills;

            if (surgeries?.Count <= 0)
            {
                return(segments.GroupedJoin());
            }

            string[] queued = surgeries !.Bills.Select(item => RichTextHelper.StripTags(item.LabelCap)).ToArray();

            segments.Add(ResponseHelper.JoinPair("TKUtils.PawnHealth.QueuedSurgeries".Localize(), queued.SectionJoin()));

            return(segments.GroupedJoin());
        }
Exemple #21
0
        public static object GetPawnHealable([NotNull] Pawn pawn)
        {
            Hediff hediff = FindLifeThreateningHediff(pawn);

            if (hediff != null)
            {
                return(hediff);
            }

            if (HealthUtility.TicksUntilDeathDueToBloodLoss(pawn) < 2500)
            {
                Hediff hediff2 = FindMostBleedingHediff(pawn);

                if (hediff2 != null)
                {
                    return(hediff2);
                }
            }

            if (pawn.health.hediffSet.GetBrain() != null)
            {
                Hediff_Injury injury = FindPermanentInjury(pawn, Gen.YieldSingle(pawn.health.hediffSet.GetBrain()) as IReadOnlyCollection <BodyPartRecord>);

                if (injury != null)
                {
                    return(injury);
                }
            }

            BodyPartRecord bodyPartRecord = FindBiggestMissingBodyPart(pawn, HandCoverageAbsWithChildren);

            if (bodyPartRecord != null)
            {
                return(bodyPartRecord);
            }

            Hediff_Injury injury2 = FindPermanentInjury(
                pawn,
                pawn.health.hediffSet.GetNotMissingParts().Where(p => p.def == BodyPartDefOf.Eye) as IReadOnlyCollection <BodyPartRecord>
                );

            if (injury2 != null)
            {
                return(injury2);
            }

            Hediff hediff3 = FindImmunizableHediffWhichCanKill(pawn);

            if (hediff3 != null)
            {
                return(hediff3);
            }

            Hediff hediff4 = FindNonInjuryMiscBadHediff(pawn, true);

            if (hediff4 != null)
            {
                return(hediff4);
            }

            Hediff hediff5 = FindNonInjuryMiscBadHediff(pawn, false);

            if (hediff5 != null)
            {
                return(hediff5);
            }

            if (pawn.health.hediffSet.GetBrain() != null)
            {
                Hediff_Injury injury3 = FindInjury(pawn, Gen.YieldSingle(pawn.health.hediffSet.GetBrain()) as IReadOnlyCollection <BodyPartRecord>);

                if (injury3 != null)
                {
                    return(injury3);
                }
            }

            BodyPartRecord bodyPartRecord2 = FindBiggestMissingBodyPart(pawn);

            if (bodyPartRecord2 != null)
            {
                return(bodyPartRecord2);
            }

            Hediff_Addiction addiction = FindAddiction(pawn);

            if (addiction != null)
            {
                return(addiction);
            }

            Hediff_Injury injury4 = FindPermanentInjury(pawn);

            return(injury4 ?? FindInjury(pawn));
        }
Exemple #22
0
        private static string MyPawnHealthSummary(Viewer viewer, Pawn pawn)
        {
            string healthPercent = (pawn.health.summaryHealth.SummaryHealthPercent * 100.0f).ToString("n1") + "%";
            string output        = $"@{viewer.username} {pawn.Name.ToStringShort.CapitalizeFirst()}'s health: {healthPercent} ";

            if (pawn.health.State != PawnHealthState.Mobile)
            {
                output += $"({HealthStateForPawn(pawn)}) ";
            }

            if (pawn.health.hediffSet.BleedRateTotal > 0.01f)
            {
                int ticksUntilDeath = HealthUtility.TicksUntilDeathDueToBloodLoss(pawn);
                if (ticksUntilDeath < 60000)
                {
                    output += "- " + "TimeToDeath".Translate(ticksUntilDeath.ToStringTicksToPeriod()) + " ";
                }
                else
                {
                    output += "- " + "WontBleedOutSoon".Translate() + " ";
                }
            }

            output += " | ";

            IEnumerable <PawnCapacityDef> capacityDefs;

            if (pawn.def.race.Humanlike)
            {
                capacityDefs = from x in DefDatabase <PawnCapacityDef> .AllDefs
                               where x.showOnHumanlikes
                               select x;
            }
            else if (pawn.def.race.Animal)
            {
                capacityDefs = from x in DefDatabase <PawnCapacityDef> .AllDefs
                               where x.showOnAnimals
                               select x;
            }
            else if (pawn.def.race.IsMechanoid)
            {
                capacityDefs = from x in DefDatabase <PawnCapacityDef> .AllDefs
                               where x.showOnMechanoids
                               select x;
            }
            else
            {
                capacityDefs = new List <PawnCapacityDef>();
                output      += "(can't show capacities for this race) ";
            }
            foreach (PawnCapacityDef pawnCapacityDef in from def in capacityDefs
                     orderby def.listOrder
                     select def)
            {
                if (PawnCapacityUtility.BodyCanEverDoCapacity(pawn.RaceProps.body, pawnCapacityDef))
                {
                    Pair <string, Color> efficiencyLabel = HealthCardUtility.GetEfficiencyLabel(pawn, pawnCapacityDef);
                    output += $"{pawnCapacityDef}: {efficiencyLabel.First} | ";
                }
            }
            if (capacityDefs.Count() > 0)
            {
                output = output.Substring(0, output.Length - 2);
            }

            if (ModSettings.Singleton.MyPawnHealthShowSurgeries)
            {
                output += " | Queued Surgeries - ";
                if (pawn.health.surgeryBills?.Count > 0)
                {
                    foreach (var surgeryBill in pawn.health.surgeryBills)
                    {
                        output += $"{surgeryBill.LabelCap}, ";
                    }
                    output = output.Substring(0, output.Length - 2);
                }
                else
                {
                    output += $"none";
                }
            }
            return(output);
        }
Exemple #23
0
        //Taken from CompUseEffect_FixWorstHealthCondition, with a bit of Resharper cleanup to stop my eyes bleeding.
        private static int CalcHealthThreatenedScore(Pawn usedBy)
        {
            Hediff hediff = FindLifeThreateningHediff(pawn: usedBy);

            if (hediff != null)
            {
                return(8192);
            }

            if (HealthUtility.TicksUntilDeathDueToBloodLoss(pawn: usedBy) < 2500)
            {
                Hediff hediff2 = FindMostBleedingHediff(pawn: usedBy);
                if (hediff2 != null)
                {
                    return(4096);
                }
            }

            if (usedBy.health.hediffSet.GetBrain() != null)
            {
                Hediff_Injury hediffInjury = FindPermanentInjury(pawn: usedBy, allowedBodyParts: Gen.YieldSingle(val: usedBy.health.hediffSet.GetBrain()));
                if (hediffInjury != null)
                {
                    return(2048);
                }
            }

            BodyPartRecord bodyPartRecord = FindBiggestMissingBodyPart(pawn: usedBy, minCoverage: HandCoverageAbsWithChildren);

            if (bodyPartRecord != null)
            {
                return(1024);
            }

            Hediff_Injury hediffInjury2 = FindPermanentInjury(pawn: usedBy,
                                                              allowedBodyParts: usedBy.health.hediffSet.GetNotMissingParts()
                                                              .Where(predicate: x => x.def == BodyPartDefOf.Eye));

            if (hediffInjury2 != null)
            {
                return(512);
            }

            Hediff hediff3 = FindImmunizableHediffWhichCanKill(pawn: usedBy);

            if (hediff3 != null)
            {
                return(255);
            }

            Hediff hediff4 = FindNonInjuryMiscBadHediff(pawn: usedBy, onlyIfCanKill: true);

            if (hediff4 != null)
            {
                return(128);
            }

            Hediff hediff5 = FindNonInjuryMiscBadHediff(pawn: usedBy, onlyIfCanKill: false);

            if (hediff5 != null)
            {
                return(64);
            }

            if (usedBy.health.hediffSet.GetBrain() != null)
            {
                Hediff_Injury hediffInjury3 = FindInjury(pawn: usedBy, allowedBodyParts: Gen.YieldSingle(val: usedBy.health.hediffSet.GetBrain()));
                if (hediffInjury3 != null)
                {
                    return(32);
                }
            }
            BodyPartRecord bodyPartRecord2 = FindBiggestMissingBodyPart(pawn: usedBy);

            if (bodyPartRecord2 != null)
            {
                return(16);
            }

            Hediff_Addiction hediffAddiction = FindAddiction(pawn: usedBy);

            if (hediffAddiction != null)
            {
                return(8);
            }

            Hediff_Injury hediffInjury4 = FindPermanentInjury(pawn: usedBy);

            if (hediffInjury4 != null)
            {
                return(4);
            }

            Hediff_Injury hediffInjury5 = FindInjury(pawn: usedBy);

            if (hediffInjury5 != null)
            {
                return(2);
            }

            return(0);
        }
Exemple #24
0
        /// <summary>
        /// Does the effect.
        /// </summary>
        /// <param name="usedBy">the pawn that used this instance</param>
        public override void DoEffect(Pawn usedBy)
        {
            base.DoEffect(usedBy);
            var mutagen = parent.def.GetModExtension <MutagenExtension>()?.mutagen;

            Hediff hediff = FindLifeThreateningHediff(usedBy);

            if (hediff != null)
            {
                Cure(hediff);
                return;
            }

            if (HealthUtility.TicksUntilDeathDueToBloodLoss(usedBy) < 2500)
            {
                Hediff hediff2 = FindMostBleedingHediff(usedBy);
                if (hediff2 != null)
                {
                    Cure(hediff2);
                    return;
                }
            }

            if (usedBy.health.hediffSet.GetBrain() != null)
            {
                Hediff_Injury hediff_Injury = FindPermanentInjury(usedBy, Gen.YieldSingle(usedBy.health.hediffSet.GetBrain()));
                if (hediff_Injury != null)
                {
                    Cure(hediff_Injury);
                    return;
                }
            }

            BodyPartRecord bodyPartRecord = FindBiggestMissingBodyPart(usedBy, HandCoverageAbsWithChildren);

            if (bodyPartRecord != null)
            {
                Cure(bodyPartRecord, usedBy);
                return;
            }

            Hediff_Injury hediff_Injury2 = FindPermanentInjury(usedBy, from x in usedBy.health.hediffSet.GetNotMissingParts()
                                                               where x.def == BodyPartDefOf.Eye
                                                               select x);

            if (hediff_Injury2 != null)
            {
                Cure(hediff_Injury2);

                if (hediff_Injury2.Part != null)
                {
                    AddMutationToPart(hediff_Injury2.Part, usedBy, usedBy.GetMutationTracker()?.HighestInfluence, mutagen: mutagen);
                }


                return;
            }

            Hediff hediff3 = FindImmunizableHediffWhichCanKill(usedBy);

            if (hediff3 != null)
            {
                Cure(hediff3);
                return;
            }

            Hediff hediff4 = FindNonInjuryMiscBadHediff(usedBy, true);

            if (hediff4 != null)
            {
                Cure(hediff4);
                return;
            }

            Hediff hediff5 = FindNonInjuryMiscBadHediff(usedBy, false);

            if (hediff5 != null)
            {
                Cure(hediff5);
                return;
            }

            if (usedBy.health.hediffSet.GetBrain() != null)
            {
                Hediff_Injury hediff_Injury3 = FindInjury(usedBy, Gen.YieldSingle(usedBy.health.hediffSet.GetBrain()));
                if (hediff_Injury3 != null)
                {
                    Cure(hediff_Injury3);
                    return;
                }
            }

            BodyPartRecord bodyPartRecord2 = FindBiggestMissingBodyPart(usedBy);

            if (bodyPartRecord2 != null)
            {
                Cure(bodyPartRecord2, usedBy);
                return;
            }

            Hediff_Addiction hediff_Addiction = FindAddiction(usedBy);

            if (hediff_Addiction != null)
            {
                Cure(hediff_Addiction);
                return;
            }

            Hediff_Injury hediff_Injury4 = FindPermanentInjury(usedBy);

            if (hediff_Injury4 != null)
            {
                Cure(hediff_Injury4);
                return;
            }

            Hediff_Injury hediff_Injury5 = FindInjury(usedBy);

            if (hediff_Injury5 != null)
            {
                Cure(hediff_Injury5);
            }

            var tracker = usedBy.GetAspectTracker();
            var bAspect = FindBadAspectToRemove(usedBy);

            if (tracker != null && bAspect != null)
            {
                tracker.Remove(bAspect);
                ApplyMutagen(usedBy);
            }
        }