protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);

            var ob = builder as MyObjectBuilder_WeaponDefinition;

            MyDebug.AssertDebug(ob != null);

            this.WeaponAmmoDatas      = new MyWeaponAmmoData[Enum.GetValues(typeof(MyAmmoType)).Length];
            this.NoAmmoSound          = new MySoundPair(ob.NoAmmoSoundName);
            this.ReloadSound          = new MySoundPair(ob.ReloadSoundName);
            this.DeviateShotAngle     = MathHelper.ToRadians(ob.DeviateShotAngle);
            this.ReleaseTimeAfterFire = ob.ReleaseTimeAfterFire;
            this.MuzzleFlashLifeSpan  = ob.MuzzleFlashLifeSpan;

            this.AmmoMagazinesId = new MyDefinitionId[ob.AmmoMagazines.Length];
            for (int i = 0; i < this.AmmoMagazinesId.Length; i++)
            {
                var ammoMagazine = ob.AmmoMagazines[i];
                this.AmmoMagazinesId[i] = new MyDefinitionId(ammoMagazine.Type, ammoMagazine.Subtype);

                var        ammoMagazineDefinition = MyDefinitionManager.Static.GetAmmoMagazineDefinition(this.AmmoMagazinesId[i]);
                MyAmmoType ammoType     = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagazineDefinition.AmmoDefinitionId).AmmoType;
                string     errorMessage = null;
                switch (ammoType)
                {
                case MyAmmoType.HighSpeed:
                    MyDebug.AssertDebug(ob.ProjectileAmmoData != null, "No weapon ammo data specified for projectile ammo");
                    if (ob.ProjectileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[(int)MyAmmoType.HighSpeed] = new MyWeaponAmmoData(ob.ProjectileAmmoData);
                    }
                    else
                    {
                        errorMessage = string.Format(ErrorMessageTemplate, "projectile", "Projectile");
                    }
                    break;

                case MyAmmoType.Missile:
                    MyDebug.AssertDebug(ob.MissileAmmoData != null, "No weapon ammo data specified for missile ammo");
                    if (ob.MissileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[(int)MyAmmoType.Missile] = new MyWeaponAmmoData(ob.MissileAmmoData);
                    }
                    else
                    {
                        errorMessage = string.Format(ErrorMessageTemplate, "missile", "Missile");
                    }
                    break;

                default:
                    throw new NotImplementedException();
                }

                if (!string.IsNullOrEmpty(errorMessage))
                {
                    MyDefinitionErrors.Add(Context, errorMessage, TErrorSeverity.Critical);
                }
            }
        }
Ejemplo n.º 2
0
        public void AddMuzzleMatrix(MyAmmoType ammoType, Matrix localMatrix)
        {
            int iAmmoType = (int)ammoType;

            if (!m_dummiesByAmmoType.ContainsKey(iAmmoType))
            {
                m_dummiesByAmmoType[iAmmoType] = new DummyContainer();
            }

            m_dummiesByAmmoType[iAmmoType].Dummies.Add(MatrixD.Normalize(localMatrix));
        }
Ejemplo n.º 3
0
 public static Vector3 GetProjectileTrailColorByType(MyAmmoType ammoType) 
 {
     Vector3 output;
     bool found = m_projectileTrailColors.TryGetValue((int)ammoType, out output);
     MyDebug.AssertDebug(found, "Could not find the trail color value. The default will be loaded. You can ignore this error.");
     if (!found)
     {
         found = m_projectileTrailColors.TryGetValue((int)MyAmmoType.Unknown, out output);
         MyDebug.AssertDebug(found, "Could not find the default value for the trail color.");
     }
     return output;
 }
Ejemplo n.º 4
0
        public static Vector3 GetProjectileTrailColorByType(MyAmmoType ammoType)
        {
            Vector3 output;
            bool    found = m_projectileTrailColors.TryGetValue((int)ammoType, out output);

            MyDebug.AssertDebug(found, "Could not find the trail color value. The default will be loaded. You can ignore this error.");
            if (!found)
            {
                found = m_projectileTrailColors.TryGetValue((int)MyAmmoType.Unknown, out output);
                MyDebug.AssertDebug(found, "Could not find the default value for the trail color.");
            }
            return(output);
        }
