Exemple #1
0
        public void SpawnMutation(Pawn pawn, BodyPartRecord part, float ratio, HediffRadiation radiation = null)
        {
            Mutation mutation;
            var      mutatedParts = RadiationHelper.MutatePawn(pawn, part, ratio, out mutation);

            lastMutation     = mutation.def;
            lastMutationTick = Find.TickManager.TicksGame;
            if (mutatedParts == null)
            {
                return;
            }

            foreach (var anotherRadiation in pawn.health.hediffSet.GetHediffs <HediffRadiation>())
            {
                if (mutatedParts.Contains(anotherRadiation.Part) && radiation != anotherRadiation)
                {
                    anotherRadiation.normal -= def.mutateThreshold.min * (1f - ratio);
                    anotherRadiation.rare   -= def.mutateThreshold.min * ratio;
                }
            }
        }
        public void Irradiate(RadiationInfo info, int ticks)
        {
            Chamber chamber = parent.Linked <Chamber>();

            SoundDefOf.RadiologyIrradiateBasic.PlayOneShot(new TargetInfo(parent.Position, parent.Map, false));
            ticksCooldown = ticks;

            if (info.pawn.IsShielded())
            {
                return;
            }

            info.part   = GetBodyPart(info.chamber, info.pawn);
            info.burn   = props.burn.perSecond.RandomInRange;
            info.normal = props.mutate.perSecond.RandomInRange;
            info.rare   = props.mutateRare.perSecond.RandomInRange;
            if (info.secondHand)
            {
                info.rare /= 2;
            }

            motesReflectAt.Clear();
            foreach (ThingComp comp in GetModifiers <ThingComp, IRadiationModifier>(info.chamber))
            {
                if (comp is CompBlocker)
                {
                    motesReflectAt.Add((parent.Rotation.IsHorizontal ? comp.parent.Position.x : comp.parent.Position.z) + 0.5f);
                }

                if (info.secondHand)
                {
                    continue;
                }

                IRadiationModifier modifier = comp as IRadiationModifier;
                modifier.Modify(ref info);
            }

            if (info.burn <= 0 && info.normal <= 0 && info.rare <= 0)
            {
                return;
            }

            HediffRadiation radiation = GetHediffRadition(info.part, info.chamber, info.pawn);

            if (radiation == null)
            {
                return;
            }

            radiation.burn   += info.burn;
            radiation.normal += info.normal;
            radiation.rare   += info.rare;

            float burnThreshold = info.chamber.def.burnThreshold.RandomInRange;
            float burnAmount    = radiation.burn - burnThreshold;

            if (burnAmount > 0)
            {
                radiation.burn -= info.chamber.def.burnThreshold.min;

                DamageInfo dinfo = new DamageInfo(DamageDefOf.Burn, burnAmount * props.burn.multiplier, 999999f, -1f, info.chamber, radiation.Part, null, DamageInfo.SourceCategory.ThingOrUnknown, null);
                info.pawn.TakeDamage(dinfo);

                if (chamber != null)
                {
                    RadiologyEffectSpawnerDef.Spawn(chamber.def.burnEffect, info.pawn);
                }
            }

            float mutateThreshold = info.chamber.def.mutateThreshold.RandomInRange;
            float mutateAmount    = radiation.normal + radiation.rare - mutateThreshold;

            if (mutateAmount > 0)
            {
                float ratio = radiation.rare / (radiation.normal + radiation.rare);
                radiation.rare   -= info.chamber.def.mutateThreshold.min * ratio;
                radiation.normal -= info.chamber.def.mutateThreshold.min * (1f - ratio);

                Mutation mutation;
                var      mutatedParts = RadiationHelper.MutatePawn(info.pawn, radiation, mutateAmount * props.mutate.multiplier, ratio, out mutation);
                if (mutatedParts != null)
                {
                    foreach (var anotherRadiation in info.pawn.health.hediffSet.GetHediffs <HediffRadiation>())
                    {
                        if (mutatedParts.Contains(anotherRadiation.Part) && radiation != anotherRadiation)
                        {
                            anotherRadiation.normal -= info.chamber.def.mutateThreshold.min * (1f - ratio);
                            anotherRadiation.rare   -= info.chamber.def.mutateThreshold.min * ratio;
                        }
                    }
                }
            }
        }