Slight trigger refactor (#4320)

* Trigger tweaks

* Finish trigger refactor

* Clusterflash too
This commit is contained in:
metalgearsloth
2021-07-25 20:09:08 +10:00
committed by GitHub
parent 8cb5df2a56
commit ced39d4b2e
19 changed files with 211 additions and 179 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Threading.Tasks;
using Content.Server.Flash.Components;
using Content.Server.Throwing;
using Content.Shared.Explosion;
using Content.Shared.Interaction;
@@ -58,7 +59,8 @@ namespace Content.Server.Explosion.Components
async Task<bool> IInteractUsing.InteractUsing(InteractUsingEventArgs args)
{
if (_grenadesContainer.ContainedEntities.Count >= _maxGrenades || !args.Using.HasComponent<FlashExplosiveComponent>())
if (_grenadesContainer.ContainedEntities.Count >= _maxGrenades ||
!args.Using.HasComponent<FlashOnTriggerComponent>())
return false;
_grenadesContainer.Insert(args.Using);
@@ -70,7 +72,7 @@ namespace Content.Server.Explosion.Components
{
base.Initialize();
_grenadesContainer = ContainerHelpers.EnsureContainer<Container>(Owner, "cluster-flash");
_grenadesContainer = Owner.EnsureContainer<Container>("cluster-flash");
}
@@ -117,10 +119,7 @@ namespace Content.Server.Explosion.Components
if (grenade.Deleted)
return;
if (grenade.TryGetComponent(out OnUseTimerTriggerComponent? useTimer))
{
useTimer.Trigger(eventArgs.User);
}
EntitySystem.Get<TriggerSystem>().Trigger(grenade, eventArgs.User);
});
}

View File

@@ -0,0 +1,13 @@
using Robust.Shared.GameObjects;
namespace Content.Server.Explosion.Components
{
/// <summary>
/// Will delete the attached entity upon a <see cref="TriggerEvent"/>.
/// </summary>
[RegisterComponent]
public class DeleteOnTriggerComponent : Component
{
public override string Name => "DeleteOnTrigger";
}
}

View File

@@ -0,0 +1,13 @@
using Robust.Shared.GameObjects;
namespace Content.Server.Explosion.Components
{
/// <summary>
/// Explode using the entity's <see cref="ExplosiveComponent"/> if Triggered.
/// </summary>
[RegisterComponent]
public class ExplodeOnTriggerComponent : Component
{
public override string Name => "ExplodeOnTrigger";
}
}

View File

@@ -1,11 +1,13 @@
using Content.Shared.Acts;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Explosion.Components
{
/// <summary>
/// Specifies an explosion range should this entity be exploded.
/// </summary>
[RegisterComponent]
public class ExplosiveComponent : Component, ITimerTrigger, IDestroyAct
public class ExplosiveComponent : Component
{
public override string Name => "Explosive";
@@ -18,31 +20,6 @@ namespace Content.Server.Explosion.Components
[DataField("flashRange")]
public int FlashRange;
public bool Exploding { get; private set; } = false;
public bool Explosion()
{
if (Exploding)
{
return false;
}
else
{
Exploding = true;
Owner.SpawnExplosion(DevastationRange, HeavyImpactRange, LightImpactRange, FlashRange);
Owner.QueueDelete();
return true;
}
}
bool ITimerTrigger.Trigger(TimerTriggerEventArgs eventArgs)
{
return Explosion();
}
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
Explosion();
}
public bool Exploding { get; set; } = false;
}
}

View File

@@ -1,27 +0,0 @@
using Robust.Shared.GameObjects;
using Robust.Shared.Physics.Collision;
using Robust.Shared.Physics.Dynamics;
namespace Content.Server.Explosion.Components
{
[RegisterComponent]
public class ExplosiveProjectileComponent : Component, IStartCollide
{
public override string Name => "ExplosiveProjectile";
protected override void Initialize()
{
base.Initialize();
Owner.EnsureComponent<ExplosiveComponent>();
}
void IStartCollide.CollideWith(Fixture ourFixture, Fixture otherFixture, in Manifold manifold)
{
if (Owner.TryGetComponent(out ExplosiveComponent? explosive))
{
explosive.Explosion();
}
}
}
}

View File

@@ -1,61 +0,0 @@
using Content.Server.Flash.Components;
using Content.Server.Storage.Components;
using Content.Shared.Acts;
using Robust.Shared.Audio;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Player;
using Robust.Shared.Serialization.Manager.Attributes;
namespace Content.Server.Explosion.Components
{
/// <summary>
/// When triggered will flash in an area around the object and destroy itself
/// </summary>
[RegisterComponent]
public class FlashExplosiveComponent : Component, ITimerTrigger, IDestroyAct
{
public override string Name => "FlashExplosive";
[DataField("range")]
private float _range = 7.0f;
[DataField("duration")]
private float _duration = 8.0f;
[DataField("sound")]
private string _sound = "/Audio/Effects/flash_bang.ogg";
[DataField("deleteOnFlash")]
private bool _deleteOnFlash = true;
public bool Explode()
{
// If we're in a locker or whatever then can't flash anything
Owner.TryGetContainer(out var container);
if (container == null || !container.Owner.HasComponent<EntityStorageComponent>())
{
FlashableComponent.FlashAreaHelper(Owner, _range, _duration);
}
if (_sound != null)
{
SoundSystem.Play(Filter.Pvs(Owner), _sound, Owner.Transform.Coordinates);
}
if (_deleteOnFlash && !Owner.Deleted)
{
Owner.Delete();
}
return true;
}
bool ITimerTrigger.Trigger(TimerTriggerEventArgs eventArgs)
{
return Explode();
}
void IDestroyAct.OnDestroy(DestructionEventArgs eventArgs)
{
Explode();
}
}
}

View File

@@ -15,12 +15,13 @@ namespace Content.Server.Explosion.Components
[DataField("delay")]
private float _delay = 0f;
// TODO: Need to split this out so it's a generic "OnUseTimerTrigger" component.
public void Trigger(IEntity user)
{
if (Owner.TryGetComponent(out AppearanceComponent? appearance))
appearance.SetData(TriggerVisuals.VisualState, TriggerVisualState.Primed);
EntitySystem.Get<TriggerSystem>().HandleTimerTrigger(TimeSpan.FromSeconds(_delay), user, Owner);
EntitySystem.Get<TriggerSystem>().HandleTimerTrigger(TimeSpan.FromSeconds(_delay), Owner, user);
}
bool IUse.UseEntity(UseEntityEventArgs eventArgs)

View File

@@ -0,0 +1,20 @@
using Content.Shared.Sound;
using Robust.Shared.GameObjects;
using Robust.Shared.Serialization.Manager.Attributes;
using Robust.Shared.ViewVariables;
namespace Content.Server.Explosion.Components
{
/// <summary>
/// Whenever a <see cref="TriggerEvent"/> is run play a sound in PVS range.
/// </summary>
[RegisterComponent]
public sealed class SoundOnTriggerComponent : Component
{
public override string Name => "SoundOnTrigger";
[ViewVariables(VVAccess.ReadWrite)]
[DataField("sound")]
public SoundSpecifier? Sound { get; set; } = null;
}
}

View File

@@ -0,0 +1,10 @@
using Robust.Shared.GameObjects;
namespace Content.Server.Explosion.Components
{
[RegisterComponent]
public class TriggerOnCollideComponent : Component
{
public override string Name => "TriggerOnCollide";
}
}