Beam Component and Lightning Component (#10196)
31
Content.Client/Beam/BeamSystem.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using Content.Client.Beam.Components;
|
||||
using Content.Shared.Beam;
|
||||
using Content.Shared.Beam.Components;
|
||||
using Robust.Client.GameObjects;
|
||||
|
||||
namespace Content.Client.Beam;
|
||||
|
||||
public sealed class BeamSystem : SharedBeamSystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeNetworkEvent<BeamVisualizerEvent>(BeamVisualizerMessage);
|
||||
}
|
||||
|
||||
//TODO: Sometime in the future this needs to be replaced with tiled sprites
|
||||
private void BeamVisualizerMessage(BeamVisualizerEvent args)
|
||||
{
|
||||
if (TryComp<SpriteComponent>(args.Beam, out var sprites))
|
||||
{
|
||||
sprites.Rotation = args.UserAngle;
|
||||
|
||||
if (args.BodyState != null)
|
||||
{
|
||||
sprites.LayerSetState(0, args.BodyState);
|
||||
sprites.LayerSetShader(0, args.Shader);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
8
Content.Client/Beam/Components/BeamComponent.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Beam.Components;
|
||||
|
||||
namespace Content.Client.Beam.Components;
|
||||
[RegisterComponent]
|
||||
public sealed class BeamComponent : SharedBeamComponent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Lightning.Components;
|
||||
|
||||
namespace Content.Client.Lightning.Components;
|
||||
[RegisterComponent]
|
||||
public sealed class LightningComponent : SharedLightningComponent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -8,6 +8,7 @@ using NUnit.Framework;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Serialization.Markdown;
|
||||
@@ -232,7 +233,7 @@ public sealed class PrototypeSaveTest
|
||||
var compName = compFact.GetComponentName(compType);
|
||||
compNames.Add(compName);
|
||||
|
||||
if (compType == typeof(MetaDataComponent) || compType == typeof(TransformComponent))
|
||||
if (compType == typeof(MetaDataComponent) || compType == typeof(TransformComponent) || compType == typeof(FixturesComponent))
|
||||
continue;
|
||||
|
||||
MappingDataNode compMapping;
|
||||
|
||||
172
Content.Server/Beam/BeamSystem.cs
Normal file
@@ -0,0 +1,172 @@
|
||||
using Content.Server.Beam.Components;
|
||||
using Content.Server.Lightning;
|
||||
using Content.Shared.Beam;
|
||||
using Content.Shared.Beam.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Lightning;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Collision.Shapes;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
|
||||
namespace Content.Server.Beam;
|
||||
|
||||
public sealed class BeamSystem : SharedBeamSystem
|
||||
{
|
||||
[Dependency] private readonly FixtureSystem _fixture = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<BeamComponent, CreateBeamSuccessEvent>(OnBeamCreationSuccess);
|
||||
SubscribeLocalEvent<BeamComponent, BeamControllerCreatedEvent>(OnControllerCreated);
|
||||
SubscribeLocalEvent<BeamComponent, BeamFiredEvent>(OnBeamFired);
|
||||
SubscribeLocalEvent<BeamComponent, ComponentRemove>(OnRemove);
|
||||
}
|
||||
|
||||
private void OnBeamCreationSuccess(EntityUid uid, BeamComponent component, CreateBeamSuccessEvent args)
|
||||
{
|
||||
component.BeamShooter = args.User;
|
||||
}
|
||||
|
||||
private void OnControllerCreated(EntityUid uid, BeamComponent component, BeamControllerCreatedEvent args)
|
||||
{
|
||||
component.OriginBeam = args.OriginBeam;
|
||||
}
|
||||
|
||||
private void OnBeamFired(EntityUid uid, BeamComponent component, BeamFiredEvent args)
|
||||
{
|
||||
component.CreatedBeams.Add(args.CreatedBeam);
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, BeamComponent component, ComponentRemove args)
|
||||
{
|
||||
if (component.VirtualBeamController == null)
|
||||
return;
|
||||
|
||||
if (component.CreatedBeams.Count == 0 && component.VirtualBeamController.Value.Valid)
|
||||
QueueDel(component.VirtualBeamController.Value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If <see cref="TryCreateBeam"/> is successful, it spawns a beam from the user to the target.
|
||||
/// </summary>
|
||||
/// <param name="prototype">The prototype used to make the beam</param>
|
||||
/// <param name="userAngle">Angle of the user firing the beam</param>
|
||||
/// <param name="calculatedDistance">The calculated distance from the user to the target.</param>
|
||||
/// <param name="beamStartPos">Where the beam will spawn in</param>
|
||||
/// <param name="distanceCorrection">Calculated correction so the <see cref="EdgeShape"/> can be properly dynamically created</param>
|
||||
/// <param name="controller"> The virtual beam controller that this beam will use. If one doesn't exist it will be created here.</param>
|
||||
/// <param name="bodyState">Optional sprite state for the <see cref="prototype"/> if it needs a dynamic one</param>
|
||||
/// <param name="shader">Optional shader for the <see cref="prototype"/> and <see cref="bodyState"/> if it needs something other than default</param>
|
||||
private void CreateBeam(string prototype,
|
||||
Angle userAngle,
|
||||
Vector2 calculatedDistance,
|
||||
MapCoordinates beamStartPos,
|
||||
Vector2 distanceCorrection,
|
||||
EntityUid? controller,
|
||||
string? bodyState = null,
|
||||
string shader = "unshaded")
|
||||
{
|
||||
var beamSpawnPos = beamStartPos;
|
||||
var ent = Spawn(prototype, beamSpawnPos);
|
||||
var shape = new EdgeShape(distanceCorrection, new Vector2(0,0));
|
||||
var distanceLength = distanceCorrection.Length;
|
||||
|
||||
if (TryComp<PhysicsComponent>(ent, out var physics) && TryComp<BeamComponent>(ent, out var beam))
|
||||
{
|
||||
var fixture = new Fixture(physics, shape)
|
||||
{
|
||||
ID = "BeamBody",
|
||||
Hard = false,
|
||||
CollisionMask = (int)CollisionGroup.ItemMask, //Change to MobMask
|
||||
CollisionLayer = (int)CollisionGroup.MobLayer //Change to WallLayer
|
||||
};
|
||||
|
||||
_fixture.TryCreateFixture(physics, fixture);
|
||||
physics.BodyType = BodyType.Dynamic;
|
||||
|
||||
var beamVisualizerEvent = new BeamVisualizerEvent(ent, distanceLength, userAngle, bodyState, shader);
|
||||
RaiseNetworkEvent(beamVisualizerEvent);
|
||||
|
||||
if (controller != null)
|
||||
beam.VirtualBeamController = controller;
|
||||
|
||||
else
|
||||
{
|
||||
var controllerEnt = Spawn("VirtualBeamEntityController", beamSpawnPos);
|
||||
beam.VirtualBeamController = controllerEnt;
|
||||
|
||||
_audio.PlayPvs(beam.Sound, beam.Owner);
|
||||
|
||||
var beamControllerCreatedEvent = new BeamControllerCreatedEvent(ent, controllerEnt);
|
||||
RaiseLocalEvent(controllerEnt, beamControllerCreatedEvent);
|
||||
}
|
||||
|
||||
//Create the rest of the beam, sprites handled through the BeamVisualizerEvent
|
||||
for (int i = 0; i < distanceLength-1; i++)
|
||||
{
|
||||
beamSpawnPos = beamSpawnPos.Offset(calculatedDistance.Normalized);
|
||||
var newEnt = Spawn(prototype, beamSpawnPos);
|
||||
|
||||
var ev = new BeamVisualizerEvent(newEnt, distanceLength, userAngle, bodyState, shader);
|
||||
RaiseNetworkEvent(ev);
|
||||
}
|
||||
|
||||
var beamFiredEvent = new BeamFiredEvent(ent);
|
||||
RaiseLocalEvent(beam.VirtualBeamController.Value, beamFiredEvent);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Called where you want an entity to create a beam from one target to another.
|
||||
/// Tries to create the beam and does calculations like the distance, angle, and offset.
|
||||
/// </summary>
|
||||
/// <param name="user">The entity that's firing off the beam</param>
|
||||
/// <param name="target">The entity that's being targeted by the user</param>
|
||||
/// <param name="bodyPrototype">The prototype spawned when this beam is created</param>
|
||||
/// <param name="bodyState">Optional sprite state for the <see cref="bodyPrototype"/> if a default one is not given</param>
|
||||
/// <param name="shader">Optional shader for the <see cref="bodyPrototype"/> if a default one is not given</param>
|
||||
/// <param name="controller"></param>
|
||||
public void TryCreateBeam(EntityUid user, EntityUid target, string bodyPrototype, string? bodyState = null, string shader = "unshaded", EntityUid? controller = null)
|
||||
{
|
||||
if (!user.IsValid() || !target.IsValid())
|
||||
return;
|
||||
|
||||
var userMapPos = Transform(user).MapPosition;
|
||||
var targetMapPos = Transform(target).MapPosition;
|
||||
|
||||
//The distance between the target and the user.
|
||||
var calculatedDistance = targetMapPos.Position - userMapPos.Position;
|
||||
var userAngle = calculatedDistance.ToWorldAngle();
|
||||
|
||||
if (userMapPos.MapId != targetMapPos.MapId)
|
||||
return;
|
||||
|
||||
//Where the start of the beam will spawn
|
||||
var beamStartPos = userMapPos.Offset(calculatedDistance.Normalized);
|
||||
|
||||
//Don't divide by zero
|
||||
if (calculatedDistance.Length == 0)
|
||||
return;
|
||||
|
||||
if (controller != null && TryComp<BeamComponent>(controller, out var controllerBeamComp))
|
||||
{
|
||||
controllerBeamComp.HitTargets.Add(user);
|
||||
controllerBeamComp.HitTargets.Add(target);
|
||||
}
|
||||
|
||||
var distanceCorrection = calculatedDistance - calculatedDistance.Normalized;
|
||||
|
||||
CreateBeam(bodyPrototype, userAngle, calculatedDistance, beamStartPos, distanceCorrection, controller, bodyState, shader);
|
||||
|
||||
var ev = new CreateBeamSuccessEvent(user, target);
|
||||
RaiseLocalEvent(user, ev);
|
||||
}
|
||||
}
|
||||
8
Content.Server/Beam/Components/BeamComponent.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Beam.Components;
|
||||
|
||||
namespace Content.Server.Beam.Components;
|
||||
[RegisterComponent]
|
||||
public sealed class BeamComponent : SharedBeamComponent
|
||||
{
|
||||
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
using Content.Shared.Lightning.Components;
|
||||
|
||||
namespace Content.Server.Lightning.Components;
|
||||
[RegisterComponent]
|
||||
public sealed class LightningComponent : SharedLightningComponent
|
||||
{
|
||||
|
||||
}
|
||||
138
Content.Server/Lightning/LightningSystem.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System.Linq;
|
||||
using Content.Server.Beam;
|
||||
using Content.Server.Beam.Components;
|
||||
using Content.Server.Lightning.Components;
|
||||
using Content.Shared.Lightning;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Physics.Events;
|
||||
using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Lightning;
|
||||
|
||||
public sealed class LightningSystem : SharedLightningSystem
|
||||
{
|
||||
[Dependency] private readonly PhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly BeamSystem _beam = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<LightningComponent, StartCollideEvent>(OnCollide);
|
||||
SubscribeLocalEvent<LightningComponent, ComponentRemove>(OnRemove);
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, LightningComponent component, ComponentRemove args)
|
||||
{
|
||||
if (!TryComp<BeamComponent>(uid, out var lightningBeam) || !TryComp<BeamComponent>(lightningBeam.VirtualBeamController, out var beamController))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
beamController.CreatedBeams.Remove(uid);
|
||||
}
|
||||
|
||||
private void OnCollide(EntityUid uid, LightningComponent component, ref StartCollideEvent args)
|
||||
{
|
||||
if (!TryComp<BeamComponent>(uid, out var lightningBeam) || !TryComp<BeamComponent>(lightningBeam.VirtualBeamController, out var beamController))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (component.CanArc)
|
||||
{
|
||||
while (beamController.CreatedBeams.Count < component.MaxTotalArcs)
|
||||
{
|
||||
Arc(component, args.OtherFixture.Body.Owner, lightningBeam.VirtualBeamController.Value);
|
||||
|
||||
var spriteState = LightningRandomizer();
|
||||
|
||||
component.ArcTargets.Add(args.OtherFixture.Body.Owner);
|
||||
component.ArcTargets.Add(component.ArcTarget);
|
||||
|
||||
_beam.TryCreateBeam(args.OtherFixture.Body.Owner, component.ArcTarget, component.LightningPrototype, spriteState, controller: lightningBeam.VirtualBeamController.Value);
|
||||
|
||||
//Break from this loop so other created bolts can collide and arc
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fires lightning from user to target
|
||||
/// </summary>
|
||||
/// <param name="user">Where the lightning fires from</param>
|
||||
/// <param name="target">Where the lightning fires to</param>
|
||||
/// <param name="lightningPrototype">The prototype for the lightning to be created</param>
|
||||
public void ShootLightning(EntityUid user, EntityUid target, string lightningPrototype = "Lightning")
|
||||
{
|
||||
var spriteState = LightningRandomizer();
|
||||
_beam.TryCreateBeam(user, target, lightningPrototype, spriteState);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks for a target to arc to in all 8 directions, adds the closest to a local dictionary and picks at random
|
||||
/// </summary>
|
||||
/// <param name="component"></param>
|
||||
/// <param name="target"></param>
|
||||
/// <param name="controllerEntity"></param>
|
||||
private void Arc(LightningComponent component, EntityUid target, EntityUid controllerEntity)
|
||||
{
|
||||
if (!TryComp<BeamComponent>(controllerEntity, out var controller))
|
||||
return;
|
||||
|
||||
var targetXForm = Transform(target);
|
||||
var directions = Enum.GetValues<Direction>().Length;
|
||||
|
||||
var lightningQuery = GetEntityQuery<LightningComponent>();
|
||||
var beamQuery = GetEntityQuery<BeamComponent>();
|
||||
var xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
Dictionary<Direction, EntityUid> arcDirections = new();
|
||||
|
||||
//TODO: Add scoring system for the Tesla PR which will have grounding rods
|
||||
for (int i = 0; i < directions; i++)
|
||||
{
|
||||
var direction = (Direction) i;
|
||||
var (targetPos, targetRot) = targetXForm.GetWorldPositionRotation(xformQuery);
|
||||
var dirRad = direction.ToAngle() + targetRot;
|
||||
var ray = new CollisionRay(targetPos, dirRad.ToVec(), component.CollisionMask);
|
||||
var rayCastResults = _physics.IntersectRay(targetXForm.MapID, ray, component.MaxLength, target, false).ToList();
|
||||
|
||||
RayCastResults? closestResult = null;
|
||||
|
||||
foreach (var result in rayCastResults)
|
||||
{
|
||||
if (lightningQuery.HasComponent(result.HitEntity)
|
||||
|| beamQuery.HasComponent(result.HitEntity)
|
||||
|| component.ArcTargets.Contains(result.HitEntity)
|
||||
|| controller.HitTargets.Contains(result.HitEntity)
|
||||
|| controller.BeamShooter == result.HitEntity)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
closestResult = result;
|
||||
break;
|
||||
}
|
||||
|
||||
if (closestResult == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
arcDirections.Add(direction, closestResult.Value.HitEntity);
|
||||
}
|
||||
|
||||
var randomDirection = (Direction) _random.Next(0, 7);
|
||||
|
||||
if (arcDirections.ContainsKey(randomDirection))
|
||||
{
|
||||
component.ArcTarget = arcDirections.GetValueOrDefault(randomDirection);
|
||||
arcDirections.Clear();
|
||||
}
|
||||
}
|
||||
}
|
||||
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
@@ -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
@@ -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);
|
||||
}
|
||||
}
|
||||
6
Resources/Audio/Effects/Lightning/licenses.txt
Normal file
@@ -0,0 +1,6 @@
|
||||
LightningShock.ogg taken from Citadel Station at commit: https://github.com/Citadel-Station-13/Citadel-Station-13/commit/35a1723e98a60f375df590ca572cc90f1bb80bd5
|
||||
|
||||
- files: ["LightningShock.ogg"]
|
||||
license: "CC-BY-NC-SA-3.0"
|
||||
copyright: "LightningShock.ogg taken from Citadel Station."
|
||||
source: "https://github.com/Citadel-Station-13/Citadel-Station-13/commit/35a1723e98a60f375df590ca572cc90f1bb80bd5"
|
||||
BIN
Resources/Audio/Effects/Lightning/lightningshock.ogg
Normal file
106
Resources/Prototypes/Entities/Effects/lightning.yml
Normal file
@@ -0,0 +1,106 @@
|
||||
- type: entity
|
||||
name: lightning
|
||||
id: BaseLightning
|
||||
abstract: true
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: /Textures/Effects/lightning.rsi
|
||||
drawdepth: Effects
|
||||
netsync: false
|
||||
layers:
|
||||
- state: "lightning_1"
|
||||
shader: unshaded
|
||||
- type: Physics
|
||||
- type: Electrified
|
||||
requirePower: false
|
||||
- type: Lightning
|
||||
- type: PointLight
|
||||
enabled: true
|
||||
color: "#4080FF"
|
||||
radius: 3.5
|
||||
softness: 1
|
||||
autoRot: true
|
||||
castShadows: false
|
||||
- type: Beam
|
||||
sound: /Audio/Effects/Lightning/lightningshock.ogg
|
||||
- type: TimedDespawn
|
||||
lifetime: 3
|
||||
- type: Tag
|
||||
tags:
|
||||
- HideContextMenu
|
||||
|
||||
- type: entity
|
||||
name: lightning
|
||||
id: Lightning
|
||||
parent: BaseLightning
|
||||
components:
|
||||
- type: Lightning
|
||||
canArc: true
|
||||
|
||||
- type: entity
|
||||
name: charged lightning
|
||||
id: ChargedLightning
|
||||
parent: BaseLightning
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: /Textures/Effects/lightning.rsi
|
||||
drawdepth: Effects
|
||||
layers:
|
||||
- state: "blue_lightning"
|
||||
shader: unshaded
|
||||
- type: Electrified
|
||||
requirePower: false
|
||||
shockDamage: 40
|
||||
- type: Lightning
|
||||
canArc: true
|
||||
lightningPrototype: ChargedLightning
|
||||
|
||||
- type: entity
|
||||
name: supercharged lightning
|
||||
id: SuperchargedLightning
|
||||
parent: ChargedLightning
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: /Textures/Effects/lightning.rsi
|
||||
drawdepth: Effects
|
||||
layers:
|
||||
- state: "yellow_lightning"
|
||||
shader: unshaded
|
||||
- type: Electrified
|
||||
requirePower: false
|
||||
shockDamage: 50
|
||||
- type: Lightning
|
||||
canArc: true
|
||||
lightningPrototype: SuperchargedLightning
|
||||
- type: PointLight
|
||||
enabled: true
|
||||
color: "#FFFF00"
|
||||
radius: 3.5
|
||||
softness: 1
|
||||
autoRot: true
|
||||
castShadows: false
|
||||
|
||||
- type: entity
|
||||
name: hypercharged lightning
|
||||
id: HyperchargedLightning
|
||||
parent: ChargedLightning
|
||||
components:
|
||||
- type: Sprite
|
||||
sprite: /Textures/Effects/lightning.rsi
|
||||
drawdepth: Effects
|
||||
layers:
|
||||
- state: "red_lightning"
|
||||
shader: unshaded
|
||||
- type: Electrified
|
||||
requirePower: false
|
||||
shockDamage: 60
|
||||
- type: Lightning
|
||||
canArc: true
|
||||
lightningPrototype: HyperchargedLightning
|
||||
- type: PointLight
|
||||
enabled: true
|
||||
color: "#ff0000"
|
||||
radius: 3.5
|
||||
softness: 1
|
||||
autoRot: true
|
||||
castShadows: false
|
||||
12
Resources/Prototypes/Entities/Virtual/beam.yml
Normal file
@@ -0,0 +1,12 @@
|
||||
# Special entity used to keep track of beams from the BeamComponent and what targets they collided with
|
||||
- type: entity
|
||||
id: VirtualBeamEntityController
|
||||
name: BEAM ENTITY YOU SHOULD NOT SEE THIS
|
||||
noSpawn: true
|
||||
components:
|
||||
- type: Beam
|
||||
- type: TimedDespawn
|
||||
lifetime: 4
|
||||
- type: Tag
|
||||
tags:
|
||||
- HideContextMenu
|
||||
BIN
Resources/Textures/Effects/lightning.rsi/blue_lightning.png
Normal file
|
After Width: | Height: | Size: 5.2 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_1.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_10.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_11.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_12.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_2.png
Normal file
|
After Width: | Height: | Size: 2.0 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_3.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_4.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_5.png
Normal file
|
After Width: | Height: | Size: 2.6 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_6.png
Normal file
|
After Width: | Height: | Size: 2.7 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_7.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_8.png
Normal file
|
After Width: | Height: | Size: 2.9 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/lightning_9.png
Normal file
|
After Width: | Height: | Size: 2.5 KiB |
152
Resources/Textures/Effects/lightning.rsi/meta.json
Normal file
@@ -0,0 +1,152 @@
|
||||
{
|
||||
"version": 1,
|
||||
"license": "CC-BY-SA-3.0",
|
||||
"copyright": "Taken from https://github.com/Citadel-Station-13/Citadel-Station-13/commit/06689416691093474d600924242f69eb7d223f3e",
|
||||
"size": {
|
||||
"x": 32,
|
||||
"y": 32
|
||||
},
|
||||
"states": [
|
||||
{
|
||||
"name": "lightning_1",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_2",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_3",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_4",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_5",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_6",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_7",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_8",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_9",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_10",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_11",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "lightning_12",
|
||||
"delays": [
|
||||
[
|
||||
0.120000005,
|
||||
0.08
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "yellow_lightning",
|
||||
"delays": [
|
||||
[
|
||||
0.1,
|
||||
0.1,
|
||||
0.1,
|
||||
0.1
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "blue_lightning",
|
||||
"delays": [
|
||||
[
|
||||
0.1,
|
||||
0.1,
|
||||
0.1,
|
||||
0.1
|
||||
]
|
||||
]
|
||||
},
|
||||
{
|
||||
"name": "red_lightning",
|
||||
"delays": [
|
||||
[
|
||||
0.1,
|
||||
0.1,
|
||||
0.1,
|
||||
0.1
|
||||
]
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
BIN
Resources/Textures/Effects/lightning.rsi/red_lightning.png
Normal file
|
After Width: | Height: | Size: 5.3 KiB |
BIN
Resources/Textures/Effects/lightning.rsi/yellow_lightning.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |