brute zlevel reloading
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
using Content.Server._CP14.StationDungeonMap.EntitySystems;
|
||||
using Content.Shared._CP14.StationZLevels;
|
||||
using Content.Shared.Destructible.Thresholds;
|
||||
|
||||
namespace Content.Server._CP14.StationDungeonMap.Components;
|
||||
|
||||
@@ -11,4 +12,28 @@ public sealed partial class CP14StationAbyssComponent : Component
|
||||
{
|
||||
[DataField]
|
||||
public Dictionary<int, HashSet<CP14ZLevelPrototype>> Levels = new();
|
||||
|
||||
[DataField]
|
||||
public TimeSpan MinReloadTime = TimeSpan.FromMinutes(5);
|
||||
|
||||
[DataField]
|
||||
public TimeSpan MaxReloadTime = TimeSpan.FromMinutes(30);
|
||||
|
||||
[DataField]
|
||||
public TimeSpan NextReloadTime = TimeSpan.Zero;
|
||||
|
||||
// Telegraphy and delays
|
||||
|
||||
[DataField]
|
||||
public TimeSpan PreReloadAlertTime = TimeSpan.FromSeconds(120f);
|
||||
|
||||
//[DataField]
|
||||
//public AbyssState Status = AbyssState.Generating;
|
||||
}
|
||||
|
||||
public enum AbyssState : byte
|
||||
{
|
||||
Generating = 0,
|
||||
Waiting = 1,
|
||||
Destroying = 2,
|
||||
}
|
||||
|
||||
@@ -1,11 +1,65 @@
|
||||
using Content.Server._CP14.StationDungeonMap.Components;
|
||||
using Content.Server.Station.Events;
|
||||
using Content.Shared._CP14.StationZLevels;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Timing;
|
||||
|
||||
namespace Content.Server._CP14.StationDungeonMap.EntitySystems;
|
||||
|
||||
public sealed partial class CP14StationAbyssSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly IGameTiming _timing = default!;
|
||||
[Dependency] private readonly CP14StationZLevelsSystem _zLevels = default!;
|
||||
[Dependency] private readonly IPrototypeManager _proto = default!;
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
|
||||
SubscribeLocalEvent<CP14StationAbyssComponent, StationPostInitEvent>(OnStationPostInit);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
base.Update(frameTime);
|
||||
|
||||
var query = new EntityQueryEnumerator<CP14StationAbyssComponent, CP14StationZLevelsComponent>();
|
||||
while (query.MoveNext(out var uid, out var abyss, out var zLevel))
|
||||
{
|
||||
if (_timing.CurTime < abyss.NextReloadTime && abyss.NextReloadTime != TimeSpan.Zero)
|
||||
continue;
|
||||
|
||||
abyss.NextReloadTime = _timing.CurTime + _random.Next(abyss.MinReloadTime, abyss.MaxReloadTime);
|
||||
|
||||
ReloadAbyssNow((uid, abyss));
|
||||
}
|
||||
}
|
||||
|
||||
private void OnStationPostInit(Entity<CP14StationAbyssComponent> abyss, ref StationPostInitEvent args)
|
||||
{
|
||||
abyss.Comp.NextReloadTime = _timing.CurTime + _random.Next(abyss.Comp.MinReloadTime, abyss.Comp.MaxReloadTime);
|
||||
ReloadAbyssNow(abyss);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Start process of removing old layers, and then generate new
|
||||
/// </summary>
|
||||
/// <param name="abyss"></param>
|
||||
public void ReloadAbyssNow(Entity<CP14StationAbyssComponent> abyss)
|
||||
{
|
||||
if (!TryComp<CP14StationZLevelsComponent>(abyss, out var zLevelComp))
|
||||
return;
|
||||
|
||||
foreach (var level in abyss.Comp.Levels)
|
||||
{
|
||||
var floor = _random.Pick(level.Value);
|
||||
if (!_proto.TryIndex<CP14ZLevelPrototype>(floor, out var indexedZLevel))
|
||||
return;
|
||||
var resPath = _random.Pick(indexedZLevel.Maps);
|
||||
|
||||
_zLevels.SetZLevel((abyss, zLevelComp), level.Key, resPath, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -20,7 +20,6 @@ public sealed partial class CP14StationZLevelsSystem : EntitySystem
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
[Dependency] private readonly MapLoaderSystem _mapLoader = default!;
|
||||
[Dependency] private readonly TransformSystem _transform = default!;
|
||||
[Dependency] private readonly TileSystem _tile = default!;
|
||||
[Dependency] private readonly LinkedEntitySystem _linkedEntity = default!;
|
||||
|
||||
public override void Initialize()
|
||||
|
||||
@@ -4,7 +4,7 @@ using Robust.Shared.Utility;
|
||||
namespace Content.Shared._CP14.StationZLevels;
|
||||
|
||||
/// <summary>
|
||||
/// Prototype “floor type”. Refers to a certain group of cards united by a common style and some common rules
|
||||
/// Prototype “floor type”. Refers to a certain group of maps united by a common style and some common data
|
||||
/// </summary>
|
||||
[Prototype("zLevel")]
|
||||
public sealed partial class CP14ZLevelPrototype : IPrototype
|
||||
|
||||
Reference in New Issue
Block a user