]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
Land mine armament (#33883)
authorkaiserbirch <150971100+kaiserbirch@users.noreply.github.com>
Fri, 25 Apr 2025 20:53:50 +0000 (22:53 +0200)
committerGitHub <noreply@github.com>
Fri, 25 Apr 2025 20:53:50 +0000 (16:53 -0400)
* Land Mine is now armable, it will not explode unless armed.

* Land Mine is now armable, it will not explode unless armed.

* Explicitly have Armed as false

* SharedLandMineSystem.cs adds the "Arm"-verb in "Content.Shared" with the Arming logic being implemented in "Content.Server"

* Land Mines now blink only when armed.

* Added prediction components, moved logic to SharedLandMineSystem.cs and inherit it in client content.

* Accessing the datafield directly instead of using methods

* Mines are now armed by default with a unarmed prototype

* Land mine now shows if it is armed when examined and in range.

* Landmine is unarmed by default with an armed variant for mapping purposes.

* Removed properties that were already defined by inheritance.

* Access the bool directly from the component

* Add booleans to change if the Arm-verb is showed and if examining the mine shows the status.

* Added status message for unarmed mine, removed using PushGroup since only one string is displayed.

* Added properties to the explosive floor sign to ensure that it is armed, not showing neither status nor arm-verb.

* The prototypes work now as before with added unarmed versions. Sprite is now only one toggable layer.

* Make the craftable land mine unarmed.

* Refactored the arming mechanic into own component and system.

* Reverted the explosive wet floor sign to previous prototype and added the Armable component and ItemToggle to the landmines.

* Moved the examination strings from land-mines.ftl to armable.ftl.

* Removed unused property.

* Formatting and fixing imports

* Added prefixes to the ftl naming. Moved LocId from system to component

* Added documentation. Moved check for armable to HandleStepTriggerAttempt.
Moved the LocId to component.

* Removed the TryArming method. Added documentation.

* Removed unnecessary TryComp

* Simplified the logic for the trigger attempt

* HasComp instead of TryComp on logic

* EmoGarbage Review

---------

Co-authored-by: Franz - Josef Björck <kaiserbirch@proton.me>
Co-authored-by: EmoGarbage404 <retron404@gmail.com>
Content.Server/LandMines/LandMineComponent.cs [deleted file]
Content.Server/LandMines/LandMineSystem.cs
Content.Shared/Armable/ArmableComponent.cs [new file with mode: 0644]
Content.Shared/Armable/ArmableSystem.cs [new file with mode: 0644]
Content.Shared/Item/ItemToggle/Components/ItemToggleComponent.cs
Content.Shared/Item/ItemToggle/ItemToggleSystem.cs
Content.Shared/LandMines/LandMineComponent.cs [new file with mode: 0644]
Resources/Locale/en-US/armable/armable.ftl [new file with mode: 0644]
Resources/Locale/en-US/land-mines/land-mines.ftl
Resources/Prototypes/Entities/Objects/Misc/land_mine.yml
Resources/Prototypes/Recipes/Construction/Graphs/weapons/modular_mine.yml

diff --git a/Content.Server/LandMines/LandMineComponent.cs b/Content.Server/LandMines/LandMineComponent.cs
deleted file mode 100644 (file)
index 1c4ba06..0000000
+++ /dev/null
@@ -1,13 +0,0 @@
-using Robust.Shared.Audio;
-
-namespace Content.Server.LandMines;
-
-[RegisterComponent]
-public sealed partial class LandMineComponent : Component
-{
-    /// <summary>
-    /// Trigger sound effect when stepping onto landmine
-    /// </summary>
-    [DataField, ViewVariables(VVAccess.ReadWrite)]
-    public SoundSpecifier? Sound;
-}
index 22dedb93375921f8b92762cdc84715bae61ddfe0..57d25ef8ab76c7fac3b130bc4b05729ad8e5bfa4 100644 (file)
@@ -1,7 +1,9 @@
 using Content.Server.Explosion.EntitySystems;
+using Content.Shared.Armable;
+using Content.Shared.Item.ItemToggle.Components;
+using Content.Shared.LandMines;
 using Content.Shared.Popups;
 using Content.Shared.StepTrigger.Systems;
-using Robust.Shared.Audio;
 using Robust.Shared.Audio.Systems;
 
 namespace Content.Server.LandMines;
@@ -14,30 +16,46 @@ public sealed class LandMineSystem : EntitySystem
 
     public override void Initialize()
     {
+        base.Initialize();
+
         SubscribeLocalEvent<LandMineComponent, StepTriggeredOnEvent>(HandleStepOnTriggered);
         SubscribeLocalEvent<LandMineComponent, StepTriggeredOffEvent>(HandleStepOffTriggered);
-
         SubscribeLocalEvent<LandMineComponent, StepTriggerAttemptEvent>(HandleStepTriggerAttempt);
     }
 
+    /// <summary>
+    /// Warns the player when stepped on.
+    /// </summary>
     private void HandleStepOnTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOnEvent args)
     {
-        _popupSystem.PopupCoordinates(
-            Loc.GetString("land-mine-triggered", ("mine", uid)),
-            Transform(uid).Coordinates,
-            args.Tripper,
-            PopupType.LargeCaution);
-
-        _audioSystem.PlayPvs(component.Sound, uid);
+      if (!string.IsNullOrEmpty(component.TriggerText))
+      {
+          _popupSystem.PopupCoordinates(
+              Loc.GetString(component.TriggerText, ("mine", uid)),
+              Transform(uid).Coordinates,
+              args.Tripper,
+              PopupType.LargeCaution);
+      }
+      _audioSystem.PlayPvs(component.Sound, uid);
     }
 
