Refactor actions to be entities with components (#19900)
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
|
||||
|
||||
namespace Content.Server.Magic.Components;
|
||||
@@ -13,22 +13,14 @@ public sealed partial class SpellbookComponent : Component
|
||||
/// List of spells that this book has. This is a combination of the WorldSpells, EntitySpells, and InstantSpells.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public readonly List<ActionType> Spells = new();
|
||||
public readonly List<EntityUid> Spells = new();
|
||||
|
||||
/// <summary>
|
||||
/// The three fields below is just used for initialization.
|
||||
/// </summary>
|
||||
[DataField("worldSpells", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, WorldTargetActionPrototype>))]
|
||||
[DataField("spells", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, EntityPrototype>))]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Dictionary<string, int> WorldSpells = new();
|
||||
|
||||
[DataField("entitySpells", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, EntityTargetActionPrototype>))]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Dictionary<string, int> EntitySpells = new();
|
||||
|
||||
[DataField("instantSpells", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<int, InstantActionPrototype>))]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public Dictionary<string, int> InstantSpells = new();
|
||||
public Dictionary<string, int> SpellActions = new();
|
||||
|
||||
[DataField("learnTime")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
|
||||
@@ -1,24 +0,0 @@
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Magic.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Spell that uses the magic of ECS to add & remove components. Components are first removed, then added.
|
||||
/// </summary>
|
||||
public sealed partial class ChangeComponentsSpellEvent : EntityTargetActionEvent, ISpeakSpell
|
||||
{
|
||||
// TODO allow it to set component data-fields?
|
||||
// for now a Hackish way to do that is to remove & add, but that doesn't allow you to selectively set specific data fields.
|
||||
|
||||
[DataField("toAdd")]
|
||||
[AlwaysPushInheritance]
|
||||
public ComponentRegistry ToAdd = new();
|
||||
|
||||
[DataField("toRemove")]
|
||||
[AlwaysPushInheritance]
|
||||
public HashSet<string> ToRemove = new();
|
||||
|
||||
[DataField("speech")]
|
||||
public string? Speech { get; private set; }
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
namespace Content.Server.Magic.Events;
|
||||
|
||||
public interface ISpeakSpell // The speak n spell interface
|
||||
{
|
||||
/// <summary>
|
||||
/// Localized string spoken by the caster when casting this spell.
|
||||
/// </summary>
|
||||
public string? Speech { get; }
|
||||
}
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Magic.Events;
|
||||
|
||||
public sealed partial class InstantSpawnSpellEvent : InstantActionEvent, ISpeakSpell
|
||||
{
|
||||
/// <summary>
|
||||
/// What entity should be spawned.
|
||||
/// </summary>
|
||||
[DataField("prototype", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string Prototype = default!;
|
||||
|
||||
[DataField("preventCollide")]
|
||||
public bool PreventCollideWithCaster = true;
|
||||
|
||||
[DataField("speech")]
|
||||
public string? Speech { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the targeted spawn positons; may lead to multiple entities being spawned.
|
||||
/// </summary>
|
||||
[DataField("posData")] public MagicSpawnData Pos = new TargetCasterPos();
|
||||
}
|
||||
|
||||
[ImplicitDataDefinitionForInheritors]
|
||||
public abstract partial class MagicSpawnData
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Spawns 1 at the caster's feet.
|
||||
/// </summary>
|
||||
public sealed partial class TargetCasterPos : MagicSpawnData {}
|
||||
|
||||
/// <summary>
|
||||
/// Targets the 3 tiles in front of the caster.
|
||||
/// </summary>
|
||||
public sealed partial class TargetInFront : MagicSpawnData
|
||||
{
|
||||
[DataField("width")]
|
||||
public int Width = 3;
|
||||
}
|
||||
@@ -1,26 +0,0 @@
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Magic.Events;
|
||||
|
||||
public sealed partial class KnockSpellEvent : InstantActionEvent, ISpeakSpell
|
||||
{
|
||||
/// <summary>
|
||||
/// The range this spell opens doors in
|
||||
/// 4f is the default
|
||||
/// </summary>
|
||||
[DataField("range")]
|
||||
public float Range = 4f;
|
||||
|
||||
[DataField("knockSound")]
|
||||
public SoundSpecifier KnockSound = new SoundPathSpecifier("/Audio/Magic/knock.ogg");
|
||||
|
||||
/// <summary>
|
||||
/// Volume control for the spell.
|
||||
/// </summary>
|
||||
[DataField("knockVolume")]
|
||||
public float KnockVolume = 5f;
|
||||
|
||||
[DataField("speech")]
|
||||
public string? Speech { get; private set; }
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Magic.Events;
|
||||
|
||||
public sealed partial class ProjectileSpellEvent : WorldTargetActionEvent, ISpeakSpell
|
||||
{
|
||||
/// <summary>
|
||||
/// What entity should be spawned.
|
||||
/// </summary>
|
||||
[DataField("prototype", required: true, customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string Prototype = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the targeted spawn positions; may lead to multiple entities being spawned.
|
||||
/// </summary>
|
||||
[DataField("posData")] public MagicSpawnData Pos = new TargetCasterPos();
|
||||
|
||||
[DataField("speech")]
|
||||
public string? Speech { get; private set; }
|
||||
}
|
||||
@@ -1,15 +0,0 @@
|
||||
using Content.Shared.Actions;
|
||||
|
||||
namespace Content.Server.Magic.Events;
|
||||
|
||||
public sealed partial class SmiteSpellEvent : EntityTargetActionEvent, ISpeakSpell
|
||||
{
|
||||
/// <summary>
|
||||
/// Should this smite delete all parts/mechanisms gibbed except for the brain?
|
||||
/// </summary>
|
||||
[DataField("deleteNonBrainParts")]
|
||||
public bool DeleteNonBrainParts = true;
|
||||
|
||||
[DataField("speech")]
|
||||
public string? Speech { get; private set; }
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
using Content.Shared.Actions;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Magic.Events;
|
||||
|
||||
public sealed partial class TeleportSpellEvent : WorldTargetActionEvent, ISpeakSpell
|
||||
{
|
||||
[DataField("blinkSound")]
|
||||
public SoundSpecifier BlinkSound = new SoundPathSpecifier("/Audio/Magic/blink.ogg");
|
||||
|
||||
[DataField("speech")]
|
||||
public string? Speech { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Volume control for the spell.
|
||||
/// </summary>
|
||||
[DataField("blinkVolume")]
|
||||
public float BlinkVolume = 5f;
|
||||
}
|
||||
@@ -1,33 +0,0 @@
|
||||
using System.Numerics;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Server.Magic.Events;
|
||||
|
||||
public sealed partial class WorldSpawnSpellEvent : WorldTargetActionEvent, ISpeakSpell
|
||||
{
|
||||
// TODO:This class needs combining with InstantSpawnSpellEvent
|
||||
|
||||
/// <summary>
|
||||
/// The list of prototypes this spell will spawn
|
||||
/// </summary>
|
||||
[DataField("prototypes")]
|
||||
public List<EntitySpawnEntry> Contents = new();
|
||||
|
||||
// TODO: This offset is liable for deprecation.
|
||||
/// <summary>
|
||||
/// The offset the prototypes will spawn in on relative to the one prior.
|
||||
/// Set to 0,0 to have them spawn on the same tile.
|
||||
/// </summary>
|
||||
[DataField("offset")]
|
||||
public Vector2 Offset;
|
||||
|
||||
/// <summary>
|
||||
/// Lifetime to set for the entities to self delete
|
||||
/// </summary>
|
||||
[DataField("lifetime")] public float? Lifetime;
|
||||
|
||||
[DataField("speech")]
|
||||
public string? Speech { get; private set; }
|
||||
}
|
||||
|
||||
@@ -4,10 +4,8 @@ using Content.Server.Body.Systems;
|
||||
using Content.Server.Chat.Systems;
|
||||
using Content.Server.Doors.Systems;
|
||||
using Content.Server.Magic.Components;
|
||||
using Content.Server.Magic.Events;
|
||||
using Content.Server.Weapons.Ranged.Systems;
|
||||
using Content.Shared.Actions;
|
||||
using Content.Shared.Actions.ActionTypes;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Coordinates.Helpers;
|
||||
using Content.Shared.DoAfter;
|
||||
@@ -15,6 +13,7 @@ using Content.Shared.Doors.Components;
|
||||
using Content.Shared.Doors.Systems;
|
||||
using Content.Shared.Interaction.Events;
|
||||
using Content.Shared.Magic;
|
||||
using Content.Shared.Magic.Events;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Spawners.Components;
|
||||
@@ -22,11 +21,8 @@ using Content.Shared.Storage;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Manager.Exceptions;
|
||||
|
||||
namespace Content.Server.Magic;
|
||||
|
||||
@@ -38,7 +34,6 @@ public sealed class MagicSystem : EntitySystem
|
||||
[Dependency] private readonly ISerializationManager _seriMan = default!;
|
||||
[Dependency] private readonly IComponentFactory _compFact = default!;
|
||||
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly DoorBoltSystem _boltsSystem = default!;
|
||||
[Dependency] private readonly BodySystem _bodySystem = default!;
|
||||
@@ -81,23 +76,9 @@ public sealed class MagicSystem : EntitySystem
|
||||
private void OnInit(EntityUid uid, SpellbookComponent component, ComponentInit args)
|
||||
{
|
||||
//Negative charges means the spell can be used without it running out.
|
||||
foreach (var (id, charges) in component.WorldSpells)
|
||||
foreach (var (id, charges) in component.SpellActions)
|
||||
{
|
||||
var spell = new WorldTargetAction(_prototypeManager.Index<WorldTargetActionPrototype>(id));
|
||||
_actionsSystem.SetCharges(spell, charges < 0 ? null : charges);
|
||||
component.Spells.Add(spell);
|
||||
}
|
||||
|
||||
foreach (var (id, charges) in component.InstantSpells)
|
||||
{
|
||||
var spell = new InstantAction(_prototypeManager.Index<InstantActionPrototype>(id));
|
||||
_actionsSystem.SetCharges(spell, charges < 0 ? null : charges);
|
||||
component.Spells.Add(spell);
|
||||
}
|
||||
|
||||
foreach (var (id, charges) in component.EntitySpells)
|
||||
{
|
||||
var spell = new EntityTargetAction(_prototypeManager.Index<EntityTargetActionPrototype>(id));
|
||||
var spell = Spawn(id);
|
||||
_actionsSystem.SetCharges(spell, charges < 0 ? null : charges);
|
||||
component.Spells.Add(spell);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user