Good artifact effects (#13223)
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used for recharging all nearby batteries when activated
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed class ChargeBatteryArtifactComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The radius of entities that will be affected
|
||||
/// </summary>
|
||||
[DataField("radius")]
|
||||
public float Radius = 15f;
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;
|
||||
using Content.Shared.Storage;
|
||||
|
||||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
|
||||
|
||||
@@ -11,18 +9,8 @@ namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
|
||||
[RegisterComponent]
|
||||
public sealed class SpawnArtifactComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The list of possible prototypes to spawn that it picks from.
|
||||
/// </summary>
|
||||
[DataField("possiblePrototypes", customTypeSerializer:typeof(PrototypeIdListSerializer<EntityPrototype>))]
|
||||
public List<string> PossiblePrototypes = new();
|
||||
|
||||
/// <summary>
|
||||
/// The prototype it selected to spawn.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("prototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string? Prototype;
|
||||
[DataField("spawns")]
|
||||
public List<EntitySpawnEntry>? Spawns;
|
||||
|
||||
/// <summary>
|
||||
/// The range around the artifact that it will spawn the entity
|
||||
@@ -34,12 +22,5 @@ public sealed class SpawnArtifactComponent : Component
|
||||
/// The maximum number of times the spawn will occur
|
||||
/// </summary>
|
||||
[DataField("maxSpawns")]
|
||||
public int MaxSpawns = 20;
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the artifact spawns the same entity every time
|
||||
/// or picks through the list each time.
|
||||
/// </summary>
|
||||
[DataField("consistentSpawn")]
|
||||
public bool ConsistentSpawn = true;
|
||||
public int MaxSpawns = 10;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
|
||||
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
|
||||
|
||||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
|
||||
|
||||
/// <summary>
|
||||
/// This handles <see cref="ChargeBatteryArtifactComponent"/>
|
||||
/// </summary>
|
||||
public sealed class ChargeBatteryArtifactSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly EntityLookupSystem _lookup = default!;
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
SubscribeLocalEvent<ChargeBatteryArtifactComponent, ArtifactActivatedEvent>(OnActivated);
|
||||
}
|
||||
|
||||
private void OnActivated(EntityUid uid, ChargeBatteryArtifactComponent component, ArtifactActivatedEvent args)
|
||||
{
|
||||
foreach (var battery in _lookup.GetComponentsInRange<BatteryComponent>(Transform(uid).MapPosition, component.Radius))
|
||||
{
|
||||
battery.CurrentCharge = battery.MaxCharge;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,9 +17,7 @@ public sealed class RandomInstrumentArtifactSystem : EntitySystem
|
||||
|
||||
private void OnStartup(EntityUid uid, RandomInstrumentArtifactComponent component, ComponentStartup args)
|
||||
{
|
||||
if (!TryComp<SharedInstrumentComponent>(uid, out var instrument))
|
||||
return;
|
||||
|
||||
var instrument = EnsureComp<InstrumentComponent>(uid);
|
||||
_instrument.SetInstrumentProgram(instrument, (byte) _random.Next(0, 127), 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
using Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Components;
|
||||
using Content.Server.Xenoarchaeology.XenoArtifacts.Events;
|
||||
using Content.Shared.Hands.EntitySystems;
|
||||
using Content.Shared.Storage;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
|
||||
@@ -8,7 +8,6 @@ namespace Content.Server.Xenoarchaeology.XenoArtifacts.Effects.Systems;
|
||||
public sealed class SpawnArtifactSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
[Dependency] private readonly SharedHandsSystem _handsSystem = default!;
|
||||
[Dependency] private readonly ArtifactSystem _artifact = default!;
|
||||
|
||||
public const string NodeDataSpawnAmount = "nodeDataSpawnAmount";
|
||||
@@ -16,45 +15,28 @@ public sealed class SpawnArtifactSystem : EntitySystem
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<SpawnArtifactComponent, ArtifactNodeEnteredEvent>(OnNodeEntered);
|
||||
SubscribeLocalEvent<SpawnArtifactComponent, ArtifactActivatedEvent>(OnActivate);
|
||||
}
|
||||
private void OnNodeEntered(EntityUid uid, SpawnArtifactComponent component, ArtifactNodeEnteredEvent args)
|
||||
{
|
||||
if (component.PossiblePrototypes.Count == 0)
|
||||
return;
|
||||
|
||||
var proto = component.PossiblePrototypes[args.RandomSeed % component.PossiblePrototypes.Count];
|
||||
component.Prototype = proto;
|
||||
}
|
||||
|
||||
private void OnActivate(EntityUid uid, SpawnArtifactComponent component, ArtifactActivatedEvent args)
|
||||
{
|
||||
if (component.Prototype == null)
|
||||
return;
|
||||
|
||||
if (!_artifact.TryGetNodeData(uid, NodeDataSpawnAmount, out int amount))
|
||||
amount = 0;
|
||||
|
||||
if (amount >= component.MaxSpawns)
|
||||
return;
|
||||
|
||||
var toSpawn = component.Prototype;
|
||||
if (!component.ConsistentSpawn)
|
||||
toSpawn = _random.Pick(component.PossiblePrototypes);
|
||||
if (component.Spawns is not {} spawns)
|
||||
return;
|
||||
|
||||
// select spawn position near artifact
|
||||
var artifactCord = Transform(uid).MapPosition;
|
||||
var dx = _random.NextFloat(-component.Range, component.Range);
|
||||
var dy = _random.NextFloat(-component.Range, component.Range);
|
||||
var spawnCord = artifactCord.Offset(new Vector2(dx, dy));
|
||||
|
||||
// spawn entity
|
||||
var spawned = EntityManager.SpawnEntity(toSpawn, spawnCord);
|
||||
_artifact.SetNodeData(uid, NodeDataSpawnAmount, amount+1);
|
||||
|
||||
// if there is an user - try to put spawned item in their hands
|
||||
// doesn't work for spawners
|
||||
_handsSystem.PickupOrDrop(args.Activator, spawned);
|
||||
foreach (var spawn in EntitySpawnCollection.GetSpawns(spawns, _random))
|
||||
{
|
||||
var dx = _random.NextFloat(-component.Range, component.Range);
|
||||
var dy = _random.NextFloat(-component.Range, component.Range);
|
||||
var spawnCord = artifactCord.Offset(new Vector2(dx, dy));
|
||||
EntityManager.SpawnEntity(spawn, spawnCord);
|
||||
}
|
||||
_artifact.SetNodeData(uid, NodeDataSpawnAmount, amount + 1);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user