ECS flash area on collision (#4311)
This commit is contained in:
parent
5befd58887
commit
4b78e0a4e0
|
|
@ -97,7 +97,7 @@ namespace Content.Client.Entry
|
|||
"PresetIdCard",
|
||||
"SolarControlConsole",
|
||||
"FlashExplosive",
|
||||
"FlashProjectile",
|
||||
"FlashAreaOnCollide",
|
||||
"Utensil",
|
||||
"UnarmedCombat",
|
||||
"TimedSpawner",
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Flash.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Upon colliding with an object this will flash in an area around it
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
internal sealed class FlashAreaOnCollide : Component
|
||||
{
|
||||
public override string Name => "FlashAreaOnCollide";
|
||||
|
||||
[DataField("range")] internal float Range = 1.0f;
|
||||
[DataField("duration")] internal float Duration = 8.0f;
|
||||
|
||||
internal bool Flashed;
|
||||
}
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
using Content.Server.Projectiles.Components;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Physics.Collision;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.Flash.Components
|
||||
{
|
||||
/// <summary>
|
||||
/// Upon colliding with an object this will flash in an area around it
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class FlashProjectileComponent : Component, IStartCollide
|
||||
{
|
||||
public override string Name => "FlashProjectile";
|
||||
|
||||
[DataField("range")]
|
||||
private float _range = 1.0f;
|
||||
[DataField("duration")]
|
||||
private float _duration = 8.0f;
|
||||
|
||||
private bool _flashed;
|
||||
|
||||
protected override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
// Shouldn't be using this without a ProjectileComponent because it will just immediately collide with thrower
|
||||
Owner.EnsureComponent<ProjectileComponent>();
|
||||
}
|
||||
|
||||
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
|
||||
{
|
||||
if (_flashed) return;
|
||||
|
||||
FlashableComponent.FlashAreaHelper(Owner, _range, _duration);
|
||||
_flashed = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -10,11 +10,12 @@ using Robust.Shared.Audio;
|
|||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Physics.Dynamics;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Server.Flash
|
||||
{
|
||||
public class FlashSystem : EntitySystem
|
||||
internal sealed class FlashSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
|
|
@ -25,6 +26,15 @@ namespace Content.Server.Flash
|
|||
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnUseInHand);
|
||||
|
||||
SubscribeLocalEvent<FlashComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<FlashAreaOnCollide, StartCollideEvent>(HandleCollide);
|
||||
}
|
||||
|
||||
private void HandleCollide(EntityUid uid, FlashAreaOnCollide component, StartCollideEvent args)
|
||||
{
|
||||
if (component.Flashed) return;
|
||||
|
||||
FlashableComponent.FlashAreaHelper(component.Owner, component.Range, component.Duration);
|
||||
component.Flashed = true;
|
||||
}
|
||||
|
||||
public void OnMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent args)
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@
|
|||
soundHit: /Audio/Weapons/Guns/Hits/snap.ogg
|
||||
damages:
|
||||
Piercing: 10
|
||||
- type: FlashProjectile
|
||||
- type: FlashAreaOnCollide
|
||||
range: 1
|
||||
|
||||
- type: entity
|
||||
|
|
@ -212,7 +212,7 @@
|
|||
- type: Projectile
|
||||
deleteOnCollide: false
|
||||
soundHit: /Audio/Effects/flash_bang.ogg
|
||||
- type: FlashProjectile
|
||||
- type: FlashAreaOnCollide
|
||||
range: 7
|
||||
|
||||
# This is supposed to spawn shrapnel and stuff so uhh... TODO?
|
||||
|
|
|
|||
Loading…
Reference in New Issue