]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
flash uses charges system now (#15898)
authordeltanedas <39013340+deltanedas@users.noreply.github.com>
Sat, 29 Apr 2023 13:38:40 +0000 (13:38 +0000)
committerGitHub <noreply@github.com>
Sat, 29 Apr 2023 13:38:40 +0000 (23:38 +1000)
Co-authored-by: deltanedas <@deltanedas:kde.org>
Content.Server/Flash/Components/FlashComponent.cs
Content.Server/Flash/FlashSystem.cs
Resources/Locale/en-US/flash/components/flash-component.ftl
Resources/Prototypes/Entities/Objects/Tools/lantern.yml
Resources/Prototypes/Entities/Objects/Weapons/security.yml

index 53213f65d86611a28875b2e65e96f3c938e919ac..3f2ca0e3892fb19f5acd11d685d5c07572cb93a3 100644 (file)
@@ -9,10 +9,6 @@ namespace Content.Server.Flash.Components
         [ViewVariables(VVAccess.ReadWrite)]
         public int FlashDuration { get; set; } = 5000;
 
-        [DataField("uses")]
-        [ViewVariables(VVAccess.ReadWrite)]
-        public int Uses { get; set; } = 5;
-
         [DataField("range")]
         [ViewVariables(VVAccess.ReadWrite)]
         public float Range { get; set; } = 7f;
@@ -30,7 +26,5 @@ namespace Content.Server.Flash.Components
         public SoundSpecifier Sound { get; set; } = new SoundPathSpecifier("/Audio/Weapons/flash.ogg");
 
         public bool Flashing;
-
-        public bool HasUses => Uses > 0;
     }
 }
index 40bb9eb6f0997c39f43ab45b319c686a74110434..6cab18daf31c0f2fb5b60b5ead23740d82dba897 100644 (file)
@@ -3,7 +3,8 @@ using Content.Server.Flash.Components;
 using Content.Server.Light.EntitySystems;
 using Content.Server.Popups;
 using Content.Server.Stunnable;
-using Content.Shared.Examine;
+using Content.Shared.Charges.Components;
+using Content.Shared.Charges.Systems;
 using Content.Shared.Eye.Blinding.Components;
 using Content.Shared.Flash;
 using Content.Shared.IdentityManagement;
