public override void UpdateBeforeSimulation() { base.UpdateBeforeSimulation(); //Sound control if (MySandboxGame.IsDedicated == false) { if (m_fallSoundShouldPlay.Value == true) { if (m_soundEmitter == null) { m_soundEmitter = new MyEntity3DSoundEmitter(this); NeedsUpdate |= MyEntityUpdateEnum.EACH_100TH_FRAME; } if (m_soundEmitter.IsPlaying == false && m_fallSound != null && m_fallSound != MySoundPair.Empty) { m_soundEmitter.PlaySound(m_fallSound, true, true); } } else { if (m_soundEmitter != null && m_soundEmitter.IsPlaying) { m_soundEmitter.StopSound(false); } } } //contact was made if (m_obstacleContact && m_groundContact == false) { if (Physics.LinearVelocity.Y > 0f || Physics.LinearVelocity.LengthSquared() < 9f) { m_groundContact = true; m_fallSoundShouldPlay.Value = false;//start crash sound m_soundStart = DateTime.UtcNow; } else { m_obstacleContact = false;//scratching } } }
internal void StartNoAmmoSound(MyEntity3DSoundEmitter soundEmitter) { if (NoAmmoSound != null) { soundEmitter.StopSound(true); soundEmitter.PlaySingleSound(NoAmmoSound, true); } }
internal void StartShootSound(MyEntity3DSoundEmitter soundEmitter) { if (ShootSound != null) { if (soundEmitter.IsPlaying && !soundEmitter.Loop) soundEmitter.StopSound(true); soundEmitter.PlaySound(ShootSound, true); } }
private void IKFeetStepSounds(MyEntity3DSoundEmitter walkEmitter, MySoundPair cueEnum) { var movementState = m_character.GetCurrentMovementState(); if (movementState.GetMode() == MyCharacterMovement.Flying) return; if (movementState.GetSpeed() != m_lastUpdateMovementState.GetSpeed()) { walkEmitter.StopSound(true); m_lastStepTime = 0; } int usedMinimumDelay = int.MaxValue; if (movementState.GetDirection() != MyCharacterMovement.NoDirection) { switch (movementState.GetSpeed()) { case MyCharacterMovement.NormalSpeed: usedMinimumDelay = m_stepMinimumDelayWalk; break; case MyCharacterMovement.Fast: usedMinimumDelay = m_stepMinimumDelayRun; break; case MyCharacterMovement.VeryFast: usedMinimumDelay = m_stepMinimumDelaySprint; break; } } bool minimumDelayExceeded = false; minimumDelayExceeded = (MySandboxGame.TotalGamePlayTimeInMilliseconds - m_lastStepTime) >= usedMinimumDelay; //MyRenderProxy.DebugDrawAABB(m_character.PositionComp.WorldAABB, Color.White); if (minimumDelayExceeded) { int leftAnkleBoneIndex, rightAnkleBoneIndex; MyCharacterBone leftAnkleBone = m_character.AnimationController != null ? m_character.AnimationController.FindBone(m_character.Definition.LeftAnkleBoneName, out leftAnkleBoneIndex) : null; MyCharacterBone rightAnkleBone = m_character.AnimationController != null ? m_character.AnimationController.FindBone(m_character.Definition.RightAnkleBoneName, out rightAnkleBoneIndex) : null; Vector3 posLeftFoot = leftAnkleBone != null ? leftAnkleBone.AbsoluteTransform.Translation : m_character.PositionComp.LocalAABB.Center; Vector3 posRightFoot = rightAnkleBone != null ? rightAnkleBone.AbsoluteTransform.Translation : m_character.PositionComp.LocalAABB.Center; float ankleHeight; MyFeetIKSettings settingsIK; if (m_character.Definition.FeetIKSettings != null && m_character.Definition.FeetIKSettings.TryGetValue(MyCharacterMovementEnum.Standing, out settingsIK)) { ankleHeight = settingsIK.FootSize.Y; } else { ankleHeight = DEFAULT_ANKLE_HEIGHT; } float charSpeed = 0f; if (m_character.AnimationController != null) m_character.AnimationController.Variables.GetValue(MyAnimationVariableStorageHints.StrIdSpeed, out charSpeed); if (posLeftFoot.Y - ankleHeight < m_character.PositionComp.LocalAABB.Min.Y || posRightFoot.Y - ankleHeight < m_character.PositionComp.LocalAABB.Min.Y) { if(charSpeed > 0.05f) walkEmitter.PlaySound(cueEnum); m_lastStepTime = MySandboxGame.TotalGamePlayTimeInMilliseconds; } } m_lastUpdateMovementState = movementState; }
private void StopLoopSound() { m_soundEmitter.StopSound(true); }
public override void UpdateAfterSimulation() { base.UpdateAfterSimulation(); bool isShooting = IsShooting; if (!m_isHit && IsShooting && (MySandboxGame.Static.UpdateTime - m_lastShot > MyTimeSpan.FromSeconds(m_shotToolAction.Value.HitStart))) { IMyHandToolComponent toolComponent; if (m_toolComponents.TryGetValue(m_shotHitCondition.Component, out toolComponent)) { MyCharacterDetectorComponent detectorComponent = m_owner.Components.Get <MyCharacterDetectorComponent>(); if (detectorComponent != null) { if (m_shotToolAction.Value.CustomShapeRadius > 0 && detectorComponent is MyCharacterShapecastDetectorComponent) { var shapeCastComponent = detectorComponent as MyCharacterShapecastDetectorComponent; shapeCastComponent.ShapeRadius = m_shotToolAction.Value.CustomShapeRadius; shapeCastComponent.DoDetectionModel(); shapeCastComponent.ShapeRadius = MyCharacterShapecastDetectorComponent.DEFAULT_SHAPE_RADIUS; } if (detectorComponent.DetectedEntity != null) { MyHitInfo hitInfo = new MyHitInfo(); hitInfo.Position = detectorComponent.HitPosition; hitInfo.Normal = detectorComponent.HitNormal; bool isBlock = false; float efficiencyMultiplier = 1.0f; bool canHit = CanHit(toolComponent, detectorComponent, ref isBlock, out efficiencyMultiplier); MyDecals.HandleAddDecal(detectorComponent.DetectedEntity, hitInfo, MyDamageType.Weapon); bool isHit = false; if (canHit) { if (!string.IsNullOrEmpty(m_shotToolAction.Value.StatsEfficiency) && Owner.StatComp != null) { efficiencyMultiplier *= Owner.StatComp.GetEfficiencyModifier(m_shotToolAction.Value.StatsEfficiency); } float efficiency = m_shotToolAction.Value.Efficiency * efficiencyMultiplier; var tool = detectorComponent.DetectedEntity as MyHandToolBase; if (isBlock && tool != null) { isHit = toolComponent.Hit(tool.Owner, hitInfo, detectorComponent.ShapeKey, efficiency); } else { isHit = toolComponent.Hit((MyEntity)detectorComponent.DetectedEntity, hitInfo, detectorComponent.ShapeKey, efficiency); } if (isHit && Sync.IsServer && Owner.StatComp != null) { if (!string.IsNullOrEmpty(m_shotHitCondition.StatsActionIfHit)) { Owner.StatComp.DoAction(m_shotHitCondition.StatsActionIfHit); } if (!string.IsNullOrEmpty(m_shotHitCondition.StatsModifierIfHit)) { Owner.StatComp.ApplyModifier(m_shotHitCondition.StatsModifierIfHit); } } } if (canHit || isBlock) // real hit is not controlled now - there isn't any server-client synchronization of hit currently and hit is performed only at server { if (!string.IsNullOrEmpty(m_shotToolAction.Value.HitSound)) { PlaySound(m_shotToolAction.Value.HitSound); } else { MyStringId collisionType = MyMaterialPropertiesHelper.CollisionType.Hit; bool showParticles = false; // If it didn't play the Sound with "Hit", it will try with "Start" if (MyAudioComponent.PlayContactSound(EntityId, m_hitCue, detectorComponent.HitPosition, m_toolItemDef.PhysicalMaterial, detectorComponent.HitMaterial)) { showParticles = true; } else if (MyAudioComponent.PlayContactSound(EntityId, m_startCue, detectorComponent.HitPosition, m_toolItemDef.PhysicalMaterial, detectorComponent.HitMaterial)) { showParticles = true; collisionType = MyMaterialPropertiesHelper.CollisionType.Start; } if (showParticles) { MyMaterialPropertiesHelper.Static.TryCreateCollisionEffect( collisionType, detectorComponent.HitPosition, detectorComponent.HitNormal, m_toolItemDef.PhysicalMaterial, detectorComponent.HitMaterial); } } this.RaiseEntityEvent(MyStringHash.GetOrCompute("Hit"), new MyEntityContainerEventExtensions.HitParams(MyStringHash.GetOrCompute(m_shotHitCondition.Component), detectorComponent.HitMaterial)); m_soundEmitter.StopSound(true); } } } } m_isHit = true; } if (!m_swingSoundPlayed && IsShooting && !m_isHit && (MySandboxGame.Static.UpdateTime - m_lastShot > MyTimeSpan.FromSeconds(m_shotToolAction.Value.SwingSoundStart))) { if (!string.IsNullOrEmpty(m_shotToolAction.Value.SwingSound)) { PlaySound(m_shotToolAction.Value.SwingSound); } m_swingSoundPlayed = true; } if (!isShooting && m_wasShooting) { m_owner.StopUpperCharacterAnimation(0.4f); m_shotToolAction = null; } m_wasShooting = isShooting; if (m_owner != null) { MatrixD blockingMatrix = MatrixD.CreateWorld(((MyEntity)m_owner.CurrentWeapon).PositionComp.GetPosition(), m_owner.WorldMatrix.Forward, m_owner.WorldMatrix.Up); ((MyBlockingBody)Physics).SetWorldMatrix(blockingMatrix); } foreach (var c in m_toolComponents.Values) { c.Update(); } }