Exemple #1
0
        public static float DamageReduction(float armor, float damage, ExplosionSourceType sourceType, float caliber = 0, float penetrationfactor = 0)
        {
            float _damageReduction;

            switch (sourceType)
            {
            case ExplosionSourceType.Missile:
                if (BDAMath.Between(armor, 100f, 200f))
                {
                    damage *= 0.95f;
                }
                else if (BDAMath.Between(armor, 200f, 400f))
                {
                    damage *= 0.875f;
                }
                else if (BDAMath.Between(armor, 400f, 500f))
                {
                    damage *= 0.80f;
                }
                break;

            default:
                if (!(penetrationfactor >= 1f))
                {
                    //if (BDAMath.Between(armor, 100f, 200f))
                    //{
                    //    damage *= 0.300f;
                    //}
                    //else if (BDAMath.Between(armor, 200f, 400f))
                    //{
                    //    damage *= 0.250f;
                    //}
                    //else if (BDAMath.Between(armor, 400f, 500f))
                    //{
                    //    damage *= 0.200f;
                    //}

                    //y=(98.34817*x)/(97.85935+x)

                    _damageReduction = (113 * armor) / (154 + armor);

                    if (BDArmorySettings.DRAW_DEBUG_LABELS)
                    {
                        Debug.Log("[BDArmory]: Damage Before Reduction : " + damage / 100);
                        Debug.Log("[BDArmory]: Damage Reduction : " + _damageReduction / 100);
                        Debug.Log("[BDArmory]: Damage After Armor : " + (damage *= (_damageReduction / 100f)));
                    }

                    damage *= (_damageReduction / 100f);
                }
                break;
            }

            return(damage);
        }
Exemple #2
0
        public static float AddExplosiveDamage(this Part p,
                                               float explosiveDamage,
                                               float caliber,
                                               ExplosionSourceType sourceType)
        {
            if (BDArmorySettings.PAINTBALL_MODE)
            {
                return(0f);                                 // Don't add damage when paintball mode is enabled
            }
            float damage_ = 0f;

            //////////////////////////////////////////////////////////
            // Explosive Hitpoints
            //////////////////////////////////////////////////////////

            switch (sourceType)
            {
            case ExplosionSourceType.Missile:
                damage_ = (BDArmorySettings.DMG_MULTIPLIER / 100) * BDArmorySettings.EXP_DMG_MOD_MISSILE * explosiveDamage;
                break;

            default:
                damage_ = (BDArmorySettings.DMG_MULTIPLIER / 100) * BDArmorySettings.EXP_DMG_MOD_BALLISTIC_NEW * explosiveDamage;
                break;
            }

            var damage_before = damage_;

            //////////////////////////////////////////////////////////
            //   Armor Reduction factors
            //////////////////////////////////////////////////////////

            if (p.HasArmor())
            {
                float armorMass_      = p.GetArmorThickness();
                float damageReduction = DamageReduction(armorMass_, damage_, sourceType, caliber);

                damage_ = damageReduction;
            }

            //////////////////////////////////////////////////////////
            //   Apply Hitpoints
            //////////////////////////////////////////////////////////

            if (p.GetComponent <KerbalEVA>() != null)
            {
                ApplyHitPoints(p.GetComponent <KerbalEVA>(), (float)damage_);
            }
            else
            {
                ApplyHitPoints(p, damage_);
            }
            return(damage_);
        }
Exemple #3
0
        public static float DamageReduction(float armor, float damage, ExplosionSourceType sourceType, float caliber = 0, float penetrationfactor = 0)
        {
            float _damageReduction;

            switch (sourceType)
            {
            case ExplosionSourceType.Missile:
                damage *= Mathf.Clamp(-0.0005f * armor + 1.025f, 0f, 0.5f);     // Cap damage reduction at 50% (armor = 1050)
                break;

            default:
                if (!(penetrationfactor >= 1f))
                {
                    //if (BDAMath.Between(armor, 100f, 200f))
                    //{
                    //    damage *= 0.300f;
                    //}
                    //else if (BDAMath.Between(armor, 200f, 400f))
                    //{
                    //    damage *= 0.250f;
                    //}
                    //else if (BDAMath.Between(armor, 400f, 500f))
                    //{
                    //    damage *= 0.200f;
                    //}

                    //y=(98.34817*x)/(97.85935+x)

                    _damageReduction = (113 * armor) / (154 + armor);

                    if (BDArmorySettings.DRAW_DEBUG_LABELS)
                    {
                        Debug.Log("[BDArmory.PartExtensions]: Damage Before Reduction : " + damage);
                        Debug.Log("[BDArmory.PartExtensions]: Damage Reduction (%) : " + 100 * (1 - Mathf.Clamp01((113f - _damageReduction) / 100f)));
                        Debug.Log("[BDArmory.PartExtensions]: Damage After Armor : " + (damage *= Mathf.Clamp01((113f - _damageReduction) / 100f)));
                    }

                    damage *= Mathf.Clamp01((113f - _damageReduction) / 100f);;
                }
                break;
            }

            return(damage);
        }
Exemple #4
0
        public static void CreateExplosion(Vector3 position, float tntMassEquivalent, string explModelPath, string soundPath, ExplosionSourceType explosionSourceType, float caliber = 0, Part explosivePart = null, string sourceVesselName = null, string sourceWeaponName = null, Vector3 direction = default(Vector3), bool isfx = false)
        {
            CreateObjectPool(explModelPath, soundPath);

            Quaternion rotation;

            if (direction == default(Vector3))
            {
                rotation = Quaternion.LookRotation(VectorUtils.GetUpDirection(position));
            }
            else
            {
                rotation = Quaternion.LookRotation(direction);
            }

            GameObject newExplosion = explosionFXPools[explModelPath + soundPath].GetPooledObject();

            newExplosion.transform.SetPositionAndRotation(position, rotation);
            ExplosionFx eFx = newExplosion.GetComponent <ExplosionFx>();

            eFx.Range            = BlastPhysicsUtils.CalculateBlastRange(tntMassEquivalent);
            eFx.Position         = position;
            eFx.Power            = tntMassEquivalent;
            eFx.ExplosionSource  = explosionSourceType;
            eFx.SourceVesselName = sourceVesselName != null ? sourceVesselName : explosionSourceType == ExplosionSourceType.Missile ? (explosivePart != null && explosivePart.vessel != null ? explosivePart.vessel.GetName() : null) : null; // Use the sourceVesselName if specified, otherwise get the sourceVesselName from the missile if it is one.
            eFx.SourceWeaponName = sourceWeaponName;
            eFx.Caliber          = caliber;
            eFx.ExplosivePart    = explosivePart;
            eFx.Direction        = direction;
            eFx.isFX             = isfx;
            eFx.pEmitters        = newExplosion.GetComponentsInChildren <KSPParticleEmitter>();
            eFx.audioSource      = newExplosion.GetComponent <AudioSource>();
            if (tntMassEquivalent <= 5)
            {
                eFx.audioSource.minDistance = 4f;
                eFx.audioSource.maxDistance = 3000;
                eFx.audioSource.priority    = 9999;
            }
            newExplosion.SetActive(true);
        }