コード例 #1
0
 protected void InternalDamageCharacter()
 {
     try
     {
         float        damage     = InternalGetCharacterHealth() - Health;
         MyDamageType damageType = MyDamageType.Unknown;
         if (Health <= 0)
         {
             damageType = MyDamageType.Suicide;
         }
         InvokeEntityMethod(BackingObject, CharacterDamageCharacterMethod, new object[] { damage, damageType, true });
     }
     catch (Exception ex)
     {
         LogManager.ErrorLog.WriteLine(ex);
     }
 }
コード例 #2
0
        public static void DoDamageSynced(MyEntity destroyable, float damage, MyDamageType type, long attackerId)
        {
            Debug.Assert(Sync.IsServer || destroyable.SyncObject is MySyncEntity || (destroyable.SyncObject as MySyncEntity).ResponsibleForUpdate(Sync.Clients.LocalClient));
            if (!(destroyable is IMyDestroyableObject))
            {
                return;
            }

            var msg = new DoDamageMsg();

            msg.DestroyableEntityId = destroyable.EntityId;
            msg.Damage           = damage;
            msg.Type             = type;
            msg.AttackerEntityId = attackerId;

            (destroyable as IMyDestroyableObject).DoDamage(damage, type, false, attackerId: attackerId);
            Sync.Layer.SendMessageToAll <DoDamageMsg>(ref msg);
        }
コード例 #3
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;
        }
コード例 #4
0
        public void DoDamage(float damage, MyDamageType damageType, bool sync, long attackerId)
        {
            if (sync)
            {
                if (Sync.IsServer)
                {
                    MySyncHelper.DoDamageSynced(this, damage, damageType, attackerId);
                }
            }
            else
            {
                if (UseDamageSystem)
                {
                    MyDamageSystem.Static.RaiseDestroyed(this, new MyDamageInformation(false, damage, damageType, attackerId));
                }

                Explode();
            }
        }
コード例 #5
0
        void IMyDestroyableObject.DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo?hitInfo, long attackerId)
        {
            if (MarkedToExplode || (!MySession.Static.DestructibleBlocks))
            {
                return;
            }
            //if (!IsFunctional)
            //    return false;

            if (sync)
            {
                if (Sync.IsServer)
                {
                    MySyncHelper.DoDamageSynced(this, damage, damageType, attackerId);
                }
            }
            else
            {
                MyDamageInformation damageInfo = new MyDamageInformation(false, damage, damageType, attackerId);
                if (UseDamageSystem)
                {
                    MyDamageSystem.Static.RaiseBeforeDamageApplied(this, ref damageInfo);
                }

                m_damageType = damageType;

                if (damageInfo.Amount > 0)
                {
                    if (UseDamageSystem)
                    {
                        MyDamageSystem.Static.RaiseAfterDamageApplied(this, damageInfo);
                    }

                    OnDestroy();

                    if (UseDamageSystem)
                    {
                        MyDamageSystem.Static.RaiseDestroyed(this, damageInfo);
                    }
                }
            }
            return;
        }
コード例 #6
0
        internal void DoDamage(float damage, MyDamageType damageType, MyHitInfo?hitInfo)
        {
            float integrity = 0;

            foreach (var block in m_blocks)
            {
                integrity += block.Value.MaxIntegrity;
            }

            if (hitInfo.HasValue)
            {
                Debug.Assert(m_blocks.Count > 0);
                CubeGrid.RenderData.AddDecal(Position, Vector3D.Transform(hitInfo.Value.Position, CubeGrid.PositionComp.WorldMatrixInvScaled),
                                             Vector3D.TransformNormal(hitInfo.Value.Normal, CubeGrid.PositionComp.WorldMatrixInvScaled), m_blocks.First().Value.BlockDefinition.PhysicalMaterial.DamageDecal);
            }

            foreach (var block in m_blocks)
            {
                block.Value.DoDamage(damage * (block.Value.MaxIntegrity / integrity), damageType, true, hitInfo, false);
            }
        }
コード例 #7
0
            public void DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo?hitInfo)
            {
                if (sync)
                {
                    if (Sync.IsServer)
                    {
                        MySyncHelper.DoDamageSynced(Entity, damage, damageType);
                    }
                }
                else
                {
                    m_integrity -= damage;

                    if (m_integrity <= 0)
                    {
                        m_closeAfterSimulation = true;
                        return;
                    }
                }
                return;
            }
