]> git.smokeofanarchy.ru Git - space-station-14.git/commitdiff
fix: spellbooks can have infinite charges (#38376)
authorPerry Fraser <perryprog@users.noreply.github.com>
Sat, 5 Jul 2025 06:28:56 +0000 (02:28 -0400)
committerGitHub <noreply@github.com>
Sat, 5 Jul 2025 06:28:56 +0000 (23:28 -0700)
* fix: spellbooks can have infinite charges

* refactor: indicate infinite spellbook charges with null

Not sure if I like this much better...

Content.Shared/Magic/Components/SpellbookComponent.cs
Content.Shared/Magic/SpellbookSystem.cs
Resources/Prototypes/Entities/Objects/Magic/books.yml

index f1b307c245d89ade43a6bc727916656962e86323..69c2bac2a43147d2f53d8937d9b320255d1e5a08 100644 (file)
@@ -16,12 +16,14 @@ public sealed partial class SpellbookComponent : Component
     [ViewVariables]
     public readonly List<EntityUid> Spells = new();
 
+    // The three fields below are just used for initialization.
     /// <summary>
-    /// The three fields below is just used for initialization.
+    /// Dictionary of spell prototypes to charge counts.
+    /// If the charge count is null, it means the spell has infinite charges.
     /// </summary>
     [DataField]
     [ViewVariables(VVAccess.ReadWrite)]
-    public Dictionary<EntProtoId, int> SpellActions = new();
+    public Dictionary<EntProtoId, int?> SpellActions = new();
 
     [DataField]
     [ViewVariables(VVAccess.ReadWrite)]
index 6ef0a10b0cd2154516dcaadb03aeccff5c3c3d60..ca01819bce5183df35fbcb9c4e64c446730864dd 100644 (file)
@@ -33,7 +33,9 @@ public sealed class SpellbookSystem : EntitySystem
             if (spell == null)
                 continue;
 
-            _sharedCharges.SetCharges(spell.Value, charges);
+            // Null means infinite charges.
+            if (charges is { } count)
+                _sharedCharges.SetCharges(spell.Value, count);
             ent.Comp.Spells.Add(spell.Value);
         }
     }
@@ -73,8 +75,9 @@ public sealed class SpellbookSystem : EntitySystem
             foreach (var (id, charges) in ent.Comp.SpellActions)
             {
                 EntityUid? actionId = null;
-                if (_actions.AddAction(args.Args.User, ref actionId, id))
-                    _sharedCharges.SetCharges(actionId.Value, charges);
+                if (_actions.AddAction(args.Args.User, ref actionId, id)
+                    && charges is { } count) // Null means infinite charges
+                    _sharedCharges.SetCharges(actionId.Value, count);
             }
         }
 
index db604f92d39198e551b98cb74172a484d1e11066..db0d3c8d51dc2b080fe1598d8ae07c9269e5532c 100644 (file)
@@ -69,7 +69,7 @@
   components:
     - type: Spellbook
       spellActions:
-        ActionSpawnMagicarpSpell: -1
+        ActionSpawnMagicarpSpell: null
 
 - type: entity
   id: ForceWallSpellbook
@@ -92,7 +92,7 @@
         color: gold
     - type: Spellbook
       spellActions:
-        ActionForceWall: -1
+        ActionForceWall: null
 
 - type: entity
   id: BlinkBook
         color: gold
     - type: Spellbook
       spellActions:
-        ActionBlink: -1
+        ActionBlink: null
 
 - type: entity
   id: SmiteBook
       - state: overlay_blood
     - type: Spellbook
       spellActions:
-        ActionSmiteNoReq: -1
+        ActionSmiteNoReq: null
 
 - type: entity
   id: KnockSpellbook
         color: "#98c495"
     - type: Spellbook
       spellActions:
-        ActionKnock: -1
+        ActionKnock: null
 
 - type: entity
   id: FireballSpellbook
         shader: unshaded
     - type: Spellbook
       spellActions:
-        ActionFireball: -1
+        ActionFireball: null
 
 - type: entity
   id: ScrollRunes
     - state: spell_default
   - type: Spellbook
     spellActions:
-      ActionFlashRune: -1
-      ActionExplosionRune: -1
-      ActionIgniteRune: -1
-      ActionStunRune: -1
+      ActionFlashRune: null
+      ActionExplosionRune: null
+      ActionIgniteRune: null
+      ActionStunRune: null