예제 #1
0
        public override void OnDestroy()
        {
            MySoundPair cueEnum = BlockDefinition.ActionSound;

            if (cueEnum != MySoundPair.Empty)
            {
                MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter();
                if (emitter != null)
                {
                    emitter.Entity = this;
                    emitter.SetPosition(PositionComp.GetPosition());
                    emitter.PlaySound(cueEnum);
                }
            }
            if (Sandbox.Game.Multiplayer.Sync.IsServer)
            {
                if (!IsFunctional)
                {
                    return;
                }
                if (m_damageType == MyDamageType.Bullet)
                {
                    Explode();
                }
                else
                {
                    MarkForExplosion();
                    ExplodeDelayed(500);
                }
            }
        }
        public override void OnDestroy()
        {
            if (MyFakes.SHOW_DAMAGE_EFFECTS)
            {
                //particle effect
                if (BlockDefinition.DestroyEffect.Length > 0)
                {
                    if (BlockDefinition.RatioEnoughForDamageEffect(SlimBlock.BuildIntegrity / SlimBlock.MaxIntegrity))//grinded down
                    {
                        return;
                    }
                    MyParticleEffect effect;
                    if (MyParticlesManager.TryCreateParticleEffect(BlockDefinition.DestroyEffect, out effect))
                    {
                        effect.Loop        = false;
                        effect.WorldMatrix = WorldMatrix;
                    }
                }

                //sound effect
                if (!BlockDefinition.DestroySound.Equals(MySoundPair.Empty))
                {
                    MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter();
                    if (emitter != null)
                    {
                        emitter.Entity = this;
                        emitter.PlaySound(BlockDefinition.DestroySound);
                    }
                }
            }
            base.OnDestroy();
        }
        public void Throw(MyObjectBuilder_CubeGrid grid, Vector3D position, Vector3D linearVelocity, float mass, MyCueId throwSound)
        {
            if (!Sync.IsServer)
            {
                return;
            }

            var entity = MyEntities.CreateFromObjectBuilder(grid);

            if (entity == null)
            {
                return;
            }

            entity.PositionComp.SetPosition(position);
            entity.Physics.LinearVelocity = linearVelocity;

            if (mass > 0)
            {
                entity.Physics.RigidBody.Mass = mass;
            }

            MyEntities.Add(entity);

            if (!throwSound.IsNull)
            {
                var emitter = MyAudioComponent.TryGetSoundEmitter();
                if (emitter != null)
                {
                    emitter.SetPosition(position);
                    emitter.PlaySoundWithDistance(throwSound);
                }
            }
        }
예제 #4
0
 public void Throw(MyObjectBuilder_CubeGrid grid, Vector3D position, Vector3D linearVelocity, float mass, MyCueId throwSound)
 {
     if (Sync.IsServer)
     {
         MyEntity entity = MyEntities.CreateFromObjectBuilder(grid, false);
         if (entity != null)
         {
             entity.PositionComp.SetPosition(position, null, false, true);
             entity.Physics.LinearVelocity = (Vector3)linearVelocity;
             if (mass > 0f)
             {
                 entity.Physics.RigidBody.Mass = mass;
             }
             MyEntities.Add(entity, true);
             if (!throwSound.IsNull)
             {
                 MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter();
                 if (emitter != null)
                 {
                     emitter.SetPosition(new Vector3D?(position));
                     bool?nullable = null;
                     emitter.PlaySoundWithDistance(throwSound, false, false, false, true, false, false, nullable);
                 }
             }
         }
     }
 }
예제 #5
0
        private static void PlaySound(Vector3D position, string cueName)
        {
            var emitter = MyAudioComponent.TryGetSoundEmitter();

            if (emitter == null)
            {
                return;
            }

            emitter.SetPosition(position);
            emitter.PlaySound(MySoundPair.GetCueId(cueName));
        }
