/// <summary>Applies the mutagenic damage.</summary>
        /// <param name="originalDamage">The original damage.</param>
        /// <param name="damageInfo">The damage information.</param>
        /// <param name="pawn">The pawn.</param>
        /// <param name="result">The result.</param>
        /// <param name="mutagenicDef">The definition of the mutagenic damage hediff to add.</param>
        /// <param name="severityPerDamage">The severity per damage.</param>
        /// <param name="mutagen">The mutagen.</param>
        /// <exception cref="ArgumentNullException">
        ///     pawn
        ///     or
        ///     result
        /// </exception>
        public static void ApplyMutagenicDamage(float originalDamage, DamageInfo damageInfo, [NotNull] Pawn pawn,
                                                [NotNull] DamageWorker.DamageResult result,
                                                HediffDef mutagenicDef = null, float severityPerDamage = SEVERITY_PER_DAMAGE,
                                                MutagenDef mutagen     = null)
        {
            if (pawn == null)
            {
                throw new ArgumentNullException(nameof(pawn));
            }
            if (result == null)
            {
                throw new ArgumentNullException(nameof(result));
            }
            MutagenicDamageExtension ext = damageInfo.Weapon?.GetModExtension <MutagenicDamageExtension>()
                                           ?? damageInfo.Def?.GetModExtension <MutagenicDamageExtension>();

            mutagen      = mutagen ?? MutagenDefOf.defaultMutagen;
            mutagenicDef = mutagenicDef
                           ?? ext?.mutagenicBuildup
                           ?? MorphTransformationDefOf.MutagenicBuildup_Weapon;
            //first check if we're given a specific hediff to use
            //then use what's ever attached to the damage def
            //then use the default

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

            ApplyMutagen(originalDamage, damageInfo, pawn, mutagenicDef, severityPerDamage, result);
        }
Esempio n. 2
0
        /// <summary>
        /// Tries to apply this hediff giver
        /// </summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="cause">The cause.</param>
        /// <param name="mutagen">The mutagen.</param>
        public void TryApply(Pawn pawn, Hediff cause, MutagenDef mutagen)
        {
            MutationDef mut   = GetRandomMutation(pawn); //grab a random mutation
            int         mPart = mut.parts?.Count ?? 0;

            int maxCount;

            if (mPart == 0)
            {
                maxCount = 0;
            }
            else
            {
                maxCount = GetMaxCount(pawn, mut.parts);
            }


            if (MutationUtilities.AddMutation(pawn, mut, maxCount))
            {
                IntermittentMagicSprayer.ThrowMagicPuffDown(pawn.Position.ToVector3(), pawn.MapHeld);

                var comp = cause.TryGetComp <HediffComp_Single>();
                if (comp != null)
                {
                    comp.stacks--;
                    if (comp.stacks <= 0)
                    {
                        pawn.health.RemoveHediff(cause);
                    }
                }
            }
        }
        /// <summary>
        ///     occurs every so often for all hediffs that have this giver
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="cause"></param>
        public override void OnIntervalPassed(Pawn pawn, Hediff cause)
        {
            if (Mutations.Count == 0)
            {
                return;
            }

            if (Rand.MTBEventOccurs(mtbDays, mtbUnits, 60) && pawn.RaceProps.intelligence == Intelligence.Humanlike)
            {
                MutagenDef mutagen = cause?.def?.GetMutagenDef() ?? MutagenDefOf.defaultMutagen;
                TryApply(pawn, cause, mutagen);
            }
        }
        /// <summary>
        ///     Applies the specified dinfo.
        /// </summary>
        /// <param name="dinfo">The dinfo.</param>
        /// <param name="thing">The thing.</param>
        /// <returns></returns>
        public override DamageResult Apply(DamageInfo dinfo, Thing thing)
        {
            if (thing is Pawn pawn)
            {
                MutagenDef mutagen = dinfo.Weapon.GetModExtension <MutagenExtension>()?.mutagen
                                     ?? dinfo.Def.GetModExtension <MutagenicDamageExtension>()?.mutagen
                                     ?? MutagenDefOf.defaultMutagen;

                if (mutagen.CanInfect(pawn))
                {
                    return(ApplyToPawn(dinfo, pawn, mutagen));
                }
            }

            return(base.Apply(dinfo, thing));
        }
