Добавил немного базы для заклинаний (Она не работает)
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server._CP14.Magic.Container;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed partial class MagicSpellContainerComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public List<ProtoId<MagicSpellPrototype>> Spells = new();
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
namespace Content.Server._CP14.Magic.Container;
|
||||
|
||||
public sealed class MagickSpellContainerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly MagicSpellSystem _magicSpell = default!;
|
||||
|
||||
public void CastSpell(Entity<MagicSpellContainerComponent> container)
|
||||
{
|
||||
_magicSpell.Cast(container, container.Comp.Spells);
|
||||
}
|
||||
}
|
||||
20
Content.Server/_CP14/Magic/MagicSpell.cs
Normal file
20
Content.Server/_CP14/Magic/MagicSpell.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Content.Server._CP14.Magic;
|
||||
|
||||
[Serializable, DataDefinition]
|
||||
public abstract class MagicSpell
|
||||
{
|
||||
protected readonly IEntityManager EntityManager;
|
||||
|
||||
public MagicSpell()
|
||||
{
|
||||
EntityManager = IoCManager.Resolve<IEntityManager>();
|
||||
}
|
||||
|
||||
[DataField]
|
||||
public virtual int BaseCost { get; set; } = 10;
|
||||
|
||||
public virtual void Modify(MagicSpellContext context)
|
||||
{
|
||||
context.Cost += BaseCost;
|
||||
}
|
||||
}
|
||||
14
Content.Server/_CP14/Magic/MagicSpellContext.cs
Normal file
14
Content.Server/_CP14/Magic/MagicSpellContext.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
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;
|
||||
}
|
||||
13
Content.Server/_CP14/Magic/MagicSpellPrototype.cs
Normal file
13
Content.Server/_CP14/Magic/MagicSpellPrototype.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
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;
|
||||
}
|
||||
60
Content.Server/_CP14/Magic/MagicSpellSystem.cs
Normal file
60
Content.Server/_CP14/Magic/MagicSpellSystem.cs
Normal file
@@ -0,0 +1,60 @@
|
||||
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<ProtoId<MagicSpellPrototype>, MagicSpellPrototype> Spells => _spells;
|
||||
|
||||
private readonly Dictionary<ProtoId<MagicSpellPrototype>, MagicSpellPrototype> _spells = new();
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
Enumerate();
|
||||
_prototype.PrototypesReloaded += OnProtoReload;
|
||||
}
|
||||
|
||||
public void Cast(EntityUid caster, IReadOnlyList<ProtoId<MagicSpellPrototype>> 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<MagicSpellPrototype>();
|
||||
foreach (var prototype in prototypes)
|
||||
{
|
||||
_spells.Add(prototype.ID, prototype);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnProtoReload(PrototypesReloadedEventArgs args)
|
||||
{
|
||||
if (!args.WasModified<MagicSpellPrototype>())
|
||||
return;
|
||||
|
||||
Enumerate();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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 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<EntityLookupSystem>();
|
||||
_transform = EntityManager.System<TransformSystem>();
|
||||
|
||||
_random = IoCManager.Resolve<IRobustRandom>();
|
||||
}
|
||||
|
||||
public override void Modify(MagicSpellContext context)
|
||||
{
|
||||
base.Modify(context);
|
||||
|
||||
var targets = _entityLookupSystem.GetEntitiesInRange<MobStateComponent>(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);
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server._CP14.Magic.Spells.TargetPoint;
|
||||
|
||||
[Serializable, DataDefinition]
|
||||
public sealed class MagicSpellTargetPointRandomMob : MagicSpellPointRandomMob
|
||||
{
|
||||
public override void ApplyCoordinates(MagicSpellContext context, MapCoordinates coordinates)
|
||||
{
|
||||
context.TargetPoint = coordinates;
|
||||
}
|
||||
}
|
||||
7
Resources/Prototypes/_CP14/MagickSpells/source_point.yml
Normal file
7
Resources/Prototypes/_CP14/MagickSpells/source_point.yml
Normal file
@@ -0,0 +1,7 @@
|
||||
- type: magicSpell
|
||||
id: sourcePointRandomMob
|
||||
action:
|
||||
!type:MagicSpellSourcePointRandomMob
|
||||
range: 5
|
||||
baseCost: 25
|
||||
|
||||
Reference in New Issue
Block a user