コード例 #8
0
            public void DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo?hitInfo, long attackerId)
            {
                if (sync)
                {
                    if (Sync.IsServer)
                    {
                        MySyncHelper.DoDamageSynced(Entity, damage, damageType, attackerId);
                    }
                }
                else
                {
                    MyDamageInformation info = new MyDamageInformation(false, damage, damageType, attackerId);

                    if (Entity.UseDamageSystem)
                    {
                        MyDamageSystem.Static.RaiseBeforeDamageApplied(Entity, ref info);
                    }

                    m_integrity -= info.Amount;

                    if (Entity.UseDamageSystem)
                    {
                        MyDamageSystem.Static.RaiseAfterDamageApplied(Entity, info);
                    }

                    if (m_integrity <= 0)
                    {
                        m_closeAfterSimulation = true;

                        if (Entity.UseDamageSystem)
                        {
                            MyDamageSystem.Static.RaiseDestroyed(Entity, info);
                        }

                        return;
                    }
                }
                return;
            }
コード例 #9
0
 /// Default implementation does nothing. If you want env. items to react to damage, subclass this
 public virtual void DoDamage(float damage, int instanceId, Vector3D position, Vector3 normal, MyDamageType type = MyDamageType.Unknown)
 {
 }
コード例 #10
0
ファイル: MyTrees.cs プロジェクト: rwohleb/SpaceEngineers
        public override void DoDamage(float damage, int itemInstanceId, Vector3D position, Vector3 normal, MyDamageType type)
        {
            // CH: TODO: Move the particle effect to definitions
            MyParticleEffect effect;

            if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.ChipOff_Wood, out effect))
            {
                effect.WorldMatrix = MatrixD.CreateWorld(position, Vector3.CalculatePerpendicularVector(normal), normal);
                effect.AutoDelete  = true;
            }

            if (!Sync.IsServer)
            {
                return;
            }

            MyCutTreeInfo cutTreeInfo = default(MyCutTreeInfo);
            int           index       = -1;

            for (int i = 0; i < m_cutTreeInfos.Count; ++i)
            {
                cutTreeInfo = m_cutTreeInfos[i];
                if (itemInstanceId == cutTreeInfo.ItemInstanceId)
                {
                    index = i;
                    break;
                }
            }

            if (index == -1)
            {
                cutTreeInfo = new MyCutTreeInfo();
                cutTreeInfo.ItemInstanceId = itemInstanceId;

                index = m_cutTreeInfos.Count;
                m_cutTreeInfos.Add(cutTreeInfo);
            }

            cutTreeInfo.LastHit   = MySandboxGame.TotalGamePlayTimeInMilliseconds;
            cutTreeInfo.Progress += damage;

            if (cutTreeInfo.Progress >= 1)
            {
                CutTree(itemInstanceId, position, normal, type == MyDamageType.Drill ? 1.0f : 4.0f);
                m_cutTreeInfos.RemoveAtFast(index);
            }
            else
            {
                m_cutTreeInfos[index] = cutTreeInfo;
            }

            return;
        }
コード例 #11
0
 void IMyDestroyableObject.DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo?hitInfo, long attackerId)
 {
     DoDamage(damage, damageType, sync, attackerId);
 }
コード例 #12
0
ファイル: MyCargoBox.cs プロジェクト: ripark/Miner-Wars-2081
        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;
            }
        }
コード例 #13
0
 void IMyDestroyableObject.DoDamage(float damage, MyDamageType damageType, bool sync)
 {
     DoDamage(damage, damageType, sync);
 }
コード例 #14
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);
                }
            }
        }
コード例 #15
0
 public void DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo?hitInfo)
 {
     GameLogic.DoDamage(damage, damageType, sync, hitInfo);
 }
コード例 #16
0
 public void DoDamage(float damage, MyDamageType damageType, bool sync)
 {
     GameLogic.DoDamage(damage, damageType, sync);
 }
コード例 #17
0
 public void DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo?hitInfo, long attackerId)
 {
     GameLogic.DoDamage(damage, damageType, sync, hitInfo, attackerId);
 }
コード例 #18
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);
        }
コード例 #19
0
        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);
            }
        }
コード例 #20
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;
            }
        }
コード例 #21
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);
        }
コード例 #22
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);
 }
コード例 #23
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);
 }
コード例 #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);
     }
 }
コード例 #25
0
        public override void DoDamage(float damage, int instanceId, Vector3D position, Vector3 normal, MyDamageType type)
        {
            if (!Sync.IsServer)
            {
                return;
            }

            RemoveItem(instanceId, sync: true);
        }
コード例 #26
0
 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);
     }
 }
