Small anomaly behavior fix (#28290)
* Small anomaly behavior fix * well put together code
This commit is contained in:
@@ -18,8 +18,6 @@ using Robust.Shared.Configuration;
|
|||||||
using Robust.Shared.Physics.Events;
|
using Robust.Shared.Physics.Events;
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
using Robust.Shared.Serialization.Manager;
|
|
||||||
using System.Linq;
|
|
||||||
|
|
||||||
namespace Content.Server.Anomaly;
|
namespace Content.Server.Anomaly;
|
||||||
|
|
||||||
@@ -69,20 +67,21 @@ public sealed partial class AnomalySystem : SharedAnomalySystem
|
|||||||
ChangeAnomalyStability(anomaly, Random.NextFloat(anomaly.Comp.InitialStabilityRange.Item1 , anomaly.Comp.InitialStabilityRange.Item2), anomaly.Comp);
|
ChangeAnomalyStability(anomaly, Random.NextFloat(anomaly.Comp.InitialStabilityRange.Item1 , anomaly.Comp.InitialStabilityRange.Item2), anomaly.Comp);
|
||||||
ChangeAnomalySeverity(anomaly, Random.NextFloat(anomaly.Comp.InitialSeverityRange.Item1, anomaly.Comp.InitialSeverityRange.Item2), anomaly.Comp);
|
ChangeAnomalySeverity(anomaly, Random.NextFloat(anomaly.Comp.InitialSeverityRange.Item1, anomaly.Comp.InitialSeverityRange.Item2), anomaly.Comp);
|
||||||
|
|
||||||
ShuffleParticlesEffect(anomaly.Comp);
|
ShuffleParticlesEffect(anomaly);
|
||||||
anomaly.Comp.Continuity = _random.NextFloat(anomaly.Comp.MinContituty, anomaly.Comp.MaxContituty);
|
anomaly.Comp.Continuity = _random.NextFloat(anomaly.Comp.MinContituty, anomaly.Comp.MaxContituty);
|
||||||
SetBehavior(anomaly, GetRandomBehavior());
|
SetBehavior(anomaly, GetRandomBehavior());
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ShuffleParticlesEffect(AnomalyComponent anomaly)
|
public void ShuffleParticlesEffect(Entity<AnomalyComponent> anomaly)
|
||||||
{
|
{
|
||||||
var particles = new List<AnomalousParticleType>
|
var particles = new List<AnomalousParticleType>
|
||||||
{ AnomalousParticleType.Delta, AnomalousParticleType.Epsilon, AnomalousParticleType.Zeta, AnomalousParticleType.Sigma };
|
{ AnomalousParticleType.Delta, AnomalousParticleType.Epsilon, AnomalousParticleType.Zeta, AnomalousParticleType.Sigma };
|
||||||
|
|
||||||
anomaly.SeverityParticleType = Random.PickAndTake(particles);
|
anomaly.Comp.SeverityParticleType = Random.PickAndTake(particles);
|
||||||
anomaly.DestabilizingParticleType = Random.PickAndTake(particles);
|
anomaly.Comp.DestabilizingParticleType = Random.PickAndTake(particles);
|
||||||
anomaly.WeakeningParticleType = Random.PickAndTake(particles);
|
anomaly.Comp.WeakeningParticleType = Random.PickAndTake(particles);
|
||||||
anomaly.TransformationParticleType = Random.PickAndTake(particles);
|
anomaly.Comp.TransformationParticleType = Random.PickAndTake(particles);
|
||||||
|
Dirty(anomaly);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnShutdown(Entity<AnomalyComponent> anomaly, ref ComponentShutdown args)
|
private void OnShutdown(Entity<AnomalyComponent> anomaly, ref ComponentShutdown args)
|
||||||
@@ -198,14 +197,12 @@ public sealed partial class AnomalySystem : SharedAnomalySystem
|
|||||||
if (anomaly.Comp.CurrentBehavior != null)
|
if (anomaly.Comp.CurrentBehavior != null)
|
||||||
RemoveBehavior(anomaly, anomaly.Comp.CurrentBehavior.Value);
|
RemoveBehavior(anomaly, anomaly.Comp.CurrentBehavior.Value);
|
||||||
|
|
||||||
//event broadcast
|
|
||||||
var ev = new AnomalyBehaviorChangedEvent(anomaly, anomaly.Comp.CurrentBehavior, behaviorProto);
|
|
||||||
anomaly.Comp.CurrentBehavior = behaviorProto;
|
anomaly.Comp.CurrentBehavior = behaviorProto;
|
||||||
RaiseLocalEvent(anomaly, ref ev, true);
|
|
||||||
|
|
||||||
var behavior = _prototype.Index(behaviorProto);
|
var behavior = _prototype.Index(behaviorProto);
|
||||||
|
|
||||||
EntityManager.AddComponents(anomaly, behavior.Components);
|
EntityManager.AddComponents(anomaly, behavior.Components);
|
||||||
|
|
||||||
|
var ev = new AnomalyBehaviorChangedEvent(anomaly, anomaly.Comp.CurrentBehavior, behaviorProto);
|
||||||
|
RaiseLocalEvent(anomaly, ref ev, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void RemoveBehavior(Entity<AnomalyComponent> anomaly, ProtoId<AnomalyBehaviorPrototype> behaviorProto)
|
private void RemoveBehavior(Entity<AnomalyComponent> anomaly, ProtoId<AnomalyBehaviorPrototype> behaviorProto)
|
||||||
@@ -213,7 +210,7 @@ public sealed partial class AnomalySystem : SharedAnomalySystem
|
|||||||
if (anomaly.Comp.CurrentBehavior == null)
|
if (anomaly.Comp.CurrentBehavior == null)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var behavior = _prototype.Index(anomaly.Comp.CurrentBehavior.Value);
|
var behavior = _prototype.Index(behaviorProto);
|
||||||
|
|
||||||
EntityManager.RemoveComponents(anomaly, behavior.Components);
|
EntityManager.RemoveComponents(anomaly, behavior.Components);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,26 +15,26 @@ public sealed class ShuffleParticlesAnomalySystem : EntitySystem
|
|||||||
SubscribeLocalEvent<ShuffleParticlesAnomalyComponent, StartCollideEvent>(OnStartCollide);
|
SubscribeLocalEvent<ShuffleParticlesAnomalyComponent, StartCollideEvent>(OnStartCollide);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnStartCollide(EntityUid uid, ShuffleParticlesAnomalyComponent shuffle, StartCollideEvent args)
|
private void OnStartCollide(Entity<ShuffleParticlesAnomalyComponent> ent, ref StartCollideEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<AnomalyComponent>(uid, out var anomaly))
|
if (!TryComp<AnomalyComponent>(ent, out var anomaly))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (shuffle.ShuffleOnParticleHit && _random.Prob(shuffle.Prob))
|
if (!HasComp<AnomalousParticleComponent>(args.OtherEntity))
|
||||||
_anomaly.ShuffleParticlesEffect(anomaly);
|
|
||||||
|
|
||||||
if (!TryComp<AnomalousParticleComponent>(args.OtherEntity, out var particle))
|
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (ent.Comp.ShuffleOnParticleHit && _random.Prob(ent.Comp.Prob))
|
||||||
|
_anomaly.ShuffleParticlesEffect((ent, anomaly));
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnPulse(EntityUid uid, ShuffleParticlesAnomalyComponent shuffle, AnomalyPulseEvent args)
|
private void OnPulse(Entity<ShuffleParticlesAnomalyComponent> ent, ref AnomalyPulseEvent args)
|
||||||
{
|
{
|
||||||
if (!TryComp<AnomalyComponent>(uid, out var anomaly))
|
if (!TryComp<AnomalyComponent>(ent, out var anomaly))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (shuffle.ShuffleOnPulse && _random.Prob(shuffle.Prob))
|
if (ent.Comp.ShuffleOnPulse && _random.Prob(ent.Comp.Prob))
|
||||||
{
|
{
|
||||||
_anomaly.ShuffleParticlesEffect(anomaly);
|
_anomaly.ShuffleParticlesEffect((ent, anomaly));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -152,25 +152,25 @@ public sealed partial class AnomalyComponent : Component
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The particle type that increases the severity of the anomaly.
|
/// The particle type that increases the severity of the anomaly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public AnomalousParticleType SeverityParticleType;
|
public AnomalousParticleType SeverityParticleType;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The particle type that destabilizes the anomaly.
|
/// The particle type that destabilizes the anomaly.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public AnomalousParticleType DestabilizingParticleType;
|
public AnomalousParticleType DestabilizingParticleType;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The particle type that weakens the anomalys health.
|
/// The particle type that weakens the anomalys health.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public AnomalousParticleType WeakeningParticleType;
|
public AnomalousParticleType WeakeningParticleType;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// The particle type that change anomaly behaviour.
|
/// The particle type that change anomaly behaviour.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DataField]
|
[DataField, AutoNetworkedField]
|
||||||
public AnomalousParticleType TransformationParticleType;
|
public AnomalousParticleType TransformationParticleType;
|
||||||
|
|
||||||
#region Points and Vessels
|
#region Points and Vessels
|
||||||
@@ -317,6 +317,7 @@ public readonly record struct AnomalyHealthChangedEvent(EntityUid Anomaly, float
|
|||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Event broadcast when an anomaly's behavior is changed.
|
/// Event broadcast when an anomaly's behavior is changed.
|
||||||
|
/// This is raised after the relevant components are applied
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ByRefEvent]
|
[ByRefEvent]
|
||||||
public readonly record struct AnomalyBehaviorChangedEvent(EntityUid Anomaly, ProtoId<AnomalyBehaviorPrototype>? Old, ProtoId<AnomalyBehaviorPrototype>? New);
|
public readonly record struct AnomalyBehaviorChangedEvent(EntityUid Anomaly, ProtoId<AnomalyBehaviorPrototype>? Old, ProtoId<AnomalyBehaviorPrototype>? New);
|
||||||
|
|||||||
Reference in New Issue
Block a user