revert wificomponent

This commit is contained in:
Evil Factory
2021-08-25 13:31:16 -03:00
parent 970ee8a93f
commit 83360b3b7e
@@ -5,6 +5,7 @@ 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
{ {
@@ -17,14 +18,12 @@ namespace Barotrauma.Items.Components
private float range; private float range;
private int channel; private int channel;
private float chatMsgCooldown; private float chatMsgCooldown;
private string prevSignal; private string prevSignal;
private readonly int[] channelMemory = new int[ChannelMemorySize]; private 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; }
@@ -65,10 +64,37 @@ 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; get
set; {
#if SERVER
return GameMain.Lua.game.allowWifiChat;
#endif
#if CLIENT
return true;
#endif
}
set
{
}
} }
// [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.")]
@@ -86,7 +112,7 @@ namespace Barotrauma.Items.Components
} }
public WifiComponent(Item item, XElement element) public WifiComponent(Item item, XElement element)
: base (item, element) : base(item, element)
{ {
list.Add(this); list.Add(this);
IsActive = true; IsActive = true;
@@ -95,10 +121,6 @@ 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++)
@@ -112,7 +134,7 @@ namespace Barotrauma.Items.Components
{ {
return HasRequiredContainedItems(user: null, addMessage: false); return HasRequiredContainedItems(user: null, addMessage: false);
} }
public IEnumerable<WifiComponent> GetReceiversInRange() public IEnumerable<WifiComponent> GetReceiversInRange()
{ {
return list.Where(w => w != this && w.CanReceive(this)); return list.Where(w => w != this && w.CanReceive(this));
@@ -125,7 +147,7 @@ namespace Barotrauma.Items.Components
if (sender.TeamID != TeamID && !AllowCrossTeamCommunication) if (sender.TeamID != TeamID && !AllowCrossTeamCommunication)
{ {
return false; return false;
} }
if (Vector2.DistanceSquared(item.WorldPosition, sender.item.WorldPosition) > sender.range * sender.range) { return false; } if (Vector2.DistanceSquared(item.WorldPosition, sender.item.WorldPosition) > sender.range * sender.range) { return false; }
@@ -161,13 +183,16 @@ namespace Barotrauma.Items.Components
public void TransmitSignal(Signal signal, bool sentFromChat) public void TransmitSignal(Signal signal, bool sentFromChat)
{ {
if (sentFromChat)
{
item.LastSentSignalRecipients.Clear();
}
var senderComponent = signal.source?.GetComponent<WifiComponent>(); var senderComponent = signal.source?.GetComponent<WifiComponent>();
if (senderComponent != null && !CanReceive(senderComponent)) { return; } if (senderComponent != null && !CanReceive(senderComponent)) { return; }
#if SERVER
var should = GameMain.Lua.hook.Call("wifiSignalTransmitted", new DynValue[] { UserData.Create(this), UserData.Create(signal), DynValue.NewBoolean(sentFromChat) });
if (should != null && should.CastToBool())
return;
#endif
bool chatMsgSent = false; bool chatMsgSent = false;
var receivers = GetReceiversInRange(); var receivers = GetReceiversInRange();
@@ -178,13 +203,12 @@ 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);
if (wifiComp.signalOutConnection != null) //Signal s = new Signal(signal.value, signal.stepsTaken, sender: signal.sender, source: signal.source, power: 0.0f, strength: sentSignalStrength);
{
wifiComp.item.SendSignal(s, wifiComp.signalOutConnection); signal.source = null;
}
wifiComp.item.SendSignal(signal, "signal_out");
if (signal.source != null) if (signal.source != null)
{ {
@@ -227,6 +251,7 @@ 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);
} }
@@ -236,15 +261,15 @@ namespace Barotrauma.Items.Components
} }
} }
} }
if (chatMsgSent) if (chatMsgSent)
{ {
chatMsgCooldown = MinChatMessageInterval; chatMsgCooldown = MinChatMessageInterval;
IsActive = true; IsActive = true;
} }
prevSignal = signal.value; prevSignal = signal.value;
} }
public override void ReceiveSignal(Signal signal, Connection connection) public override void ReceiveSignal(Signal signal, Connection connection)
{ {
if (connection == null) { return; } if (connection == null) { return; }
@@ -282,4 +307,4 @@ namespace Barotrauma.Items.Components
return element; return element;
} }
} }
} }