Ejemplo n.º 1
0
        public override void ReceiveSignal(int stepsTaken, string signal, Connection connection, Item source, Character sender, float power = 0.0f)
        {
            var senderComponent = source.GetComponent <WifiComponent>();

            if (senderComponent != null && !CanReceive(senderComponent))
            {
                return;
            }

            if (LinkToChat)
            {
                if (item.ParentInventory != null &&
                    item.ParentInventory.Owner != null &&
                    item.ParentInventory.Owner == Character.Controlled &&
                    GameMain.NetworkMember != null)
                {
                    if (senderComponent != null)
                    {
                        signal = ChatMessage.ApplyDistanceEffect(item, sender, signal, senderComponent.range);
                    }

                    GameMain.NetworkMember.AddChatMessage(signal, ChatMessageType.Radio);
                }
            }

            if (connection == null)
            {
                return;
            }

            switch (connection.Name)
            {
            case "signal_in":
                var receivers = GetReceiversInRange();

                foreach (WifiComponent wifiComp in receivers)
                {
                    wifiComp.item.SendSignal(stepsTaken, signal, "signal_out", sender);
                    if (source != null)
                    {
                        foreach (Item receiverItem in wifiComp.item.LastSentSignalRecipients)
                        {
                            if (!source.LastSentSignalRecipients.Contains(receiverItem))
                            {
                                source.LastSentSignalRecipients.Add(receiverItem);
                            }
                        }
                    }
                }
                break;
            }
        }
Ejemplo n.º 2
0
        public void TransmitSignal(Signal signal, bool sentFromChat)
        {
            var senderComponent = signal.source?.GetComponent <WifiComponent>();

            if (senderComponent != null && !CanReceive(senderComponent))
            {
                return;
            }

            bool chatMsgSent = false;

            var receivers = GetReceiversInRange();

            foreach (WifiComponent wifiComp in receivers)
            {
                if (sentFromChat && !wifiComp.LinkToChat)
                {
                    continue;
                }

                //signal strength diminishes by distance
                float sentSignalStrength = signal.strength *
                                           MathHelper.Clamp(1.0f - (Vector2.Distance(item.WorldPosition, wifiComp.item.WorldPosition) / wifiComp.range), 0.0f, 1.0f);
                Signal s = new Signal(signal.value, signal.stepsTaken, sender: signal.sender, source: signal.source,
                                      power: 0.0f, strength: sentSignalStrength);
                wifiComp.item.SendSignal(s, "signal_out");

                if (signal.source != null)
                {
                    foreach (Connection receiver in wifiComp.item.LastSentSignalRecipients)
                    {
                        if (!signal.source.LastSentSignalRecipients.Contains(receiver))
                        {
                            signal.source.LastSentSignalRecipients.Add(receiver);
                        }
                    }
                }

                if (DiscardDuplicateChatMessages && signal.value == prevSignal)
                {
                    continue;
                }

                //create a chat message
                if (LinkToChat && wifiComp.LinkToChat && chatMsgCooldown <= 0.0f && !sentFromChat)
                {
                    if (wifiComp.item.ParentInventory != null &&
                        wifiComp.item.ParentInventory.Owner != null)
                    {
                        string chatMsg = signal.value;
                        if (senderComponent != null)
                        {
                            chatMsg = ChatMessage.ApplyDistanceEffect(chatMsg, 1.0f - sentSignalStrength);
                        }
                        if (chatMsg.Length > ChatMessage.MaxLength)
                        {
                            chatMsg = chatMsg.Substring(0, ChatMessage.MaxLength);
                        }
                        if (string.IsNullOrEmpty(chatMsg))
                        {
                            continue;
                        }

#if CLIENT
                        if (wifiComp.item.ParentInventory.Owner == Character.Controlled)
                        {
                            if (GameMain.Client == null)
                            {
                                GameMain.GameSession?.CrewManager?.AddSinglePlayerChatMessage(signal.source?.Name ?? "", signal.value, ChatMessageType.Radio, sender: null);
                            }
                        }
#elif SERVER
                        if (GameMain.Server != null)
                        {
                            Client recipientClient = GameMain.Server.ConnectedClients.Find(c => c.Character == wifiComp.item.ParentInventory.Owner);
                            if (recipientClient != null)
                            {
                                GameMain.Server.SendDirectChatMessage(
                                    ChatMessage.Create(signal.source?.Name ?? "", chatMsg, ChatMessageType.Radio, null), recipientClient);
                            }
                        }
#endif
                        chatMsgSent = true;
                    }
                }
            }
            if (chatMsgSent)
            {
                chatMsgCooldown = MinChatMessageInterval;
                IsActive        = true;
            }

            prevSignal = signal.value;
        }