Ejemplo n.º 5
0
        private void MoveToNextMuzzle(MyAmmoType ammoType)
        {
            int            index = (int)ammoType;
            DummyContainer container;

            if (m_dummiesByAmmoType.TryGetValue(index, out container))
            {
                if (container.Dummies.Count > 1)
                {
                    container.DummyIndex++;
                    if (container.DummyIndex == container.Dummies.Count)
                    {
                        container.DummyIndex = 0;
                    }
                    container.Dirty = true;
                }
            }
        }
Ejemplo n.º 6
0
        public WeaponDefinitionExpanded(MyWeaponDefinition weaponDefn)
        {
            this.WeaponDefinition = weaponDefn;

            for (int i = 0; i < weaponDefn.WeaponAmmoDatas.Length; i++)
            {
                if (weaponDefn.WeaponAmmoDatas[i] != null)
                {
                    AmmoType = (MyAmmoType)i;
                    FirstAmmo = Ammo.GetAmmo(WeaponDefinition.AmmoMagazinesId[0]);
                    RequiredAccuracy = (float)Math.Cos(0.02f + Math.Min(weaponDefn.WeaponAmmoDatas[i].RateOfFire, 1000) / 72000f);
                    return;
                }
            }

            AmmoType = MyAmmoType.Unknown;
            RequiredAccuracy = 2f;
        }
Ejemplo n.º 7
0
        public readonly MyCustomHitMaterialMethod OnHitMaterialSpecificParticles; // Delegate to method to create material specific particles

        public MyAmmoProperties(float InitialSpeed,
                                float DesiredSpeed,
                                float SpeedVar,
                                float MaxTrajectory,
                                float HealthDamage,
                                float ShipDamage,
                                float EMPDamage,
                                float ExplosionRadius,
                                float DeviateAngle,
                                Vector3 TrailColor,
                                MySoundCuesEnum ShotSound,
                                bool IsExplosive,
                                bool AllowAimCorrection,
                                float DecalEmissivity,
                                int ProjectileGroupSize,
                                MyDamageType DamageType,
                                MyAmmoType AmmoType,

                                MyCustomHitParticlesMethod OnHitParticles,
                                MyCustomHitMaterialMethod OnHitMaterialSpecificParticles)
        {
            this.InitialSpeed = InitialSpeed;
            this.DesiredSpeed = DesiredSpeed;
            this.SpeedVar = SpeedVar;
            this.MaxTrajectory = MaxTrajectory;
            this.HealthDamage = HealthDamage;
            this.ShipDamage = ShipDamage;
            this.EMPDamage = EMPDamage;
            this.ExplosionRadius = ExplosionRadius;
            this.DeviateAngle = DeviateAngle;
            this.TrailColor = TrailColor;
            this.ShotSound = ShotSound;
            this.IsExplosive = IsExplosive;
            this.AllowAimCorrection = AllowAimCorrection;
            this.DecalEmissivity = DecalEmissivity;
            this.ProjectileGroupSize = ProjectileGroupSize;

            this.DamageType = DamageType;
            this.AmmoType = AmmoType;

            this.OnHitParticles = OnHitParticles;
            this.OnHitMaterialSpecificParticles = OnHitMaterialSpecificParticles;
        }
Ejemplo n.º 8
0
        private WeaponDefinitionExpanded(MyWeaponDefinition weaponDefn)
        {
            this.WeaponDefinition = weaponDefn;

            for (int i = 0; i < weaponDefn.WeaponAmmoDatas.Length; i++)
            {
                if (weaponDefn.WeaponAmmoDatas[i] != null)
                {
                    AmmoType  = (MyAmmoType)i;
                    FirstAmmo = Ammo.GetAmmo(WeaponDefinition.AmmoMagazinesId[0]);

                    RequiredAccuracyRadians = FirstAmmo.Description != null ?
                                              0.15f :   // fire guided missile with less accuracy, despite slower RoF
                                              0.02f + Math.Min(weaponDefn.WeaponAmmoDatas[i].RateOfFire, 1000) / 72000f;
                    RequiredAccuracyCos = (float)Math.Cos(RequiredAccuracyRadians);
                    return;
                }
            }

            AmmoType            = MyAmmoType.Unknown;
            RequiredAccuracyCos = 2f;
        }
Ejemplo n.º 9
0
 protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
 {
     base.DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
     if (damage > 0)
     {
         OrderOpenAndClose();
     }
 }
