using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
namespace Content.Server.Spawners.Components;
///
/// Spawns entities at a set interval.
/// Can configure the set of entities, spawn timing, spawn chance,
/// and min/max number of entities to spawn.
///
[RegisterComponent, EntityCategory("Spawner")]
[AutoGenerateComponentPause]
public sealed partial class TimedSpawnerComponent : Component, ISerializationHooks
{
///
/// List of entities that can be spawned by this component. One will be randomly
/// chosen for each entity spawned. When multiple entities are spawned at once,
/// each will be randomly chosen separately.
///
[DataField]
public List Prototypes = [];
///
/// Chance of an entity being spawned at the end of each interval.
///
[DataField]
public float Chance = 1.0f;
///
/// Length of the interval between spawn attempts.
///
[DataField]
public TimeSpan IntervalSeconds = TimeSpan.FromSeconds(60);
///
/// The minimum number of entities that can be spawned when an interval elapses.
///
[DataField]
public int MinimumEntitiesSpawned = 1;
///
/// The maximum number of entities that can be spawned when an interval elapses.
///
[DataField]
public int MaximumEntitiesSpawned = 1;
///
/// The time at which the current interval will have elapsed and entities may be spawned.
///
[DataField(customTypeSerializer: typeof(TimeOffsetSerializer)), AutoPausedField]
public TimeSpan NextFire = TimeSpan.Zero;
void ISerializationHooks.AfterDeserialization()
{
if (MinimumEntitiesSpawned > MaximumEntitiesSpawned)
throw new ArgumentException("MaximumEntitiesSpawned can't be lower than MinimumEntitiesSpawned!");
}
}