Ejemplo n.º 3
0
        public void TransmitSignal(int stepsTaken, string signal, Item source, Character sender, bool sendToChat, float signalStrength = 1.0f)
        {
            var senderComponent = source?.GetComponent <WifiComponent>();

            if (senderComponent != null && !CanReceive(senderComponent))
            {
                return;
            }

            bool chatMsgSent = false;

            var receivers = GetReceiversInRange();

            foreach (WifiComponent wifiComp in receivers)
            {
                //signal strength diminishes by distance
                float sentSignalStrength = signalStrength *
                                           MathHelper.Clamp(1.0f - (Vector2.Distance(item.WorldPosition, wifiComp.item.WorldPosition) / wifiComp.range), 0.0f, 1.0f);
                wifiComp.item.SendSignal(stepsTaken, signal, "signal_out", sender, 0, source, sentSignalStrength);

                if (source != null)
                {
                    foreach (Item receiverItem in wifiComp.item.LastSentSignalRecipients)
                    {
                        if (!source.LastSentSignalRecipients.Contains(receiverItem))
                        {
                            source.LastSentSignalRecipients.Add(receiverItem);
                        }
                    }
                }

                if (DiscardDuplicateChatMessages && signal == prevSignal)
                {
                    continue;
                }

                if (LinkToChat && wifiComp.LinkToChat && chatMsgCooldown <= 0.0f && sendToChat)
                {
                    if (wifiComp.item.ParentInventory != null &&
                        wifiComp.item.ParentInventory.Owner != null &&
                        GameMain.NetworkMember != null)
                    {
                        string chatMsg = signal;
                        if (senderComponent != null)
                        {
                            chatMsg = ChatMessage.ApplyDistanceEffect(chatMsg, 1.0f - sentSignalStrength);
                        }
                        if (chatMsg.Length > ChatMessage.MaxLength)
                        {
                            chatMsg = chatMsg.Substring(0, ChatMessage.MaxLength);
                        }
                        if (string.IsNullOrEmpty(chatMsg))
                        {
                            continue;
                        }

#if CLIENT
                        if (wifiComp.item.ParentInventory.Owner == Character.Controlled)
                        {
                            if (GameMain.Client == null)
                            {
                                GameMain.NetworkMember.AddChatMessage(signal, ChatMessageType.Radio, source == null ? "" : source.Name);
                            }
                        }
#endif

#if SERVER
                        if (GameMain.Server != null)
                        {
                            Client recipientClient = GameMain.Server.ConnectedClients.Find(c => c.Character == wifiComp.item.ParentInventory.Owner);
                            if (recipientClient != null)
                            {
                                GameMain.Server.SendDirectChatMessage(
                                    ChatMessage.Create(source == null ? "" : source.Name, chatMsg, ChatMessageType.Radio, null), recipientClient);
                            }
                        }
#endif
                        chatMsgSent = true;
                    }
                }
            }
            if (chatMsgSent)
            {
                chatMsgCooldown = MinChatMessageInterval;
            }

            prevSignal = signal;
        }