示例#1
0
        /// <summary>tries to apply the mutations to the given body part records</summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="recordsToAdd">The records to add.</param>
        /// <param name="mutagen">The mutagen.</param>
        /// <returns></returns>
        public bool TryApply(Pawn pawn, List <BodyPartRecord> recordsToAdd, MutagenDef mutagen = null)
        {
            mutagen = mutagen ?? MutagenDefOf.defaultMutagen;
            if (!mutagen.CanInfect(pawn))
            {
                return(false);
            }
            if (!hediff.IsValidFor(pawn))
            {
                return(false);
            }
            bool anyAdded = false;
            HashSet <BodyPartRecord> nonMissingRecords = new HashSet <BodyPartRecord>(pawn.health.hediffSet.GetNotMissingParts());

            foreach (BodyPartRecord bodyPartRecord in recordsToAdd)
            {
                if (!nonMissingRecords.Contains(bodyPartRecord))
                {
                    continue;
                }
                anyAdded |= TryApply(pawn, bodyPartRecord, mutagen, nonMissingRecords);
            }

            return(anyAdded);
        }
示例#2
0
        /// <summary>Tries the apply the mutation to the given pawn</summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="mutagenDef">The mutagen definition. used to determine if it's a valid target or not</param>
        /// <param name="outAddedHediffs">The out added hediffs.</param>
        /// <param name="cause">The cause.</param>
        /// <param name="addLogEntry">if set to <c>true</c> [add log entry].</param>
        /// <returns>if the mutation was added or not</returns>
        public bool TryApply(Pawn pawn, MutagenDef mutagenDef, List <Hediff> outAddedHediffs = null, Hediff cause = null, bool addLogEntry = true)
        {
            if (!mutagenDef.CanInfect(pawn))
            {
                return(false);
            }
            if (!hediff.IsValidFor(pawn))
            {
                return(false);
            }
            bool added = PawnmorphHediffGiverUtility.TryApply(pawn, hediff, partsToAffect, canAffectAnyLivePart, countToAffect, outAddedHediffs);

            if (addLogEntry && added && partsToAffect != null)
            {
                AddMutationLogFor(pawn);
            }

            if (added)
            {
                var cDef = cause?.def;
                if (cDef != null)
                {
                    AspectUtils.TryApplyAspectsFrom(cDef, pawn);
                }
            }
            return(added);
        }
 /// <summary>
 /// Gets the net mutagenic buildup multiplier for this pawn.
 /// </summary>
 /// <param name="pawn">The pawn.</param>
 /// <param name="mutagenDef">The mutagen definition.</param>
 /// <returns></returns>
 public static float GetMutagenicBuildupMultiplier([NotNull] this Pawn pawn, MutagenDef mutagenDef = null)
 {
     mutagenDef = mutagenDef ?? MutagenDefOf.defaultMutagen;
     if (!mutagenDef.CanInfect(pawn))
     {
         return(0);
     }
     return(pawn.GetStatValue(StatDefOf.ToxicSensitivity) * pawn.GetStatValue(PMStatDefOf.MutagenSensitivity));
 }
示例#4
0
        /// <summary>Tries to apply the mutation to the given body part record</summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="recordToAdd">The record to add.</param>
        /// <param name="mutagen">The mutagen.</param>
        /// <returns></returns>
        public bool TryApply(Pawn pawn, BodyPartRecord recordToAdd, MutagenDef mutagen = null)
        {
            mutagen = mutagen ?? MutagenDefOf.defaultMutagen;
            if (!mutagen.CanInfect(pawn))
            {
                return(false);
            }
            HashSet <BodyPartRecord> nonMissingRecords = new HashSet <BodyPartRecord>(pawn.health.hediffSet.GetNotMissingParts());

            return(TryApply(pawn, recordToAdd, mutagen, nonMissingRecords));
        }
        private static void MutatePawn(Pawn pawn, MutagenDef mutagen)
        {
            HediffSet hediffSet = pawn.health.hediffSet;

            if (!pawn.Spawned || !mutagen.CanInfect(pawn))
            {
                return;
            }

            pawn.health.AddHediff(MorphTransformationDefOf.FullRandomTF);
            IntermittentMagicSprayer.ThrowMagicPuffDown(pawn.Position.ToVector3(), pawn.Map);
        }
        /// <summary> Determines whether this instance can infect the specified pawn. </summary>
        /// <param name="mutationDef"> The mutation definition. </param>
        /// <param name="pawn"> The pawn. </param>
        /// <returns> <c>true</c> if this instance can infect the specified pawn; otherwise, <c>false</c>. </returns>
        /// <exception cref="System.ArgumentNullException"> mutationDef or pawn is null. </exception>
        public static bool CanInfect([NotNull] this HediffDef mutationDef, [NotNull] Pawn pawn)
        {
            if (mutationDef == null)
            {
                throw new ArgumentNullException(nameof(mutationDef));
            }
            if (pawn == null)
            {
                throw new ArgumentNullException(nameof(pawn));
            }



            MutagenDef mutagenSource = mutationDef.GetMutagenDef();

            return(mutagenSource.CanInfect(pawn));
        }
示例#7
0
        bool TryApply(Pawn pawn, BodyPartRecord recordToAdd, [NotNull] MutagenDef mutagen, HashSet <BodyPartRecord> nonMissingRecords)
        {
            if (!mutagen.CanInfect(pawn))
            {
                return(false);
            }
            if (!nonMissingRecords.Contains(recordToAdd))
            {
                return(false);
            }
            if (!hediff.IsValidFor(pawn))
            {
                return(false);
            }
            var hediffInst = HediffMaker.MakeHediff(hediff, pawn, recordToAdd);

            pawn.health.AddHediff(hediffInst, recordToAdd);
            DoMutationAddedEffects(pawn);
            AddMutationLogFor(pawn);

            return(true);
        }