Ejemplo n.º 10
0
        protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            base.DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);

            if (IsDead())
            {
                MarkForClose();

                var effect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Explosion_SmallPrefab);
                effect.WorldMatrix = WorldMatrix;
                effect.UserScale   = 0.5f;
            }
        }
Ejemplo n.º 11
0
        protected override void Init(MyObjectBuilder_DefinitionBase builder)
        {
            base.Init(builder);
            MyObjectBuilder_WeaponDefinition definition = builder as MyObjectBuilder_WeaponDefinition;

            this.WeaponAmmoDatas = new MyWeaponAmmoData[Enum.GetValues(typeof(MyAmmoType)).Length];
            this.WeaponEffects   = new MyWeaponEffect[(definition.Effects == null) ? 0 : definition.Effects.Length];
            if (definition.Effects != null)
            {
                for (int j = 0; j < definition.Effects.Length; j++)
                {
                    this.WeaponEffects[j] = new MyWeaponEffect(definition.Effects[j].Action, definition.Effects[j].Dummy, definition.Effects[j].Particle, definition.Effects[j].Loop, definition.Effects[j].InstantStop);
                }
            }
            this.PhysicalMaterial      = MyStringHash.GetOrCompute(definition.PhysicalMaterial);
            this.UseDefaultMuzzleFlash = definition.UseDefaultMuzzleFlash;
            this.NoAmmoSound           = new MySoundPair(definition.NoAmmoSoundName, true);
            this.ReloadSound           = new MySoundPair(definition.ReloadSoundName, true);
            this.SecondarySound        = new MySoundPair(definition.SecondarySoundName, true);
            this.DeviateShotAngle      = MathHelper.ToRadians(definition.DeviateShotAngle);
            this.ReleaseTimeAfterFire  = definition.ReleaseTimeAfterFire;
            this.MuzzleFlashLifeSpan   = definition.MuzzleFlashLifeSpan;
            this.ReloadTime            = definition.ReloadTime;
            this.DamageMultiplier      = definition.DamageMultiplier;
            this.RangeMultiplier       = definition.RangeMultiplier;
            this.UseRandomizedRange    = definition.UseRandomizedRange;
            this.AmmoMagazinesId       = new MyDefinitionId[definition.AmmoMagazines.Length];
            for (int i = 0; i < this.AmmoMagazinesId.Length; i++)
            {
                MyObjectBuilder_WeaponDefinition.WeaponAmmoMagazine magazine = definition.AmmoMagazines[i];
                this.AmmoMagazinesId[i] = new MyDefinitionId(magazine.Type, magazine.Subtype);
                MyAmmoMagazineDefinition ammoMagazineDefinition = MyDefinitionManager.Static.GetAmmoMagazineDefinition(this.AmmoMagazinesId[i]);
                MyAmmoType ammoType = MyDefinitionManager.Static.GetAmmoDefinition(ammoMagazineDefinition.AmmoDefinitionId).AmmoType;
                string     str      = null;
                if (ammoType == MyAmmoType.HighSpeed)
                {
                    if (definition.ProjectileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[0] = new MyWeaponAmmoData(definition.ProjectileAmmoData);
                    }
                    else
                    {
                        str = string.Format(ErrorMessageTemplate, "projectile", "Projectile");
                    }
                }
                else
                {
                    if (ammoType != MyAmmoType.Missile)
                    {
                        throw new NotImplementedException();
                    }
                    if (definition.MissileAmmoData != null)
                    {
                        this.WeaponAmmoDatas[1] = new MyWeaponAmmoData(definition.MissileAmmoData);
                    }
                    else
                    {
                        str = string.Format(ErrorMessageTemplate, "missile", "Missile");
                    }
                }
                if (!string.IsNullOrEmpty(str))
                {
                    MyDefinitionErrors.Add(base.Context, str, TErrorSeverity.Critical, true);
                }
            }
        }
