]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
microwave can be turned on with signal (#21138)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Sat, 4 Nov 2023 12:44:59 +0000 (12:44 +0000)
committerGitHub <noreply@github.com>
Sat, 4 Nov 2023 12:44:59 +0000 (15:44 +0300)
* microwave can be turned on with signal

* update prototype

* mapinit

* init for storage

---------

Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/Kitchen/Components/MicrowaveComponent.cs
Content.Server/Kitchen/EntitySystems/MicrowaveSystem.cs
Resources/Prototypes/Entities/Structures/Machines/microwave.yml

index 538a069d16cb8950719788600656f4143182f3de..56ea23e27e6a3e633803906bc8fc970b36f3d625 100644 (file)
@@ -1,4 +1,5 @@
 using Content.Shared.Construction.Prototypes;
+using Content.Shared.DeviceLinking;
 using Robust.Shared.Audio;
 using Robust.Shared.Containers;
 using Robust.Shared.Prototypes;
@@ -37,6 +38,9 @@ namespace Content.Server.Kitchen.Components
         [ViewVariables]
         public bool Broken;
 
+        [DataField, ViewVariables(VVAccess.ReadWrite)]
+        public ProtoId<SinkPortPrototype> OnPort = "On";
+
         /// <summary>
         /// This is a fixed offset of 5.
         /// The cook times for all recipes should be divisible by 5,with a minimum of 1 second.
index 1c8dbfb4df95dbdd2d3a1638440fa88132e62e00..5cee960df884b5daf467a13d4505b520a60d81b6 100644 (file)
@@ -1,9 +1,13 @@
 using System.Linq;
 using Content.Server.Body.Systems;
 using Content.Server.Construction;
+using Content.Server.DeviceLinking.Events;
+using Content.Server.DeviceLinking.Systems;
+using Content.Server.DeviceNetwork;
 using Content.Server.Hands.Systems;
 using Content.Server.Kitchen.Components;
 using Content.Server.Power.Components;
+using Content.Server.Power.EntitySystems;
 using Content.Server.Temperature.Components;
 using Content.Server.Temperature.Systems;
 using Content.Shared.Body.Components;
@@ -33,7 +37,9 @@ namespace Content.Server.Kitchen.EntitySystems
     {
         [Dependency] private readonly BodySystem _bodySystem = default!;
         [Dependency] private readonly ContainerSystem _container = default!;
+        [Dependency] private readonly DeviceLinkSystem _deviceLink = default!;
         [Dependency] private readonly SharedPopupSystem _popupSystem = default!;
+        [Dependency] private readonly PowerReceiverSystem _power = default!;
         [Dependency] private readonly RecipeManager _recipeManager = default!;
         [Dependency] private readonly SharedAppearanceSystem _appearance = default!;
         [Dependency] private readonly SharedAudioSystem _audio = default!;
@@ -49,6 +55,7 @@ namespace Content.Server.Kitchen.EntitySystems
             base.Initialize();
 
             SubscribeLocalEvent<MicrowaveComponent, ComponentInit>(OnInit);
+            SubscribeLocalEvent<MicrowaveComponent, MapInitEvent>(OnMapInit);
             SubscribeLocalEvent<MicrowaveComponent, SolutionChangedEvent>(OnSolutionChange);
             SubscribeLocalEvent<MicrowaveComponent, InteractUsingEvent>(OnInteractUsing, after: new[] { typeof(AnchorableSystem) });
             SubscribeLocalEvent<MicrowaveComponent, BreakageEventArgs>(OnBreak);
@@ -57,6 +64,8 @@ namespace Content.Server.Kitchen.EntitySystems
             SubscribeLocalEvent<MicrowaveComponent, RefreshPartsEvent>(OnRefreshParts);
             SubscribeLocalEvent<MicrowaveComponent, UpgradeExamineEvent>(OnUpgradeExamine);
 
+            SubscribeLocalEvent<MicrowaveComponent, SignalReceivedEvent>(OnSignalReceived);
+
             SubscribeLocalEvent<MicrowaveComponent, MicrowaveStartCookMessage>((u, c, m) => Wzhzhzh(u, c, m.Session.AttachedEntity));
             SubscribeLocalEvent<MicrowaveComponent, MicrowaveEjectMessage>(OnEjectMessage);
             SubscribeLocalEvent<MicrowaveComponent, MicrowaveEjectSolidIndexedMessage>(OnEjectIndex);
@@ -172,9 +181,15 @@ namespace Content.Server.Kitchen.EntitySystems
             }
         }
 
-        private void OnInit(EntityUid uid, MicrowaveComponent component, ComponentInit ags)
+        private void OnInit(Entity<MicrowaveComponent> ent, ref ComponentInit args)
+        {
+            // this really does have to be in ComponentInit
+            ent.Comp.Storage = _container.EnsureContainer<Container>(ent, "microwave_entity_container");
+        }
+
+        private void OnMapInit(Entity<MicrowaveComponent> ent, ref MapInitEvent args)
         {
-            component.Storage = _container.EnsureContainer<Container>(uid, "microwave_entity_container");
+            _deviceLink.EnsureSinkPorts(ent, ent.Comp.OnPort);
         }
 
         private void OnSuicide(EntityUid uid, MicrowaveComponent component, SuicideEvent args)
@@ -277,6 +292,17 @@ namespace Content.Server.Kitchen.EntitySystems
             args.AddPercentageUpgrade("microwave-component-upgrade-cook-time", component.CookTimeMultiplier);
         }
 
+        private void OnSignalReceived(Entity<MicrowaveComponent> ent, ref SignalReceivedEvent args)
+        {
+            if (args.Port != ent.Comp.OnPort)
+                return;
+
+            if (ent.Comp.Broken || !_power.IsPowered(ent))
+                return;
+
+            Wzhzhzh(ent.Owner, ent.Comp, null);
+        }
+
         public void UpdateUserInterfaceState(EntityUid uid, MicrowaveComponent component)
         {
             var ui = _userInterface.GetUiOrNull(uid, MicrowaveUiKey.Key);
index 48ac7c339356c830671b861a3aa353a40a71d968..0a1a6f431f1a4b3e7c3dd85941238f0629df25b3 100644 (file)
           False: { visible: false }
   - type: ActivatableUI
     key: enum.MicrowaveUiKey.Key
+  - type: DeviceLinkSink
+    ports:
+    - On
+  - type: DeviceNetwork
+    deviceNetId: Wireless
+    receiveFrequencyId: BasicDevice
+  - type: WirelessNetworkConnection
+    range: 200
   - type: UserInterface
     interfaces:
     - key: enum.MicrowaveUiKey.Key