2 using Microsoft.Xna.Framework;
4 using System.Collections.Generic;
5 using System.Globalization;
13 private static readonly List<WifiComponent> list =
new List<WifiComponent>();
15 const int ChannelMemorySize = 10;
17 private const int MinChannel = 0;
18 private const int MaxChannel = 10000;
24 private float chatMsgCooldown;
26 private string prevSignal;
28 private int[] channelMemory =
new int[ChannelMemorySize];
36 [
Editable,
Serialize(20000.0f,
IsPropertySaveable.No, description:
"How close the recipient has to be to receive a signal from this WiFi component.", alwaysUseInstanceValues:
true)]
42 range = Math.Max(value, 0.0f);
52 get {
return channel; }
55 channel = MathHelper.Clamp(value, MinChannel, MaxChannel);
60 [
Editable,
Serialize(
false,
IsPropertySaveable.Yes, description:
"Can the component communicate with wifi components in another team's submarine (e.g. enemy sub in Combat missions, respawn shuttle). Needs to be enabled on both the component transmitting the signal and the component receiving it.", alwaysUseInstanceValues:
true)]
68 [
Serialize(
false,
IsPropertySaveable.No, description:
"If enabled, any signals received from another chat-linked wifi component are displayed " +
69 "as chat messages in the chatbox of the player holding the item.", alwaysUseInstanceValues:
true)]
77 "Setting this to a very low value is not recommended, because it may cause an excessive amount of chat messages to be created " +
78 "if there are chat-linked wifi components that transmit a continuous signal.")]
92 private float jamTimer;
95 get {
return jamTimer; }
103 HintManager.OnRadioJammed(
Item);
108 jamTimer = Math.Max(0, value);
113 : base (
item, element)
121 base.Load(componentElement, usePrefabValues, idRemap, isItemSwap);
122 channelMemory = componentElement.
GetAttributeIntArray(
"channelmemory",
new int[ChannelMemorySize]);
123 if (channelMemory.Length != ChannelMemorySize)
125 DebugConsole.AddWarning($
"Error when loading item {item.Prefab.Identifier}: the size of the channel memory doesn't match the default value of {ChannelMemorySize}. Resizing...");
126 Array.Resize(ref channelMemory, ChannelMemorySize);
134 signalOutConnection =
item.
Connections.Find(c => c.Name ==
"signal_out");
135 signalInConnection =
item.
Connections.Find(c => c.Name ==
"signal_in");
137 if (channelMemory.All(m => m == 0))
139 for (
int i = 0; i < channelMemory.Length; i++)
141 channelMemory[i] = i;
150 if (jamTimer > 0) {
return false; }
160 return list.Where(w => w !=
this && w.CanReceive(
this));
165 if (sender ==
null || sender.channel != channel) {
return false; }
167 if (jamTimer > 0) {
return false; }
189 return list.Where(w => w !=
this && w.CanTransmit(
this));
194 if (sender ==
null || sender.channel != channel) {
return false; }
197 if (jamTimer > 0) {
return false; }
203 chatMsgCooldown -= deltaTime;
206 if (chatMsgCooldown <= 0.0f &&
JamTimer <= 0.0f)
214 if (index < 0 || index >= ChannelMemorySize)
218 return channelMemory[index];
223 if (index < 0 || index >= ChannelMemorySize)
227 channelMemory[index] = MathHelper.Clamp(value, 0, 10000);
234 if (should !=
null && should.Value)
242 bool chatMsgSent =
false;
247 if (sentFromChat && !wifiComp.
LinkToChat) {
continue; }
250 float sentSignalStrength = signal.strength *
252 Signal s =
new Signal(signal.value, signal.stepsTaken + 1, sender: signal.sender, source: signal.source,
253 power: 0.0f, strength: sentSignalStrength);
255 if (wifiComp.signalOutConnection !=
null)
257 if (signal.source !=
null && wifiComp.signalInConnection !=
null)
259 if (signal.source.LastSentSignalRecipients.Contains(wifiComp.signalInConnection))
266 signal.source.LastSentSignalRecipients.Add(wifiComp.signalInConnection);
272 if (signal.source !=
null)
276 if (!signal.source.LastSentSignalRecipients.Contains(receiver))
278 signal.source.LastSentSignalRecipients.Add(receiver);
291 string chatMsg = signal.value;
292 if (sentSignalStrength <= 1.0f)
297 if (
string.IsNullOrEmpty(chatMsg)) {
continue; }
311 if (recipientClient !=
null)
313 GameMain.Server.SendDirectChatMessage(
328 prevSignal = signal.value;
333 if (connection ==
null) {
return; }
335 switch (connection.
Name)
341 if (
int.TryParse(signal.
value, out
int newChannel))
348 item.CreateServerEvent(
this);
354 if (
float.TryParse(signal.
value, NumberStyles.Float, CultureInfo.InvariantCulture, out
float newRange))
364 base.RemoveComponentSpecific();
368 public override XElement
Save(XElement parentElement)
370 var element = base.Save(parentElement);
371 element.Add(
new XAttribute(
"channelmemory",
string.Join(
',', channelMemory)));
static Character? Controlled
int?[] GetAttributeIntArray(string key, int[]? def)
void AddSinglePlayerChatMessage(LocalizedString senderName, LocalizedString text, ChatMessageType messageType, Entity sender)
Adds the message to the single player chatbox.
static GameSession?? GameSession
void ResetCachedVisibleSize()
List< Connection > Connections
Inventory ParentInventory
List< Connection > LastSentSignalRecipients
A list of connections the last signal sent by this item went through
void SendSignal(string signal, string connectionName)
bool IsConnectedToSomething()
Checks if the the connection is connected to a wire or a circuit box connection
The base class for components holding the different functionalities of the item
bool HasRequiredContainedItems(Character user, bool addMessage, LocalizedString msg=null)
void ApplyStatusEffects(ActionType type, float deltaTime, Character character=null, Limb targetLimb=null, Entity useTarget=null, Character user=null, Vector2? worldPosition=null, float afflictionMultiplier=1.0f)
bool CanTransmit(bool ignoreJamming=false)
bool CanTransmit(WifiComponent sender)
override void OnItemLoaded()
Called when all the components of the item have been loaded. Use to initialize connections between co...
override void ReceiveSignal(Signal signal, Connection connection)
int GetChannelMemory(int index)
override void Update(float deltaTime, Camera cam)
override void Load(ContentXElement componentElement, bool usePrefabValues, IdRemap idRemap, bool isItemSwap)
override XElement Save(XElement parentElement)
void TransmitSignal(Signal signal, bool sentFromChat)
bool CanReceive(WifiComponent sender)
override void RemoveComponentSpecific()
float MinChatMessageInterval
bool DiscardDuplicateChatMessages
IEnumerable< WifiComponent > GetReceiversInRange()
Returns the wifi components that can receive signals from this one
WifiComponent(Item item, ContentXElement element)
IEnumerable< WifiComponent > GetTransmittersInRange()
Returns the wifi components that can transmit signals to this one
void SetChannelMemory(int index, int value)
bool AllowCrossTeamCommunication
object Call(string name, params object[] args)
string ApplyDistanceEffect(Character listener)
static ChatMessage Create(string senderName, string text, ChatMessageType type, Entity sender, Client client=null, PlayerConnectionChangeType changeType=PlayerConnectionChangeType.None, Color? textColor=null)
Interface for entities that the server can send events to the clients
ActionType
ActionTypes define when a StatusEffect is executed.