Esempio n. 5
0
        /// <summary>
        ///     occurs every so often for all hediffs that have this giver
        /// </summary>
        /// <param name="pawn"></param>
        /// <param name="cause"></param>
        public override void OnIntervalPassed(Pawn pawn, Hediff cause)
        {
            if (!animalClass.GetAllMutationIn().Any())
            {
                return;
            }

            //if (MP.IsInMultiplayer) Rand.PushState(RandUtilities.MPSafeSeed);

            if (Rand.MTBEventOccurs(mtbDays, mtbUnits, 60) && pawn.RaceProps.intelligence == Intelligence.Humanlike)
            {
                MutagenDef mutagen = cause?.def?.GetMutagenDef() ?? MutagenDefOf.defaultMutagen;
                TryApply(pawn, cause, mutagen);
            }

            //if (MP.IsInMultiplayer) Rand.PopState();
        }
        private DamageResult ApplyToPawn(DamageInfo dinfo, Pawn pawn, MutagenDef mutagen)
        {
            //reduce the amount to make it less likely to kill the pawn
            float originalDamage = dinfo.Amount;

            dinfo = ReduceDamage(dinfo, pawn);

            DamageResult res = base.Apply(dinfo, pawn);
            float        severityPerDamage = dinfo.GetSeverityPerDamage();

            if (!mutagen.CanInfect(pawn))
            {
                return(res);
            }
            MutagenicDamageUtilities.ApplyMutagenicDamage(originalDamage, dinfo, pawn, res, severityPerDamage: severityPerDamage,
                                                          mutagen: mutagen);

            return(res);
        }
Esempio n. 7
0
        static void TryRevertTransformedPawn(Pawn pawn)
        {
            if (pawn == null)
            {
                return;
            }
            var gComp = Find.World.GetComponent <PawnmorphGameComp>();

            (TransformedPawn pawn, TransformedStatus status)? tfPawn = gComp?.GetTransformedPawnContaining(pawn);
            TransformedPawn transformedPawn = tfPawn?.pawn;

            if (transformedPawn == null || tfPawn?.status != TransformedStatus.Transformed)
            {
                return;
            }
            MutagenDef mut = transformedPawn.mutagenDef ?? MutagenDefOf.defaultMutagen;

            mut.MutagenCached.TryRevert(transformedPawn);
        }
        /// <summary>
        ///     Tries to apply this hediff giver
        /// </summary>
        /// <param name="pawn">The pawn.</param>
        /// <param name="cause">The cause.</param>
        /// <param name="mutagen">The mutagen.</param>
        public void TryApply(Pawn pawn, Hediff cause, [NotNull] MutagenDef mutagen)
        {
            if (mutagen == null)
            {
                throw new ArgumentNullException(nameof(mutagen));
            }
            var mut = Mutations[Rand.Range(0, Mutations.Count)]; //grab a random mutation

            if (MutationUtilities.AddMutation(pawn, mut))
            {
                IntermittentMagicSprayer.ThrowMagicPuffDown(pawn.Position.ToVector3(), pawn.MapHeld);
                if (cause.def.HasComp(typeof(HediffComp_Single)))
                {
                    pawn.health.RemoveHediff(cause);
                }
                mutagen.TryApplyAspects(pawn);
                if (mut.mutationTale != null)
                {
                    TaleRecorder.RecordTale(mut.mutationTale, pawn);
                }
            }
        }
        /// <summary>
        ///     Applies the pure mutagenic damage.
        /// </summary>
        /// this does not actually damage the pawn
        /// <param name="dInfo">The damage info.</param>
        /// <param name="pawn">The pawn.</param>
        /// <param name="mutationHediffDef">The mutation hediff definition.</param>
        /// <param name="severityPerDamage">The severity per damage.</param>
        /// <param name="mutagen">The mutagen.</param>
        public static void ApplyPureMutagenicDamage(DamageInfo dInfo, [NotNull] Pawn pawn,
                                                    HediffDef mutationHediffDef = null,
                                                    float severityPerDamage     = SEVERITY_PER_DAMAGE, MutagenDef mutagen = null)
        {
            mutagen = mutagen ?? MutagenDefOf.defaultMutagen;
            MutagenicDamageExtension ext = dInfo.Weapon?.GetModExtension <MutagenicDamageExtension>()
                                           ?? dInfo.Def?.GetModExtension <MutagenicDamageExtension>();

            mutationHediffDef = mutationHediffDef
                                ?? ext?.mutagenicBuildup
                                ?? MorphTransformationDefOf.MutagenicBuildup_Weapon;
            //first check if we're given a specific hediff to use
            //then use what's ever attached to the damage def
            //then use the default

            float severityToAdd = Mathf.Clamp(dInfo.Amount * severityPerDamage, 0, mutationHediffDef.maxSeverity);

            Hediff hediff = HediffMaker.MakeHediff(mutationHediffDef, pawn);

            hediff.Severity = severityToAdd;
            pawn.health.AddHediff(hediff);
        }