ECS flash area on collision (#4311)

This commit is contained in:
metalgearsloth
2021-07-21 19:20:13 +10:00
committed by GitHub
parent 5befd58887
commit 4b78e0a4e0
5 changed files with 33 additions and 43 deletions

View File

@@ -97,7 +97,7 @@ namespace Content.Client.Entry
"PresetIdCard", "PresetIdCard",
"SolarControlConsole", "SolarControlConsole",
"FlashExplosive", "FlashExplosive",
"FlashProjectile", "FlashAreaOnCollide",
"Utensil", "Utensil",
"UnarmedCombat", "UnarmedCombat",
"TimedSpawner", "TimedSpawner",

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -10,11 +10,12 @@ using Robust.Shared.Audio;
using Robust.Shared.GameObjects; using Robust.Shared.GameObjects;
using Robust.Shared.IoC; using Robust.Shared.IoC;
using Robust.Shared.Localization; using Robust.Shared.Localization;
using Robust.Shared.Physics.Dynamics;
using Robust.Shared.Player; using Robust.Shared.Player;
namespace Content.Server.Flash namespace Content.Server.Flash
{ {
public class FlashSystem : EntitySystem internal sealed class FlashSystem : EntitySystem
{ {
public override void Initialize() public override void Initialize()
{ {
@@ -25,6 +26,15 @@ namespace Content.Server.Flash
SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnUseInHand); SubscribeLocalEvent<FlashComponent, UseInHandEvent>(OnUseInHand);
SubscribeLocalEvent<FlashComponent, ExaminedEvent>(OnExamined); 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) public void OnMeleeHit(EntityUid uid, FlashComponent comp, MeleeHitEvent args)

View File

@@ -38,7 +38,7 @@
soundHit: /Audio/Weapons/Guns/Hits/snap.ogg soundHit: /Audio/Weapons/Guns/Hits/snap.ogg
damages: damages:
Piercing: 10 Piercing: 10
- type: FlashProjectile - type: FlashAreaOnCollide
range: 1 range: 1
- type: entity - type: entity
@@ -212,7 +212,7 @@
- type: Projectile - type: Projectile
deleteOnCollide: false deleteOnCollide: false
soundHit: /Audio/Effects/flash_bang.ogg soundHit: /Audio/Effects/flash_bang.ogg
- type: FlashProjectile - type: FlashAreaOnCollide
range: 7 range: 7
# This is supposed to spawn shrapnel and stuff so uhh... TODO? # This is supposed to spawn shrapnel and stuff so uhh... TODO?