private bool CanReceive(Client sender, Client recipient) { if (Screen.Selected != GameMain.GameScreen) { return(true); } //no-one can hear muted players if (sender.Muted) { return(false); } bool recipientSpectating = recipient.Character == null || recipient.Character.IsDead; bool senderSpectating = sender.Character == null || sender.Character.IsDead; //TODO: only allow spectators to hear the voice chat if close enough to the speaker? //non-spectators cannot hear spectators if (senderSpectating && !recipientSpectating) { return(false); } //both spectating, no need to do radio/distance checks if (recipientSpectating && senderSpectating) { return(true); } //spectators can hear non-spectators if (!senderSpectating && recipientSpectating) { return(true); } //sender can't speak //if (sender.Character != null && sender.Character.SpeechImpediment >= 100.0f) { return false; } //check if the message can be sent via radio if (!sender.VoipQueue.ForceLocal && ChatMessage.CanUseRadio(sender.Character, out WifiComponent senderRadio) && ChatMessage.CanUseRadio(recipient.Character, out WifiComponent recipientRadio)) { //if (recipientRadio.CanReceive(senderRadio)) { return true; } WifiComponent test = senderRadio; test.Range = 2000.0f; if (recipientRadio.CanReceive(senderRadio)) { return(true); } } //otherwise do a distance check return(ChatMessage.GetGarbleAmount(recipient.Character, sender.Character, ChatMessage.SpeakRange) < 1.0f); }
public static bool CanUseRadio(Character sender, out WifiComponent radio) { radio = null; if (sender?.Inventory == null || sender.Removed) { return(false); } radio = sender.Inventory.Items.FirstOrDefault(i => i?.GetComponent <WifiComponent>() != null)?.GetComponent <WifiComponent>(); if (radio?.Item == null) { return(false); } return(sender.HasEquippedItem(radio.Item) && radio.CanTransmit()); }
public static bool CanUseRadio(Character sender, out WifiComponent radio) { radio = null; if (sender?.Inventory == null || sender.Removed) { return(false); } foreach (Item item in sender.Inventory.AllItems) { var wifiComponent = item.GetComponent <WifiComponent>(); if (wifiComponent == null || !wifiComponent.CanTransmit() || !sender.HasEquippedItem(item)) { continue; } if (radio == null || wifiComponent.Range > radio.Range) { radio = wifiComponent; } } return(radio?.Item != null); }
public void Read(IReadMessage msg) { byte queueId = msg.ReadByte(); VoipQueue queue = queues.Find(q => q.QueueID == queueId); if (queue == null) { #if DEBUG DebugConsole.NewMessage("Couldn't find VoipQueue with id " + queueId.ToString() + "!", GUI.Style.Red); #endif return; } Client client = gameClient.ConnectedClients.Find(c => c.VoipQueue == queue); if (queue.Read(msg, discardData: client.Muted || client.MutedLocally)) { if (client.Muted || client.MutedLocally) { return; } if (client.VoipSound == null) { DebugConsole.Log("Recreating voipsound " + queueId); client.VoipSound = new VoipSound(client.Name, GameMain.SoundManager, client.VoipQueue); } if (client.Character != null && !client.Character.IsDead && !client.Character.Removed && client.Character.SpeechImpediment <= 100.0f) { WifiComponent radio = null; var messageType = !client.VoipQueue.ForceLocal && ChatMessage.CanUseRadio(client.Character, out radio) ? ChatMessageType.Radio : ChatMessageType.Default; client.Character.ShowSpeechBubble(1.25f, ChatMessage.MessageColor[(int)messageType]); client.VoipSound.UseRadioFilter = messageType == ChatMessageType.Radio && !GameMain.Config.DisableVoiceChatFilters; if (client.VoipSound.UseRadioFilter) { client.VoipSound.SetRange(radio.Range * 0.8f, radio.Range); } else { client.VoipSound.SetRange(ChatMessage.SpeakRange * 0.4f, ChatMessage.SpeakRange); } if (!client.VoipSound.UseRadioFilter && Character.Controlled != null && !GameMain.Config.DisableVoiceChatFilters) { client.VoipSound.UseMuffleFilter = SoundPlayer.ShouldMuffleSound(Character.Controlled, client.Character.WorldPosition, ChatMessage.SpeakRange, client.Character.CurrentHull); } } GameMain.NetLobbyScreen?.SetPlayerSpeaking(client); GameMain.GameSession?.CrewManager?.SetClientSpeaking(client); if ((client.VoipSound.CurrentAmplitude * client.VoipSound.Gain * GameMain.SoundManager.GetCategoryGainMultiplier("voip")) > 0.1f) //TODO: might need to tweak { if (client.Character != null && !client.Character.Removed) { Vector3 clientPos = new Vector3(client.Character.WorldPosition.X, client.Character.WorldPosition.Y, 0.0f); Vector3 listenerPos = GameMain.SoundManager.ListenerPosition; float attenuationDist = client.VoipSound.Near * 1.125f; if (Vector3.DistanceSquared(clientPos, listenerPos) < attenuationDist * attenuationDist) { GameMain.SoundManager.VoipAttenuatedGain = 0.5f; } } else { GameMain.SoundManager.VoipAttenuatedGain = 0.5f; } } } }