partial void UpdateProjSpecific(float deltaTime) { if (FakeBrokenTimer > 0.0f) { item.FakeBroken = true; if (Character.Controlled == null || (Character.Controlled.CharacterHealth.GetAffliction("psychosis")?.Strength ?? 0.0f) <= 0.0f) { FakeBrokenTimer = 0.0f; } else { FakeBrokenTimer -= deltaTime; } } else { item.FakeBroken = false; } if (!GameMain.IsMultiplayer) { switch (requestStartFixAction) { case FixActions.Repair: case FixActions.Sabotage: case FixActions.Tinker: StartRepairing(Character.Controlled, requestStartFixAction); requestStartFixAction = FixActions.None; break; default: requestStartFixAction = FixActions.None; break; } } for (int i = 0; i < particleEmitters.Count; i++) { if ((item.ConditionPercentage >= particleEmitterConditionRanges[i].X && item.ConditionPercentage <= particleEmitterConditionRanges[i].Y) || FakeBrokenTimer > 0.0f) { particleEmitters[i].Emit(deltaTime, item.WorldPosition, item.CurrentHull); } } if (CurrentFixer != null && CurrentFixer.SelectedConstruction == item) { if (repairSoundChannel == null || !repairSoundChannel.IsPlaying) { repairSoundChannel = SoundPlayer.PlaySound("repair", item.WorldPosition, hullGuess: item.CurrentHull); } } else { repairSoundChannel?.FadeOutAndDispose(); repairSoundChannel = null; } }
partial void UpdateProjSpecific(float deltaTime) { foreach (var _ in DisconnectedWires) { if (Rand.Range(0.0f, 500.0f) < 1.0f) { SoundPlayer.PlaySound("zap", item.WorldPosition, hullGuess: item.CurrentHull); Vector2 baseVel = new Vector2(0.0f, -100.0f); for (int i = 0; i < 5; i++) { var particle = GameMain.ParticleManager.CreateParticle("spark", item.WorldPosition, baseVel + Rand.Vector(100.0f), 0.0f, item.CurrentHull); if (particle != null) { particle.Size *= Rand.Range(0.5f, 1.0f); } } } } rewireSoundTimer -= deltaTime; if (user != null && user.SelectedConstruction == item && rewireSoundTimer > 0.0f) { if (rewireSoundChannel == null || !rewireSoundChannel.IsPlaying) { rewireSoundChannel = SoundPlayer.PlaySound("rewire", item.WorldPosition, hullGuess: item.CurrentHull); } } else { rewireSoundChannel?.FadeOutAndDispose(); rewireSoundChannel = null; rewireSoundTimer = 0.0f; } }
partial void UpdateProjSpecific(float deltaTime) { if (!GameMain.IsMultiplayer) { switch (requestStartFixAction) { case FixActions.Repair: case FixActions.Sabotage: StartRepairing(Character.Controlled, requestStartFixAction); requestStartFixAction = FixActions.None; break; default: requestStartFixAction = FixActions.None; break; } } for (int i = 0; i < particleEmitters.Count; i++) { if (item.ConditionPercentage >= particleEmitterConditionRanges[i].X && item.ConditionPercentage <= particleEmitterConditionRanges[i].Y) { particleEmitters[i].Emit(deltaTime, item.WorldPosition, item.CurrentHull); } } if (CurrentFixer != null && CurrentFixer.SelectedConstruction == item) { if (repairSoundChannel == null || !repairSoundChannel.IsPlaying) { repairSoundChannel = SoundPlayer.PlaySound("repair", item.WorldPosition, hullGuess: item.CurrentHull); } } else { repairSoundChannel?.FadeOutAndDispose(); repairSoundChannel = null; } }
partial void UpdateProjSpecific(float deltaTime) { float chargeRatio = currentChargeTime / MaxChargeTime; switch (currentChargingState) { case ChargingState.WindingUp: case ChargingState.WindingDown: Vector2 particlePos = item.WorldPosition + ConvertUnits.ToDisplayUnits(TransformedBarrelPos); float sizeMultiplier = Math.Clamp(chargeRatio, 0.1f, 1f); foreach (ParticleEmitter emitter in particleEmitterCharges) { emitter.Emit(deltaTime, particlePos, hullGuess: null, sizeMultiplier: sizeMultiplier, colorMultiplier: emitter.Prefab.Properties.ColorMultiplier); } if (chargeSoundChannel == null || !chargeSoundChannel.IsPlaying) { if (chargeSound != null) { chargeSoundChannel = SoundPlayer.PlaySound(chargeSound.Sound, item.WorldPosition, chargeSound.Volume, chargeSound.Range, ignoreMuffling: chargeSound.IgnoreMuffling); if (chargeSoundChannel != null) { chargeSoundChannel.Looping = true; } } } else if (chargeSoundChannel != null) { chargeSoundChannel.FrequencyMultiplier = MathHelper.Lerp(0.5f, 1.5f, chargeRatio); } break; default: if (chargeSoundChannel != null) { if (chargeSoundChannel.IsPlaying) { chargeSoundChannel.FadeOutAndDispose(); chargeSoundChannel.Looping = false; } else { chargeSoundChannel = null; } } break; } }
public void PlaySound(ActionType type, Vector2 position, Character user = null) { if (loopingSound != null) { if (Vector3.DistanceSquared(GameMain.SoundManager.ListenerPosition, new Vector3(position.X, position.Y, 0.0f)) > loopingSound.Range * loopingSound.Range) { if (loopingSoundChannel != null) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; } return; } if (loopingSoundChannel != null && loopingSoundChannel.Sound != loopingSound.RoundSound.Sound) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; } if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { loopingSoundChannel = loopingSound.RoundSound.Sound.Play( new Vector3(position.X, position.Y, 0.0f), 0.01f, SoundPlayer.ShouldMuffleSound(Character.Controlled, position, loopingSound.Range, Character.Controlled?.CurrentHull)); loopingSoundChannel.Looping = true; //TODO: tweak loopingSoundChannel.Near = loopingSound.Range * 0.4f; loopingSoundChannel.Far = loopingSound.Range; } if (loopingSoundChannel != null) { if (Timing.TotalTime > lastMuffleCheckTime + 0.2f) { shouldMuffleLooping = SoundPlayer.ShouldMuffleSound(Character.Controlled, position, loopingSound.Range, Character.Controlled?.CurrentHull); lastMuffleCheckTime = (float)Timing.TotalTime; } loopingSoundChannel.Muffled = shouldMuffleLooping; float targetGain = GetSoundVolume(loopingSound); float gainDiff = targetGain - loopingSoundChannel.Gain; loopingSoundChannel.Gain += Math.Abs(gainDiff) < 0.1f ? gainDiff : Math.Sign(gainDiff) * 0.1f; loopingSoundChannel.Position = new Vector3(position.X, position.Y, 0.0f); } return; } if (!sounds.TryGetValue(type, out List <ItemSound> matchingSounds)) { return; } ItemSound itemSound = null; if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { SoundSelectionMode soundSelectionMode = soundSelectionModes[type]; int index; if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && user != null) { index = user.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.ItemSpecific) { index = item.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.All) { foreach (ItemSound sound in matchingSounds) { PlaySound(sound, position, user); } return; } else { index = Rand.Int(matchingSounds.Count); } itemSound = matchingSounds[index]; PlaySound(matchingSounds[index], position, user); } }
partial void UpdateProjSpecific(float deltaTime) { recoilTimer -= deltaTime; if (crosshairSprite != null) { Vector2 itemPos = cam.WorldToScreen(new Vector2(item.WorldRect.X + transformedBarrelPos.X, item.WorldRect.Y - transformedBarrelPos.Y)); Vector2 turretDir = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); Vector2 mouseDiff = itemPos - PlayerInput.MousePosition; crosshairPos = new Vector2( MathHelper.Clamp(itemPos.X + turretDir.X * mouseDiff.Length(), 0, GameMain.GraphicsWidth), MathHelper.Clamp(itemPos.Y + turretDir.Y * mouseDiff.Length(), 0, GameMain.GraphicsHeight)); } crosshairPointerPos = PlayerInput.MousePosition; if (Math.Abs(angularVelocity) > 0.1f) { if (moveSoundChannel == null && startMoveSound != null) { moveSoundChannel = SoundPlayer.PlaySound(startMoveSound.Sound, item.WorldPosition, startMoveSound.Volume, startMoveSound.Range, ignoreMuffling: startMoveSound.IgnoreMuffling); } else if (moveSoundChannel == null || !moveSoundChannel.IsPlaying) { if (moveSound != null) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = SoundPlayer.PlaySound(moveSound.Sound, item.WorldPosition, moveSound.Volume, moveSound.Range, ignoreMuffling: moveSound.IgnoreMuffling); if (moveSoundChannel != null) { moveSoundChannel.Looping = true; } } } } else if (Math.Abs(angularVelocity) < 0.05f) { if (moveSoundChannel != null) { if (endMoveSound != null && moveSoundChannel.Sound != endMoveSound.Sound) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = SoundPlayer.PlaySound(endMoveSound.Sound, item.WorldPosition, endMoveSound.Volume, endMoveSound.Range, ignoreMuffling: endMoveSound.IgnoreMuffling); if (moveSoundChannel != null) { moveSoundChannel.Looping = false; } } else if (!moveSoundChannel.IsPlaying) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = null; } } } float chargeRatio = currentChargeTime / MaxChargeTime; currentBarrelSpin = (currentBarrelSpin + MaxCircle * chargeRatio * deltaTime * 3f) % MaxCircle; switch (currentChargingState) { case ChargingState.WindingUp: Vector2 particlePos = GetRelativeFiringPosition(); float sizeMultiplier = Math.Clamp(chargeRatio, 0.1f, 1f); foreach (ParticleEmitter emitter in particleEmitterCharges) { // color is currently not connected to ammo type, should be updated when ammo is changed emitter.Emit(deltaTime, particlePos, hullGuess: null, angle: -rotation, particleRotation: rotation, sizeMultiplier: sizeMultiplier, colorMultiplier: emitter.Prefab.Properties.ColorMultiplier); } if (chargeSoundChannel == null || !chargeSoundChannel.IsPlaying) { if (chargeSound != null) { chargeSoundChannel = SoundPlayer.PlaySound(chargeSound.Sound, item.WorldPosition, chargeSound.Volume, chargeSound.Range, ignoreMuffling: chargeSound.IgnoreMuffling); if (chargeSoundChannel != null) { chargeSoundChannel.Looping = true; } } } else if (chargeSoundChannel != null) { chargeSoundChannel.FrequencyMultiplier = MathHelper.Lerp(0.5f, 1.5f, chargeRatio); } break; default: if (chargeSoundChannel != null) { if (chargeSoundChannel.IsPlaying) { chargeSoundChannel.FadeOutAndDispose(); chargeSoundChannel.Looping = false; } else { chargeSoundChannel = null; } } break; } if (moveSoundChannel != null && moveSoundChannel.IsPlaying) { moveSoundChannel.Gain = MathHelper.Clamp(Math.Abs(angularVelocity), 0.5f, 1.0f); } if (flashLowPower || flashNoAmmo || flashLoaderBroken) { flashTimer += deltaTime; if (flashTimer >= flashLength) { flashTimer = 0; flashLowPower = false; flashNoAmmo = false; flashLoaderBroken = false; } } }
partial void UpdateProjSpecific(float deltaTime) { recoilTimer -= deltaTime; if (crosshairSprite != null) { Vector2 itemPos = cam.WorldToScreen(new Vector2(item.WorldRect.X + transformedBarrelPos.X, item.WorldRect.Y - transformedBarrelPos.Y)); Vector2 turretDir = new Vector2((float)Math.Cos(rotation), (float)Math.Sin(rotation)); Vector2 mouseDiff = itemPos - PlayerInput.MousePosition; crosshairPos = new Vector2( MathHelper.Clamp(itemPos.X + turretDir.X * mouseDiff.Length(), 0, GameMain.GraphicsWidth), MathHelper.Clamp(itemPos.Y + turretDir.Y * mouseDiff.Length(), 0, GameMain.GraphicsHeight)); } crosshairPointerPos = PlayerInput.MousePosition; if (Math.Abs(angularVelocity) > 0.1f) { if (moveSoundChannel == null && startMoveSound != null) { moveSoundChannel = SoundPlayer.PlaySound(startMoveSound.Sound, item.WorldPosition, startMoveSound.Volume, startMoveSound.Range); } else if (moveSoundChannel == null || !moveSoundChannel.IsPlaying) { if (moveSound != null) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = SoundPlayer.PlaySound(moveSound.Sound, item.WorldPosition, moveSound.Volume, moveSound.Range); if (moveSoundChannel != null) { moveSoundChannel.Looping = true; } } } } else if (Math.Abs(angularVelocity) < 0.05f) { if (moveSoundChannel != null) { if (endMoveSound != null && moveSoundChannel.Sound != endMoveSound.Sound) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = SoundPlayer.PlaySound(endMoveSound.Sound, item.WorldPosition, endMoveSound.Volume, endMoveSound.Range); if (moveSoundChannel != null) { moveSoundChannel.Looping = false; } } else if (!moveSoundChannel.IsPlaying) { moveSoundChannel.FadeOutAndDispose(); moveSoundChannel = null; } } } if (moveSoundChannel != null && moveSoundChannel.IsPlaying) { moveSoundChannel.Gain = MathHelper.Clamp(Math.Abs(angularVelocity), 0.5f, 1.0f); } if (flashLowPower || flashNoAmmo) { flashTimer += deltaTime; if (flashTimer >= flashLength) { flashTimer = 0; flashLowPower = false; flashNoAmmo = false; } } }
public void PlaySound(ActionType type, Character user = null) { if (!hasSoundsOfType[(int)type]) { return; } if (loopingSound != null) { if (Vector3.DistanceSquared(GameMain.SoundManager.ListenerPosition, new Vector3(item.WorldPosition, 0.0f)) > loopingSound.Range * loopingSound.Range || (GetSoundVolume(loopingSound)) <= 0.0001f) { if (loopingSoundChannel != null) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } return; } if (loopingSoundChannel != null && loopingSoundChannel.Sound != loopingSound.RoundSound.Sound) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { loopingSoundChannel = loopingSound.RoundSound.Sound.Play( new Vector3(item.WorldPosition, 0.0f), 0.01f, SoundPlayer.ShouldMuffleSound(Character.Controlled, item.WorldPosition, loopingSound.Range, Character.Controlled?.CurrentHull)); loopingSoundChannel.Looping = true; //TODO: tweak loopingSoundChannel.Near = loopingSound.Range * 0.4f; loopingSoundChannel.Far = loopingSound.Range; } return; } var matchingSounds = sounds[type]; if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { SoundSelectionMode soundSelectionMode = soundSelectionModes[type]; int index; if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && user != null) { index = user.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.ItemSpecific) { index = item.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.All) { foreach (ItemSound sound in matchingSounds) { PlaySound(sound, item.WorldPosition); } return; } else { index = Rand.Int(matchingSounds.Count); } PlaySound(matchingSounds[index], item.WorldPosition); } }
public void PlaySound(ActionType type, Character user = null) { if (!hasSoundsOfType[(int)type]) { return; } if (GameMain.Client?.MidRoundSyncing ?? false) { return; } if (loopingSound != null) { if (Vector3.DistanceSquared(GameMain.SoundManager.ListenerPosition, new Vector3(item.WorldPosition, 0.0f)) > loopingSound.Range * loopingSound.Range || (GetSoundVolume(loopingSound)) <= 0.0001f) { if (loopingSoundChannel != null) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } return; } if (loopingSoundChannel != null && loopingSoundChannel.Sound != loopingSound.RoundSound.Sound) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { loopingSoundChannel = loopingSound.RoundSound.Sound.Play( new Vector3(item.WorldPosition, 0.0f), 0.01f, loopingSound.RoundSound.GetRandomFrequencyMultiplier(), SoundPlayer.ShouldMuffleSound(Character.Controlled, item.WorldPosition, loopingSound.Range, Character.Controlled?.CurrentHull)); loopingSoundChannel.Looping = true; //TODO: tweak loopingSoundChannel.Near = loopingSound.Range * 0.4f; loopingSoundChannel.Far = loopingSound.Range; } // Looping sound with manual selection mode should be changed if value of ManuallySelectedSound has changed // Otherwise the sound won't change until the sound condition (such as being active) is disabled and re-enabled if (loopingSoundChannel != null && loopingSoundChannel.IsPlaying && soundSelectionModes[type] == SoundSelectionMode.Manual) { var playingIndex = sounds[type].IndexOf(loopingSound); var shouldBePlayingIndex = Math.Clamp(ManuallySelectedSound, 0, sounds[type].Count); if (playingIndex != shouldBePlayingIndex) { loopingSoundChannel.FadeOutAndDispose(); loopingSoundChannel = null; loopingSound = null; } } return; } var matchingSounds = sounds[type]; if (loopingSoundChannel == null || !loopingSoundChannel.IsPlaying) { SoundSelectionMode soundSelectionMode = soundSelectionModes[type]; int index; if (soundSelectionMode == SoundSelectionMode.CharacterSpecific && user != null) { index = user.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.ItemSpecific) { index = item.ID % matchingSounds.Count; } else if (soundSelectionMode == SoundSelectionMode.All) { foreach (ItemSound sound in matchingSounds) { PlaySound(sound, item.WorldPosition); } return; } else if (soundSelectionMode == SoundSelectionMode.Manual) { index = Math.Clamp(ManuallySelectedSound, 0, matchingSounds.Count); } else { index = Rand.Int(matchingSounds.Count); } PlaySound(matchingSounds[index], item.WorldPosition); } }