From a0a2e8fabf8b3d58ab59dab609c39759edfc1566 Mon Sep 17 00:00:00 2001 From: Tornado Tech <54727692+Tornado-Technology@users.noreply.github.com> Date: Fri, 3 May 2024 20:27:12 +1000 Subject: [PATCH] =?UTF-8?q?=D0=9D=D1=83=20=D0=BE=D0=BD=D0=BE=20=D1=80?= =?UTF-8?q?=D0=B0=D0=B1=D0=BE=D1=82=D0=B0=D0=B5=D1=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../_CP14/Magic/CPMagicEffectPrototype.cs | 16 +++++ .../Magic/CPMagicSpellContainerComponent.cs | 15 +++++ .../Magic/CPMagicSpellContainerSystem.cs | 64 +++++++++++++++++++ .../MagickSpellContainerComponent.cs | 10 --- .../Container/MagickSpellContainerSystem.cs | 11 ---- Content.Server/_CP14/Magic/MagicSpell.cs | 20 ------ .../_CP14/Magic/MagicSpellContext.cs | 14 ---- .../_CP14/Magic/MagicSpellPrototype.cs | 13 ---- .../_CP14/Magic/MagicSpellSystem.cs | 60 ----------------- .../Magic/Spells/MagicSpellPointRandomMob.cs | 44 ------------- .../MagicSpellSourcePointRandomMob.cs | 12 ---- .../MagicSpellTargetPointRandomMob.cs | 12 ---- .../Prototypes/_CP14/Magic/Effects/light.yml | 13 ++++ Resources/Prototypes/_CP14/Magic/base.yml | 5 ++ Resources/Prototypes/_CP14/Magic/charms.yml | 10 +++ .../_CP14/MagickSpells/source_point.yml | 7 -- 16 files changed, 123 insertions(+), 203 deletions(-) create mode 100644 Content.Server/_CP14/Magic/CPMagicEffectPrototype.cs create mode 100644 Content.Server/_CP14/Magic/CPMagicSpellContainerComponent.cs create mode 100644 Content.Server/_CP14/Magic/CPMagicSpellContainerSystem.cs delete mode 100644 Content.Server/_CP14/Magic/Container/MagickSpellContainerComponent.cs delete mode 100644 Content.Server/_CP14/Magic/Container/MagickSpellContainerSystem.cs delete mode 100644 Content.Server/_CP14/Magic/MagicSpell.cs delete mode 100644 Content.Server/_CP14/Magic/MagicSpellContext.cs delete mode 100644 Content.Server/_CP14/Magic/MagicSpellPrototype.cs delete mode 100644 Content.Server/_CP14/Magic/MagicSpellSystem.cs delete mode 100644 Content.Server/_CP14/Magic/Spells/MagicSpellPointRandomMob.cs delete mode 100644 Content.Server/_CP14/Magic/Spells/SourcePoint/MagicSpellSourcePointRandomMob.cs delete mode 100644 Content.Server/_CP14/Magic/Spells/TargetPoint/MagicSpellTargetPointRandomMob.cs create mode 100644 Resources/Prototypes/_CP14/Magic/Effects/light.yml create mode 100644 Resources/Prototypes/_CP14/Magic/base.yml create mode 100644 Resources/Prototypes/_CP14/Magic/charms.yml delete mode 100644 Resources/Prototypes/_CP14/MagickSpells/source_point.yml diff --git a/Content.Server/_CP14/Magic/CPMagicEffectPrototype.cs b/Content.Server/_CP14/Magic/CPMagicEffectPrototype.cs new file mode 100644 index 0000000000..443956842b --- /dev/null +++ b/Content.Server/_CP14/Magic/CPMagicEffectPrototype.cs @@ -0,0 +1,16 @@ +using Robust.Shared.Prototypes; + +namespace Content.Server._CP14.Magic; + +[Prototype("CPMagicEffect")] +public sealed partial class CPMagicEffectPrototype : IPrototype +{ + [IdDataField] + public string ID { get; } = string.Empty; + + [DataField] + public ComponentRegistry Components = new(); + + [DataField] + public float Complexity = 1f; +} diff --git a/Content.Server/_CP14/Magic/CPMagicSpellContainerComponent.cs b/Content.Server/_CP14/Magic/CPMagicSpellContainerComponent.cs new file mode 100644 index 0000000000..24fb23482d --- /dev/null +++ b/Content.Server/_CP14/Magic/CPMagicSpellContainerComponent.cs @@ -0,0 +1,15 @@ +using Robust.Shared.Prototypes; + +namespace Content.Server._CP14.Magic; + +[RegisterComponent] +public sealed partial class CPMagicSpellContainerComponent : Component +{ + public readonly EntProtoId BaseSpellEffectEntity = "CPBaseSpellEntity"; + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public List> Effects = new(); + + [DataField, ViewVariables(VVAccess.ReadWrite)] + public float MaximumCompleteness = 1f; +} diff --git a/Content.Server/_CP14/Magic/CPMagicSpellContainerSystem.cs b/Content.Server/_CP14/Magic/CPMagicSpellContainerSystem.cs new file mode 100644 index 0000000000..9754ff6131 --- /dev/null +++ b/Content.Server/_CP14/Magic/CPMagicSpellContainerSystem.cs @@ -0,0 +1,64 @@ +using Content.Server.Popups; +using Content.Shared.Verbs; +using Robust.Shared.Prototypes; + +namespace Content.Server._CP14.Magic; + +public sealed class CPMagicSpellContainerSystem : EntitySystem +{ + [Dependency] private readonly IPrototypeManager _prototype = default!; + [Dependency] private readonly PopupSystem _popup = default!; + + public override void Initialize() + { + base.Initialize(); + + SubscribeLocalEvent>(OnGetVerb); + } + + private void OnGetVerb(Entity container, ref GetVerbsEvent args) + { + var user = args.User; + + args.Verbs.Add(new AlternativeVerb + { + Text = "cast", + Disabled = container.Comp.Effects.Count == 0, + Priority = 10, + Act = () => + { + Cast(container, user); + } + }); + } + + public void Cast(Entity container, EntityUid caster) + { + var effectPrototypes = new List(); + var complexity = 0f; + + foreach (var effectId in container.Comp.Effects) + { + if (!_prototype.TryIndex(effectId, out var prototype)) + { + _popup.PopupEntity("Fuck!", container); + return; + } + + complexity += prototype.Complexity; + effectPrototypes.Add(prototype); + } + + if (complexity > container.Comp.MaximumCompleteness) + { + _popup.PopupEntity("Too much complicated", container); + return; + } + + var entity = Spawn(container.Comp.BaseSpellEffectEntity, Transform(container).Coordinates); + foreach (var effect in effectPrototypes) + { + EntityManager.AddComponents(entity, effect.Components); + } + } +} diff --git a/Content.Server/_CP14/Magic/Container/MagickSpellContainerComponent.cs b/Content.Server/_CP14/Magic/Container/MagickSpellContainerComponent.cs deleted file mode 100644 index 5465064be6..0000000000 --- a/Content.Server/_CP14/Magic/Container/MagickSpellContainerComponent.cs +++ /dev/null @@ -1,10 +0,0 @@ -using Robust.Shared.Prototypes; - -namespace Content.Server._CP14.Magic.Container; - -[RegisterComponent] -public sealed partial class MagicSpellContainerComponent : Component -{ - [DataField] - public List> Spells = new(); -} diff --git a/Content.Server/_CP14/Magic/Container/MagickSpellContainerSystem.cs b/Content.Server/_CP14/Magic/Container/MagickSpellContainerSystem.cs deleted file mode 100644 index 228d0464e8..0000000000 --- a/Content.Server/_CP14/Magic/Container/MagickSpellContainerSystem.cs +++ /dev/null @@ -1,11 +0,0 @@ -namespace Content.Server._CP14.Magic.Container; - -public sealed class MagickSpellContainerSystem : EntitySystem -{ - [Dependency] private readonly MagicSpellSystem _magicSpell = default!; - - public void CastSpell(Entity container) - { - _magicSpell.Cast(container, container.Comp.Spells); - } -} diff --git a/Content.Server/_CP14/Magic/MagicSpell.cs b/Content.Server/_CP14/Magic/MagicSpell.cs deleted file mode 100644 index d2e9300e1c..0000000000 --- a/Content.Server/_CP14/Magic/MagicSpell.cs +++ /dev/null @@ -1,20 +0,0 @@ -namespace Content.Server._CP14.Magic; - -[Serializable, DataDefinition] -public abstract partial class MagicSpell -{ - protected readonly IEntityManager EntityManager; - - public MagicSpell() - { - EntityManager = IoCManager.Resolve(); - } - - [DataField] - public virtual int BaseCost { get; set; } = 10; - - public virtual void Modify(MagicSpellContext context) - { - context.Cost += BaseCost; - } -} diff --git a/Content.Server/_CP14/Magic/MagicSpellContext.cs b/Content.Server/_CP14/Magic/MagicSpellContext.cs deleted file mode 100644 index 2299fc4089..0000000000 --- a/Content.Server/_CP14/Magic/MagicSpellContext.cs +++ /dev/null @@ -1,14 +0,0 @@ -using Robust.Shared.Map; - -namespace Content.Server._CP14.Magic; - -public sealed class MagicSpellContext -{ - public EntityUid Caster; - - public MapCoordinates SourcePoint; - public MapCoordinates TargetPoint; - - public int MaxCost = 100; - public int Cost; -} diff --git a/Content.Server/_CP14/Magic/MagicSpellPrototype.cs b/Content.Server/_CP14/Magic/MagicSpellPrototype.cs deleted file mode 100644 index 8945a39a19..0000000000 --- a/Content.Server/_CP14/Magic/MagicSpellPrototype.cs +++ /dev/null @@ -1,13 +0,0 @@ -using Robust.Shared.Prototypes; - -namespace Content.Server._CP14.Magic; - -[Prototype("magicSpell")] -public sealed class MagicSpellPrototype : IPrototype -{ - [IdDataField] - public string ID { get; } = string.Empty; - - [DataField] - public required MagicSpell Action; -} diff --git a/Content.Server/_CP14/Magic/MagicSpellSystem.cs b/Content.Server/_CP14/Magic/MagicSpellSystem.cs deleted file mode 100644 index e8dff1f5b9..0000000000 --- a/Content.Server/_CP14/Magic/MagicSpellSystem.cs +++ /dev/null @@ -1,60 +0,0 @@ -using System.Runtime.CompilerServices; -using Robust.Server.GameObjects; -using Robust.Shared.Prototypes; - -namespace Content.Server._CP14.Magic; - -public sealed class MagicSpellSystem : EntitySystem -{ - [Robust.Shared.IoC.Dependency] private readonly IPrototypeManager _prototype = default!; - [Robust.Shared.IoC.Dependency] private readonly TransformSystem _transform = default!; - - public IReadOnlyDictionary, MagicSpellPrototype> Spells => _spells; - - private readonly Dictionary, MagicSpellPrototype> _spells = new(); - - public override void Initialize() - { - base.Initialize(); - - Enumerate(); - _prototype.PrototypesReloaded += OnProtoReload; - } - - public void Cast(EntityUid caster, IReadOnlyList> spells) - { - var casterPosition = _transform.GetMapCoordinates(caster); - - var context = new MagicSpellContext - { - SourcePoint = casterPosition, - TargetPoint = casterPosition - }; - - foreach (var spellProto in spells) - { - if (!Spells.TryGetValue(spellProto, out var spell)) - continue; - - spell.Action.Modify(context); - } - } - - [MethodImpl(MethodImplOptions.AggressiveInlining)] - private void Enumerate() - { - var prototypes = _prototype.EnumeratePrototypes(); - foreach (var prototype in prototypes) - { - _spells.Add(prototype.ID, prototype); - } - } - - private void OnProtoReload(PrototypesReloadedEventArgs args) - { - if (!args.WasModified()) - return; - - Enumerate(); - } -} diff --git a/Content.Server/_CP14/Magic/Spells/MagicSpellPointRandomMob.cs b/Content.Server/_CP14/Magic/Spells/MagicSpellPointRandomMob.cs deleted file mode 100644 index 2d97e623a8..0000000000 --- a/Content.Server/_CP14/Magic/Spells/MagicSpellPointRandomMob.cs +++ /dev/null @@ -1,44 +0,0 @@ -using Content.Shared.Mobs.Components; -using Robust.Server.GameObjects; -using Robust.Shared.Map; -using Robust.Shared.Random; - -namespace Content.Server._CP14.Magic.Spells; - -[Serializable, DataDefinition] -public abstract partial class MagicSpellPointRandomMob : MagicSpell -{ - private readonly EntityLookupSystem _entityLookupSystem; - private readonly IRobustRandom _random; - private readonly TransformSystem _transform; - - [DataField] - public virtual float Range { get; set; } = 5f; - - [DataField] - public override int BaseCost { get; set; } = 50; - - public MagicSpellPointRandomMob() - { - _entityLookupSystem = EntityManager.System(); - _transform = EntityManager.System(); - - _random = IoCManager.Resolve(); - } - - public override void Modify(MagicSpellContext context) - { - base.Modify(context); - - var targets = _entityLookupSystem.GetEntitiesInRange(context.SourcePoint, Range); - if (targets.Count == 0) - return; - - var target = _random.Pick(targets); - var coordinates = _transform.GetMapCoordinates(target); - - ApplyCoordinates(context, coordinates); - } - - public abstract void ApplyCoordinates(MagicSpellContext context, MapCoordinates coordinates); -} diff --git a/Content.Server/_CP14/Magic/Spells/SourcePoint/MagicSpellSourcePointRandomMob.cs b/Content.Server/_CP14/Magic/Spells/SourcePoint/MagicSpellSourcePointRandomMob.cs deleted file mode 100644 index cc5af26af0..0000000000 --- a/Content.Server/_CP14/Magic/Spells/SourcePoint/MagicSpellSourcePointRandomMob.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Robust.Shared.Map; - -namespace Content.Server._CP14.Magic.Spells.SourcePoint; - -[Serializable, DataDefinition] -public sealed partial class MagicSpellSourcePointRandomMob : MagicSpellPointRandomMob -{ - public override void ApplyCoordinates(MagicSpellContext context, MapCoordinates coordinates) - { - context.SourcePoint = coordinates; - } -} diff --git a/Content.Server/_CP14/Magic/Spells/TargetPoint/MagicSpellTargetPointRandomMob.cs b/Content.Server/_CP14/Magic/Spells/TargetPoint/MagicSpellTargetPointRandomMob.cs deleted file mode 100644 index 2d95eadff1..0000000000 --- a/Content.Server/_CP14/Magic/Spells/TargetPoint/MagicSpellTargetPointRandomMob.cs +++ /dev/null @@ -1,12 +0,0 @@ -using Robust.Shared.Map; - -namespace Content.Server._CP14.Magic.Spells.TargetPoint; - -[Serializable, DataDefinition] -public sealed partial class MagicSpellTargetPointRandomMob : MagicSpellPointRandomMob -{ - public override void ApplyCoordinates(MagicSpellContext context, MapCoordinates coordinates) - { - context.TargetPoint = coordinates; - } -} diff --git a/Resources/Prototypes/_CP14/Magic/Effects/light.yml b/Resources/Prototypes/_CP14/Magic/Effects/light.yml new file mode 100644 index 0000000000..29710bbc6b --- /dev/null +++ b/Resources/Prototypes/_CP14/Magic/Effects/light.yml @@ -0,0 +1,13 @@ +- type: CPMagicEffect + id: CPPointLight + components: + - type: PointLight + radius: 10 + energy: 10 + color: "#ffffff" + +- type: CPMagicEffect + id: CPPaintPointLightRed + components: + - type: PointLight + color: "#ff0000" diff --git a/Resources/Prototypes/_CP14/Magic/base.yml b/Resources/Prototypes/_CP14/Magic/base.yml new file mode 100644 index 0000000000..e78fbd5791 --- /dev/null +++ b/Resources/Prototypes/_CP14/Magic/base.yml @@ -0,0 +1,5 @@ +- type: entity + id: CPBaseSpellEntity + name: magic entity + noSpawn: true + diff --git a/Resources/Prototypes/_CP14/Magic/charms.yml b/Resources/Prototypes/_CP14/Magic/charms.yml new file mode 100644 index 0000000000..1bbc767f49 --- /dev/null +++ b/Resources/Prototypes/_CP14/Magic/charms.yml @@ -0,0 +1,10 @@ +- type: entity + parent: BaseItem + id: CPBaseMagicCharm + name: charm + description: The simplest storage for your spell + components: + - type: CPMagicSpellContainer + effects: + - CPPointLight + - CPPaintPointLightRed \ No newline at end of file diff --git a/Resources/Prototypes/_CP14/MagickSpells/source_point.yml b/Resources/Prototypes/_CP14/MagickSpells/source_point.yml deleted file mode 100644 index 5df3c24b6a..0000000000 --- a/Resources/Prototypes/_CP14/MagickSpells/source_point.yml +++ /dev/null @@ -1,7 +0,0 @@ -- type: magicSpell - id: sourcePointRandomMob - action: - !type:MagicSpellSourcePointRandomMob - range: 5 - baseCost: 25 -