Ejemplo n.º 12
0
        protected virtual void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            if (damageSource == MySession.PlayerShip && (damageSource != this && MinerWars.AppCode.Game.World.Global.MyFactions.GetFactionsRelation(damageSource, this) == MinerWars.AppCode.Game.World.Global.MyFactionRelationEnum.Enemy))
            {
                playerDamage *= MyGameplayConstants.GameplayDifficultyProfile.DamageFromPlayerToEnemyMultiplicator;
                damage *= MyGameplayConstants.GameplayDifficultyProfile.DamageFromPlayerToEnemyMultiplicator;
                empDamage *= MyGameplayConstants.GameplayDifficultyProfile.DamageFromPlayerToEnemyMultiplicator;
            }

            Health = MathHelper.Clamp(Health - damage, 0, MaxHealth);

            TestDeath(damageSource);

        }
Ejemplo n.º 13
0
        public void AddMuzzleMatrix(MyAmmoType ammoType, Matrix localMatrix)
        {
            int iAmmoType = (int)ammoType;
            if (!m_dummiesByAmmoType.ContainsKey(iAmmoType))
            {
                m_dummiesByAmmoType[iAmmoType] = new DummyContainer();
            }

            m_dummiesByAmmoType[iAmmoType].Dummies.Add(MatrixD.Normalize(localMatrix));
        }
Ejemplo n.º 14
0
        protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            base.DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);

            if (IsDead())
            {
                MarkForClose();

                var effect = MyParticlesManager.CreateParticleEffect((int)MyParticleEffectsIDEnum.Explosion_SmallPrefab);
                effect.WorldMatrix = WorldMatrix;
                effect.UserScale = 0.5f;
            }
        }
Ejemplo n.º 15
0
        protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            if (damageSource != null && damageSource == MySession.PlayerShip)
            {
                var factionRelation = MyFactions.GetFactionsRelation(damageSource.Faction, Faction);
                if ((factionRelation == MyFactionRelationEnum.Friend || factionRelation == MyFactionRelationEnum.Neutral) &&
                    !MyGuiScreenGamePlay.Static.IsCheatEnabled(MyGameplayCheatsEnum.FRIEND_NEUTRAL_CANT_DIE) &&
                    !MyFakes.INDESTRUCTIBLE_PREFABS)
                {
                    MySession.PlayerShip.AddFriendlyFireDamage(this, damage);
                    return;
                }
            }

            base.DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
        }
        public void DoDamage(MyEntity target, float player, float normal, float emp, MyDamageType damageType, MyAmmoType ammoType, MyEntity source, float newHealthRatio)
        {
            if (IsControlledByMe(target))
            {
                MyEventDoDamage msg = new MyEventDoDamage();
                msg.TargetEntityId = target.EntityId.Value.NumericValue;
                msg.PlayerDamage   = player;
                msg.Damage         = normal;
                msg.EmpDamage      = emp;
                msg.DamageType     = (byte)damageType;
                msg.AmmoType       = (byte)ammoType;
                msg.DamageSource   = source != null?MyEntityIdentifier.ToNullableInt(source.EntityId) : null;

                msg.NewHealthRatio = newHealthRatio;
                Peers.SendToAll(ref msg, NetDeliveryMethod.ReliableUnordered);
            }
        }
