コード例 #1
0
        /// <summary>
        /// Clears the overlapping hediffs on the given pawn.
        /// </summary>
        /// <param name="mutationGiver">The mutation giver.</param>
        /// <param name="pawn">The pawn.</param>
        /// <exception cref="ArgumentNullException">
        /// mutationGiver
        /// or
        /// pawn
        /// </exception>
        public static void ClearOverlappingHediffs([NotNull] this HediffGiver_Mutation mutationGiver, [NotNull] Pawn pawn)
        {
            if (mutationGiver == null)
            {
                throw new ArgumentNullException(nameof(mutationGiver));
            }
            if (pawn == null)
            {
                throw new ArgumentNullException(nameof(pawn));
            }
            var health = pawn.health;

            if (health?.hediffSet?.hediffs == null)
            {
                return;
            }
            List <Hediff_AddedMutation> hediffsToRemove = new List <Hediff_AddedMutation>(); //save the result, otherwise we'd invalidate the enumerator when we start removing them

            foreach (BodyPartDef bodyPartDef in mutationGiver.GetPartsToAddTo())
            {
                var hediffs = health.hediffSet.hediffs.Where(h => h?.Part?.def == bodyPartDef).OfType <Hediff_AddedMutation>();
                hediffsToRemove.AddRange(hediffs); //don't start removing them until we have all mutation we need to remove
            }

            hediffsToRemove.RemoveDuplicates(); //don't want to remove a hediff more then once

            foreach (Hediff_AddedMutation hediffAddedMutation in hediffsToRemove)
            {
                health.RemoveHediff(hediffAddedMutation);
            }
        }
コード例 #2
0
        public HediffGiver_Mutation CreateMutationGiver([NotNull] HediffDef parentDef)
        {
            var mutationGiver = new HediffGiver_Mutation
            {
                hediff        = parentDef,
                partsToAffect = parts.ToList(),
                countToAffect = countToAffect
            };

            return(mutationGiver);
        }