public static void DamageUntilDowned(Pawn p, bool allowBleedingWounds = true) { if (p.health.Downed) { return; } HediffSet hediffSet = p.health.hediffSet; p.health.forceIncap = true; IEnumerable <BodyPartRecord> source = from x in HealthUtility.HittablePartsViolence(hediffSet) where !p.health.hediffSet.hediffs.Any((Hediff y) => y.Part == x && y.CurStage != null && y.CurStage.partEfficiencyOffset < 0f) select x; int num = 0; while (num < 300 && !p.Downed && source.Any <BodyPartRecord>()) { num++; BodyPartRecord bodyPartRecord = source.RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Mathf.RoundToInt(hediffSet.GetPartHealth(bodyPartRecord)) - 3; if (num2 >= 8) { DamageDef damageDef; if (bodyPartRecord.depth == BodyPartDepth.Outside) { if (!allowBleedingWounds && bodyPartRecord.def.bleedRate > 0f) { damageDef = DamageDefOf.Blunt; } else { damageDef = HealthUtility.RandomViolenceDamageType(); } } else { damageDef = DamageDefOf.Blunt; } int num3 = Rand.RangeInclusive(Mathf.RoundToInt((float)num2 * 0.65f), num2); HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(damageDef, p, bodyPartRecord); if (!p.health.WouldDieAfterAddingHediff(hediffDefFromDamage, bodyPartRecord, (float)num3)) { DamageDef def = damageDef; float amount = (float)num3; float armorPenetration = 999f; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, armorPenetration, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown, null); dinfo.SetAllowDamagePropagation(false); p.TakeDamage(dinfo); } } } if (p.Dead) { StringBuilder stringBuilder = new StringBuilder(); stringBuilder.AppendLine(p + " died during GiveInjuriesToForceDowned"); for (int i = 0; i < p.health.hediffSet.hediffs.Count; i++) { stringBuilder.AppendLine(" -" + p.health.hediffSet.hediffs[i].ToString()); } Log.Error(stringBuilder.ToString(), false); } p.health.forceIncap = false; }
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(); } } }
public static void GiveInjuriesOperationFailureCatastrophic(Pawn p, BodyPartRecord part) { HealthUtility.GiveRandomSurgeryInjuries(p, 65, part); }
public static void GiveInjuriesOperationFailureRidiculous(Pawn p) { HealthUtility.GiveRandomSurgeryInjuries(p, 65, null); }
public static void GiveInjuriesOperationFailureMinor(Pawn p, BodyPartRecord part) { HealthUtility.GiveRandomSurgeryInjuries(p, 20, part); }
private static void DoPlayLoad() { GraphicDatabase.Clear(); DeepProfiler.Start("Load all active mods."); try { LoadedModManager.LoadAllActiveMods(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Load language metadata."); try { LanguageDatabase.LoadAllMetadata(); } finally { DeepProfiler.End(); } LongEventHandler.SetCurrentEventText("LoadingDefs".Translate()); DeepProfiler.Start("Copy all Defs from mods to global databases."); try { foreach (Type item in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods"); } } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between non-implied Defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind defs (early)."); try { DefOfHelper.RebindAllDefOfs(true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (pre-resolve)."); try { DefGenerator.GenerateImpliedDefs_PreResolve(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs."); try { DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors); } finally { DeepProfiler.End(); } DeepProfiler.Start("Rebind DefOfs (final)."); try { DefOfHelper.RebindAllDefOfs(false); } finally { DeepProfiler.End(); } DeepProfiler.Start("Other def binding, resetting and global operations."); try { PlayerKnowledgeDatabase.ReloadAndRebind(); LessonAutoActivator.Reset(); CostListCalculator.Reset(); PawnApparelGenerator.Reset(); RestUtility.Reset(); ThoughtUtility.Reset(); PawnWeaponGenerator.Reset(); ThinkTreeKeyAssigner.Reset(); ThingCategoryNodeDatabase.FinalizeInit(); TrainableUtility.Reset(); HaulAIUtility.Reset(); GenConstruct.Reset(); WorkGiver_FillFermentingBarrel.Reset(); WorkGiver_DoBill.Reset(); Pawn.Reset(); WorkGiver_InteractAnimal.Reset(); WorkGiver_Warden_DoExecution.Reset(); WorkGiver_GrowerSow.Reset(); WorkGiver_Miner.Reset(); MedicalCareUtility.Reset(); InspectPaneUtility.Reset(); GraphicDatabaseHeadRecords.Reset(); DateReadout.Reset(); ResearchProjectDef.GenerateNonOverlappingCoordinates(); WorkGiver_FixBrokenDownBuilding.CacheTranslations(); ItemCollectionGeneratorUtility.Reset(); BaseGen.Reset(); HealthUtility.Reset(); ResourceCounter.ResetDefs(); WildSpawner.Reset(); ApparelProperties.Reset(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Resolve references."); try { foreach (Type item2 in typeof(Def).AllSubclasses()) { if (item2 != typeof(ThingDef)) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true); } } DefDatabase <ThingDef> .ResolveAllReferences(true); } finally { DeepProfiler.End(); } DeepProfiler.Start("Generate implied Defs (post-resolve)."); try { DefGenerator.GenerateImpliedDefs_PostResolve(); } finally { DeepProfiler.End(); } if (Prefs.DevMode) { DeepProfiler.Start("Error check all defs."); try { foreach (Type item3 in typeof(Def).AllSubclasses()) { GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs"); } } finally { DeepProfiler.End(); } } LongEventHandler.SetCurrentEventText("Initializing".Translate()); DeepProfiler.Start("Load keyboard preferences."); try { KeyPrefs.Init(); } finally { DeepProfiler.End(); } DeepProfiler.Start("Short hash giving."); try { ShortHashGiver.GiveAllShortHashes(); } finally { DeepProfiler.End(); } LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Load backstories."); try { BackstoryDatabase.ReloadAllBackstories(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { DeepProfiler.Start("Inject selected language data into game data."); try { LanguageDatabase.activeLanguage.InjectIntoData(); GenLabel.ClearCache(); } finally { DeepProfiler.End(); } }); LongEventHandler.ExecuteWhenFinished(delegate { StaticConstructorOnStartupUtility.CallAll(); if (Prefs.DevMode) { StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes(); } }); }
private void CheckDuplicateDamageToOuterParts(DamageInfo dinfo, Pawn pawn, float totalDamage, DamageResult result) { if (!dinfo.AllowDamagePropagation || !dinfo.Def.harmAllLayersUntilOutside || dinfo.HitPart.depth != BodyPartDepth.Inside) { return; } BodyPartRecord parent = dinfo.HitPart.parent; do { if (pawn.health.hediffSet.GetPartHealth(parent) != 0f && parent.coverageAbs > 0f) { Hediff_Injury hediff_Injury = (Hediff_Injury)HediffMaker.MakeHediff(HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, parent), pawn); hediff_Injury.Part = parent; hediff_Injury.source = dinfo.Weapon; hediff_Injury.sourceBodyPartGroup = dinfo.WeaponBodyPartGroup; hediff_Injury.Severity = totalDamage; if (hediff_Injury.Severity <= 0f) { hediff_Injury.Severity = 1f; } FinalizeAndAddInjury(pawn, hediff_Injury, dinfo, result); } if (parent.depth != BodyPartDepth.Outside) { parent = parent.parent; continue; } break; }while (parent != null); }
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)); }
public static void DamageUntilDead(Pawn p) { HediffSet hediffSet = p.health.hediffSet; int num = 0; while (!p.Dead && num < 200 && HealthUtility.HittablePartsViolence(hediffSet).Any()) { num++; BodyPartRecord bodyPartRecord = HealthUtility.HittablePartsViolence(hediffSet).RandomElementByWeight((BodyPartRecord x) => x.coverageAbs); int num2 = Rand.RangeInclusive(8, 25); DamageDef damageDef = (bodyPartRecord.depth != BodyPartDepth.Outside) ? DamageDefOf.Blunt : HealthUtility.RandomViolenceDamageType(); DamageDef def = damageDef; int amount = num2; BodyPartRecord hitPart = bodyPartRecord; DamageInfo dinfo = new DamageInfo(def, amount, -1f, null, hitPart, null, DamageInfo.SourceCategory.ThingOrUnknown); p.TakeDamage(dinfo); } if (!p.Dead) { Log.Error(p + " not killed during GiveInjuriesToKill"); } }