fix singulo decay (#28743)
This commit is contained in:
@@ -49,7 +49,7 @@ public sealed partial class ParticleAcceleratorSystem
|
||||
ParticleAcceleratorPowerState.Level0 => 1,
|
||||
ParticleAcceleratorPowerState.Level1 => 2,
|
||||
ParticleAcceleratorPowerState.Level2 => 3,
|
||||
ParticleAcceleratorPowerState.Level3 => 10,
|
||||
ParticleAcceleratorPowerState.Level3 => 6,
|
||||
_ => 0,
|
||||
} * 10;
|
||||
}
|
||||
|
||||
@@ -55,14 +55,12 @@ public sealed class SingularitySystem : SharedSingularitySystem
|
||||
|
||||
var vvHandle = Vvm.GetTypeHandler<SingularityComponent>();
|
||||
vvHandle.AddPath(nameof(SingularityComponent.Energy), (_, comp) => comp.Energy, SetEnergy);
|
||||
vvHandle.AddPath(nameof(SingularityComponent.TargetUpdatePeriod), (_, comp) => comp.TargetUpdatePeriod, SetUpdatePeriod);
|
||||
}
|
||||
|
||||
public override void Shutdown()
|
||||
{
|
||||
var vvHandle = Vvm.GetTypeHandler<SingularityComponent>();
|
||||
vvHandle.RemovePath(nameof(SingularityComponent.Energy));
|
||||
vvHandle.RemovePath(nameof(SingularityComponent.TargetUpdatePeriod));
|
||||
base.Shutdown();
|
||||
}
|
||||
|
||||
@@ -78,39 +76,10 @@ public sealed class SingularitySystem : SharedSingularitySystem
|
||||
var query = EntityQueryEnumerator<SingularityComponent>();
|
||||
while (query.MoveNext(out var uid, out var singularity))
|
||||
{
|
||||
var curTime = _timing.CurTime;
|
||||
if (singularity.NextUpdateTime <= curTime)
|
||||
Update(uid, curTime - singularity.LastUpdateTime, singularity);
|
||||
AdjustEnergy(uid, -singularity.EnergyDrain * frameTime, singularity: singularity);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the gradual energy loss and dissipation of singularity.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the singularity to update.</param>
|
||||
/// <param name="singularity">The state of the singularity to update.</param>
|
||||
public void Update(EntityUid uid, SingularityComponent? singularity = null)
|
||||
{
|
||||
if (Resolve(uid, ref singularity))
|
||||
Update(uid, _timing.CurTime - singularity.LastUpdateTime, singularity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Handles the gradual energy loss and dissipation of a singularity.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the singularity to update.</param>
|
||||
/// <param name="frameTime">The amount of time that has elapsed since the last update.</param>
|
||||
/// <param name="singularity">The state of the singularity to update.</param>
|
||||
public void Update(EntityUid uid, TimeSpan frameTime, SingularityComponent? singularity = null)
|
||||
{
|
||||
if(!Resolve(uid, ref singularity))
|
||||
return;
|
||||
|
||||
singularity.LastUpdateTime = _timing.CurTime;
|
||||
singularity.NextUpdateTime = singularity.LastUpdateTime + singularity.TargetUpdatePeriod;
|
||||
AdjustEnergy(uid, -singularity.EnergyDrain * (float)frameTime.TotalSeconds, singularity: singularity);
|
||||
}
|
||||
|
||||
#region Getters/Setters
|
||||
|
||||
/// <summary>
|
||||
@@ -166,28 +135,6 @@ public sealed class SingularitySystem : SharedSingularitySystem
|
||||
SetEnergy(uid, MathHelper.Clamp(newValue, min, max), singularity);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Setter for <see cref="SingularityComponent.TargetUpdatePeriod"/>.
|
||||
/// If the new target time implies that the singularity should have updated it does so immediately.
|
||||
/// </summary>
|
||||
/// <param name="uid">The uid of the singularity to set the update period for.</param>
|
||||
/// <param name="value">The new update period for the singularity.</param>
|
||||
/// <param name="singularity">The state of the singularity to set the update period for.</param>
|
||||
public void SetUpdatePeriod(EntityUid uid, TimeSpan value, SingularityComponent? singularity = null)
|
||||
{
|
||||
if(!Resolve(uid, ref singularity))
|
||||
return;
|
||||
|
||||
if (MathHelper.CloseTo(singularity.TargetUpdatePeriod.TotalSeconds, value.TotalSeconds))
|
||||
return;
|
||||
|
||||
singularity.TargetUpdatePeriod = value;
|
||||
singularity.NextUpdateTime = singularity.LastUpdateTime + singularity.TargetUpdatePeriod;
|
||||
|
||||
var curTime = _timing.CurTime;
|
||||
if (singularity.NextUpdateTime <= curTime)
|
||||
Update(uid, curTime - singularity.LastUpdateTime, singularity);
|
||||
}
|
||||
|
||||
#endregion Getters/Setters
|
||||
|
||||
@@ -203,9 +150,6 @@ public sealed class SingularitySystem : SharedSingularitySystem
|
||||
/// <param name="args">The event arguments.</param>
|
||||
protected override void OnSingularityStartup(EntityUid uid, SingularityComponent comp, ComponentStartup args)
|
||||
{
|
||||
comp.LastUpdateTime = _timing.CurTime;
|
||||
comp.NextUpdateTime = comp.LastUpdateTime + comp.TargetUpdatePeriod;
|
||||
|
||||
MetaDataComponent? metaData = null;
|
||||
if (Resolve(uid, ref metaData) && metaData.EntityLifeStage <= EntityLifeStage.Initializing)
|
||||
_audio.PlayPvs(comp.FormationSound, uid);
|
||||
@@ -223,7 +167,7 @@ public sealed class SingularitySystem : SharedSingularitySystem
|
||||
/// <param name="args">The event arguments.</param>
|
||||
public void OnDistortionStartup(EntityUid uid, SingularityDistortionComponent comp, ComponentStartup args)
|
||||
{
|
||||
_pvs.AddGlobalOverride(GetNetEntity(uid));
|
||||
_pvs.AddGlobalOverride(uid);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -269,6 +213,10 @@ public sealed class SingularitySystem : SharedSingularitySystem
|
||||
/// <param name="args">The event arguments.</param>
|
||||
public void OnConsumedEntity(EntityUid uid, SingularityComponent comp, ref EntityConsumedByEventHorizonEvent args)
|
||||
{
|
||||
// Don't double count singulo food
|
||||
if (HasComp<SinguloFoodComponent>(args.Entity))
|
||||
return;
|
||||
|
||||
AdjustEnergy(uid, BaseEntityEnergy, singularity: comp);
|
||||
}
|
||||
|
||||
|
||||
@@ -81,26 +81,4 @@ public sealed partial class SingularityComponent : Component
|
||||
);
|
||||
|
||||
#endregion Audio
|
||||
|
||||
#region Update Timing
|
||||
|
||||
/// <summary>
|
||||
/// The amount of time that should elapse between automated updates to this singularity.
|
||||
/// </summary>
|
||||
[DataField("updatePeriod")]
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public TimeSpan TargetUpdatePeriod = TimeSpan.FromSeconds(1.0);
|
||||
|
||||
/// <summary>
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public TimeSpan NextUpdateTime = default!;
|
||||
|
||||
/// <summary>
|
||||
/// The last time this singularity was updated.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
public TimeSpan LastUpdateTime = default!;
|
||||
|
||||
#endregion Update Timing
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user