Ejemplo n.º 17
0
        /// <summary>
        /// Damage is first taken from armor, at full rate. The amount taken from armor is then multiplied by armor
        /// ratio to get how much damage armor absorbed. The rest is taken from ship health.
        /// </summary>
        /// <param name="healthDamage">Damage which should be taken from player health</param>
        /// <param name="damage">Damage to be taken from ship/entity</param>
        /// <param name="damageType"></param>
        /// <param name="ammoType"></param>
        /// <param name="damageSource"></param>
        protected override void DoDamageInternal(float healthDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            if (HasSunWindArmor && damageType == MyDamageType.Sunwind)
            {
                return;
            }

            HandleAttack(damageSource);

            // Mantis 5877: There will be "friendly fire" voice notification, but nobody will get hurt.
            // It will work only on small ships.

            if (damageSource is MySmallShip && damageSource != this)
            {
                var factionRelation = MyFactions.GetFactionsRelation(this, damageSource);
                if (factionRelation == MyFactionRelationEnum.Friend || factionRelation == MyFactionRelationEnum.Neutral)
                {
                    // Report friendly fire on friendly units, when too much damage over time is done, friends will aggro
                    if (damageSource == MySession.PlayerShip && (this.PersistentFlags & MyPersistentEntityFlags.Parked) == 0)
                    {
                        MySession.PlayerShip.AddFriendlyFireDamage(this, damage);
                    }

                    healthDamage = damage = empDamage = 0;
                }
            }
            
            // When ship damages itself and it's player ship, don't do damage
            if (damageSource == this && damageSource == MySession.PlayerShip)
            {
                healthDamage = damage = empDamage = 0;
            }

            bool isPlayerShip = this == MySession.PlayerShip;

#if RENDER_PROFILING
            if (isPlayerShip)
                return;
#endif
            // Invincibility for player in editor or when profiling
            if (isPlayerShip && MyGuiScreenGamePlay.Static.IsEditorActive())
            {
                return;
            }


            if (isPlayerShip && (MyGuiScreenGamePlay.Static.IsCheatEnabled(MyGameplayCheatsEnum.PLAYER_SHIP_INDESTRUCTIBLE)))
            {
                damage = empDamage = 0;
            }

            if (MyFakes.TEST_MISSION_GAMEPLAY && (damage != 10000 || damageType != MyDamageType.Explosion))
            {
                damage = empDamage = healthDamage = 0;
            }

            if (isPlayerShip)
            {
                if (damageType != MyDamageType.Unknown)
                {
                    damage *= MyGameplayConstants.GameplayDifficultyProfile.DamageToPlayerMultiplicator;
                }
            }

            //how much armor absorbs damage (0.0 no absorbtion, 1.0 full absorbtion)
            float armorReduction = m_armorProperties.HasValue ? m_armorProperties.Value.Resistance : 0;

            if (ammoType == MyAmmoType.Piercing)
            {
                armorReduction *= MyAmmoConstants.ArmorEffectivityVsPiercingAmmo; // Armor effectivity is lower against piercing ammo
            }

            //actual damage armor absorbed
            float armorDamage = Math.Min(ArmorHealth, damage);

            //update armor health value
            ArmorHealth -= armorDamage;

            //calculate actual damage to the ship (decrease it by the absorbed damage by armor)
            float shipDamage = damage - armorDamage * armorReduction;


            if (this == MySession.PlayerShip)
            {
                if (MySession.Static.Player.Medicines[(int)MyMedicineType.HEALTH_ENHANCING_MEDICINE].IsActive())
                    healthDamage *= MyMedicineConstants.HEALTH_ENHANCING_MEDICINE_DAMAGE_MULTIPLIER;

                if (damageType == MyDamageType.Radioactivity || damageType == MyDamageType.Sunwind)
                {
                    // activate if not active
                    if (!MySession.Static.Player.Medicines[(int)MyMedicineType.ANTIRADIATION_MEDICINE].IsActive())
                    {
                        MySession.Static.Player.Medicines[(int)MyMedicineType.ANTIRADIATION_MEDICINE].ActivateIfInInventory(Inventory);
                    }
                    // if active, modify health damage
                    if (MySession.Static.Player.Medicines[(int)MyMedicineType.ANTIRADIATION_MEDICINE].IsActive())
                    {
                        healthDamage *= MyMedicineConstants.ANTIRADIATION_MEDICINE_RADIATION_DAMAGE_MULTIPLIER;
                    }
                }

                if (damageSource == null || (damageSource != this && MyFactions.GetFactionsRelation(damageSource, this) == MyFactionRelationEnum.Enemy))
                {
                    healthDamage *= MyGameplayConstants.GameplayDifficultyProfile.DamageToPlayerFromEnemyMultiplicator;
                    shipDamage *= MyGameplayConstants.GameplayDifficultyProfile.DamageToPlayerFromEnemyMultiplicator;
                    empDamage *= MyGameplayConstants.GameplayDifficultyProfile.DamageToPlayerFromEnemyMultiplicator;
                }

                if (MySession.Static != null)
                {
                    if (!MySession.Static.Player.IsDead())
                    {
                        MySession.Static.Player.AddHealth(-healthDamage, damageSource);
                    }
                }

                if (damageType == MyDamageType.Radioactivity || damageType == MyDamageType.Sunwind)
                {
                    m_radiationLastDamage = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                    //PlayGeigerBeeping();
                    if (healthDamage >= MySmallShipConstants.WARNING_RADIATION_DAMAGE_PER_SECOND * MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS)
                    {
                        m_radiationCriticalLastDamage = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                        //PlayRadiationWarning();
                    }
                }
            }

            DisableByEMP(TimeSpan.FromSeconds(MySmallShipConstants.EMP_SMALLSHIP_DISABLE_DURATION_MULTIPLIER * empDamage));

            if (isPlayerShip)
            {
                if (damageSource != null)
                {
                    MyHud.SetDamageIndicator(damageSource, damageSource.GetPosition(), shipDamage);
                }
            }

            base.DoDamageInternal(healthDamage, shipDamage, empDamage, damageType, ammoType, damageSource, justDeactivate);

            UpdateDamageEffect();
        }