예제 #6
0
        private void PlayHitSound(MyStringHash materialType, IMyEntity entity, Vector3D position)
        {
            if ((OwnerEntity == null) || !(OwnerEntity is MyWarhead)) // do not play bullet sound when coming from warheads
            {
                var emitter = MyAudioComponent.TryGetSoundEmitter();
                if (emitter == null)
                {
                    return;
                }

                ProfilerShort.Begin("Play projectile sound");
                emitter.SetPosition(m_position);
                emitter.SetVelocity(Vector3.Zero);
                MyAutomaticRifleGun rifleGun = m_weapon as MyAutomaticRifleGun;

                MySoundPair  cueEnum = null;
                MyStringHash thisType;
                if (m_projectileAmmoDefinition.IsExplosive)
                {
                    thisType = MyMaterialType.EXPBULLET;
                }
                else if (rifleGun != null && rifleGun.GunBase.IsAmmoProjectile && m_projectileAmmoDefinition.ProjectileType == MyProjectileType.Bullet)
                {
                    thisType = MyMaterialType.RIFLEBULLET;
                }
                else if (m_projectileAmmoDefinition.ProjectileType == MyProjectileType.Bolt)
                {
                    thisType = MyMaterialType.BOLT;
                }
                else
                {
                    thisType = MyMaterialType.GUNBULLET;
                }

                cueEnum = MyMaterialPropertiesHelper.Static.GetCollisionCue(MyMaterialPropertiesHelper.CollisionType.Start, thisType, materialType);
                if (cueEnum.SoundId.IsNull && entity is MyVoxelBase)    // Play rock sounds if we have a voxel material that doesn't have an assigned sound for thisType
                {
                    materialType = MyMaterialType.ROCK;
                    cueEnum      = MyMaterialPropertiesHelper.Static.GetCollisionCue(MyMaterialPropertiesHelper.CollisionType.Start, thisType, materialType);
                }

                if (MySession.Static != null && MySession.Static.Settings.RealisticSound)
                {
                    Func <bool> canHear = () => MySession.ControlledEntity != null && MySession.ControlledEntity.Entity == entity;
                    emitter.StoppedPlaying += (e) => { e.EmitterMethods[MyEntity3DSoundEmitter.MethodsEnum.CanHear].Remove(canHear); };
                    emitter.EmitterMethods[MyEntity3DSoundEmitter.MethodsEnum.CanHear].Add(canHear);
                }

                emitter.PlaySound(cueEnum, false);

                ProfilerShort.End();
            }
        }
예제 #7
0
        protected override void OnRemoveItem(int instanceId, ref Matrix matrix, MyStringHash myStringId)
        {
            base.OnRemoveItem(instanceId, ref matrix, myStringId);

            var emitter = MyAudioComponent.TryGetSoundEmitter();

            if (emitter == null)
            {
                return;
            }

            emitter.SetPosition(matrix.Translation);
            emitter.PlaySound(m_soundTreeBreak);
        }
예제 #8
0
        private static void PlaySound(Vector3D position, string cueName)
        {
            MySoundPair objA = new MySoundPair(cueName, true);

            if (!ReferenceEquals(objA, MySoundPair.Empty))
            {
                MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter();
                if (emitter != null)
                {
                    emitter.SetPosition(new Vector3D?(position));
                    bool?nullable = null;
                    emitter.PlaySound(objA, false, false, false, false, false, nullable);
                }
            }
        }
