3 using Microsoft.Xna.Framework;
4 using System.Collections.Generic;
12 const int MaxConnectionCount = 256;
13 public readonly List<Connection>
Connections =
new List<Connection>();
22 private List<ushort> disconnectedWireIds;
59 get {
return base.IsActive; }
71 foreach (var subElement
in element.Elements())
75 DebugConsole.ThrowError($
"Too many connections in the item {item.Prefab.Identifier} (> {MaxConnectionCount}).");
78 switch (subElement.Name.ToString())
93 partial
void InitProjSpecific();
95 private bool linksInitialized;
98 if (linksInitialized) {
return; }
109 if (disconnectedWireIds !=
null)
111 foreach (ushort disconnectedWireId
in disconnectedWireIds)
114 Wire wire = wireItem.GetComponent<
Wire>();
124 base.IsActive =
true;
129 linksInitialized =
true;
137 if (holdable ==
null || !holdable.Attachable)
139 DebugConsole.ThrowError(
"Item \"" +
item.
Name +
"\" has a ConnectionPanel component," +
140 " but cannot be wired because it has an active physics body that cannot be attached to a wall." +
141 " Remove the physics body or add a Holdable component with the Attachable attribute set to true.");
153 if (wire ==
null) {
continue; }
163 void TryMoveWire(
Wire wire)
169 if (wireNodes.Count == 0) {
return; }
177 wire.
MoveNode(wireNodes.Count - 1, amount);
184 UpdateProjSpecific(deltaTime);
189 if (user !=
null) {
item.CreateServerEvent(
this); }
199 base.IsActive =
false;
211 partial
void UpdateProjSpecific(
float deltaTime);
237 if (user !=
null) {
item.CreateServerEvent(
this); }
239 base.IsActive =
true;
245 if (character ==
null || character != user) {
return false; }
254 if (character ==
null) {
return false; }
262 if (MathUtils.NearlyEqual(reactor.CurrPowerConsumption, 0.0f)) {
return true; }
265 if (powerContainer !=
null)
269 if (powerContainer.Charge <= 0.0f) {
return true; }
272 if (powered !=
null && powerContainer ==
null)
275 if (powered.Voltage < 0.1f) {
return true; }
279 if (Rand.Range(0.0f, 0.5f) < degreeOfSuccess) {
return true; }
287 base.Load(element, usePrefabValues, idRemap, isItemSwap);
289 List<Connection> loadedConnections =
new List<Connection>();
291 foreach (var subElement
in element.Elements())
293 switch (subElement.Name.ToString())
296 loadedConnections.Add(
new Connection(subElement,
this, idRemap));
299 loadedConnections.Add(
new Connection(subElement,
this, idRemap));
304 for (
int i = 0; i < loadedConnections.Count && i <
Connections.Count; i++)
307 Connections[i].LoadedWires.AddRange(loadedConnections[i].LoadedWires);
310 disconnectedWireIds = element.GetAttributeUshortArray(
"disconnectedwires", Array.Empty<ushort>()).ToList();
311 for (
int i = 0; i < disconnectedWireIds.Count; i++)
313 disconnectedWireIds[i] = idRemap.GetOffsetId(disconnectedWireIds[i]);
317 public override XElement
Save(XElement parentElement)
319 XElement componentElement = base.Save(parentElement);
323 c.
Save(componentElement);
328 componentElement.Add(
new XAttribute(
"disconnectedwires",
string.Join(
",",
DisconnectedWires.Select(w => w.Item.ID))));
331 return componentElement;
341 base.RemoveComponentSpecific();
344 if (wire.OtherConnection(
null) ==
null)
353 wire.Item.Drop(
null);
356 wire.Item.Drop(
null);
391 connection.Recipients.Clear();
396 rewireSoundChannel?.FadeOutAndDispose();
397 rewireSoundChannel =
null;
415 msg.WriteVariableUInt32((uint)connection.Wires.Count);
416 foreach (
Wire wire
in connection.Wires)
418 msg.WriteUInt16(wire?.
Item ==
null ? (ushort)0 : wire.
Item.
ID);
425 msg.WriteUInt16(disconnectedWire.
Item.
ID);
void UpdateUseItem(bool allowMovement, Vector2 handWorldPos)
Item????????? SelectedItem
The primary selected item. It can be any device that character interacts with. This excludes items li...
Item SelectedSecondaryItem
The secondary selected item. It's an item other than a device (see SelectedItem), e....
readonly AnimController AnimController
readonly ushort ID
Unique, but non-persistent identifier. Stays the same if the entities are created in the exactly same...
static Entity FindEntityByID(ushort ID)
Find an entity based on the ID
static SubEditorScreen SubEditorScreen
static readonly IdRemap DiscardId
void Drop(Character dropper, bool createNetworkEvent=true, bool setTransform=true)
override string Name
Note that this is not a LocalizedString instance, just the current name of the item as a string....
static readonly List< Item > ItemList
IReadOnlyCollection< Wire > Wires
void Save(XElement parentElement)
void InitializeFromLoaded()
override void OnItemLoaded()
Called when all the components of the item have been loaded. Use to initialize connections between co...
readonly List< Connection > Connections
override bool Select(Character picker)
readonly HashSet< Wire > DisconnectedWires
Wires that have been disconnected from the panel, but not removed completely (visible at the bottom o...
void MoveConnectedWires(Vector2 amount)
bool??? TemporarilyLocked
override void OnMapLoaded()
Called when all items have been loaded. Use to initialize connections between items.
bool AlwaysAllowRewiring
Allows rewiring the connection panel despite rewiring being disabled on a server
void TriggerRewiringSound()
override void Load(ContentXElement element, bool usePrefabValues, IdRemap idRemap, bool isItemSwap)
bool CheckCharacterSuccess(Character character)
Check if the character manages to succesfully rewire the panel, and if not, apply OnFailure effects
override bool Use(float deltaTime, Character character=null)
void ClientEventWrite(IWriteMessage msg, NetEntityEvent.IData extraData=null)
override void Update(float deltaTime, Camera cam)
override void RemoveComponentSpecific()
override void ReceiveSignal(Signal signal, Connection connection)
ConnectionPanel(Item item, ContentXElement element)
override XElement Save(XElement parentElement)
override void ShallowRemoveComponentSpecific()
override void UpdateBroken(float deltaTime, Camera cam)
The base class for components holding the different functionalities of the item
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)
virtual bool HasRequiredItems(Character character, bool addMessage, LocalizedString msg=null)
float DegreeOfSuccess(Character character)
Returns 0.0f-1.0f based on how well the Character can use the itemcomponent
static readonly HashSet< Connection > ChangedConnections
List< Vector2 > GetNodes()
void RemoveConnection(Item item)
void MoveNode(int index, Vector2 amount)
Connection OtherConnection(Connection connection)
static bool IsLoadedOutpost
Is there a loaded level set and is it an outpost?
static bool IsSubEditor()
static bool RectContains(Rectangle rect, Vector2 pos, bool inclusive=false)
Vector2 HiddenSubPosition
Interface for entities that the clients can send events to the server
Interface for entities that the server can send events to the clients
ActionType
ActionTypes define when a StatusEffect is executed.