wifi wiring

This commit is contained in:
Evil Factory
2021-04-26 23:46:58 -03:00
parent b84d6a2872
commit 250163e1f5
2 changed files with 255 additions and 212 deletions
@@ -75,12 +75,28 @@ namespace Barotrauma
client.SpectatePos = pos; client.SpectatePos = pos;
} }
public static void SetRadioRange(Character character, float range)
{
if(character.Inventory == null) { return; }
foreach(Item item in character.Inventory.AllItems)
{
if(item == null) { continue; }
if(item.Name == "Headset")
{
item.GetComponent<Items.Components.WifiComponent>().Range = range;
}
}
}
} }
public class LuaGame public class LuaGame
{ {
LuaSetup env; LuaSetup env;
public bool allowWifiChat = false;
public bool overrideTraitors = false; public bool overrideTraitors = false;
public bool overrideRespawnSub = false; public bool overrideRespawnSub = false;
@@ -119,6 +135,11 @@ namespace Barotrauma
overrideRespawnSub = o; overrideRespawnSub = o;
} }
public void AllowWifiChat(bool o)
{
allowWifiChat = o;
}
public static void Log(string message, ServerLog.MessageType type) public static void Log(string message, ServerLog.MessageType type)
{ {
GameServer.Log(message, type); GameServer.Log(message, type);
@@ -62,8 +62,16 @@ 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 LinkToChat;
#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. " +
@@ -167,9 +175,23 @@ 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 (sentFromChat && wifiComp.LinkToChat)
{
//Signal s = new Signal(signal.value, signal.stepsTaken, sender: null, source: null, power: 0.0f, strength: sentSignalStrength);
signal.source = null;
wifiComp.item.SendSignal(signal, "signal_out");
}
else
{
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"); wifiComp.item.SendSignal(s, "signal_out");
}
if (signal.source != null) if (signal.source != null)
{ {