Exemplo n.º 1
0
        public static int GetPostArmorDamage(Pawn pawn, int amountInt, BodyPartRecord part, DamageDef damageDef)
        {
            float num = (float)amountInt;

            if (damageDef.armorCategory == null)
            {
                return(amountInt);
            }
            StatDef deflectionStat = damageDef.armorCategory.deflectionStat;

            if (pawn.apparel != null)
            {
                List <Apparel> wornApparel = pawn.apparel.WornApparel;
                for (int i = 0; i < wornApparel.Count; i++)
                {
                    Apparel apparel = wornApparel[i];
                    if (apparel.def.apparel.CoversBodyPart(part))
                    {
                        ArmorUtility.ApplyArmor(ref num, apparel.GetStatValue(deflectionStat, true), apparel, damageDef);
                        if (num < 0.001f)
                        {
                            return(0);
                        }
                    }
                }
            }
            ArmorUtility.ApplyArmor(ref num, pawn.GetStatValue(deflectionStat, true), null, damageDef);
            return(GenMath.RoundRandom(num));
        }
Exemplo n.º 2
0
        public static float GetPostArmorDamage(Pawn pawn, float amount, float armorPenetration, BodyPartRecord part, ref DamageDef damageDef, out bool deflectedByMetalArmor, out bool diminishedByMetalArmor)
        {
            deflectedByMetalArmor  = false;
            diminishedByMetalArmor = false;
            float result;

            if (damageDef.armorCategory == null)
            {
                result = amount;
            }
            else
            {
                StatDef armorRatingStat = damageDef.armorCategory.armorRatingStat;
                if (pawn.apparel != null)
                {
                    List <Apparel> wornApparel = pawn.apparel.WornApparel;
                    for (int i = wornApparel.Count - 1; i >= 0; i--)
                    {
                        Apparel apparel = wornApparel[i];
                        if (apparel.def.apparel.CoversBodyPart(part))
                        {
                            float num = amount;
                            bool  flag;
                            ArmorUtility.ApplyArmor(ref amount, armorPenetration, apparel.GetStatValue(armorRatingStat, true), apparel, ref damageDef, pawn, out flag);
                            if (amount < 0.001f)
                            {
                                deflectedByMetalArmor = flag;
                                return(0f);
                            }
                            if (amount < num && flag)
                            {
                                diminishedByMetalArmor = true;
                            }
                        }
                    }
                }
                float num2 = amount;
                bool  flag2;
                ArmorUtility.ApplyArmor(ref amount, armorPenetration, pawn.GetStatValue(armorRatingStat, true), null, ref damageDef, pawn, out flag2);
                if (amount < 0.001f)
                {
                    deflectedByMetalArmor = flag2;
                    result = 0f;
                }
                else
                {
                    if (amount < num2 && flag2)
                    {
                        diminishedByMetalArmor = true;
                    }
                    result = amount;
                }
            }
            return(result);
        }
Exemplo n.º 3
0
        private void ApplyDamageToPart(DamageInfo dinfo, Pawn pawn, ref DamageResult result)
        {
            BodyPartRecord exactPartFromDamageInfo = this.GetExactPartFromDamageInfo(dinfo, pawn);

            if (exactPartFromDamageInfo != null)
            {
                dinfo.SetHitPart(exactPartFromDamageInfo);
                int num = dinfo.Amount;
                if (!dinfo.InstantOldInjury)
                {
                    num = ArmorUtility.GetPostArmorDamage(pawn, dinfo.Amount, dinfo.HitPart, dinfo.Def);
                }
                if (num <= 0)
                {
                    result.deflected = true;
                }
                else
                {
                    if (DamageWorker_AddInjury.IsHeadshot(dinfo, pawn))
                    {
                        result.headshot = true;
                    }
                    if (dinfo.InstantOldInjury)
                    {
                        HediffDef hediffDefFromDamage = HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart);
                        if (hediffDefFromDamage.CompPropsFor(typeof(HediffComp_GetsOld)) == null)
                        {
                            return;
                        }
                        if (dinfo.HitPart.def.oldInjuryBaseChance == 0.0)
                        {
                            return;
                        }
                        if (dinfo.HitPart.def.IsSolid(dinfo.HitPart, pawn.health.hediffSet.hediffs))
                        {
                            return;
                        }
                        if (pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(dinfo.HitPart))
                        {
                            return;
                        }
                    }
                    if (!dinfo.AllowDamagePropagation)
                    {
                        this.FinalizeAndAddInjury(pawn, (float)num, dinfo, ref result);
                    }
                    else
                    {
                        this.ApplySpecialEffectsToPart(pawn, (float)num, dinfo, ref result);
                    }
                }
            }
        }