예제 #9
0
        private void PlayHitSound(MyStringHash materialType, IMyEntity entity, Vector3D position, MyStringHash thisType)
        {
            if ((OwnerEntity == null) || !(OwnerEntity is MyWarhead)) // do not play bullet sound when coming from warheads
            {
                ProfilerShort.Begin("Play projectile sound");
                MyAutomaticRifleGun rifleGun = m_weapon as MyAutomaticRifleGun;

                MySoundPair cueEnum = null;

                cueEnum = MyMaterialPropertiesHelper.Static.GetCollisionCue(MyMaterialPropertiesHelper.CollisionType.Hit, thisType, materialType);
                if (cueEnum == null || cueEnum == MySoundPair.Empty)
                {
                    cueEnum = MyMaterialPropertiesHelper.Static.GetCollisionCue(MyMaterialPropertiesHelper.CollisionType.Start, thisType, materialType);
                }
                if (cueEnum.SoundId.IsNull && entity is MyVoxelBase)    // Play rock sounds if we have a voxel material that doesn't have an assigned sound for thisType
                {
                    materialType = MyMaterialType.ROCK;
                    cueEnum      = MyMaterialPropertiesHelper.Static.GetCollisionCue(MyMaterialPropertiesHelper.CollisionType.Start, thisType, materialType);
                }
                if (cueEnum == null || cueEnum == MySoundPair.Empty)
                {
                    ProfilerShort.End();
                    return;
                }

                var emitter = MyAudioComponent.TryGetSoundEmitter();
                if (emitter == null)
                {
                    ProfilerShort.End();
                    return;
                }
                emitter.Entity = (MyEntity)entity;
                emitter.SetPosition(m_position);
                emitter.SetVelocity(Vector3.Zero);

                if (MySession.Static != null && MyFakes.ENABLE_NEW_SOUNDS && MySession.Static.Settings.RealisticSound)
                {
                    Func <bool> canHear = () => MySession.Static.ControlledEntity != null && MySession.Static.ControlledEntity.Entity == entity;
                    emitter.StoppedPlaying += (e) => { e.EmitterMethods[MyEntity3DSoundEmitter.MethodsEnum.CanHear].Remove(canHear); };
                    emitter.EmitterMethods[MyEntity3DSoundEmitter.MethodsEnum.CanHear].Add(canHear);
                }

                emitter.PlaySound(cueEnum, false);

                ProfilerShort.End();
            }
        }
        public void PlayFallSound()
        {
            var walkSurfaceMaterial = RayCastGround();

            if (walkSurfaceMaterial != MyStringHash.NullOrEmpty && MyMaterialPropertiesHelper.Static != null)
            {
                var cue = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Fall, MyMaterialType.CHARACTER, walkSurfaceMaterial);
                if (cue.SoundId.IsNull == false)
                {
                    var emitter = MyAudioComponent.TryGetSoundEmitter(); //we need to use other emmiter otherwise the sound would be cut by silence next frame
                    if (emitter != null)
                    {
                        emitter.Entity = m_character;
                        emitter.PlaySingleSound(cue);
                    }
                }
            }
        }
예제 #11
0
        private static void PlaySound(Vector3D position, string cueName)
        {
            MySoundPair sound = new MySoundPair(cueName);

            if (sound == MySoundPair.Empty)
            {
                return;
            }
            var emitter = MyAudioComponent.TryGetSoundEmitter();

            if (emitter == null)
            {
                return;
            }

            emitter.SetPosition(position);
            emitter.PlaySound(sound);
        }
예제 #12
0
        public void OnUse(long hookIdTarget)
        {
            bool     flag   = false;
            MyEntity entity = null;

            if (MyEntities.TryGetEntityById(hookIdTarget, out entity, false))
            {
                if (hookIdTarget != this.m_hookIdFrom)
                {
                    if (this.m_hookIdFrom == 0)
                    {
                        this.m_hookIdFrom = hookIdTarget;
                        entity.OnClosing += this.m_selectedHook_OnClosing;
                        flag = true;
                    }
                    else if (MyRopeComponent.HasRope(this.m_hookIdFrom))
                    {
                        this.m_hookIdFrom = hookIdTarget;
                        flag = true;
                    }
                    else
                    {
                        if (MyRopeComponent.CanConnectHooks(this.m_hookIdFrom, hookIdTarget, this.m_ropeDefinition))
                        {
                            MyRopeComponent.AddRopeRequest(this.m_hookIdFrom, hookIdTarget, this.m_ropeDefinition.Id);
                            flag = true;
                        }
                        this.Clear();
                    }
                }
                MySoundPair soundId = flag ? this.m_ropeDefinition.AttachSound : null;
                if (soundId != null)
                {
                    MyEntity3DSoundEmitter emitter = MyAudioComponent.TryGetSoundEmitter();
                    if (emitter != null)
                    {
                        emitter.SetPosition(new Vector3D?(entity.PositionComp.GetPosition()));
                        bool?nullable = null;
                        emitter.PlaySound(soundId, false, false, false, false, false, nullable);
                    }
                }
            }
        }
