/// <summary> /// Looks at the part children and adds the corresponding Thing to the item /// </summary> /// <param name="item">Where the item parts are to be added</param> /// <param name="pawn">The pawn from which to check if the parts are ok</param> /// <param name="part">The parent part</param> public static void AddSubparts(ref ThingWithComps item, Pawn pawn, BodyPartRecord part) { List <Thing> childThings = new List <Thing>(); // populates childThings foreach (BodyPartRecord subPart in from x in part.GetDirectChildParts() where pawn.health.hediffSet.GetNotMissingParts().Contains(x) // subpart is missing: skip it select x) { Thing childThing = MakeNaturalPartIfClean(pawn, subPart); if (childThing != null) { childThings.Add(childThing); } } // if it found childthings add them as comp to the item if (childThings.Count > 0) { CompIncludedChildParts comp = item.TryGetComp <CompIncludedChildParts>(); if (comp == null) // if it doesn't have the comp, make it { comp = new CompIncludedChildParts(); comp.parent = item; comp.props = new CompProperties_IncludedChildParts(); comp.PostSpawnSetup(false); item.AllComps.Add(comp); } comp.IncludedParts = childThings; // replace child part list } }
/// <summary> /// From the list of available Things, add the compatible subparts to the item /// </summary> /// <param name="item">The item to add the subparts to</param> /// <param name="available">The available things to add</param> /// <param name="reset">Should it reset the list of subparts in the item</param> public static void AddSubparts(ThingWithComps item, List <Thing> available, bool reset = true) { CompIncludedChildParts comp = item.TryGetComp <CompIncludedChildParts>(); if (comp != null) { if (reset) { comp.IncludedParts.Clear(); } foreach (ThingDef missing in comp.MissingParts) { Thing match = available.Find(x => x.def == missing); if (match != null) { available.Remove(match); comp.AddPart(match); } } } }