Mass hallucinations event (#17321)
* paracusia component auto comp state * it works * rule component config
This commit is contained in:
@@ -0,0 +1,11 @@
|
||||
using Content.Server.StationEvents.Events;
|
||||
|
||||
namespace Content.Server.StationEvents.Components;
|
||||
|
||||
/// <summary>
|
||||
/// This is used to keep track of hallucinated entities to remove effects when event ends
|
||||
/// </summary>
|
||||
[RegisterComponent, Access(typeof(MassHallucinationsRule))]
|
||||
public sealed class MassHallucinationsComponent : Component
|
||||
{
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using Content.Server.StationEvents.Events;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.StationEvents.Components;
|
||||
|
||||
[RegisterComponent, Access(typeof(MassHallucinationsRule))]
|
||||
public sealed class MassHallucinationsRuleComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum time between incidents in seconds
|
||||
/// </summary>
|
||||
[DataField("maxTimeBetweenIncidents", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MaxTimeBetweenIncidents;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum time between incidents in seconds
|
||||
/// </summary>
|
||||
[DataField("minTimeBetweenIncidents", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MinTimeBetweenIncidents;
|
||||
|
||||
[DataField("maxSoundDistance", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MaxSoundDistance;
|
||||
|
||||
[DataField("sounds", required: true)]
|
||||
public SoundSpecifier Sounds = default!;
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Content.Server.GameTicking.Rules.Components;
|
||||
using Content.Server.Mind.Components;
|
||||
using Content.Server.StationEvents.Components;
|
||||
using Content.Server.Traits.Assorted;
|
||||
using Content.Shared.Traits.Assorted;
|
||||
|
||||
namespace Content.Server.StationEvents.Events;
|
||||
|
||||
public sealed class MassHallucinationsRule : StationEventSystem<MassHallucinationsRuleComponent>
|
||||
{
|
||||
[Dependency] private readonly ParacusiaSystem _paracusia = default!;
|
||||
|
||||
protected override void Started(EntityUid uid, MassHallucinationsRuleComponent component, GameRuleComponent gameRule, GameRuleStartedEvent args)
|
||||
{
|
||||
base.Started(uid, component, gameRule, args);
|
||||
var query = EntityQueryEnumerator<MindComponent>();
|
||||
while (query.MoveNext(out var ent, out _))
|
||||
{
|
||||
if (!HasComp<ParacusiaComponent>(ent))
|
||||
{
|
||||
EnsureComp<MassHallucinationsComponent>(ent);
|
||||
var paracusia = EnsureComp<ParacusiaComponent>(ent);
|
||||
_paracusia.SetSounds(ent, component.Sounds, paracusia);
|
||||
_paracusia.SetTime(ent, component.MinTimeBetweenIncidents, component.MaxTimeBetweenIncidents, paracusia);
|
||||
_paracusia.SetDistance(ent, component.MaxSoundDistance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Ended(EntityUid uid, MassHallucinationsRuleComponent component, GameRuleComponent gameRule, GameRuleEndedEvent args)
|
||||
{
|
||||
base.Ended(uid, component, gameRule, args);
|
||||
var query = EntityQueryEnumerator<MassHallucinationsComponent>();
|
||||
while (query.MoveNext(out var ent, out _))
|
||||
{
|
||||
RemComp<ParacusiaComponent>(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,8 +1,38 @@
|
||||
using Content.Shared.Traits.Assorted;
|
||||
using Robust.Shared.Audio;
|
||||
|
||||
namespace Content.Server.Traits.Assorted;
|
||||
|
||||
public sealed class ParacusiaSystem : SharedParacusiaSystem
|
||||
{
|
||||
public void SetSounds(EntityUid uid, SoundSpecifier sounds, ParacusiaComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
{
|
||||
return;
|
||||
}
|
||||
component.Sounds = sounds;
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
public void SetTime(EntityUid uid, float minTime, float maxTime, ParacusiaComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
{
|
||||
return;
|
||||
}
|
||||
component.MinTimeBetweenIncidents = minTime;
|
||||
component.MaxTimeBetweenIncidents = maxTime;
|
||||
Dirty(component);
|
||||
}
|
||||
|
||||
public void SetDistance(EntityUid uid, float maxSoundDistance, ParacusiaComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component))
|
||||
{
|
||||
return;
|
||||
}
|
||||
component.MaxSoundDistance = maxSoundDistance;
|
||||
Dirty(component);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameStates;
|
||||
using System;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Shared.Traits.Assorted;
|
||||
@@ -10,31 +8,36 @@ namespace Content.Shared.Traits.Assorted;
|
||||
/// This component is used for paracusia, which causes auditory hallucinations.
|
||||
/// </summary>
|
||||
[RegisterComponent, NetworkedComponent]
|
||||
[AutoGenerateComponentState]
|
||||
[Access(typeof(SharedParacusiaSystem))]
|
||||
public sealed class ParacusiaComponent : Component
|
||||
public sealed partial class ParacusiaComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The maximum time between incidents in seconds
|
||||
/// </summary>
|
||||
[DataField("maxTimeBetweenIncidents", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MaxTimeBetweenIncidents = 30f;
|
||||
[AutoNetworkedField]
|
||||
public float MaxTimeBetweenIncidents = 60f;
|
||||
|
||||
/// <summary>
|
||||
/// The minimum time between incidents in seconds
|
||||
/// </summary>
|
||||
[DataField("minTimeBetweenIncidents", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float MinTimeBetweenIncidents = 60f;
|
||||
[AutoNetworkedField]
|
||||
public float MinTimeBetweenIncidents = 30f;
|
||||
|
||||
/// <summary>
|
||||
/// How far away at most can the sound be?
|
||||
/// </summary>
|
||||
[DataField("maxSoundDistance", required: true), ViewVariables(VVAccess.ReadWrite)]
|
||||
[AutoNetworkedField]
|
||||
public float MaxSoundDistance;
|
||||
|
||||
/// <summary>
|
||||
/// The sounds to choose from
|
||||
/// </summary>
|
||||
[DataField("sounds", required: true)]
|
||||
[AutoNetworkedField]
|
||||
public SoundSpecifier Sounds = default!;
|
||||
|
||||
[DataField("timeBetweenIncidents", customTypeSerializer: typeof(TimeOffsetSerializer)), ViewVariables(VVAccess.ReadWrite)]
|
||||
@@ -42,20 +45,3 @@ public sealed class ParacusiaComponent : Component
|
||||
|
||||
public IPlayingAudioStream? Stream;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class ParacusiaComponentState : ComponentState
|
||||
{
|
||||
public readonly float MaxTimeBetweenIncidents;
|
||||
public readonly float MinTimeBetweenIncidents;
|
||||
public readonly float MaxSoundDistance;
|
||||
public readonly SoundSpecifier Sounds = default!;
|
||||
|
||||
public ParacusiaComponentState(float maxTimeBetweenIncidents, float minTimeBetweenIncidents, float maxSoundDistance, SoundSpecifier sounds)
|
||||
{
|
||||
MaxTimeBetweenIncidents = maxTimeBetweenIncidents;
|
||||
MinTimeBetweenIncidents = minTimeBetweenIncidents;
|
||||
MaxSoundDistance = maxSoundDistance;
|
||||
Sounds = sounds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,30 +1,5 @@
|
||||
using Content.Shared.GameTicking;
|
||||
using Robust.Shared.GameStates;
|
||||
|
||||
namespace Content.Shared.Traits.Assorted;
|
||||
|
||||
public abstract class SharedParacusiaSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
SubscribeLocalEvent<ParacusiaComponent, ComponentGetState>(GetCompState);
|
||||
SubscribeLocalEvent<ParacusiaComponent, ComponentHandleState>(HandleCompState);
|
||||
}
|
||||
|
||||
private void GetCompState(EntityUid uid, ParacusiaComponent component, ref ComponentGetState args)
|
||||
{
|
||||
args.State = new ParacusiaComponentState(component.MaxTimeBetweenIncidents, component.MinTimeBetweenIncidents, component.MaxSoundDistance, component.Sounds);
|
||||
}
|
||||
|
||||
private void HandleCompState(EntityUid uid, ParacusiaComponent component, ref ComponentHandleState args)
|
||||
{
|
||||
if (args.Current is not ParacusiaComponentState state)
|
||||
return;
|
||||
|
||||
component.MaxTimeBetweenIncidents = state.MaxTimeBetweenIncidents;
|
||||
component.MinTimeBetweenIncidents = state.MinTimeBetweenIncidents;
|
||||
component.MaxSoundDistance = state.MaxSoundDistance;
|
||||
component.Sounds = state.Sounds;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -316,3 +316,19 @@
|
||||
reoccurrenceDelay: 25
|
||||
duration: 1
|
||||
- type: LoneOpsSpawnRule
|
||||
|
||||
- type: entity
|
||||
id: MassHallucinations
|
||||
parent: BaseGameRule
|
||||
noSpawn: true
|
||||
components:
|
||||
- type: StationEvent
|
||||
weight: 10
|
||||
duration: 150
|
||||
maxDuration: 300
|
||||
- type: MassHallucinationsRule
|
||||
minTimeBetweenIncidents: 0.1
|
||||
maxTimeBetweenIncidents: 300
|
||||
maxSoundDistance: 7
|
||||
sounds:
|
||||
collection: Paracusia
|
||||
|
||||
Reference in New Issue
Block a user