@@ -25,22 +26,23 @@ namespace Content.Server.Flash
 {
     internal sealed class FlashSystem : SharedFlashSystem
     {
-        [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
-        [Dependency] private readonly IGameTiming _gameTiming = default!;
-        [Dependency] private readonly StunSystem _stunSystem = default!;
-        [Dependency] private readonly InventorySystem _inventorySystem = default!;
+        [Dependency] private readonly AppearanceSystem _appearance = default!;
         [Dependency] private readonly AudioSystem _audio = default!;
-        [Dependency] private readonly SharedInteractionSystem _interactionSystem = default!;
-        [Dependency] private readonly TagSystem _tagSystem = default!;
+        [Dependency] private readonly SharedChargesSystem _charges = default!;
+        [Dependency] private readonly EntityLookupSystem _entityLookup = default!;
+        [Dependency] private readonly IGameTiming _timing = default!;
+        [Dependency] private readonly SharedInteractionSystem _interaction = default!;
+        [Dependency] private readonly InventorySystem _inventory = default!;
         [Dependency] private readonly PopupSystem _popup = default!;
-        [Dependency] private readonly AppearanceSystem _appearance = default!;
+        [Dependency] private readonly StunSystem _stun = default!;
+        [Dependency] private readonly TagSystem _tag = default!;
 
         public override void Initialize()
         {
             base.Initialize();
             SubscribeLocalEvent<FlashComponent, MeleeHitEvent>(OnFlashMeleeHit);
+            // ran before toggling light for extra-bright lantern
             SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnFlashUseInHand, before: new []{ typeof(HandheldLightSystem) });
-            SubscribeLocalEvent<FlashComponent, ExaminedEvent>(OnFlashExamined);
 
             SubscribeLocalEvent<InventoryComponent, FlashAttemptEvent>(OnInventoryFlashAttempt);
 
@@ -76,18 +78,22 @@ namespace Content.Server.Flash
 
         private bool UseFlash(EntityUid uid, FlashComponent comp, EntityUid user)
         {
-            if (!comp.HasUses || comp.Flashing)
+            if (comp.Flashing)
                 return false;
 
-            comp.Uses--;
+            TryComp<LimitedChargesComponent>(uid, out var charges);
+            if (_charges.IsEmpty(uid, charges))
+                return false;
+
+            _charges.UseCharge(uid, charges);
             _audio.PlayPvs(comp.Sound, uid);
             comp.Flashing = true;
             _appearance.SetData(uid, FlashVisuals.Flashing, true);
 
-            if (comp.Uses == 0)
+            if (_charges.IsEmpty(uid, charges))
             {
                 _appearance.SetData(uid, FlashVisuals.Burnt, true);
-                _tagSystem.AddTag(uid, "Trash");
+                _tag.AddTag(uid, "Trash");
                 _popup.PopupEntity(Loc.GetString("flash-component-becomes-empty"), user);
             }
 
@@ -110,11 +116,11 @@ namespace Content.Server.Flash
             if (attempt.Cancelled)
                 return;
 
-            flashable.LastFlash = _gameTiming.CurTime;
+            flashable.LastFlash = _timing.CurTime;
             flashable.Duration = flashDuration / 1000f; // TODO: Make this sane...
             Dirty(flashable);
 
-            _stunSystem.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
+            _stun.TrySlowdown(target, TimeSpan.FromSeconds(flashDuration/1000f), true,
                 slowTo, slowTo);
 
             if (displayPopup && user != null && target != user && EntityManager.EntityExists(user.Value))
@@ -142,7 +148,7 @@ namespace Content.Server.Flash
             foreach (var entity in flashableEntities)
             {
                 // Check for unobstructed entities while ignoring the mobs with flashable components.
-                if (!_interactionSystem.InRangeUnobstructed(entity, mapPosition, range, CollisionGroup.Opaque, (e) => flashableEntities.Contains(e) || e == source))
+                if (!_interaction.InRangeUnobstructed(entity, mapPosition, range, CollisionGroup.Opaque, (e) => flashableEntities.Contains(e) || e == source))
                     continue;
 
                 // They shouldn't have flash removed in between right?
@@ -154,33 +160,13 @@ namespace Content.Server.Flash
             }
         }
 
-        private void OnFlashExamined(EntityUid uid, FlashComponent comp, ExaminedEvent args)
-        {
-            if (!comp.HasUses)
-            {
-                args.PushText(Loc.GetString("flash-component-examine-empty"));
-                return;
-            }
-
-            if (args.IsInDetailsRange)
-            {
-                args.PushMarkup(
-                    Loc.GetString(
-                        "flash-component-examine-detail-count",
-                        ("count", comp.Uses),
-                        ("markupCountColor", "green")
-                    )
-                );
-            }
-        }
-
         private void OnInventoryFlashAttempt(EntityUid uid, InventoryComponent component, FlashAttemptEvent args)
         {
             foreach (var slot in new[] { "head", "eyes", "mask" })
             {
                 if (args.Cancelled)
                     break;
-                if (_inventorySystem.TryGetSlotEntity(uid, slot, out var item, component))
+                if (_inventory.TryGetSlotEntity(uid, slot, out var item, component))
                     RaiseLocalEvent(item.Value, args, true);
             }
         }
index 352077fa0f172feee4cccd40ee68f7960af51f6e..efa44287ebb11522334efd53706574684af0e571 100644 (file)
@@ -1,19 +1,7 @@
-
-### UI
-
-# Shown when an empty flash is examined at any range
-flash-component-examine-empty = It's burnt out!
-
-# Shown when a flash is examined in details range
-flash-component-examine-detail-count = The flash has [color={$markupCountColor}]{$count}[/color] {$count ->
-    [one] use
-    *[other] uses
-} remaining.
-
 ### Interaction Messages
 
 # Shown when someone flashes you with a flash
 flash-component-user-blinds-you = {$user} blinds you with the flash!
 
 # Shown when a flash runs out of uses
-flash-component-becomes-empty = The flash burns out!
\ No newline at end of file
+flash-component-becomes-empty = The flash burns out!
index 2262675d35662a01995181ea809c012dfdeeb045..11cbf0ff65e4c79740d8e878d60590e4db46bb99 100644 (file)
       energy: 10
       color: "#FFC458"
     - type: Flash
-      uses: 15
+    - type: LimitedCharges
+      maxCharges: 15
+      charges: 15
+    - type: MeleeWeapon
+      damage:
+        types:
+          Blunt: 0 # melee weapon to allow flashing individual targets
     - type: Appearance
     - type: GenericVisualizer
       visuals:
index 8e3e333090741d0c926836824df023611012a719..f56fcbef36ae3ac131cd67fff07b00b26e5188e6 100644 (file)
         visible: false
         shader: unshaded
     - type: Flash
+    - type: LimitedCharges
+      maxCharges: 5
+      charges: 5
     - type: MeleeWeapon
       damage:
         types:
-          Blunt: 0 # why is this classed as a melee weapon? Is it needed for some interaction?
+          Blunt: 0 # melee weapon to allow flashing individual targets
       angle: 10
     - type: Item
       size: 5
       radius: 0
       softness: 0
       enabled: true
-