Beam Component and Lightning Component (#10196)
This commit is contained in:
120
Content.Shared/Beam/Components/SharedBeamComponent.cs
Normal file
120
Content.Shared/Beam/Components/SharedBeamComponent.cs
Normal file
@@ -0,0 +1,120 @@
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Beam.Components;
|
||||
/// <summary>
|
||||
/// Use this as a generic beam. Not for something like a laser gun, more for something continuous like lightning.
|
||||
/// </summary>
|
||||
public abstract class SharedBeamComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// A unique list of targets that this beam collided with.
|
||||
/// Useful for code like Arcing in the Lightning Component.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("hitTargets")]
|
||||
public HashSet<EntityUid> HitTargets = new();
|
||||
|
||||
/// <summary>
|
||||
/// The virtual entity representing a beam.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("virtualBeamController")]
|
||||
public EntityUid? VirtualBeamController;
|
||||
|
||||
/// <summary>
|
||||
/// The first beam created, useful for keeping track of chains.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("originBeam")]
|
||||
public EntityUid OriginBeam;
|
||||
|
||||
/// <summary>
|
||||
/// The entity that fired the beam originally
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("beamShooter")]
|
||||
public EntityUid BeamShooter;
|
||||
|
||||
/// <summary>
|
||||
/// A unique list of created beams that the controller keeps track of.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("createdBeams")]
|
||||
public HashSet<EntityUid> CreatedBeams = new();
|
||||
|
||||
/// <summary>
|
||||
/// Sound played upon creation
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("sound")]
|
||||
public SoundSpecifier? Sound;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called where a <see cref="BeamControllerEntity"/> is first created. Stores the originator beam euid and the controller euid.
|
||||
/// Raised on the <see cref="BeamControllerEntity"/> and broadcast.
|
||||
/// </summary>
|
||||
public sealed class BeamControllerCreatedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid OriginBeam;
|
||||
public EntityUid BeamControllerEntity;
|
||||
|
||||
public BeamControllerCreatedEvent(EntityUid originBeam, EntityUid beamControllerEntity)
|
||||
{
|
||||
OriginBeam = originBeam;
|
||||
BeamControllerEntity = beamControllerEntity;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called after TryCreateBeam succeeds.
|
||||
/// </summary>
|
||||
public sealed class CreateBeamSuccessEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid User;
|
||||
public readonly EntityUid Target;
|
||||
|
||||
public CreateBeamSuccessEvent(EntityUid user, EntityUid target)
|
||||
{
|
||||
User = user;
|
||||
Target = target;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called once the beam is fully created
|
||||
/// </summary>
|
||||
public sealed class BeamFiredEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid CreatedBeam;
|
||||
|
||||
public BeamFiredEvent(EntityUid createdBeam)
|
||||
{
|
||||
CreatedBeam = createdBeam;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raised on the new entity created after the <see cref="SharedBeamSystem"/> creates one.
|
||||
/// Used to get sprite data over to the client.
|
||||
/// </summary>
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class BeamVisualizerEvent : EntityEventArgs
|
||||
{
|
||||
public readonly EntityUid Beam;
|
||||
public readonly float DistanceLength;
|
||||
public readonly Angle UserAngle;
|
||||
public readonly string? BodyState;
|
||||
public readonly string Shader = "unshaded";
|
||||
|
||||
public BeamVisualizerEvent(EntityUid beam, float distanceLength, Angle userAngle, string? bodyState = null, string shader = "unshaded")
|
||||
{
|
||||
Beam = beam;
|
||||
DistanceLength = distanceLength;
|
||||
UserAngle = userAngle;
|
||||
BodyState = bodyState;
|
||||
Shader = shader;
|
||||
}
|
||||
}
|
||||
6
Content.Shared/Beam/SharedBeamSystem.cs
Normal file
6
Content.Shared/Beam/SharedBeamSystem.cs
Normal file
@@ -0,0 +1,6 @@
|
||||
namespace Content.Shared.Beam;
|
||||
|
||||
public abstract class SharedBeamSystem : EntitySystem
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Shared.Lightning.Components;
|
||||
/// <summary>
|
||||
/// Handles how lightning acts and is spawned. Use the ShootLightning method to fire lightning from one user to a target.
|
||||
/// </summary>
|
||||
public abstract class SharedLightningComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Can this lightning arc?
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("canArc")]
|
||||
public bool CanArc;
|
||||
|
||||
/// <summary>
|
||||
/// How much should lightning arc in total?
|
||||
/// Controls the amount of bolts that will spawn.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("maxTotalArc")]
|
||||
public int MaxTotalArcs = 50;
|
||||
|
||||
/// <summary>
|
||||
/// The prototype ID used for arcing bolts. Usually will be the same name as the main proto but it could be flexible.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("lightningPrototype", customTypeSerializer:typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
public string LightningPrototype = "Lightning";
|
||||
|
||||
/// <summary>
|
||||
/// The target that the lightning will Arc to.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("arcTarget")]
|
||||
public EntityUid ArcTarget;
|
||||
|
||||
/// <summary>
|
||||
/// How far should this lightning go?
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("maxLength")]
|
||||
public float MaxLength = 5f;
|
||||
|
||||
/// <summary>
|
||||
/// List of targets that this collided with already
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("arcTargets")]
|
||||
public HashSet<EntityUid> ArcTargets = new();
|
||||
|
||||
/// <summary>
|
||||
/// What should this arc to?
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
[DataField("collisionMask")]
|
||||
public int CollisionMask = (int) (CollisionGroup.MobMask | CollisionGroup.MachineMask);
|
||||
}
|
||||
19
Content.Shared/Lightning/SharedLightningSystem.cs
Normal file
19
Content.Shared/Lightning/SharedLightningSystem.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Shared.Lightning;
|
||||
|
||||
public abstract class SharedLightningSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Picks a random sprite state for the lightning. It's just data that gets passed to the <see cref="BeamComponent"/>
|
||||
/// </summary>
|
||||
/// <returns>Returns a string "lightning_" + the chosen random number.</returns>
|
||||
public string LightningRandomizer()
|
||||
{
|
||||
//When the lightning is made with TryCreateBeam, spawns random sprites for each beam to make it look nicer.
|
||||
var spriteStateNumber = _random.Next(1, 12);
|
||||
return ("lightning_" + spriteStateNumber);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user