예제 #1
0
 public override void Initialize(CompProperties props)
 {
     base.Initialize(props);
     CompProperties_AP cprops = props as CompProperties_AP;
     if (cprops != null)
     {
         this.props = cprops;
     }
 }
예제 #2
0
        public override void Initialize(CompProperties props)
        {
            base.Initialize(props);
            CompProperties_AP cprops = props as CompProperties_AP;

            if (cprops != null)
            {
                this.props = cprops;
            }
        }
예제 #3
0
        public static readonly DamageDef absorbDamageDef = DamageDefOf.Blunt;   //The damage def to convert absorbed shots into

        /// <summary>
        /// Calculates deflection chance and damage through armor
        /// </summary>
        public static int GetAfterArmorDamage(Pawn pawn, int amountInt, BodyPartRecord part, DamageInfo dinfo, bool damageArmor, ref bool deflected)
        {
            DamageDef damageDef = dinfo.Def;

            if (damageDef.armorCategory == DamageArmorCategory.IgnoreArmor)
            {
                return(amountInt);
            }

            float   damageAmount   = (float)amountInt;
            StatDef deflectionStat = damageDef.armorCategory.DeflectionStat();
            float   pierceAmount   = 0f;

            //Check if the projectile has the armor-piercing comp
            CompProperties_AP props = null;

            if (dinfo.Source != null)
            {
                VerbProperties verbProps = dinfo.Source.Verbs.Where(x => x.isPrimary).First();
                if (verbProps != null)
                {
                    ThingDef projectile = verbProps.projectileDef;
                    if (projectile != null && projectile.HasComp(typeof(CompAP)))
                    {
                        props = (CompProperties_AP)projectile.GetCompProperties(typeof(CompAP));
                    }
                }

                //Check weapon for comp if projectile doesn't have it
                if (props == null && dinfo.Source.HasComp(typeof(CompAP)))
                {
                    props = (CompProperties_AP)dinfo.Source.GetCompProperties(typeof(CompAP));
                }
            }

            if (props != null)
            {
                pierceAmount = props.armorPenetration;
            }

            //Run armor calculations on all apparel
            if (pawn.apparel != null)
            {
                List <Apparel> wornApparel = new List <Apparel>(pawn.apparel.WornApparel);
                for (int i = wornApparel.Count - 1; i >= 0; i--)
                {
                    if (wornApparel[i].def.apparel.CoversBodyPart(part))
                    {
                        Thing armorThing = damageArmor ? wornApparel[i] : null;

                        //Check for deflection
                        if (Utility.ApplyArmor(ref damageAmount, ref pierceAmount, wornApparel[i].GetStatValue(deflectionStat, true), armorThing, damageDef))
                        {
                            deflected = true;
                            if (damageDef != absorbDamageDef)
                            {
                                damageDef      = absorbDamageDef;
                                deflectionStat = damageDef.armorCategory.DeflectionStat();
                                i++;
                            }
                        }
                        if (damageAmount < 0.001)
                        {
                            return(0);
                        }
                    }
                }
            }
            //Check for pawn racial armor
            if (Utility.ApplyArmor(ref damageAmount, ref pierceAmount, pawn.GetStatValue(deflectionStat, true), null, damageDef))
            {
                deflected = true;
                if (damageAmount < 0.001)
                {
                    return(0);
                }
                damageDef      = absorbDamageDef;
                deflectionStat = damageDef.armorCategory.DeflectionStat();
                Utility.ApplyArmor(ref damageAmount, ref pierceAmount, pawn.GetStatValue(deflectionStat, true), pawn, damageDef);
            }
            return(Mathf.RoundToInt(damageAmount));
        }