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:
@@ -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)]
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user