Ejemplo n.º 18
0
 protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
 {
     base.DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
     if (damage > 0)
     {
         OrderOpenAndClose();
     }
 }
Ejemplo n.º 19
0
        ///<summary>
        ///Does domage to entity
        ///</summary>
        ///<param name="deltaHealth">Amount of damage</param>
        public void DoDamage(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate = false)
        {
            Debug.Assert(!Closed, "Cannot do damage, entity is closed");

#if GPU_PROFILING
            if (this == MySession.PlayerShip)
                return; //We dont want die anymore while profiling!
#endif
            if (!IsDestructible || IsDummy) // Dummy entities are driven by host
            {
                return;
            }

            DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);

            if (MyMultiplayerGameplay.IsRunning)
            {
                MyMultiplayerGameplay.Static.DoDamage(this, playerDamage, damage, empDamage, damageType, ammoType, damageSource, HealthRatio);
            }
        }
Ejemplo n.º 20
0
 protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
 {
     Parent.DoDamage(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
 }
Ejemplo n.º 21
0
        /// <summary>
        /// Does domage to entity
        /// </summary>
        /// <param name="deltaHealth">Amount of damage</param>
        public override void DoDamage(float healthDamage, float damage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource)
        {     
            MyFactionRelationEnum? factionRelation = null;
            if (damageSource != null)
            {
                factionRelation = MyFactions.GetFactionsRelation(this.Faction, damageSource.Faction);
            }

            // notify group
            if (damageSource is MySmallShip && factionRelation == MyFactionRelationEnum.Enemy)
            {
                NotifyMyGroupAboutEnemy(damageSource);                
            }
            
            bool wasDead = IsDead();
            
            if (CanDie(damageSource))
            {
                base.DoDamage(healthDamage, damage, damageType, ammoType, damageSource);
            }
            
            // if player's ship fired
            if (damageSource == MySession.PlayerShip)
            {
                // friendly fire warning
                if (factionRelation == MyFactionRelationEnum.Friend)
                {
                    if (m_friendlyFireCue == null || !m_friendlyFireCue.Value.IsPlaying)
                    {
                        m_friendlyFireCue = MyAudio.AddCue2D(MySoundCuesEnum.SfxFriendlyFireWarning);
                    }
                }
                // targed destroyed notification
                if (factionRelation == MyFactionRelationEnum.Enemy && !wasDead && IsDead())
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.SfxTargetDestroyed);
                }
            }
        }
Ejemplo n.º 22
0
        protected override void DoDamageInternal(float healthDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            bool wasDead = IsDead();
            bool pilotWasDead = IsPilotDead();
            if (CanDie(damageSource))
            {
                PilotHealth -= healthDamage;
                PilotHealth = MathHelper.Clamp(PilotHealth, 0, MyGameplayConstants.HEALTH_BASIC);

                base.DoDamageInternal(healthDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);

                if (IsDamagedForWarnignAlert())
                {
                    LowHealth();
                }
            }
            bool died = !wasDead && IsDead();
            bool pilotDied = !pilotWasDead && IsPilotDead();

            // if player's ship fired
            if (damageSource == MySession.PlayerShip)
            {
                MyFactionRelationEnum? factionRelation = MyFactions.GetFactionsRelation(this, damageSource);

                // friendly fire warning
                if (factionRelation == MyFactionRelationEnum.Friend)
                {
                    if (m_friendlyFireCue == null ||
                        !m_friendlyFireCue.Value.IsPlaying && MyMinerGame.TotalGamePlayTimeInMilliseconds - m_friendlyFireTimeFromLastPlayed >= MySmallShipConstants.WARNING_FRIENDLY_FIRE_INTERVAL)
                    {
                        m_friendlyFireCue = MyAudio.AddCue2D(MySoundCuesEnum.HudFriendlyFireWarning);
                        m_friendlyFireTimeFromLastPlayed = MyMinerGame.TotalGamePlayTimeInMilliseconds;
                    }
                }

                // targed destroyed notification
                if (factionRelation == MyFactionRelationEnum.Enemy && died)
                {
                    MyAudio.AddCue2D(MySoundCuesEnum.HudTargetDestroyed);
                }

                // Only when pilot
                if (died && MyMultiplayerGameplay.IsRunning && MinerWars.AppCode.Game.World.MyClientServer.LoggedPlayer != null)
                {
                    MyMultiplayerGameplay.Static.PlayerStatistics.PlayersKilled++;
                    MyMultiplayerGameplay.Static.UpdateStats();
                }
            }

            if (pilotDied)
            {
                Save = false;
                DisplayName = m_pilotDeadString;
            }

            if (damageType == MyDamageType.Explosion)
            {
                Shock(MySmallShipConstants.EXPLOSION_SHOCK_TIME);
            }

            UpdateBioChemEffect(pilotDied && ammoType == MyAmmoType.Biochem);
        }
