/// <summary> /// Adds the mutation to the given pawn /// </summary> /// <param name="pawn">The pawn.</param> /// <param name="mutation">The mutation.</param> /// <param name="records">The records to add mutations to</param> /// <param name="ancillaryEffects">The ancillary effects.</param> /// <exception cref="ArgumentNullException"> /// pawn /// or /// mutation /// or /// records /// </exception> public static MutationResult AddMutation([NotNull] Pawn pawn, [NotNull] MutationDef mutation, [NotNull] IEnumerable <BodyPartRecord> records, AncillaryMutationEffects?ancillaryEffects = null) { if (pawn == null) { throw new ArgumentNullException(nameof(pawn)); } if (mutation == null) { throw new ArgumentNullException(nameof(mutation)); } if (records == null) { throw new ArgumentNullException(nameof(records)); } HediffSet hSet = pawn.health?.hediffSet; if (hSet == null) { return(MutationResult.Empty); } List <Hediff_AddedMutation> lst = new List <Hediff_AddedMutation>(); foreach (BodyPartRecord bodyPartRecord in records) { if (bodyPartRecord.IsMissingAtAllIn(pawn)) { LogMsg(LogLevel.Pedantic, $"could not add {mutation.defName} to {pawn.Name} on {bodyPartRecord.Label} because it is missing or has a prosthetic"); continue; } if (HasAnyBlockingMutations(pawn, mutation, bodyPartRecord)) { continue; } var existingMutation = hSet.hediffs.FirstOrDefault(h => h.def == mutation && h.Part == bodyPartRecord); if (existingMutation != null) //resume adaption for mutations that are already added instead of re adding them { LogMsg(LogLevel.Pedantic, $"could not add {mutation.defName} to {pawn.Name} on {bodyPartRecord.Label} because it already has that mutation"); existingMutation.ResumeAdjustment(); //don't do count restarted mutations as new ones continue; } var hediff = HediffMaker.MakeHediff(mutation, pawn, bodyPartRecord) as Hediff_AddedMutation; if (hediff == null) { Log.Error($"{mutation.defName} is not a mutation but is being added like one!"); continue; } lst.Add(hediff); hSet.AddDirect(hediff); } AncillaryMutationEffects aEffects = ancillaryEffects ?? AncillaryMutationEffects.Default; if (lst.Count > 0) //only do this if we actually added any mutations { DoAncillaryMutationEffects(pawn, mutation, lst, aEffects); } return(new MutationResult(lst)); }