예제 #13
0
        private MySoundPair SelectSound()
        {
            MySoundPair           soundPair        = EmptySoundPair;
            MyCharacterDefinition myCharDefinition = m_character.Definition;
            MyStringHash          physMaterial     = MyStringHash.GetOrCompute(myCharDefinition.PhysicalMaterial);

            m_isWalking = false;

            bool updateEmitterSounds = false;
            MyCharacterMovementEnum movementState = m_character.GetCurrentMovementState();

            switch (movementState)
            {
            case MyCharacterMovementEnum.Walking:
            case MyCharacterMovementEnum.BackWalking:
            case MyCharacterMovementEnum.WalkingLeftFront:
            case MyCharacterMovementEnum.WalkingRightFront:
            case MyCharacterMovementEnum.WalkingLeftBack:
            case MyCharacterMovementEnum.WalkingRightBack:
            case MyCharacterMovementEnum.WalkStrafingLeft:
            case MyCharacterMovementEnum.WalkStrafingRight:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                soundPair   = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Walk, physMaterial, RayCastGround());
                m_isWalking = true;
            }
            break;

            case MyCharacterMovementEnum.Running:
            case MyCharacterMovementEnum.Backrunning:
            case MyCharacterMovementEnum.RunStrafingLeft:
            case MyCharacterMovementEnum.RunStrafingRight:
            case MyCharacterMovementEnum.RunningRightFront:
            case MyCharacterMovementEnum.RunningRightBack:
            case MyCharacterMovementEnum.RunningLeftFront:
            case MyCharacterMovementEnum.RunningLeftBack:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Heated;
                }
                soundPair   = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Run, physMaterial, RayCastGround());
                m_isWalking = true;
            }
            break;

            case MyCharacterMovementEnum.CrouchWalking:
            case MyCharacterMovementEnum.CrouchBackWalking:
            case MyCharacterMovementEnum.CrouchWalkingLeftFront:
            case MyCharacterMovementEnum.CrouchWalkingRightFront:
            case MyCharacterMovementEnum.CrouchWalkingLeftBack:
            case MyCharacterMovementEnum.CrouchWalkingRightBack:
            case MyCharacterMovementEnum.CrouchStrafingLeft:
            case MyCharacterMovementEnum.CrouchStrafingRight:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                soundPair   = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.CrouchWalk, physMaterial, RayCastGround());
                m_isWalking = true;
            }
            break;

            case MyCharacterMovementEnum.Crouching:
            case MyCharacterMovementEnum.Standing:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                var previousMovementState = m_character.GetPreviousMovementState();
                var currentMovementState  = m_character.GetCurrentMovementState();
                if (previousMovementState != currentMovementState &&
                    (previousMovementState == MyCharacterMovementEnum.Standing || previousMovementState == MyCharacterMovementEnum.Crouching))
                {
                    soundPair = (currentMovementState == MyCharacterMovementEnum.Standing) ? CharacterSounds[(int)CharacterSoundsEnum.CROUCH_UP_SOUND] : CharacterSounds[(int)CharacterSoundsEnum.CROUCH_DOWN_SOUND];
                }
            }
            break;

            case MyCharacterMovementEnum.Sprinting:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.VeryHeated;
                }
                soundPair   = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Sprint, physMaterial, RayCastGround());
                m_isWalking = true;
            }
            break;

            case MyCharacterMovementEnum.Jump:
            {
                if (!m_jumpReady)
                {
                    break;
                }
                m_jumpReady = false;
                m_character.SetPreviousMovementState(m_character.GetCurrentMovementState());
                var emitter = MyAudioComponent.TryGetSoundEmitter();                                 // We need to use another emitter otherwise the sound would be cut by silence next frame
                if (emitter != null)
                {
                    emitter.Entity = m_character;
                    emitter.PlaySingleSound(CharacterSounds[(int)CharacterSoundsEnum.JUMP_SOUND]);
                }

                if ((m_standingOnGrid != null || m_standingOnVoxel != null) && ShouldUpdateSoundEmitters)
                {
                    updateEmitterSounds = true;
                }
                m_standingOnGrid  = null;
                m_standingOnVoxel = null;
            }
            break;

            case MyCharacterMovementEnum.Flying:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                if (m_character.JetpackComp != null && m_jetpackMinIdleTime <= 0f && m_character.JetpackComp.FinalThrust.LengthSquared() >= 50000f)
                {
                    soundPair             = CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND];
                    m_jetpackSustainTimer = Math.Min(JETPACK_TIME_BETWEEN_SOUNDS, m_jetpackSustainTimer + MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
                }
                else
                {
                    soundPair             = CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND];
                    m_jetpackSustainTimer = Math.Max(0f, m_jetpackSustainTimer - MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS);
                }
                m_jetpackMinIdleTime -= MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS;

                if ((m_standingOnGrid != null || m_standingOnVoxel != null) && ShouldUpdateSoundEmitters)
                {
                    updateEmitterSounds = true;
                }
                m_standingOnGrid  = null;
                m_standingOnVoxel = null;
            }
            break;

            case MyCharacterMovementEnum.Falling:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }

                if ((m_standingOnGrid != null || m_standingOnVoxel != null) && ShouldUpdateSoundEmitters)
                {
                    updateEmitterSounds = true;
                }
                m_standingOnGrid  = null;
                m_standingOnVoxel = null;
            }
            break;

            default:
            {
            }
            break;
            }

            //MyRenderProxy.DebugDrawText2D(Vector2.Zero, movementState.ToString(), Color.Red, 1.0f);

            if (movementState != MyCharacterMovementEnum.Flying)
            {
                m_jetpackSustainTimer = 0f;
                m_jetpackMinIdleTime  = 0.5f;
            }
            if (updateEmitterSounds)
            {
                MyEntity3DSoundEmitter.UpdateEntityEmitters(true, true, false);
            }
            return(soundPair);
        }
        private MySoundPair SelectSound()
        {
            MySoundPair soundPair = EmptySoundPair;

            Definitions.MyCharacterDefinition myCharDefinition = (Definitions.MyCharacterDefinition)m_character.Definition;
            MyStringHash physMaterial = MyStringHash.GetOrCompute(myCharDefinition.PhysicalMaterial);

            switch (m_character.GetCurrentMovementState())
            {
            case MyCharacterMovementEnum.Walking:
            case MyCharacterMovementEnum.BackWalking:
            case MyCharacterMovementEnum.WalkingLeftFront:
            case MyCharacterMovementEnum.WalkingRightFront:
            case MyCharacterMovementEnum.WalkingLeftBack:
            case MyCharacterMovementEnum.WalkingRightBack:
            case MyCharacterMovementEnum.WalkStrafingLeft:
            case MyCharacterMovementEnum.WalkStrafingRight:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                soundPair = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Walk, physMaterial, RayCastGround());
            }
            break;

            case MyCharacterMovementEnum.Running:
            case MyCharacterMovementEnum.Backrunning:
            case MyCharacterMovementEnum.RunStrafingLeft:
            case MyCharacterMovementEnum.RunStrafingRight:
            case MyCharacterMovementEnum.RunningRightFront:
            case MyCharacterMovementEnum.RunningRightBack:
            case MyCharacterMovementEnum.RunningLeftFront:
            case MyCharacterMovementEnum.RunningLeftBack:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Heated;
                }
                soundPair = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Run, physMaterial, RayCastGround());
            }
            break;

            case MyCharacterMovementEnum.CrouchWalking:
            case MyCharacterMovementEnum.CrouchBackWalking:
            case MyCharacterMovementEnum.CrouchWalkingLeftFront:
            case MyCharacterMovementEnum.CrouchWalkingRightFront:
            case MyCharacterMovementEnum.CrouchWalkingLeftBack:
            case MyCharacterMovementEnum.CrouchWalkingRightBack:
            case MyCharacterMovementEnum.CrouchStrafingLeft:
            case MyCharacterMovementEnum.CrouchStrafingRight:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                soundPair = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.CrouchWalk, physMaterial, RayCastGround());
            }
            break;

            case MyCharacterMovementEnum.Crouching:
            case MyCharacterMovementEnum.Standing:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                var previousMovementState = m_character.GetPreviousMovementState();
                var currentMovementState  = m_character.GetCurrentMovementState();
                if (previousMovementState != currentMovementState &&
                    (previousMovementState == MyCharacterMovementEnum.Standing || previousMovementState == MyCharacterMovementEnum.Crouching))
                {
                    soundPair = (currentMovementState == MyCharacterMovementEnum.Standing) ? CharacterSounds[(int)CharacterSoundsEnum.CROUCH_UP_SOUND] : CharacterSounds[(int)CharacterSoundsEnum.CROUCH_DOWN_SOUND];
                }
            }
            break;

            case MyCharacterMovementEnum.Sprinting:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Heated;
                }
                soundPair = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Sprint, physMaterial, RayCastGround());
            }
            break;

            case MyCharacterMovementEnum.Jump:
            {
                if (m_character.GetPreviousMovementState() == MyCharacterMovementEnum.Jump)
                {
                    break;
                }
                m_character.SetPreviousMovementState(m_character.GetCurrentMovementState());
                var emitter = MyAudioComponent.TryGetSoundEmitter();                                 // We need to use another emitter otherwise the sound would be cut by silence next frame
                if (emitter != null)
                {
                    emitter.Entity = m_character;
                    emitter.PlaySingleSound(CharacterSounds[(int)CharacterSoundsEnum.JUMP_SOUND]);
                }
                m_standingOnGrid = null;
            }
            break;

            case MyCharacterMovementEnum.Flying:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                if (m_character.Physics.LinearAcceleration.Length() < 1)
                {
                    soundPair = CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND];
                }
                else
                {
                    soundPair = CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND];
                }

                m_standingOnGrid = null;
            }
            break;

            case MyCharacterMovementEnum.Falling:
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                }
                m_standingOnGrid = null;
            }
            break;

            default:
            {
            }
            break;
            }

            // turn off breathing when helmet is off and there is no oxygen https://app.asana.com/0/64822442925263/33431071589757
            if (m_character.OxygenComponent != null && !m_character.OxygenComponent.EnabledHelmet &&
                m_character.OxygenComponent.EnvironmentOxygenLevel < MyCharacterOxygenComponent.LOW_OXYGEN_RATIO)
            {
                if (m_character.Breath != null)
                {
                    m_character.Breath.CurrentState = MyCharacterBreath.State.NoBreath;
                }
            }

            return(soundPair);
        }