Ejemplo n.º 23
0
        protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            if (damageSource != null && damageSource == MySession.PlayerShip)
            {
                var factionRelation = MyFactions.GetFactionsRelation(damageSource.Faction, Faction);
                if ((factionRelation == MyFactionRelationEnum.Friend || factionRelation == MyFactionRelationEnum.Neutral) &&
                    !MyGuiScreenGamePlay.Static.IsCheatEnabled(MyGameplayCheatsEnum.FRIEND_NEUTRAL_CANT_DIE) &&
                    !MyFakes.INDESTRUCTIBLE_PREFABS)
                {
                    MySession.PlayerShip.AddFriendlyFireDamage(this, damage);
                    return;
                }
            }

            base.DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
        }
Ejemplo n.º 24
0
 protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
 {
     if (Parent != null) //Because in objects got for explosion damage can be parent and children together
     {
         Parent.DoDamage(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
     }
 }
Ejemplo n.º 25
0
 protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
 {
     Parent.DoDamage(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
 }
Ejemplo n.º 26
0
 private void MoveToNextMuzzle(MyAmmoType ammoType)
 {
     int index = (int)ammoType;
     DummyContainer container;
     if (m_dummiesByAmmoType.TryGetValue(index, out container))
     {
         if (container.Dummies.Count > 1)
         {
             container.DummyIndex++;
             if (container.DummyIndex == container.Dummies.Count)
             {
                 container.DummyIndex = 0;
             }
             container.Dirty = true;
         }
     }
 }
 public void DoDamage(MyEntity target, float player, float normal, float emp, MyDamageType damageType, MyAmmoType ammoType, MyEntity source, float newHealthRatio)
 {
     if (IsControlledByMe(target))
     {
         MyEventDoDamage msg = new MyEventDoDamage();
         msg.TargetEntityId = target.EntityId.Value.NumericValue;
         msg.PlayerDamage = player;
         msg.Damage = normal;
         msg.EmpDamage = emp;
         msg.DamageType = (byte)damageType;
         msg.AmmoType = (byte)ammoType;
         msg.DamageSource = source != null ? MyEntityIdentifier.ToNullableInt(source.EntityId) : null;
         msg.NewHealthRatio = newHealthRatio;
         Peers.SendToAll(ref msg, NetDeliveryMethod.ReliableUnordered);
     }
 }
        protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
        {
            if (damage > 0)
            {
                m_ownerKinematic.OrderOpenAndClose();
            }
            if (m_ownerKinematic.IsDestructible)
            {
                if (((MyPrefabConfigurationKinematicPart)m_config).m_damageType == DamageTypesEnum.SHARE_WITH_PARENT)
                {
                    m_ownerKinematic.DoDamage(playerDamage, damage, empDamage, damageType, ammoType, damageSource);
                    return;
                }

                base.DoDamageInternal(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
            }
        }
 protected override void DoDamageInternal(float playerDamage, float damage, float empDamage, MyDamageType damageType, MyAmmoType ammoType, MyEntity damageSource, bool justDeactivate)
 {
     if (Parent != null) //Because in objects got for explosion damage can be parent and children together
     {
         Parent.DoDamage(playerDamage, damage, empDamage, damageType, ammoType, damageSource, justDeactivate);
     }
 }