+    /// <summary>
+    /// Sends a trigger when stepped off.
+    /// </summary>
     private void HandleStepOffTriggered(EntityUid uid, LandMineComponent component, ref StepTriggeredOffEvent args)
     {
         _trigger.Trigger(uid, args.Tripper);
     }
 
-    private static void HandleStepTriggerAttempt(EntityUid uid, LandMineComponent component, ref StepTriggerAttemptEvent args)
+    /// <summary>
+    /// Presumes that the landmine isn't armable and should be treated as always armed.
+    /// If Armable and ItemToggle is present the event will continue only if the mine is activated.
+    /// </summary>
+    private void HandleStepTriggerAttempt(EntityUid uid, LandMineComponent component, ref StepTriggerAttemptEvent args)
     {
         args.Continue = true;
+
+        if (HasComp<ArmableComponent>(uid) && TryComp<ItemToggleComponent>(uid, out var itemToggle))
+            args.Continue = itemToggle.Activated;
     }
 }
diff --git a/Content.Shared/Armable/ArmableComponent.cs b/Content.Shared/Armable/ArmableComponent.cs
new file mode 100644 (file)
index 0000000..11809c1
--- /dev/null
@@ -0,0 +1,35 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.Armable;
+
+/// <summary>
+/// Makes an item armable, needs ItemToggleComponent to work.
+/// </summary>
+[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
+[Access(typeof(ArmableSystem))]
+public sealed partial class ArmableComponent : Component
+{
+    /// <summary>
+    /// Does it show its status on examination?
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool ShowStatusOnExamination = true;
+
+    /// <summary>
+    /// Does it change appearance when activated?
+    /// </summary>
+    [DataField, AutoNetworkedField]
+    public bool ChangeAppearance = true;
+
+    /// <summary>
+    /// Text to show on examination when the entity is armed.
+    /// </summary>
+    [DataField]
+    public LocId? ExamineTextArmed = "armable-examine-armed";
+
+    /// <summary>
+    /// Text to show on examination when the entity is not armed
+    /// </summary>
+    [DataField]
+    public LocId? ExamineTextNotArmed ="armable-examine-not-armed";
+}
diff --git a/Content.Shared/Armable/ArmableSystem.cs b/Content.Shared/Armable/ArmableSystem.cs
new file mode 100644 (file)
index 0000000..b0752cc
--- /dev/null
@@ -0,0 +1,54 @@
+using Content.Shared.Examine;
+using Content.Shared.Item.ItemToggle;
+using Content.Shared.Item.ItemToggle.Components;
+
+namespace Content.Shared.Armable;
+
+/// <summary>
+/// When used together with ItemToggle this will make the ItemToggle one way which is then used to represent an armed
+/// state. If ItemComponent.Activated is true then the item is considered to be armed and should be able to be
+/// triggered.
+/// </summary>
+public sealed class ArmableSystem : EntitySystem
+{
+    [Dependency] private readonly ItemToggleSystem _itemToggle = default!;
+
+    public override void Initialize()
+    {
+        base.Initialize();
+
+        SubscribeLocalEvent<ArmableComponent, ExaminedEvent>(OnExamine);
+        SubscribeLocalEvent<ArmableComponent, ItemToggledEvent>(ArmingDone);
+    }
+
+    /// <summary>
+    /// Shows the status of the armable entity on examination.
+    /// </summary>
+    private void OnExamine(EntityUid uid, ArmableComponent comp, ExaminedEvent args)
+    {
+        if (!args.IsInDetailsRange || !comp.ShowStatusOnExamination || !TryComp<ItemToggleComponent>(uid, out var itemToggle))
+            return;
+
+        if (itemToggle.Activated)
+        {
+            if (!string.IsNullOrEmpty(comp.ExamineTextArmed))
+                args.PushMarkup(Loc.GetString(comp.ExamineTextArmed, ("name", uid)));
+        }
+        else
+        {
+            if (!string.IsNullOrEmpty(comp.ExamineTextNotArmed))
+                args.PushMarkup(Loc.GetString(comp.ExamineTextNotArmed,("name", uid)));
+        }
+    }
+
+    /// <summary>
+    /// Changes the appearance and disables the ItemToggleComponent as to not show the deactivate verb.
+    /// Whatever is armed should probably not be trivially disarmed.
+    /// </summary>
+    private void ArmingDone(Entity<ArmableComponent> entity, ref ItemToggledEvent args)
+    {
+        if (!args.Activated)
+            return;
+        _itemToggle.SetOnActivate(entity.Owner, false);
+    }
+}
index cb6470f5d63202acf3bd76e6b06dead9924395e0..424bd12bb3f0a0aca733c11cddb074d1d21c5ae9 100644 (file)
@@ -22,7 +22,7 @@ public sealed partial class ItemToggleComponent : Component
     /// <summary>
     /// Can the entity be activated in the world.
     /// </summary>
-    [DataField]
+    [DataField, AutoNetworkedField]
     public bool OnActivate = true;
 
     /// <summary>
index 819975ecda5e37a4c75ab856990e94b70a03b9eb..2c3e596a275895b6567c04847b3c62b04975e2bc 100644 (file)
@@ -263,6 +263,21 @@ public sealed class ItemToggleSystem : EntitySystem
         RaiseLocalEvent(uid, ref toggleUsed);
     }
 
