using Robust.Shared.Physics.Events;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
-using Robust.Shared.Serialization.Manager;
-using System.Linq;
namespace Content.Server.Anomaly;
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);
- ShuffleParticlesEffect(anomaly.Comp);
+ ShuffleParticlesEffect(anomaly);
anomaly.Comp.Continuity = _random.NextFloat(anomaly.Comp.MinContituty, anomaly.Comp.MaxContituty);
SetBehavior(anomaly, GetRandomBehavior());
}
- public void ShuffleParticlesEffect(AnomalyComponent anomaly)
+ public void ShuffleParticlesEffect(Entity<AnomalyComponent> anomaly)
{
var particles = new List<AnomalousParticleType>
{ AnomalousParticleType.Delta, AnomalousParticleType.Epsilon, AnomalousParticleType.Zeta, AnomalousParticleType.Sigma };
- anomaly.SeverityParticleType = Random.PickAndTake(particles);
- anomaly.DestabilizingParticleType = Random.PickAndTake(particles);
- anomaly.WeakeningParticleType = Random.PickAndTake(particles);
- anomaly.TransformationParticleType = Random.PickAndTake(particles);
+ anomaly.Comp.SeverityParticleType = Random.PickAndTake(particles);
+ anomaly.Comp.DestabilizingParticleType = Random.PickAndTake(particles);
+ anomaly.Comp.WeakeningParticleType = Random.PickAndTake(particles);
+ anomaly.Comp.TransformationParticleType = Random.PickAndTake(particles);
+ Dirty(anomaly);
}
private void OnShutdown(Entity<AnomalyComponent> anomaly, ref ComponentShutdown args)
if (anomaly.Comp.CurrentBehavior != null)
RemoveBehavior(anomaly, anomaly.Comp.CurrentBehavior.Value);
- //event broadcast
- var ev = new AnomalyBehaviorChangedEvent(anomaly, anomaly.Comp.CurrentBehavior, behaviorProto);
anomaly.Comp.CurrentBehavior = behaviorProto;
- RaiseLocalEvent(anomaly, ref ev, true);
-
var behavior = _prototype.Index(behaviorProto);
-
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)
if (anomaly.Comp.CurrentBehavior == null)
return;
- var behavior = _prototype.Index(anomaly.Comp.CurrentBehavior.Value);
+ var behavior = _prototype.Index(behaviorProto);
EntityManager.RemoveComponents(anomaly, behavior.Components);
}
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;
- if (shuffle.ShuffleOnParticleHit && _random.Prob(shuffle.Prob))
- _anomaly.ShuffleParticlesEffect(anomaly);
-
- if (!TryComp<AnomalousParticleComponent>(args.OtherEntity, out var particle))
+ if (!HasComp<AnomalousParticleComponent>(args.OtherEntity))
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;
- if (shuffle.ShuffleOnPulse && _random.Prob(shuffle.Prob))
+ if (ent.Comp.ShuffleOnPulse && _random.Prob(ent.Comp.Prob))
{
- _anomaly.ShuffleParticlesEffect(anomaly);
+ _anomaly.ShuffleParticlesEffect((ent, anomaly));
}
}
}
/// <summary>
/// The particle type that increases the severity of the anomaly.
/// </summary>
- [DataField]
+ [DataField, AutoNetworkedField]
public AnomalousParticleType SeverityParticleType;
/// <summary>
/// The particle type that destabilizes the anomaly.
/// </summary>
- [DataField]
+ [DataField, AutoNetworkedField]
public AnomalousParticleType DestabilizingParticleType;
/// <summary>
/// The particle type that weakens the anomalys health.
/// </summary>
- [DataField]
+ [DataField, AutoNetworkedField]
public AnomalousParticleType WeakeningParticleType;
/// <summary>
/// The particle type that change anomaly behaviour.
/// </summary>
- [DataField]
+ [DataField, AutoNetworkedField]
public AnomalousParticleType TransformationParticleType;
#region Points and Vessels
/// <summary>
/// Event broadcast when an anomaly's behavior is changed.
+/// This is raised after the relevant components are applied
/// </summary>
[ByRefEvent]
public readonly record struct AnomalyBehaviorChangedEvent(EntityUid Anomaly, ProtoId<AnomalyBehaviorPrototype>? Old, ProtoId<AnomalyBehaviorPrototype>? New);