fix: spellbooks can have infinite charges (#38376)

* fix: spellbooks can have infinite charges

* refactor: indicate infinite spellbook charges with null

Not sure if I like this much better...
This commit is contained in:
Perry Fraser
2025-07-05 02:28:56 -04:00
committed by GitHub
parent 78e8d98137
commit 6cefc412a3
3 changed files with 20 additions and 15 deletions

View File

@@ -16,12 +16,14 @@ public sealed partial class SpellbookComponent : Component
[ViewVariables] [ViewVariables]
public readonly List<EntityUid> Spells = new(); public readonly List<EntityUid> Spells = new();
// The three fields below are just used for initialization.
/// <summary> /// <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> /// </summary>
[DataField] [DataField]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]
public Dictionary<EntProtoId, int> SpellActions = new(); public Dictionary<EntProtoId, int?> SpellActions = new();
[DataField] [DataField]
[ViewVariables(VVAccess.ReadWrite)] [ViewVariables(VVAccess.ReadWrite)]

View File

@@ -33,7 +33,9 @@ public sealed class SpellbookSystem : EntitySystem
if (spell == null) if (spell == null)
continue; 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); ent.Comp.Spells.Add(spell.Value);
} }
} }
@@ -73,8 +75,9 @@ public sealed class SpellbookSystem : EntitySystem
foreach (var (id, charges) in ent.Comp.SpellActions) foreach (var (id, charges) in ent.Comp.SpellActions)
{ {
EntityUid? actionId = null; EntityUid? actionId = null;
if (_actions.AddAction(args.Args.User, ref actionId, id)) if (_actions.AddAction(args.Args.User, ref actionId, id)
_sharedCharges.SetCharges(actionId.Value, charges); && charges is { } count) // Null means infinite charges
_sharedCharges.SetCharges(actionId.Value, count);
} }
} }

View File

@@ -69,7 +69,7 @@
components: components:
- type: Spellbook - type: Spellbook
spellActions: spellActions:
ActionSpawnMagicarpSpell: -1 ActionSpawnMagicarpSpell: null
- type: entity - type: entity
id: ForceWallSpellbook id: ForceWallSpellbook
@@ -92,7 +92,7 @@
color: gold color: gold
- type: Spellbook - type: Spellbook
spellActions: spellActions:
ActionForceWall: -1 ActionForceWall: null
- type: entity - type: entity
id: BlinkBook id: BlinkBook
@@ -113,7 +113,7 @@
color: gold color: gold
- type: Spellbook - type: Spellbook
spellActions: spellActions:
ActionBlink: -1 ActionBlink: null
- type: entity - type: entity
id: SmiteBook id: SmiteBook
@@ -136,7 +136,7 @@
- state: overlay_blood - state: overlay_blood
- type: Spellbook - type: Spellbook
spellActions: spellActions:
ActionSmiteNoReq: -1 ActionSmiteNoReq: null
- type: entity - type: entity
id: KnockSpellbook id: KnockSpellbook
@@ -158,7 +158,7 @@
color: "#98c495" color: "#98c495"
- type: Spellbook - type: Spellbook
spellActions: spellActions:
ActionKnock: -1 ActionKnock: null
- type: entity - type: entity
id: FireballSpellbook id: FireballSpellbook
@@ -182,7 +182,7 @@
shader: unshaded shader: unshaded
- type: Spellbook - type: Spellbook
spellActions: spellActions:
ActionFireball: -1 ActionFireball: null
- type: entity - type: entity
id: ScrollRunes id: ScrollRunes
@@ -197,7 +197,7 @@
- state: spell_default - state: spell_default
- type: Spellbook - type: Spellbook
spellActions: spellActions:
ActionFlashRune: -1 ActionFlashRune: null
ActionExplosionRune: -1 ActionExplosionRune: null
ActionIgniteRune: -1 ActionIgniteRune: null
ActionStunRune: -1 ActionStunRune: null