예제 #15
0
        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();
            }
        }
        private MySoundPair SelectSound()
        {
            MySoundPair soundPair = CharacterSounds[(int)CharacterSoundsEnum.NONE_SOUND];

            switch (m_character.GetCurrentMovementState())
            {
            case MyCharacterMovementEnum.Walking:
            case MyCharacterMovementEnum.BackWalking:
            case MyCharacterMovementEnum.WalkingLeftFront:
            case MyCharacterMovementEnum.WalkingRightFront:
            case MyCharacterMovementEnum.WalkingLeftBack:
            case MyCharacterMovementEnum.WalkingRightBack:
            case MyCharacterMovementEnum.WalkStrafingLeft:
            case MyCharacterMovementEnum.WalkStrafingRight:
            {
                m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                soundPair = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Walk, MyMaterialType.CHARACTER, RayCastGround());
            }
            break;

            case MyCharacterMovementEnum.Running:
            case MyCharacterMovementEnum.Backrunning:
            case MyCharacterMovementEnum.RunStrafingLeft:
            case MyCharacterMovementEnum.RunStrafingRight:
            case MyCharacterMovementEnum.RunningRightFront:
            case MyCharacterMovementEnum.RunningRightBack:
            case MyCharacterMovementEnum.RunningLeftFront:
            case MyCharacterMovementEnum.RunningLeftBack:
            {
                m_character.Breath.CurrentState = MyCharacterBreath.State.Heated;
                soundPair = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Run, MyMaterialType.CHARACTER, RayCastGround());
            }
            break;

            case MyCharacterMovementEnum.CrouchWalking:
            case MyCharacterMovementEnum.CrouchBackWalking:
            case MyCharacterMovementEnum.CrouchWalkingLeftFront:
            case MyCharacterMovementEnum.CrouchWalkingRightFront:
            case MyCharacterMovementEnum.CrouchWalkingLeftBack:
            case MyCharacterMovementEnum.CrouchWalkingRightBack:
            case MyCharacterMovementEnum.CrouchStrafingLeft:
            case MyCharacterMovementEnum.CrouchStrafingRight:
            {
                m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                soundPair = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.CrouchWalk, MyMaterialType.CHARACTER, RayCastGround());
            }
            break;

            case MyCharacterMovementEnum.Crouching:
            case MyCharacterMovementEnum.Standing:
            {
                m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                var previousMovementState = m_character.GetPreviousMovementState();
                var currentMovementState  = m_character.GetCurrentMovementState();
                if (previousMovementState != currentMovementState &&
                    (previousMovementState == MyCharacterMovementEnum.Standing || previousMovementState == MyCharacterMovementEnum.Crouching))
                {
                    soundPair = (currentMovementState == MyCharacterMovementEnum.Standing) ? CharacterSounds[(int)CharacterSoundsEnum.CROUCH_UP_SOUND] : CharacterSounds[(int)CharacterSoundsEnum.CROUCH_DOWN_SOUND];
                }
            }
            break;

            case MyCharacterMovementEnum.Sprinting:
            {
                m_character.Breath.CurrentState = MyCharacterBreath.State.Heated;
                soundPair = MyMaterialPropertiesHelper.Static.GetCollisionCue(MovementSoundType.Sprint, MyMaterialType.CHARACTER, RayCastGround());
            }
            break;

            case MyCharacterMovementEnum.Jump:
            {
                if (m_character.GetPreviousMovementState() == MyCharacterMovementEnum.Jump)
                {
                    break;
                }
                m_character.SetPreviousMovementState(m_character.GetCurrentMovementState());
                var emitter = MyAudioComponent.TryGetSoundEmitter();                                 // We need to use another emitter otherwise the sound would be cut by silence next frame
                if (emitter != null)
                {
                    emitter.Entity = m_character;
                    emitter.PlaySingleSound(CharacterSounds[(int)CharacterSoundsEnum.JUMP_SOUND]);
                }
            }
            break;

            case MyCharacterMovementEnum.Flying:
            {
                m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
                if (m_character.Physics.LinearAcceleration.Length() < 1)
                {
                    soundPair = CharacterSounds[(int)CharacterSoundsEnum.JETPACK_IDLE_SOUND];
                }
                else
                {
                    soundPair = CharacterSounds[(int)CharacterSoundsEnum.JETPACK_RUN_SOUND];
                }
            }
            break;

            case MyCharacterMovementEnum.Falling:
            {
                m_character.Breath.CurrentState = MyCharacterBreath.State.Calm;
            }
            break;

            default:
            {
            }
            break;
            }

            return(soundPair);
        }