Exemplo n.º 4
0
        private void ApplyDamageToPart(DamageInfo dinfo, Pawn pawn, DamageWorker.DamageResult result)
        {
            BodyPartRecord exactPartFromDamageInfo = this.GetExactPartFromDamageInfo(dinfo, pawn);

            if (exactPartFromDamageInfo != null)
            {
                dinfo.SetHitPart(exactPartFromDamageInfo);
                float num  = dinfo.Amount;
                bool  flag = !dinfo.InstantPermanentInjury;
                bool  deflectedByMetalArmor = false;
                if (flag)
                {
                    DamageDef def = dinfo.Def;
                    bool      diminishedByMetalArmor;
                    num       = ArmorUtility.GetPostArmorDamage(pawn, num, dinfo.ArmorPenetrationInt, dinfo.HitPart, ref def, out deflectedByMetalArmor, out 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;
                }
                else
                {
                    if (DamageWorker_AddInjury.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.permanentInjuryBaseChance == 0f || dinfo.HitPart.def.IsSolid(dinfo.HitPart, pawn.health.hediffSet.hediffs) || pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(dinfo.HitPart))
                        {
                            return;
                        }
                    }
                    if (!dinfo.AllowDamagePropagation)
                    {
                        this.FinalizeAndAddInjury(pawn, num, dinfo, result);
                    }
                    else
                    {
                        this.ApplySpecialEffectsToPart(pawn, num, dinfo, result);
                    }
                }
            }
        }
Exemplo n.º 5
0
        private void ApplyDamageToPart(DamageInfo dinfo, Pawn pawn, DamageResult result)
        {
            BodyPartRecord exactPartFromDamageInfo = GetExactPartFromDamageInfo(dinfo, pawn);

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

            if (num2)
            {
                DamageDef damageDef = dinfo.Def;
                num       = ArmorUtility.GetPostArmorDamage(pawn, num, dinfo.ArmorPenetrationInt, dinfo.HitPart, ref damageDef, out deflectedByMetalArmor, out bool diminishedByMetalArmor);
                dinfo.Def = damageDef;
                if (num < dinfo.Amount)
                {
                    result.diminished             = true;
                    result.diminishedByMetalArmor = diminishedByMetalArmor;
                }
            }
            if (dinfo.Def.ExternalViolenceFor(pawn))
            {
                num *= pawn.GetStatValue(StatDefOf.IncomingDamageFactor);
            }
            if (num <= 0f)
            {
                result.AddPart(pawn, dinfo.HitPart);
                result.deflected             = true;
                result.deflectedByMetalArmor = deflectedByMetalArmor;
                return;
            }
            if (IsHeadshot(dinfo, pawn))
            {
                result.headshot = true;
            }
            if (!dinfo.InstantPermanentInjury || (HealthUtility.GetHediffDefFromDamage(dinfo.Def, pawn, dinfo.HitPart).CompPropsFor(typeof(HediffComp_GetsPermanent)) != null && dinfo.HitPart.def.permanentInjuryChanceFactor != 0f && !pawn.health.hediffSet.PartOrAnyAncestorHasDirectlyAddedParts(dinfo.HitPart)))
            {
                if (!dinfo.AllowDamagePropagation)
                {
                    FinalizeAndAddInjury(pawn, num, dinfo, result);
                }
                else
                {
                    ApplySpecialEffectsToPart(pawn, num, dinfo, result);
                }
            }
        }