コード例 #27
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();
     }
 }
コード例 #28
0
ファイル: MyEntity.cs プロジェクト: Bunni/Miner-Wars-2081
        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);

        }
コード例 #29
0
        public void DoDamage(float damage, MyDamageType damageType, bool sync)
        {
            if (MarkedForClose)
            {
                return;
            }

            if (sync)
            {
                if (!Sync.IsServer)
                {
                    return;
                }
                else
                {
                    MySyncHelper.DoDamageSynced(this, damage, damageType);
                    return;
                }
            }


            var typeId = Item.Content.TypeId;

            if (typeId == typeof(MyObjectBuilder_Ore) ||
                typeId == typeof(MyObjectBuilder_Ingot))
            {
                if (Item.Amount < 1)
                {
                    //TODO: SYNC particle
                    MyParticleEffect effect;
                    if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out effect))
                    {
                        effect.WorldMatrix = WorldMatrix;
                        effect.UserScale   = 0.4f;
                        MyFloatingObjects.RemoveFloatingObject(this);
                    }
                }
                else
                {
                    if (Sync.IsServer)
                    {
                        MyFloatingObjects.RemoveFloatingObject(this, (MyFixedPoint)damage);
                    }
                }
            }
            else
            {
                m_health -= (10 + 90 * DamageMultiplier) * damage;

                if (m_health < 0)
                {
                    //TODO: SYNC particle
                    MyParticleEffect effect;
                    if (MyParticlesManager.TryCreateParticleEffect((int)MyParticleEffectsIDEnum.Smoke_Construction, out effect))
                    {
                        effect.WorldMatrix = WorldMatrix;
                        effect.UserScale   = 0.4f;
                    }
                    if (Sync.IsServer)
                    {
                        MyFloatingObjects.RemoveFloatingObject(this);
                    }
                    //TODO: dont compare to string?
                    if (Item.Content.SubtypeId == m_explosives && Sync.IsServer)
                    {
                        var             expSphere = new BoundingSphere(WorldMatrix.Translation, (float)Item.Amount * 0.01f + 0.5f);// MathHelper.Clamp((float)Item.Amount, 0, 300) * 0.5f);
                        MyExplosionInfo info      = new MyExplosionInfo()
                        {
                            PlayerDamage                    = 0,
                            Damage                          = 800,
                            ExplosionType                   = MyExplosionTypeEnum.WARHEAD_EXPLOSION_15,
                            ExplosionSphere                 = expSphere,
                            LifespanMiliseconds             = MyExplosionsConstants.EXPLOSION_LIFESPAN,
                            CascadeLevel                    = 0,
                            HitEntity                       = this,
                            ParticleScale                   = 1,
                            OwnerEntity                     = this,
                            Direction                       = WorldMatrix.Forward,
                            VoxelExplosionCenter            = expSphere.Center,
                            ExplosionFlags                  = MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.CREATE_DEBRIS | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_SHRAPNELS | MyExplosionFlags.APPLY_DEFORMATION,
                            VoxelCutoutScale                = 0.5f,
                            PlaySound                       = true,
                            ApplyForceAndDamage             = true,
                            ObjectsRemoveDelayInMiliseconds = 40
                        };
                        MyExplosions.AddExplosion(ref info);
                    }

                    if (MyFakes.ENABLE_SCRAP && Sync.IsServer)
                    {
                        if (Item.Content.SubtypeId == ScrapBuilder.SubtypeId)
                        {
                            return;
                        }

                        var contentDefinitionId = Item.Content.GetId();
                        if (contentDefinitionId.TypeId == typeof(MyObjectBuilder_Component))
                        {
                            var definition = MyDefinitionManager.Static.GetComponentDefinition((Item.Content as MyObjectBuilder_Component).GetId());
                            if (MyRandom.Instance.NextFloat() < definition.DropProbability)
                            {
                                MyFloatingObjects.Spawn(new MyInventoryItem(Item.Amount * 0.8f, ScrapBuilder), PositionComp.GetPosition(), WorldMatrix.Forward, WorldMatrix.Up);
                            }
                        }
                    }
                }
            }

            return;
        }
コード例 #30
0
ファイル: MyEntity.cs プロジェクト: Bunni/Miner-Wars-2081
        ///<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);
            }
        }
コード例 #31
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);
        }
コード例 #32
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();
     }
 }
コード例 #33
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);
     }
 }
コード例 #34
0
ファイル: MySmallShip.cs プロジェクト: Bunni/Miner-Wars-2081
        /// <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();
        }