Files
tbd-station-14/Content.Server/DeviceNetwork/Systems/WirelessNetworkSystem.cs
Julian Giebel a6f2c21919 Device network as ecs (#4205)
* Work on DeviceNetworkSystem

* Implement device networking as ecs
Remove mailing unit code for now
Remove device network metadata

* Implement integration tests for device networking

* Remove manual updating DeviceNetworkSystem and use WaitRunTicks

* Fix wrong component name in ignored components

* Apply suggestions from code review

Co-authored-by: mirrorcult <notzombiedude@gmail.com>

* Rename NetworkUtils to DeviceNetworkConstants
Change connection type constants to enum
Remove create function from network payload class

* Change broken nodegroup check in wirenet to grid check

* Change ComponentManager to entity manager in DeviceNetworkSystem

* Fix smaller mistakes

* Wtf random test fail pls run them again smh

* Fix DataField in DeviceNetworkComponent

* Fix yaml in DeviceNetworkTest

* Fix DeviceNetworkComponent DeviceNetId property

Co-authored-by: Julian Giebel <j.giebel@netrocks.info>
Co-authored-by: mirrorcult <notzombiedude@gmail.com>
2021-10-11 14:41:18 -07:00

34 lines
1.2 KiB
C#

using Content.Server.DeviceNetwork.Components;
using JetBrains.Annotations;
using Robust.Shared.GameObjects;
namespace Content.Server.DeviceNetwork.Systems
{
[UsedImplicitly]
public class WirelessNetworkSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<WirelessNetworkComponent, BeforePacketSentEvent>(OnBeforePacketSent);
}
/// <summary>
/// Gets the position of both the sending and receiving entity and checks if the receiver is in range of the sender.
/// </summary>
private void OnBeforePacketSent(EntityUid uid, WirelessNetworkComponent component, BeforePacketSentEvent args)
{
var sender = EntityManager.GetEntity(args.Sender);
var ownPosition = component.Owner.Transform.WorldPosition;
var position = sender.Transform.WorldPosition;
var distance = (ownPosition - position).Length;
if(sender.TryGetComponent<WirelessNetworkComponent>(out var sendingComponent) && distance > sendingComponent.Range)
{
args.Cancel();
}
}
}
}