bool IMyDestroyableObject.DoDamage(float damage, MyStringHash damageType, bool sync, MyHitInfo?hitInfo, long attackerId) { if (MarkedToExplode || (!MySession.Static.DestructibleBlocks)) { return(false); } //if (!IsFunctional) // return false; if (sync) { if (Sync.IsServer) { MySyncDamage.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(true); }
public void DoDamage(float damage, MyStringHash damageType, bool sync, long attackerId) { if (sync) { if (Sync.IsServer) { MySyncDamage.DoDamageSynced(this, damage, damageType, attackerId); } } else { if (UseDamageSystem) { MyDamageSystem.Static.RaiseDestroyed(this, new MyDamageInformation(false, damage, damageType, attackerId)); } Explode(); } }
public void DoDamage(float damage, MyStringHash damageType, bool sync, MyHitInfo?hitInfo, long attackerId) { if (sync) { if (Sync.IsServer) { MySyncDamage.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 && Sync.IsServer) { m_closeAfterSimulation = Sync.IsServer; if (Entity.UseDamageSystem) { MyDamageSystem.Static.RaiseDestroyed(Entity, info); } return; } } return; }
public bool DoDamage(float damage, MyStringHash damageType, bool sync, long attackerId) { if (MarkedForClose) { return(false); } if (sync) { if (Sync.IsServer) { MySyncDamage.DoDamageSynced(this, damage, damageType, attackerId); return(true); } else { return(false); } } MyDamageInformation damageinfo = new MyDamageInformation(false, damage, damageType, attackerId); if (UseDamageSystem) { MyDamageSystem.Static.RaiseBeforeDamageApplied(this, ref damageinfo); } 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; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } } else { if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this, (MyFixedPoint)damageinfo.Amount); } } } else { m_health -= 10 * damageinfo.Amount; if (UseDamageSystem) { MyDamageSystem.Static.RaiseAfterDamageApplied(this, damageinfo); } 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(true); } 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 MyPhysicalInventoryItem(Item.Amount * 0.8f, ScrapBuilder), PositionComp.GetPosition(), WorldMatrix.Forward, WorldMatrix.Up); } } } if (ItemDefinition != null && ItemDefinition.DestroyedPieceId.HasValue && Sync.IsServer) { MyPhysicalItemDefinition pieceDefinition; if (MyDefinitionManager.Static.TryGetPhysicalItemDefinition(ItemDefinition.DestroyedPieceId.Value, out pieceDefinition)) { MyFloatingObjects.Spawn(pieceDefinition, WorldMatrix.Translation, WorldMatrix.Forward, WorldMatrix.Up, ItemDefinition.DestroyedPieces); } else { System.Diagnostics.Debug.Fail("Trying to spawn piece of the item after being destroyed, but definition wasn't found! - " + ItemDefinition.DestroyedPieceId.Value); } } if (UseDamageSystem) { MyDamageSystem.Static.RaiseDestroyed(this, damageinfo); } } } return(true); }
public bool DoDamage(float damage, MyStringHash damageType, bool sync, long attackerId) { if (base.MarkedForClose) { return(false); } if (sync) { if (!Sync.IsServer) { return(false); } MySyncDamage.DoDamageSynced(this, damage, damageType, attackerId); return(true); } MyDamageInformation information = new MyDamageInformation(false, damage, damageType, attackerId); if (this.UseDamageSystem) { MyDamageSystem.Static.RaiseBeforeDamageApplied(this, ref information); } MyObjectBuilderType typeId = this.Item.Content.TypeId; if ((typeId == typeof(MyObjectBuilder_Ore)) || (typeId == typeof(MyObjectBuilder_Ingot))) { if (this.Item.Amount >= 1) { if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this, (MyFixedPoint)information.Amount); } } else { MyParticleEffect effect; if (MyParticlesManager.TryCreateParticleEffect("Smoke_Construction", base.WorldMatrix, out effect)) { effect.UserScale = 0.4f; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } } } else { this.m_health -= 10f * information.Amount; if (this.UseDamageSystem) { MyDamageSystem.Static.RaiseAfterDamageApplied(this, information); } if (this.m_health < 0f) { MyParticleEffect effect2; MyPhysicalItemDefinition definition2; if (MyParticlesManager.TryCreateParticleEffect("Smoke_Construction", base.WorldMatrix, out effect2)) { effect2.UserScale = 0.4f; } if (Sync.IsServer) { MyFloatingObjects.RemoveFloatingObject(this); } if ((this.Item.Content.SubtypeId == m_explosives) && Sync.IsServer) { BoundingSphere sphere = new BoundingSphere((Vector3)base.WorldMatrix.Translation, (((float)this.Item.Amount) * 0.01f) + 0.5f); MyExplosionInfo explosionInfo = new MyExplosionInfo { PlayerDamage = 0f, Damage = 800f, ExplosionType = MyExplosionTypeEnum.WARHEAD_EXPLOSION_15, ExplosionSphere = sphere, LifespanMiliseconds = 700, HitEntity = this, ParticleScale = 1f, OwnerEntity = this, Direction = new Vector3?((Vector3)base.WorldMatrix.Forward), VoxelExplosionCenter = sphere.Center, ExplosionFlags = MyExplosionFlags.APPLY_DEFORMATION | MyExplosionFlags.CREATE_SHRAPNELS | MyExplosionFlags.CREATE_PARTICLE_EFFECT | MyExplosionFlags.CREATE_DECALS | MyExplosionFlags.APPLY_FORCE_AND_DAMAGE | MyExplosionFlags.AFFECT_VOXELS | MyExplosionFlags.CREATE_DEBRIS, VoxelCutoutScale = 0.5f, PlaySound = true, ApplyForceAndDamage = true, ObjectsRemoveDelayInMiliseconds = 40 }; if (this.Physics != null) { explosionInfo.Velocity = this.Physics.LinearVelocity; } MyExplosions.AddExplosion(ref explosionInfo, true); } if (MyFakes.ENABLE_SCRAP && Sync.IsServer) { if (this.Item.Content.SubtypeId == ScrapBuilder.SubtypeId) { return(true); } if (this.Item.Content.GetId().TypeId == typeof(MyObjectBuilder_Component)) { MyComponentDefinition componentDefinition = MyDefinitionManager.Static.GetComponentDefinition((this.Item.Content as MyObjectBuilder_Component).GetId()); if (MyRandom.Instance.NextFloat() < componentDefinition.DropProbability) { MyFloatingObjects.Spawn(new MyPhysicalInventoryItem(this.Item.Amount * 0.8f, ScrapBuilder, 1f), base.PositionComp.GetPosition(), base.WorldMatrix.Forward, base.WorldMatrix.Up, null, null); } } } if (((this.ItemDefinition != null) && ((this.ItemDefinition.DestroyedPieceId != null) && Sync.IsServer)) && MyDefinitionManager.Static.TryGetPhysicalItemDefinition(this.ItemDefinition.DestroyedPieceId.Value, out definition2)) { MyFloatingObjects.Spawn(definition2, base.WorldMatrix.Translation, base.WorldMatrix.Forward, base.WorldMatrix.Up, this.ItemDefinition.DestroyedPieces, 1f); } if (this.UseDamageSystem) { MyDamageSystem.Static.RaiseDestroyed(this, information); } } } return(true); }