Exemplo n.º 1
0
        // Token: 0x06004B87 RID: 19335 RVA: 0x00234638 File Offset: 0x00232A38
        private void ApplyDamageToPart(DamageInfo dinfo, Pawn pawn, DamageWorker.DamageResult result)
        {
            BodyPartRecord exactPartFromDamageInfo = this.GetExactPartFromDamageInfo(dinfo, pawn);

            if (exactPartFromDamageInfo == null)
            {
                return;
            }
            dinfo.SetHitPart(exactPartFromDamageInfo);
            float num  = dinfo.Amount;
            bool  flag = !dinfo.InstantPermanentInjury;
            bool  deflectedByMetalArmor = false;

            if (flag)
            {
                DamageDef def = dinfo.Def;
                num       = ArmorUtility.GetPostArmorDamage(pawn, num, dinfo.ArmorPenetrationInt, dinfo.HitPart, ref def, out deflectedByMetalArmor, out bool diminishedByMetalArmor);
                dinfo.Def = def;
                if (num < dinfo.Amount)
                {
                    result.diminished             = true;
                    result.diminishedByMetalArmor = diminishedByMetalArmor;
                }
            }
            if (num <= 0f)
            {
                result.AddPart(pawn, dinfo.HitPart);
                result.deflected             = true;
                result.deflectedByMetalArmor = deflectedByMetalArmor;
                return;
            }
            if (DamageWorker_CombiPin.IsHeadshot(dinfo, pawn))
            {
                result.headshot = true;
            }
            if (dinfo.InstantPermanentInjury)
            {
                HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart);
                if (hediffDefFromDamage.CompPropsFor(typeof(HediffComp_GetsPermanent)) == null || dinfo.HitPart.def.permanentInjuryChanceFactor == 0f || pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(dinfo.HitPart))
                {
                    return;
                }
            }
            if (!dinfo.AllowDamagePropagation)
            {
                this.FinalizeAndAddInjury(pawn, num, dinfo, result);
                return;
            }
            this.ApplySpecialEffectsToPart(pawn, num, dinfo, result);
        }
Exemplo n.º 2
0
        // Token: 0x06004B90 RID: 19344 RVA: 0x00234B88 File Offset: 0x00232F88
        protected float ReduceDamageToPreserveOutsideParts(float postArmorDamage, DamageInfo dinfo, Pawn pawn)
        {
            if (!DamageWorker_CombiPin.ShouldReduceDamageToPreservePart(dinfo.HitPart))
            {
                return(postArmorDamage);
            }
            float partHealth = pawn.health.hediffSet.GetPartHealth(dinfo.HitPart);

            if (postArmorDamage < partHealth)
            {
                return(postArmorDamage);
            }
            float maxHealth = dinfo.HitPart.def.GetMaxHealth(pawn);
            float num       = postArmorDamage - partHealth;
            float f         = num / maxHealth;
            float chance    = this.def.overkillPctToDestroyPart.InverseLerpThroughRange(f);

            if (Rand.Chance(chance))
            {
                return(postArmorDamage);
            }
            return(postArmorDamage = partHealth - 1f);
        }
Exemplo n.º 3
0
        // Token: 0x06004B84 RID: 19332 RVA: 0x002341E4 File Offset: 0x002325E4
        private DamageWorker.DamageResult ApplyToPawn(DamageInfo dinfo, Pawn pawn)
        {
            DamageWorker.DamageResult damageResult = new DamageWorker.DamageResult();
            if (dinfo.Amount <= 0f)
            {
                return(damageResult);
            }
            if (!DebugSettings.enablePlayerDamage && pawn.Faction == Faction.OfPlayer)
            {
                return(damageResult);
            }
            Map  mapHeld = pawn.MapHeld;
            bool spawnedOrAnyParentSpawned = pawn.SpawnedOrAnyParentSpawned;

            if (dinfo.AllowDamagePropagation && dinfo.Amount >= (float)dinfo.Def.minDamageToFragment)
            {
                int num = Rand.RangeInclusive(2, 4);
                for (int i = 0; i < num; i++)
                {
                    DamageInfo dinfo2 = dinfo;
                    dinfo2.SetAmount(dinfo.Amount / (float)num);
                    this.ApplyDamageToPart(dinfo2, pawn, damageResult);
                }
            }
            else
            {
                this.ApplyDamageToPart(dinfo, pawn, damageResult);
                this.ApplySmallPawnDamagePropagation(dinfo, pawn, damageResult);
            }
            if (damageResult.wounded)
            {
                DamageWorker_CombiPin.PlayWoundedVoiceSound(dinfo, pawn);
                pawn.Drawer.Notify_DamageApplied(dinfo);
            }
            if (damageResult.headshot && pawn.Spawned)
            {
                MoteMaker.ThrowText(new Vector3((float)pawn.Position.x + 1f, (float)pawn.Position.y, (float)pawn.Position.z + 1f), pawn.Map, "Headshot".Translate(), Color.white, -1f);
                if (dinfo.Instigator != null)
                {
                    if (dinfo.Instigator is Pawn pawn2)
                    {
                        pawn2.records.Increment(RecordDefOf.Headshots);
                    }
                }
            }
            if ((damageResult.deflected || damageResult.diminished) && spawnedOrAnyParentSpawned)
            {
                EffecterDef effecterDef;
                if (damageResult.deflected)
                {
                    if (damageResult.deflectedByMetalArmor && dinfo.Def.canUseDeflectMetalEffect)
                    {
                        if (dinfo.Def == DamageDefOf.Bullet)
                        {
                            effecterDef = EffecterDefOf.Deflect_Metal_Bullet;
                        }
                        else
                        {
                            effecterDef = EffecterDefOf.Deflect_Metal;
                        }
                    }
                    else if (dinfo.Def == DamageDefOf.Bullet)
                    {
                        effecterDef = EffecterDefOf.Deflect_General_Bullet;
                    }
                    else
                    {
                        effecterDef = EffecterDefOf.Deflect_General;
                    }
                }
                else if (damageResult.diminishedByMetalArmor)
                {
                    effecterDef = EffecterDefOf.DamageDiminished_Metal;
                }
                else
                {
                    effecterDef = EffecterDefOf.DamageDiminished_General;
                }
                if (pawn.health.deflectionEffecter == null || pawn.health.deflectionEffecter.def != effecterDef)
                {
                    if (pawn.health.deflectionEffecter != null)
                    {
                        pawn.health.deflectionEffecter.Cleanup();
                        pawn.health.deflectionEffecter = null;
                    }
                    pawn.health.deflectionEffecter = effecterDef.Spawn();
                }
                pawn.health.deflectionEffecter.Trigger(pawn, dinfo.Instigator ?? pawn);
                if (damageResult.deflected)
                {
                    pawn.Drawer.Notify_DamageDeflected(dinfo);
                }
            }
            if (!damageResult.deflected && spawnedOrAnyParentSpawned)
            {
                ImpactSoundUtility.PlayImpactSound(pawn, dinfo.Def.impactSoundType, mapHeld);
            }
            return(damageResult);
        }