void IMyDestroyableObject.DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo? hitInfo, long attackerId) { DoDamage(damage, damageType, sync, attackerId); }
void IMyDestroyableObject.DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo? hitInfo) { if (sync) { Debug.Assert(Sync.IsServer); if (Sync.IsServer) MySyncHelper.DoDamageSynced(this, damage, damageType, hitInfo); } else this.DoDamage(damage, damageType, hitInfo: hitInfo); return; }
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; }
void RigidBody_ContactPointCallback_Destruction(ref HkContactPointEvent value) { ProfilerShort.Begin("Grid Contact counter"); ProfilerShort.End(); MyGridContactInfo info = new MyGridContactInfo(ref value, m_grid); if (info.IsKnown) return; var myBody = info.CurrentEntity.Physics.RigidBody;//value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA : value.Base.BodyB; var myEntity = info.CurrentEntity;//value.Base.BodyA.GetEntity() == m_grid.Components ? value.Base.BodyA.GetEntity() : value.Base.BodyB.GetEntity(); // CH: DEBUG var entity1 = value.Base.BodyA.GetEntity(); var entity2 = value.Base.BodyB.GetEntity(); var rigidBody1 = value.Base.BodyA; var rigidBody2 = value.Base.BodyB; if (entity1 == null || entity2 == null || entity1.Physics == null || entity2.Physics == null) return; if (entity1 is MyFracturedPiece && entity2 is MyFracturedPiece) return; info.HandleEvents(); if (rigidBody1.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT) || rigidBody2.HasProperty(HkCharacterRigidBody.MANIPULATED_OBJECT)) return; if (info.CollidingEntity is Sandbox.Game.Entities.Character.MyCharacter || info.CollidingEntity == null || info.CollidingEntity.MarkedForClose) return; if (MyFakes.ENABLE_CHARACTER_VIRTUAL_PHYSICS) { MyCharacter character = MySession.ControlledEntity as MyCharacter; if (character != null && character.VirtualPhysics != null) { foreach (var constraint in character.VirtualPhysics.Constraints) { IMyEntity cstrEntityA = constraint.RigidBodyA.GetEntity(); IMyEntity cstrEntityB = constraint.RigidBodyB.GetEntity(); if (info.CurrentEntity == cstrEntityA || info.CurrentEntity == cstrEntityB || info.CollidingEntity == cstrEntityA || info.CollidingEntity == cstrEntityB) return; } } } var grid1 = entity1 as MyCubeGrid; var grid2 = entity2 as MyCubeGrid; if (grid1 != null && grid2 != null && (MyCubeGridGroups.Static.Physical.GetGroup(grid1) == MyCubeGridGroups.Static.Physical.GetGroup(grid2))) return; ProfilerShort.Begin("Grid contact point callback"); if (Sync.IsServer) { var vel = Math.Abs(value.SeparatingVelocity); bool enoughSpeed = vel > 3; //float dot = Vector3.Dot(Vector3.Normalize(LinearVelocity), Vector3.Normalize(info.CollidingEntity.Physics.LinearVelocity)); Vector3 velocity1 = rigidBody1.GetVelocityAtPoint(info.Event.ContactPoint.Position); Vector3 velocity2 = rigidBody2.GetVelocityAtPoint(info.Event.ContactPoint.Position); float speed1 = velocity1.Length(); float speed2 = velocity2.Length(); Vector3 dir1 = speed1 > 0 ? Vector3.Normalize(velocity1) : Vector3.Zero; Vector3 dir2 = speed2 > 0 ? Vector3.Normalize(velocity2) : Vector3.Zero; float mass1 = MyDestructionHelper.MassFromHavok(rigidBody1.Mass); float mass2 = MyDestructionHelper.MassFromHavok(rigidBody2.Mass); float impact1 = speed1 * mass1; float impact2 = speed2 * mass2; float dot1withNormal = speed1 > 0 ? Vector3.Dot(dir1, value.ContactPoint.Normal) : 0; float dot2withNormal = speed2 > 0 ? Vector3.Dot(dir2, value.ContactPoint.Normal) : 0; speed1 *= Math.Abs(dot1withNormal); speed2 *= Math.Abs(dot2withNormal); bool is1Static = mass1 == 0; bool is2Static = mass2 == 0; bool is1Small = entity1 is MyFracturedPiece || (grid1 != null && grid1.GridSizeEnum == MyCubeSize.Small); bool is2Small = entity2 is MyFracturedPiece || (grid2 != null && grid2.GridSizeEnum == MyCubeSize.Small); float dot = Vector3.Dot(dir1, dir2); float maxDestructionRadius = 0.5f; impact1 *= info.ImpulseMultiplier; impact2 *= info.ImpulseMultiplier; MyHitInfo hitInfo = new MyHitInfo(); var hitPos = info.ContactPosition; hitInfo.Normal = value.ContactPoint.Normal; //direct hit if (dot1withNormal < 0.0f) { if (entity1 is MyFracturedPiece) impact1 /= 10; impact1 *= Math.Abs(dot1withNormal); //respect angle of hit if (entity2 is MyFracturedPiece) { } if ((impact1 > 2000 && speed1 > 2 && !is2Small) || (impact1 > 500 && speed1 > 10)) //must be fast enought to destroy fracture piece (projectile) { //1 is big hitting if (is2Static || impact1 / impact2 > 10) { hitInfo.Position = hitPos + 0.1f * hitInfo.Normal; impact1 -= mass1; if (grid1 != null) { var blockPos = GetGridPosition(value, grid1, 0); grid1.DoDamage(impact1, hitInfo, blockPos); } else MyDestructionHelper.TriggerDestruction(impact1, (MyPhysicsBody)entity1.Physics, info.ContactPosition, value.ContactPoint.Normal, maxDestructionRadius); hitInfo.Position = hitPos - 0.1f * hitInfo.Normal; if (grid2 != null) { var blockPos = GetGridPosition(value, grid2, 1); grid2.DoDamage(impact1, hitInfo, blockPos); } else MyDestructionHelper.TriggerDestruction(impact1, (MyPhysicsBody)entity2.Physics, info.ContactPosition, value.ContactPoint.Normal, maxDestructionRadius); ReduceVelocities(info); } } } if (dot2withNormal < 0.0f) { if (entity2 is MyFracturedPiece) impact2 /= 10; impact2 *= Math.Abs(dot1withNormal); //respect angle of hit if (impact2 > 2000 && speed2 > 2 && !is1Small || (impact2 > 500 && speed2 > 10)) //must be fast enought to destroy fracture piece (projectile) { //2 is big hitting if (is1Static || impact2 / impact1 > 10) { hitInfo.Position = hitPos + 0.1f * hitInfo.Normal; impact2 -= mass2; if (grid1 != null) { var blockPos = GetGridPosition(value, grid1, 0); grid1.DoDamage(impact2, hitInfo, blockPos); } else MyDestructionHelper.TriggerDestruction(impact2, (MyPhysicsBody)entity1.Physics, info.ContactPosition, value.ContactPoint.Normal, maxDestructionRadius); hitInfo.Position = hitPos - 0.1f * hitInfo.Normal; if (grid2 != null) { var blockPos = GetGridPosition(value, grid2, 1); grid2.DoDamage(impact2, hitInfo, blockPos); } else MyDestructionHelper.TriggerDestruction(impact2, (MyPhysicsBody)entity2.Physics, info.ContactPosition, value.ContactPoint.Normal, maxDestructionRadius); ReduceVelocities(info); } } } //float destructionImpact = vel * (MyDestructionHelper.MassFromHavok(Mass) + MyDestructionHelper.MassFromHavok(info.CollidingEntity.Physics.Mass)); //destructionImpact *= info.ImpulseMultiplier; //if (destructionImpact > 2000 && enoughSpeed) //{ // CreateDestructionFor(destructionImpact, LinearVelocity + info.CollidingEntity.Physics.LinearVelocity, this, info, value.ContactPoint.Normal); // CreateDestructionFor(destructionImpact, LinearVelocity + info.CollidingEntity.Physics.LinearVelocity, info.CollidingEntity.Physics, info, value.ContactPoint.Normal); // ReduceVelocities(info); //} } ProfilerShort.End(); }
public bool DoDamage(float damage, MyStringHash damageType, bool sync, MyHitInfo? hitInfo, long attackerId) { if (Sync.IsServer) { MyDamageInformation info = new MyDamageInformation(false, damage, damageType, attackerId); if (UseDamageSystem) MyDamageSystem.Static.RaiseBeforeDamageApplied(this, ref info); m_hitPoints -= info.Amount; if (UseDamageSystem) MyDamageSystem.Static.RaiseAfterDamageApplied(this, info); if (m_hitPoints <= 0) { MyFracturedPiecesManager.Static.RemoveFracturePiece(this, 2); if (UseDamageSystem) MyDamageSystem.Static.RaiseDestroyed(this, info); } } return true; }
public void DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo? hitInfo) { GameLogic.DoDamage(damage, damageType, sync, hitInfo); }
internal void DoDamage(float damage, MyDamageType damageType, MyHitInfo? hitInfo, long attackerId) { 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, attackerId); } }
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; }
bool IMyDestroyableObject.DoDamage(float damage, MyStringHash damageType, bool sync, MyHitInfo? hitInfo, long attackerId) { return DoDamage(damage, damageType, sync, attackerId); }
void IMyDestroyableObject.DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo? hitInfo) { DoDamage(damage, damageType, sync); }
void IMyDestroyableObject.DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo? hitInfo) { if (MarkedToExplode || (!MySession.Static.DestructibleBlocks)) return; //if (!IsFunctional) // return false; if (sync) { if (Sync.IsServer) MySyncHelper.DoDamageSynced(this, damage, damageType); } else { m_damageType = damageType; if (damage > 0) OnDestroy(); } return; }
void IMyDestroyableObject.DoDamage(float damage, MyStringHash damageType, bool sync, MyHitInfo? hitInfo, long attackerId) { if (sync) { Debug.Assert(Sync.IsServer); if (Sync.IsServer) MySyncHelper.DoDamageSynced(this, damage, damageType, hitInfo, attackerId); } else this.DoDamage(damage, damageType, hitInfo: hitInfo, attackerId: attackerId); return; }
public void DoDamage(float damage, Common.ObjectBuilders.Definitions.MyDamageType damageType, bool sync, MyHitInfo? hitInfo) { if (Sync.IsServer) { m_hitPoints -= damage; if (m_hitPoints <= 0) { MyFracturedPiecesManager.Static.RemoveFracturePiece(this, 2); } } }
public void DoDamage(float damage, MyDamageType damageType, bool addDirtyParts = true, MyHitInfo? hitInfo = null, bool createDecal = true) { if (!CubeGrid.BlocksDestructionEnabled) return; if(FatBlock is MyCompoundCubeBlock) //jn: TODO think of something better { (FatBlock as MyCompoundCubeBlock).DoDamage(damage, damageType, hitInfo); return; } damage *= DamageRatio; // Low-integrity blocks get more damage if (MyPerGameSettings.Destruction) { damage *= DeformationRatio; } ProfilerShort.Begin("FatBlock.DoDamage"); try { if (FatBlock != null && CubeGrid.Physics != null && CubeGrid.Physics.Enabled) //Fatblock dont have physics { var destroyable = FatBlock as IMyDestroyableObject; if (destroyable != null) destroyable.DoDamage(damage, damageType, false); } } finally { ProfilerShort.End(); } MySession.Static.NegativeIntegrityTotal += damage; AccumulatedDamage += damage; if (m_componentStack.Integrity - AccumulatedDamage <= MyComponentStack.MOUNT_THRESHOLD) { if (MyPerGameSettings.Destruction && hitInfo.HasValue) { AccumulatedDamage = 0; var gridPhysics = CubeGrid.Physics; float maxDestructionRadius = CubeGrid.GridSizeEnum == MyCubeSize.Small ? 0.5f : 3; if(Sync.IsServer) Sandbox.Engine.Physics.MyDestructionHelper.TriggerDestruction(damage - m_componentStack.Integrity, gridPhysics, hitInfo.Value.Position, hitInfo.Value.Normal, maxDestructionRadius); } else { ApplyAccumulatedDamage(addDirtyParts); } CubeGrid.RemoveFromDamageApplication(this); } else { if (MyFakes.SHOW_DAMAGE_EFFECTS && FatBlock != null && BlockDefinition.RationEnoughForDamageEffect((Integrity - damage) / MaxIntegrity)) FatBlock.SetDamageEffect(true); if (hitInfo.HasValue && createDecal) CubeGrid.RenderData.AddDecal(Position, Vector3D.Transform(hitInfo.Value.Position, CubeGrid.PositionComp.WorldMatrixInvScaled), Vector3D.TransformNormal(hitInfo.Value.Normal, CubeGrid.PositionComp.WorldMatrixInvScaled), BlockDefinition.PhysicalMaterial.DamageDecal); } return; }
public void DoDamage(float damage, Common.ObjectBuilders.Definitions.MyDamageType damageType, bool sync, MyHitInfo? hitInfo, long attackerId) { if (Sync.IsServer) { MyDamageInformation info = new MyDamageInformation(false, damage, damageType, attackerId); if (UseDamageSystem) MyDamageSystem.Static.RaiseBeforeDamageApplied(this, ref info); m_hitPoints -= info.Amount; if (UseDamageSystem) MyDamageSystem.Static.RaiseAfterDamageApplied(this, info); if (m_hitPoints <= 0) { MyFracturedPiecesManager.Static.RemoveFracturePiece(this, 2); if (UseDamageSystem) MyDamageSystem.Static.RaiseDestroyed(this, info); } } }
public bool DoDamage(float damage, MyStringHash damageType, bool sync, MyHitInfo? hitInfo, long attackerId) { GameLogic.DoDamage(damage, damageType, sync, hitInfo, attackerId); return true; }
internal static void DoDamageSynced(MySlimBlock block, float damage, MyStringHash damageType, MyHitInfo? hitInfo, long attackerId) { Debug.Assert(Sync.IsServer); var msg = new DoDamageSlimBlockMsg(); msg.GridEntityId = block.CubeGrid.EntityId; msg.Position = block.Position; msg.Damage = damage; msg.HitInfo = hitInfo; msg.AttackerEntityId = attackerId; block.DoDamage(damage, damageType, hitInfo: hitInfo, attackerId: attackerId); Sync.Layer.SendMessageToAll<DoDamageSlimBlockMsg>(ref msg); }
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; }
public void DoDamage(float damage, MyDamageType damageType, bool sync, MyHitInfo? hitInfo, long attackerId) { GameLogic.DoDamage(damage, damageType, sync, hitInfo, attackerId); }