fix wifi components not working correctly
This commit is contained in:
@@ -5,7 +5,6 @@ using System.Collections.Generic;
|
|||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Xml.Linq;
|
using System.Xml.Linq;
|
||||||
using MoonSharp.Interpreter;
|
|
||||||
|
|
||||||
namespace Barotrauma.Items.Components
|
namespace Barotrauma.Items.Components
|
||||||
{
|
{
|
||||||
@@ -23,7 +22,9 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
private string prevSignal;
|
private string prevSignal;
|
||||||
|
|
||||||
private int[] channelMemory = new int[ChannelMemorySize];
|
private readonly int[] channelMemory = new int[ChannelMemorySize];
|
||||||
|
|
||||||
|
private Connection signalOutConnection;
|
||||||
|
|
||||||
[Serialize(CharacterTeamType.None, true, description: "WiFi components can only communicate with components that have the same Team ID.", alwaysUseInstanceValues: true)]
|
[Serialize(CharacterTeamType.None, true, description: "WiFi components can only communicate with components that have the same Team ID.", alwaysUseInstanceValues: true)]
|
||||||
public CharacterTeamType TeamID { get; set; }
|
public CharacterTeamType TeamID { get; set; }
|
||||||
@@ -64,37 +65,22 @@ namespace Barotrauma.Items.Components
|
|||||||
"as chat messages in the chatbox of the player holding the item.", alwaysUseInstanceValues: true)]
|
"as chat messages in the chatbox of the player holding the item.", alwaysUseInstanceValues: true)]
|
||||||
public bool LinkToChat
|
public bool LinkToChat
|
||||||
{
|
{
|
||||||
get
|
|
||||||
{
|
|
||||||
#if SERVER
|
#if SERVER
|
||||||
|
get
|
||||||
|
{
|
||||||
return GameMain.Lua.game.allowWifiChat;
|
return GameMain.Lua.game.allowWifiChat;
|
||||||
#endif
|
}
|
||||||
#if CLIENT
|
|
||||||
return true;
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
set
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
set
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
#else
|
||||||
|
get;
|
||||||
|
set;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// [Editable, Serialize(false, false, description: "If enabled, any signals received from another chat-linked wifi component are displayed " +
|
|
||||||
// "as chat messages in the chatbox of the player holding the item.", alwaysUseInstanceValues: true)]
|
|
||||||
// public bool LinkToChat
|
|
||||||
// {
|
|
||||||
// get
|
|
||||||
// {
|
|
||||||
//#if SERVER
|
|
||||||
// return GameMain.Lua.game.allowWifiChat;
|
|
||||||
//#endif
|
|
||||||
//#if CLIENT
|
|
||||||
// return true;
|
|
||||||
//#endif
|
|
||||||
// }
|
|
||||||
// set { }
|
|
||||||
// }
|
|
||||||
|
|
||||||
[Editable, Serialize(1.0f, true, description: "How many seconds have to pass between signals for a message to be displayed in the chatbox. " +
|
[Editable, Serialize(1.0f, true, description: "How many seconds have to pass between signals for a message to be displayed in the chatbox. " +
|
||||||
"Setting this to a very low value is not recommended, because it may cause an excessive amount of chat messages to be created " +
|
"Setting this to a very low value is not recommended, because it may cause an excessive amount of chat messages to be created " +
|
||||||
"if there are chat-linked wifi components that transmit a continuous signal.")]
|
"if there are chat-linked wifi components that transmit a continuous signal.")]
|
||||||
@@ -121,6 +107,10 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public override void OnItemLoaded()
|
public override void OnItemLoaded()
|
||||||
{
|
{
|
||||||
|
if (item.Connections != null)
|
||||||
|
{
|
||||||
|
signalOutConnection = item.Connections.Find(c => c.Name == "signal_out");
|
||||||
|
}
|
||||||
if (channelMemory.All(m => m == 0))
|
if (channelMemory.All(m => m == 0))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < channelMemory.Length; i++)
|
for (int i = 0; i < channelMemory.Length; i++)
|
||||||
@@ -183,14 +173,18 @@ namespace Barotrauma.Items.Components
|
|||||||
|
|
||||||
public void TransmitSignal(Signal signal, bool sentFromChat)
|
public void TransmitSignal(Signal signal, bool sentFromChat)
|
||||||
{
|
{
|
||||||
var senderComponent = signal.source?.GetComponent<WifiComponent>();
|
|
||||||
if (senderComponent != null && !CanReceive(senderComponent)) { return; }
|
|
||||||
|
|
||||||
var should = new LuaResult(GameMain.Lua.hook.Call("wifiSignalTransmitted", new object[] { this, signal, sentFromChat }));
|
var should = new LuaResult(GameMain.Lua.hook.Call("wifiSignalTransmitted", new object[] { this, signal, sentFromChat }));
|
||||||
|
|
||||||
if (should.Bool())
|
if (should.Bool())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (sentFromChat)
|
||||||
|
{
|
||||||
|
item.LastSentSignalRecipients.Clear();
|
||||||
|
}
|
||||||
|
var senderComponent = signal.source?.GetComponent<WifiComponent>();
|
||||||
|
if (senderComponent != null && !CanReceive(senderComponent)) { return; }
|
||||||
|
|
||||||
bool chatMsgSent = false;
|
bool chatMsgSent = false;
|
||||||
|
|
||||||
var receivers = GetReceiversInRange();
|
var receivers = GetReceiversInRange();
|
||||||
@@ -201,12 +195,13 @@ namespace Barotrauma.Items.Components
|
|||||||
//signal strength diminishes by distance
|
//signal strength diminishes by distance
|
||||||
float sentSignalStrength = signal.strength *
|
float sentSignalStrength = signal.strength *
|
||||||
MathHelper.Clamp(1.0f - (Vector2.Distance(item.WorldPosition, wifiComp.item.WorldPosition) / wifiComp.range), 0.0f, 1.0f);
|
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);
|
||||||
|
|
||||||
//Signal s = new Signal(signal.value, signal.stepsTaken, sender: signal.sender, source: signal.source, power: 0.0f, strength: sentSignalStrength);
|
if (wifiComp.signalOutConnection != null)
|
||||||
|
{
|
||||||
signal.source = null;
|
wifiComp.item.SendSignal(s, wifiComp.signalOutConnection);
|
||||||
|
}
|
||||||
wifiComp.item.SendSignal(signal, "signal_out");
|
|
||||||
|
|
||||||
if (signal.source != null)
|
if (signal.source != null)
|
||||||
{
|
{
|
||||||
@@ -249,7 +244,6 @@ namespace Barotrauma.Items.Components
|
|||||||
Client recipientClient = GameMain.Server.ConnectedClients.Find(c => c.Character == wifiComp.item.ParentInventory.Owner);
|
Client recipientClient = GameMain.Server.ConnectedClients.Find(c => c.Character == wifiComp.item.ParentInventory.Owner);
|
||||||
if (recipientClient != null)
|
if (recipientClient != null)
|
||||||
{
|
{
|
||||||
|
|
||||||
GameMain.Server.SendDirectChatMessage(
|
GameMain.Server.SendDirectChatMessage(
|
||||||
ChatMessage.Create(signal.source?.Name ?? "", chatMsg, ChatMessageType.Radio, null), recipientClient);
|
ChatMessage.Create(signal.source?.Name ?? "", chatMsg, ChatMessageType.Radio, null), recipientClient);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user