ExtinguishOnTrigger and TriggerOnInteractHand (#39537)
* simplely one commit * simplelly two commit * requested changes --------- Co-authored-by: iaada <iaada@users.noreply.github.com>
This commit is contained in:
53
Content.Server/Trigger/Systems/FireStackOnTriggerSystem.cs
Normal file
53
Content.Server/Trigger/Systems/FireStackOnTriggerSystem.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using Content.Server.Atmos.EntitySystems;
|
||||||
|
using Content.Shared.Trigger;
|
||||||
|
using Content.Shared.Trigger.Components.Effects;
|
||||||
|
|
||||||
|
namespace Content.Server.Trigger.Systems;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Trigger system for adding or removing fire stacks from an entity with <see cref="FlammableComponent"/>.
|
||||||
|
/// </summary>
|
||||||
|
/// <seealso cref="IgniteOnTriggerSystem"/>
|
||||||
|
public sealed class FireStackOnTriggerSystem : EntitySystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly FlammableSystem _flame = default!;
|
||||||
|
|
||||||
|
/// <inheritdoc/>
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
SubscribeLocalEvent<FireStackOnTriggerComponent, TriggerEvent>(OnTriggerFlame);
|
||||||
|
SubscribeLocalEvent<ExtinguishOnTriggerComponent, TriggerEvent>(OnTriggerExtinguish);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTriggerFlame(Entity<FireStackOnTriggerComponent> ent, ref TriggerEvent args)
|
||||||
|
{
|
||||||
|
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
||||||
|
|
||||||
|
if (target == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_flame.AdjustFireStacks(target.Value, ent.Comp.FireStacks, ignite: ent.Comp.DoIgnite);
|
||||||
|
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnTriggerExtinguish(Entity<ExtinguishOnTriggerComponent> ent, ref TriggerEvent args)
|
||||||
|
{
|
||||||
|
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
||||||
|
|
||||||
|
if (target == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_flame.Extinguish(target.Value);
|
||||||
|
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,37 +0,0 @@
|
|||||||
using Content.Server.Atmos.EntitySystems;
|
|
||||||
using Content.Shared.Trigger;
|
|
||||||
using Content.Shared.Trigger.Components.Effects;
|
|
||||||
|
|
||||||
namespace Content.Server.Trigger.Systems;
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Trigger system for setting something on fire.
|
|
||||||
/// </summary>
|
|
||||||
/// <seealso cref="IgniteOnTriggerSystem"/>
|
|
||||||
public sealed class FlameStackOnTriggerSystem : EntitySystem
|
|
||||||
{
|
|
||||||
[Dependency] private readonly FlammableSystem _flame = default!;
|
|
||||||
|
|
||||||
/// <inheritdoc/>
|
|
||||||
public override void Initialize()
|
|
||||||
{
|
|
||||||
base.Initialize();
|
|
||||||
|
|
||||||
SubscribeLocalEvent<FlameStackOnTriggerComponent, TriggerEvent>(OnTrigger);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnTrigger(Entity<FlameStackOnTriggerComponent> ent, ref TriggerEvent args)
|
|
||||||
{
|
|
||||||
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var target = ent.Comp.TargetUser ? args.User : ent.Owner;
|
|
||||||
|
|
||||||
if (target == null)
|
|
||||||
return;
|
|
||||||
|
|
||||||
_flame.AdjustFireStacks(target.Value, ent.Comp.FireStacks, ignite: ent.Comp.DoIgnite);
|
|
||||||
|
|
||||||
args.Handled = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -8,7 +8,7 @@ namespace Content.Server.Trigger.Systems;
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Handles igniting when triggered and stopping ignition after the delay.
|
/// Handles igniting when triggered and stopping ignition after the delay.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="FlameStackOnTriggerSystem"/>
|
/// <seealso cref="FireStackOnTriggerSystem"/>
|
||||||
public sealed class IgniteOnTriggerSystem : EntitySystem
|
public sealed class IgniteOnTriggerSystem : EntitySystem
|
||||||
{
|
{
|
||||||
[Dependency] private readonly IGameTiming _timing = default!;
|
[Dependency] private readonly IGameTiming _timing = default!;
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Trigger.Components.Effects;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// This trigger removes all the fire stacks on a target with <see cref="FlammableComponent"/>.
|
||||||
|
/// If TargetUser is true, the entity that caused this trigger will be extinguished instead.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
|
public sealed partial class ExtinguishOnTriggerComponent : BaseXOnTriggerComponent;
|
||||||
@@ -9,7 +9,7 @@ namespace Content.Shared.Trigger.Components.Effects;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="IgniteOnTriggerComponent"/>
|
/// <seealso cref="IgniteOnTriggerComponent"/>
|
||||||
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
public sealed partial class FlameStackOnTriggerComponent : BaseXOnTriggerComponent
|
public sealed partial class FireStackOnTriggerComponent : BaseXOnTriggerComponent
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// How many fire stacks to add or remove.
|
/// How many fire stacks to add or remove.
|
||||||
@@ -8,7 +8,7 @@ namespace Content.Shared.Trigger.Components.Effects;
|
|||||||
/// Requires <see cref="IgnitionSourceComponent"/> along with triggering components.
|
/// Requires <see cref="IgnitionSourceComponent"/> along with triggering components.
|
||||||
/// The if TargetUser is true they will be ignited instead (they need IgnitionSourceComponent as well).
|
/// The if TargetUser is true they will be ignited instead (they need IgnitionSourceComponent as well).
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <seealso cref="FlameStackOnTriggerComponent"/>
|
/// <seealso cref="FireStackOnTriggerComponent"/>
|
||||||
[RegisterComponent, NetworkedComponent]
|
[RegisterComponent, NetworkedComponent]
|
||||||
[AutoGenerateComponentState, AutoGenerateComponentPause]
|
[AutoGenerateComponentState, AutoGenerateComponentPause]
|
||||||
public sealed partial class IgniteOnTriggerComponent : BaseXOnTriggerComponent
|
public sealed partial class IgniteOnTriggerComponent : BaseXOnTriggerComponent
|
||||||
|
|||||||
@@ -0,0 +1,11 @@
|
|||||||
|
using Content.Shared.Interaction;
|
||||||
|
using Robust.Shared.GameStates;
|
||||||
|
|
||||||
|
namespace Content.Shared.Trigger.Components.Triggers;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Trigger on <see cref="InteractHandEvent"/>, aka clicking on an entity with an empty hand.
|
||||||
|
/// User is the player with the hand doing the clicking.
|
||||||
|
/// </summary>
|
||||||
|
[RegisterComponent, NetworkedComponent, AutoGenerateComponentState]
|
||||||
|
public sealed partial class TriggerOnInteractHandComponent : BaseTriggerOnXComponent;
|
||||||
@@ -12,6 +12,7 @@ public sealed partial class TriggerSystem
|
|||||||
{
|
{
|
||||||
SubscribeLocalEvent<TriggerOnActivateComponent, ActivateInWorldEvent>(OnActivate);
|
SubscribeLocalEvent<TriggerOnActivateComponent, ActivateInWorldEvent>(OnActivate);
|
||||||
SubscribeLocalEvent<TriggerOnUseComponent, UseInHandEvent>(OnUse);
|
SubscribeLocalEvent<TriggerOnUseComponent, UseInHandEvent>(OnUse);
|
||||||
|
SubscribeLocalEvent<TriggerOnInteractHandComponent, InteractHandEvent>(OnInteractHand);
|
||||||
|
|
||||||
SubscribeLocalEvent<ItemToggleOnTriggerComponent, TriggerEvent>(HandleItemToggleOnTrigger);
|
SubscribeLocalEvent<ItemToggleOnTriggerComponent, TriggerEvent>(HandleItemToggleOnTrigger);
|
||||||
SubscribeLocalEvent<AnchorOnTriggerComponent, TriggerEvent>(HandleAnchorOnTrigger);
|
SubscribeLocalEvent<AnchorOnTriggerComponent, TriggerEvent>(HandleAnchorOnTrigger);
|
||||||
@@ -39,6 +40,15 @@ public sealed partial class TriggerSystem
|
|||||||
args.Handled = true;
|
args.Handled = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void OnInteractHand(Entity<TriggerOnInteractHandComponent> ent, ref InteractHandEvent args)
|
||||||
|
{
|
||||||
|
if (args.Handled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Trigger(ent.Owner, args.User, ent.Comp.KeyOut);
|
||||||
|
args.Handled = true;
|
||||||
|
}
|
||||||
|
|
||||||
private void HandleItemToggleOnTrigger(Entity<ItemToggleOnTriggerComponent> ent, ref TriggerEvent args)
|
private void HandleItemToggleOnTrigger(Entity<ItemToggleOnTriggerComponent> ent, ref TriggerEvent args)
|
||||||
{
|
{
|
||||||
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
if (args.Key != null && !ent.Comp.KeysIn.Contains(args.Key))
|
||||||
|
|||||||
Reference in New Issue
Block a user