Add hot potato (#14204)

Co-authored-by: AJCM <AJCM@tutanota.com>
This commit is contained in:
Slava0135
2023-04-22 14:40:36 +03:00
committed by GitHub
parent 1907b249d7
commit c00bd9c247
14 changed files with 274 additions and 0 deletions

View File

@@ -0,0 +1,23 @@
using Robust.Shared.GameStates;
namespace Content.Shared.HotPotato;
/// <summary>
/// Added to an activated hot potato. Controls hot potato transfer on server / effect spawning on client.
/// </summary>
[RegisterComponent, NetworkedComponent]
[Access(typeof(SharedHotPotatoSystem))]
public sealed class ActiveHotPotatoComponent : Component
{
/// <summary>
/// Hot potato effect spawn cooldown in seconds
/// </summary>
[DataField("effectCooldown"), ViewVariables(VVAccess.ReadWrite)]
public float EffectCooldown = 0.3f;
/// <summary>
/// Moment in time next effect will be spawned
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public TimeSpan TargetTime = TimeSpan.Zero;
}

View File

@@ -0,0 +1,20 @@
using Robust.Shared.GameStates;
namespace Content.Shared.HotPotato;
/// <summary>
/// Similar to <see cref="Content.Shared.Interaction.Components.UnremoveableComponent"/>
/// except entities with this component can be removed in specific case: <see cref="CanTransfer"/>
/// </summary>
[RegisterComponent, NetworkedComponent]
[AutoGenerateComponentState]
[Access(typeof(SharedHotPotatoSystem))]
public sealed partial class HotPotatoComponent : Component
{
/// <summary>
/// If set to true entity can be removed by hitting entities if they have hands
/// </summary>
[DataField("canTransfer"), ViewVariables(VVAccess.ReadWrite)]
[AutoNetworkedField]
public bool CanTransfer = true;
}

View File

@@ -0,0 +1,18 @@
using Robust.Shared.Containers;
namespace Content.Shared.HotPotato;
public abstract class SharedHotPotatoSystem : EntitySystem
{
public override void Initialize()
{
base.Initialize();
SubscribeLocalEvent<HotPotatoComponent, ContainerGettingRemovedAttemptEvent>(OnRemoveAttempt);
}
private void OnRemoveAttempt(EntityUid uid, HotPotatoComponent comp, ContainerGettingRemovedAttemptEvent args)
{
if (!comp.CanTransfer)
args.Cancel();
}
}