+    /// <summary>
+    /// Sets if this toggleable item can be activated in world by pressing "e"
+    /// </summary>
+    public void SetOnActivate(Entity<ItemToggleComponent?> ent, bool val)
+    {
+        if (!Resolve(ent, ref ent.Comp))
+            return;
+
+        if (ent.Comp.OnActivate == val)
+            return;
+
+        ent.Comp.OnActivate = val;
+        Dirty(ent);
+    }
+
     private void UpdateVisuals(Entity<ItemToggleComponent> ent)
     {
         if (TryComp(ent, out AppearanceComponent? appearance))
diff --git a/Content.Shared/LandMines/LandMineComponent.cs b/Content.Shared/LandMines/LandMineComponent.cs
new file mode 100644 (file)
index 0000000..1ed8091
--- /dev/null
@@ -0,0 +1,23 @@
+using Robust.Shared.Audio;
+
+namespace Content.Shared.LandMines;
+
+/// <summary>
+/// Give a warning if stepped on and will execute a trigger on step off. When used together with ArmableComponent and
+/// ItemToggleComponent it will only trigger if "ItemToggle.Activated" is true.
+/// </summary>
+[RegisterComponent]
+public sealed partial class LandMineComponent : Component
+{
+    /// <summary>
+    /// The text that popups when the landmine is stepped on.
+    /// </summary>
+    [DataField]
+    public LocId? TriggerText = "land-mine-triggered";
+
+    /// <summary>
+    /// Trigger sound effect when stepping onto landmine
+    /// </summary>
+    [DataField]
+    public SoundSpecifier? Sound;
+}
diff --git a/Resources/Locale/en-US/armable/armable.ftl b/Resources/Locale/en-US/armable/armable.ftl
new file mode 100644 (file)
index 0000000..ebdae76
--- /dev/null
@@ -0,0 +1,2 @@
+armable-examine-armed = {CAPITALIZE(THE($name))} is [color=red]armed[/color].
+armable-examine-not-armed = {CAPITALIZE(THE($name))} needs to be armed.
index b00c9fd2b5d000793c7b80ccd98065e6dc50d642..f6ce2aa1f7f74ec55d18991d0f32739c99d1596b 100644 (file)
@@ -1 +1,2 @@
 land-mine-triggered = You step on the { $mine }!
+land-mine-verb-begin = Arm
index a3e3485bc652ba245c313a3d8cb558a78ccf02a7..08991ec11fa8146388a78dcfe6070262fb04e0ce 100644 (file)
@@ -4,7 +4,11 @@
   components:
   - type: Clickable
   - type: InteractionOutline
-  - type: Anchorable
+  - type: ItemToggle
+    soundActivate:
+      path: /Audio/Weapons/click.ogg
+      params:
+        maxDistance: 1
   - type: Pullable
   - type: MovedByPressure
   - type: Physics
   - type: Sprite
     drawdepth: Items
     sprite: Objects/Misc/landmine.rsi
-    state: landmine
+    layers:
+    - state: landmine-inactive
+      map: [ "enum.ToggleVisuals.Layer" ]
+  - type: Appearance
+  - type: GenericVisualizer
+    visuals:
+      enum.ToggleVisuals.Toggled:
+        enum.ToggleVisuals.Layer:
+          True: {state: landmine}
+          False: {state: landmine-inactive}
   - type: Damageable
     damageContainer: Inorganic
   - type: Destructible
         path: /Audio/Effects/beep_landmine.ogg
         params:
             maxDistance: 10
+  - type: Armable
   - type: StepTrigger
     requiredTriggeredSpeed: 0
     stepOn: true
 
 - type: entity
+  id: LandMineKickUnarmed
   name: kick mine
   parent: BaseLandMine
-  id: LandMineKick
   components:
   - type: GhostKickUserOnTrigger
   - type: DeleteOnTrigger
 
+- type: entity
+  id: LandMineKick
+  suffix: armed
+  parent: LandMineKickUnarmed
+  components:
+  - type: ItemToggle
+    activated: true
+    onActivate: false
+  - type: Armable
+  - type: Sprite
+    layers:
+    - state: landmine
+
 - type: entity
   name: modular mine
   description: This bad boy could be packing any number of dangers. Or a bike horn.
   parent: BaseLandMine
-  id: LandMineModular
+  id: LandMineModularUnarmed
   components:
   - type: PayloadCase
   - type: Construction
     graph: ModularMineGraph
     node: emptyCase
 
+- type: entity
+  id: LandMineModular
+  suffix: armed
+  parent: LandMineModularUnarmed
+  components:
+  - type: ItemToggle
+    activated: true
+    onActivate: false
+  - type: Armable
+  - type: Sprite
+    layers:
+    - state: landmine
+
 - type: entity
   name: explosive mine
   parent: BaseLandMine
-  id: LandMineExplosive
+  id: LandMineExplosiveUnarmed
   components:
   - type: ExplodeOnTrigger
   - type: Explosive
     intensitySlope: 3
     totalIntensity: 120 # about a ~4 tile radius
     canCreateVacuum: false
+
+- type: entity
+  suffix: armed
+  parent: LandMineExplosiveUnarmed
+  id: LandMineExplosive
+  components:
+  - type: ItemToggle
+    activated: true
+    onActivate: false
+  - type: Armable
+  - type: Sprite
+    layers:
+    - state: landmine
index 39272a9b6109e4d166127cccc8263f998423b2d2..b598c01cde769c76fc684f97706cc2218c2222e9 100644 (file)
@@ -12,7 +12,7 @@
         doAfter: 1
 
   - node: emptyCase
-    entity: LandMineModular
+    entity: LandMineModularUnarmed
     edges:
     - to: wiredCase
       steps:
@@ -34,7 +34,7 @@
         doAfter: 2
 
   - node: wiredCase
-    entity: LandMineModular
+    entity: LandMineModularUnarmed
     actions:
     - !type:PlaySound
       sound: /Audio/Machines/button.ogg