private void ReadFormXML() { ItemThingDefs newThingDefs = (ItemThingDefs)this.def; if (newThingDefs != null) { HediffToAdd = newThingDefs.HediffToAdd; BodyPartToHediff = newThingDefs.BodyPartToHediff; HediffSeverityStage = newThingDefs.HediffSeverityStage; } }
public List <UniqueBodyPart> FindBodyPartsForDef(BodyPartDef def) { if (bodyPartDefLookup.TryGetValue(def, out List <UniqueBodyPart> result)) { return(result); } else { return(null); } }
public static BodyPartRecord GetBodyPartRecord( this HediffSet hediffSet, BodyPartDef bodyPartDef ) { foreach( BodyPartRecord bodyPartRecord in hediffSet.GetNotMissingParts( new BodyPartHeight?(), new BodyPartDepth?() ) ) { if( bodyPartRecord.def == bodyPartDef ) { return bodyPartRecord; } } return (BodyPartRecord) null; }
public static bool CheckIfExistingNaturalBP(this Pawn pawn, BodyPartDef bodyPartDef, bool myDebug = false) { BodyPartRecord BPR = pawn.GetBPRecord(bodyPartDef) ?? null; if (BPR == null || pawn.health.hediffSet.PartIsMissing(BPR) || pawn.health.hediffSet.AncestorHasDirectlyAddedParts(BPR)) { return(false); } return(true); }
public void AddBodyPartReplacement(string name, string newPart, int index) { BodyPartDef def = DefDatabase <BodyPartDef> .GetNamedSilentFail(newPart); if (def == null) { Log.Warning("Could not find body part definition \"" + newPart + "\" to replace body part \"" + name + "\""); return; } bodyPartReplacements.Add(name, new ReplacementBodyPart(def, index)); }
public static BodyPartRecord GetBodyPartRecord(this HediffSet hediffSet, BodyPartDef bodyPartDef) { foreach (BodyPartRecord bodyPartRecord in hediffSet.GetNotMissingParts(new BodyPartHeight?(), new BodyPartDepth?())) { if (bodyPartRecord.def == bodyPartDef) { return(bodyPartRecord); } } return((BodyPartRecord)null); }
public static float GetMaxHealth(BodyPartDef def, Pawn pawn, BodyPartRecord record) { if (makeshiftEbfEndpoint != null) { if (myDelegate == null) { myDelegate = MethodInvoker.GetHandler(makeshiftEbfEndpoint); } return((float)myDelegate(null, new object[] { def, pawn, record })); } return(def.GetMaxHealth(pawn)); }
public static BodyPartRecord GetRelevantBodyPartRecord(Pawn pawn, std_def std) { if (std.appliedOnFixedBodyParts == null) { return(null); } BodyPartDef target = std.appliedOnFixedBodyParts.Single(); return(pawn?.RaceProps.body.GetPartsWithDef(target).Single()); //return pawn?.RaceProps.body.GetPartsWithDef(std.appliedOnFixedBodyParts.Single()).Single(); }
public static Hediff HasRelevantHediff(this Pawn pawn, BodyPartDef BPDef, string customLabel, bool debug = false) { Hediff priorityH = null; IEnumerable <BodyPartRecord> IEBpr = pawn.RaceProps.body.GetPartsWithDef(BPDef).Where(bpr => bpr.customLabel == customLabel); if (IEBpr.EnumerableNullOrEmpty()) { Tools.Warn("Could not find " + BPDef.defName + " with custom label " + customLabel); return(null); } BodyPartRecord AimedBpr = IEBpr.First(); foreach (HediffDef hDef in relevantHediffList) { Hediff myH = null; IEnumerable <Hediff> hList = pawn.health.hediffSet.hediffs.Where(h => h.Part == AimedBpr && h.def == hDef); if (hList.EnumerableNullOrEmpty()) { continue; } if ((myH = hList.First()) == null) { continue; } if (hDef == HediffDefOf.MissingBodyPart && HasBionicParent(pawn, AimedBpr)) { continue; } if (priorityH == null) { priorityH = myH; } else { if ((hDef == HediffDefOf.PegLeg || hDef == MyDefs.WoodenFootHediffDef) && priorityH.def == HediffDefOf.MissingBodyPart) { priorityH = myH; } } } if (priorityH != null) { Tools.Warn(pawn.LabelShort + " disability found:" + priorityH.def.defName, debug); } return(priorityH); }
public static IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { for (int i = 0; i < recipe.appliedOnFixedBodyParts.Count; i++) { BodyPartDef part = recipe.appliedOnFixedBodyParts[i]; BodyPartRecord r = pawn.health.hediffSet.GetNotMissingParts().FirstOrDefault((BodyPartRecord x) => x.def == part); if (r != null) { yield return(r); } } }
public int CountOfMatchingBodyParts(BodyPartDef def) { List <UniqueBodyPart> result; if (bodyPartDefLookup.TryGetValue(def, out result)) { return(result.Count); } else { return(0); } }
public static bool DoesBodyPartMatch(BodyPartDef bpd, string match) { if (match == null) { return(false); } string cleanMatch = SimplifyBodyPartLabel(match); return( SimplifyBodyPartLabel(bpd.defName) == cleanMatch || SimplifyBodyPartLabel(bpd.LabelShort) == cleanMatch ); }
public UniqueBodyPart FindBodyPart(BodyPartDef def, int index) { List <UniqueBodyPart> result; if (bodyPartDefLookup.TryGetValue(def, out result)) { if (index < result.Count) { return(result[index]); } } return(null); }
protected bool TrySendLetter(BodyPartDef part) { if (!PawnUtility.ShouldSendNotificationAbout(base.Pawn)) { return(false); } string label = "Cancer Spread"; string text = base.Pawn.Label.CapitalizeFirst(); text = text + "'s cancer has spread to their " + part; text = text.AdjustedFor(base.Pawn, "PAWN"); Find.LetterStack.ReceiveLetter(label, text, LetterDefOf.NegativeEvent, base.Pawn, null, null); return(true); }
private void GiveCarcinoma(Pawn p) { if (p.RaceProps.IsFlesh) { List <BodyPartRecord> allParts = p.RaceProps.body.AllParts; BodyPartDef partDef = allParts.RandomElement <BodyPartRecord>().def; if (p.RaceProps.body == BodyDefOf.Human) { float value = Rand.Value; if (value < 0.1f) { partDef = DefDatabase <BodyPartDef> .GetNamed("Lung", true); } else if (value < 0.2f) { partDef = DefDatabase <BodyPartDef> .GetNamed("Lung", true); } else if (value < 0.4f) { partDef = BodyPartDefOf.Stomach; } else if (value < 0.6f) { partDef = BodyPartDefOf.Liver; } else if (value < 0.8f) { partDef = BodyPartDefOf.Brain; } } IEnumerable <BodyPartRecord> source = from part in allParts where part.def == partDef select part; if (source.Count <BodyPartRecord>() != 0) { BodyPartRecord bodyPartRecord = source.RandomElement <BodyPartRecord>(); if (allParts.Contains(bodyPartRecord)) { if (!p.health.hediffSet.PartIsMissing(bodyPartRecord)) { p.health.AddHediff(HediffDef.Named("Carcinoma"), bodyPartRecord, null); Log.Message(string.Format("Added carcinoma to {0}, part {1}", p.Label, bodyPartRecord.def.label)); } } } } }
public static bool HasRemovedRequiredPart(Pawn pawn, BodyPartDef part) { List <BodyPartRecord> AllParts = pawn.RaceProps.body.AllParts; bool IsRemovedParts = AllParts.Where(parts => parts.def == part) .All(parts => pawn.health.hediffSet.GetPartHealth(parts) == 0f); for (int i = 0; i < AllParts.Count; i++) { BodyPartRecord record = pawn.RaceProps.body.AllParts[i]; if (record != null && record.def == part && IsRemovedParts && record != pawn.RaceProps.body.corePart) { return(true); } } return(false); }
private static void AddPartToThing(ThingDef thingDef, BodyPartDef warGear, BodyPartGroupDef bodyPartGroupDef, string customLabel) { if (thingDef == null || warGear == null || bodyPartGroupDef == null) { return; } thingDef.race.body.corePart.parts.Add(new BodyPartRecord { customLabel = customLabel, coverage = 0f, def = warGear, depth = BodyPartDepth.Undefined, groups = new List <BodyPartGroupDef>(new[] { bodyPartGroupDef }), height = BodyPartHeight.Middle }); }
public static BodyPartRecord GetBPRecord(this Pawn pawn, string BPPartDefName, bool myDebug = false) { IEnumerable <BodyPartDef> BPDefIE = DefDatabase <BodyPartDef> .AllDefs.Where((BodyPartDef b) => b.defName == BPPartDefName); if (BPDefIE.EnumerableNullOrEmpty()) { Tools.Warn(pawn.Label + " - GetBPRecord - did not find any " + BPPartDefName, myDebug); return(null); } BodyPartDef BPDef = BPDefIE.RandomElement(); pawn.RaceProps.body.GetPartsWithDef(BPDef).TryRandomElement(out BodyPartRecord bodyPart); Tools.Warn(pawn.Label + "GetBPRecord - DID find " + BPPartDefName, myDebug); return(bodyPart); }
private bool SetupModExtensions(HediffDef hediffDef, Pawn pawn) { if (!hediffDef.HasModExtension <HediffDefModExtension>() && Prefs.DevMode) { Log.Warning(ErrStr + pawn.LabelShort + " No Mod extension found in hediffDef => Impossible to get needed values"); return(false); } race = hediffDef.GetModExtension <HediffDefModExtension>()?.race ?? null; myDebug = hediffDef.GetModExtension <HediffDefModExtension>()?.debug ?? false; conditionnalBodyPart = hediffDef.GetModExtension <HediffDefModExtension>()?.conditionalBodyPart ?? null; TriggeredOnHediffAdded = hediffDef.GetModExtension <HediffDefModExtension>()?.TriggeredOnHediffAdded ?? false; TriggeredOnIntervalPassed = hediffDef.GetModExtension <HediffDefModExtension>()?.TriggeredOnIntervalPassed ?? false; return(true); }
public void ApplyHediff() { HediffDef hediff2use = Props.hediffToApply; if (hediff2use == null) { if (MyDebug) { Log.Warning("cant find hediff called: " + Props.hediffToApply); } return; } BodyPartDef myBPDef = DefDatabase <BodyPartDef> .AllDefs.Where((BodyPartDef b) => b == Props.bodyPartDef).RandomElementWithFallback(); BodyPartRecord myBP = null; if (myBPDef != null) { myBP = Pawn.RaceProps.body.GetPartsWithDef(myBPDef).RandomElementWithFallback(); if (myBP == null) { if (MyDebug) { Log.Warning("cant find body part record called: " + Props.bodyPartDef.defName); } return; } } Hediff hediff2apply = HediffMaker.MakeHediff(hediff2use, Pawn, myBP); if (hediff2apply == null) { if (MyDebug) { Log.Warning("cant create hediff " + hediff2use.defName + " to apply on " + Props.bodyPartDef.defName); } return; } Pawn.health.AddHediff(hediff2apply, myBP, null); }
public static BodyPartRecord Where(this Pawn pawn, BodyPartDef where) { if (where == BodyPartDefOf.Chest) { return(BodyCache.Chest(pawn)); } else if (where == BodyPartDefOf.Groin) { return(BodyCache.Groin(pawn)); } else if (where == BodyPartDefOf.LifeStages_ReproductiveOrgans) { return(BodyCache.LifeStages_ReproductiveOrgans(pawn)); } else { return(BodyHairHelper.WhatPart(pawn)); } }
public static BodyPartRecord GetBPRecordWithoutHediff(this Pawn pawn, BodyPartDef bodyPartDef, HediffDef hd, bool myDebug = false) { IEnumerable <BodyPartDef> BPDefIE = DefDatabase <BodyPartDef> .AllDefs.Where((BodyPartDef b) => b == bodyPartDef); if (BPDefIE.EnumerableNullOrEmpty()) { Tools.Warn(pawn.Label + " - GetBPRecord - did not find any " + bodyPartDef.defName, myDebug); return(null); } BodyPartDef BPDef = BPDefIE.RandomElement(); List <BodyPartRecord> bprToExclude = new List <BodyPartRecord>(); foreach (Hediff hediff in pawn.health.hediffSet.hediffs.Where(h => h.def == hd)) { if (!bprToExclude.Contains(hediff.Part)) { bprToExclude.Add(hediff.Part); } } BodyPartRecord bodyPart = null; if (bprToExclude.NullOrEmpty()) { pawn.RaceProps.body.GetPartsWithDef(BPDef).TryRandomElement(out bodyPart); } else { pawn.RaceProps.body.GetPartsWithDef(BPDef).Where(bp => !bprToExclude.Contains(bp)).TryRandomElement(out bodyPart); } if (bodyPart == null) { Tools.Warn(pawn.Label + "GetBPRecord - did not find " + bodyPartDef.defName + " without " + hd.defName, myDebug); } else { Tools.Warn(pawn.Label + "GetBPRecord - did find " + bodyPartDef.defName, myDebug); } return(bodyPart); }
public static IEnumerable <BodyPartRecord> GetAdjustedPartsToApplyOn(List <BodyPartRecord> parts, Pawn pawn, Func <BodyPartRecord, bool> validator = null) { int num; for (int l = 0; l < parts.Count; l = num) { BodyPartDef part = parts[l].def; List <BodyPartRecord> bpList = pawn.RaceProps.body.AllParts; for (int i = 0; i < bpList.Count; i++) { BodyPartRecord bodyPartRecord = bpList[i]; if (bodyPartRecord.def == part && (validator == null || validator(bodyPartRecord))) { yield return(bodyPartRecord); } } num = l + 1; } }
// Token: 0x0600000E RID: 14 RVA: 0x000029BC File Offset: 0x00000BBC public static bool GetBPR(Pawn p, out BodyPartRecord part, out BodyPartDef partdef) { part = null; partdef = null; var partsChance = Rand.Range(1, 100); if (partsChance <= 50) { partdef = partsChance <= 20 ? BodyPartDefOf.Arm : BodyPartDefOf.Hand; } else if (partsChance >= 80) { partdef = BodyPartDefOf.Leg; } else { partdef = DefDatabase <BodyPartDef> .GetNamed("Foot", false); } var body = p.RaceProps.body; var parts = body?.GetPartsWithDef(partdef) !.ToList(); part = parts.RandomElement(); if (part == null || partdef == null) { return(false); } var condition = HealthUtility.GetPartConditionLabel(p, part); if (condition.First == "SeriouslyImpaired".Translate() || condition.First == "ShatteredBodyPart".Translate() || condition.First == "DestroyedBodyPart".Translate() || condition.First == "MissingBodyPart".Translate()) { return(false); } var health = p.health; return(health?.hediffSet == null || !p.health.hediffSet.HasDirectlyAddedPartFor(part)); }
public UniqueBodyPart FindBodyPartByName(string name, int index) { BodyPartDef def = DefDatabase <BodyPartDef> .GetNamedSilentFail(name); if (def != null) { return(FindBodyPart(def, index)); } List <UniqueBodyPart> result; if (bodyPartDefLookup.TryGetValue(def, out result)) { if (index < result.Count) { return(result[index]); } } return(null); }
public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { for (int j = 0; j < recipe.appliedOnFixedBodyParts.Count; j++) { BodyPartDef recipePart = recipe.appliedOnFixedBodyParts[j]; List <BodyPartRecord> bpList = pawn.RaceProps.body.AllParts; for (int i = 0; i < bpList.Count; i++) { _003CGetPartsToApplyOn_003Ec__Iterator0 _003CGetPartsToApplyOn_003Ec__Iterator = (_003CGetPartsToApplyOn_003Ec__Iterator0) /*Error near IL_0081: stateMachine*/; BodyPartRecord record = bpList[i]; if (record.def == recipePart && pawn.health.hediffSet.hediffs.Any((Hediff x) => x.Part == record) && (record.parent == null || pawn.health.hediffSet.GetNotMissingParts().Contains(record.parent)) && (!pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(record) || pawn.health.hediffSet.HasDirectlyAddedPartFor(record))) { yield return(record); /*Error: Unable to find new state assignment for yield return*/; } } } }
// Token: 0x0600000A RID: 10 RVA: 0x00002808 File Offset: 0x00000A08 public static HediffDef GetBPHed(BodyPartDef partdef) { HediffDef hediffdef = null; if (Rand.Range(1, 100) <= 50) { if (partdef == BodyPartDefOf.Hand) { hediffdef = ComAilDefOf.HediffDefOf.CA_Sprain_Hand; } else if (partdef == BodyPartDefOf.Arm) { hediffdef = ComAilDefOf.HediffDefOf.CA_Sprain_Arm; } else if (partdef == DefDatabase <BodyPartDef> .GetNamed("Foot", false)) { hediffdef = ComAilDefOf.HediffDefOf.CA_Sprain_Foot; } else if (partdef == BodyPartDefOf.Leg) { hediffdef = ComAilDefOf.HediffDefOf.CA_Sprain_Leg; } } else if (partdef == BodyPartDefOf.Hand) { hediffdef = ComAilDefOf.HediffDefOf.CA_Knick_Hand; } else if (partdef == BodyPartDefOf.Arm) { hediffdef = ComAilDefOf.HediffDefOf.CA_Knick_Arm; } else if (partdef == DefDatabase <BodyPartDef> .GetNamed("Foot", false)) { hediffdef = ComAilDefOf.HediffDefOf.CA_Knick_Foot; } else if (partdef == BodyPartDefOf.Leg) { hediffdef = ComAilDefOf.HediffDefOf.CA_Knick_Leg; } return(hediffdef); }
private static List <BodyPartDef> AllChildPartDefs(this BodyPartDef bodyPartDef, IEnumerable <BodyDef> bodies = null) { List <BodyPartDef> list = new List <BodyPartDef>(); foreach (var bodyDef in bodies ?? DefDatabase <BodyDef> .AllDefs) { foreach (var partRecord in bodyDef.AllParts) { if (partRecord.def == bodyPartDef) { list.AddRange( partRecord.AllChildParts() .Select(r => r.def) .Where(d => !list.Contains(d))); } } } return(list); }
public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { bool partFound = false; if (IsValidPawn(pawn)) { //Copy from vanilla. Much more complex than needed, but does the trick for (int i = 0; i < recipe.appliedOnFixedBodyParts.Count; i++) { BodyPartDef part = recipe.appliedOnFixedBodyParts[i]; List <BodyPartRecord> bpList = pawn.RaceProps.body.AllParts; for (int j = 0; j < bpList.Count; j++) { BodyPartRecord record = bpList[j]; if (record.def == part && !partFound || allowMultipleParts) { IEnumerable <Hediff> diffs = from x in pawn.health.hediffSet.hediffs where x.Part == record select x; if (diffs.Count <Hediff>() != 1 || diffs.First <Hediff>().def != recipe.addsHediff) { if (record.parent == null || pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null).Contains(record.parent)) { if (!pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(record) || pawn.health.hediffSet.HasDirectlyAddedPartFor(record)) { yield return(record); partFound = true; } } } } } if (recipe.GetModExtension <DefModExtension_Recipe>() is DefModExtension_Recipe ext && !ext.needsFixedBodyPart && !partFound) { yield return(null); } } } }
private static void ApplyBionicPart([NotNull] Pawn pawn, [NotNull] BodyPartDef bodyPart) { switch (bodyPart.defName) { case "Arm": ApplyPart(pawn, HediffDefOf.BionicArm, bodyPart); return; case "Leg": ApplyPart(pawn, HediffDefOf.BionicLeg, bodyPart); return; case "Eye": ApplyPart(pawn, HediffDefOf.BionicEye, bodyPart); return; case "Ear": ApplyPart(pawn, HediffDef.Named("BionicEar"), bodyPart); return; case "Spine": ApplyPart(pawn, HediffDef.Named("BionicSpine"), bodyPart); return; case "Heart": ApplyPart(pawn, HediffDef.Named("BionicHeart"), bodyPart); return; case "Stomach": ApplyPart(pawn, HediffDef.Named("BionicStomach"), bodyPart); return; } }
public override IEnumerable <BodyPartRecord> GetPartsToApplyOn(Pawn pawn, RecipeDef recipe) { for (int i = 0; i < recipe.appliedOnFixedBodyParts.Count; i++) { BodyPartDef part = recipe.appliedOnFixedBodyParts[i]; List <BodyPartRecord> bpList = pawn.RaceProps.body.AllParts; for (int j = 0; j < bpList.Count; j++) { BodyPartRecord record = bpList[j]; if (record.def == part) { if (pawn.health.hediffSet.GetNotMissingParts(BodyPartHeight.Undefined, BodyPartDepth.Undefined, null, null).Contains(record)) { var implants = pawn.health.hediffSet.hediffs .Where(d => d.Part == record && d is Hediff_Implant && d.Visible); if (implants.Count() == 3 && pawn.health.hediffSet.HasDirectlyAddedPartFor(record)) { yield break; } MSE_ImplantSystem implantSystem = recipe.GetModExtension <MSE_ImplantSystem>(); if (implantSystem != null && implantSystem.isSpecial) { if (pawn.health.hediffSet.HasDirectlyAddedPartFor(record) && !MSE_VanillaExtender.PartHasAdvancedImplantSystem(pawn, record)) { yield break; } } if (!pawn.health.hediffSet.hediffs.Any((Hediff x) => x.Part == record && x.def == recipe.addsHediff)) { yield return(record); } } } } } yield break; }
public static bool PreFix(BodyPartDef __instance, float __result, Pawn pawn) { StackFrame investigateFrame = new StackFrame(2); string namespaceString = investigateFrame.GetMethod().ReflectedType.Namespace; if (shouldSupressNextWarning) { shouldSupressNextWarning = false; } else if (!reportedNamespaces.Contains(namespaceString)) { reportedNamespaces.Add(namespaceString); string errorMessage = "Elite Bionics Framework has detected some mods" + " using the unmodified GetMaxHealth() method, which violates the" + " EBF protocol. The author(s) of the involved mod(s) should " + "adopt the EBF to clarify their intentions.\n" + "For now, the unmodified max HP is returned.\n" + "The detected mod comes from: " + namespaceString; EliteBionicsFrameworkMain.LogError(errorMessage); } return(true); }