From 52d8e8b00fb109a0656996a52a9cde278b3998ae Mon Sep 17 00:00:00 2001 From: Ed Date: Mon, 7 Oct 2024 00:07:47 +0300 Subject: [PATCH] brute zlevel reloading --- .../Components/CP14StationAbyssComponent.cs | 25 +++++++++ .../EntitySystems/CP14StationAbyssSystem.cs | 54 +++++++++++++++++++ .../EntitySystems/CP14StationZLevelsSystem.cs | 1 - .../StationZLevels/CP14ZLevelPrototype.cs | 2 +- 4 files changed, 80 insertions(+), 2 deletions(-) diff --git a/Content.Server/_CP14/StationDungeonMap/Components/CP14StationAbyssComponent.cs b/Content.Server/_CP14/StationDungeonMap/Components/CP14StationAbyssComponent.cs index 0310d85f09..0e08207b3d 100644 --- a/Content.Server/_CP14/StationDungeonMap/Components/CP14StationAbyssComponent.cs +++ b/Content.Server/_CP14/StationDungeonMap/Components/CP14StationAbyssComponent.cs @@ -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> 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, } diff --git a/Content.Server/_CP14/StationDungeonMap/EntitySystems/CP14StationAbyssSystem.cs b/Content.Server/_CP14/StationDungeonMap/EntitySystems/CP14StationAbyssSystem.cs index e1fa1cde8e..a38a6170e2 100644 --- a/Content.Server/_CP14/StationDungeonMap/EntitySystems/CP14StationAbyssSystem.cs +++ b/Content.Server/_CP14/StationDungeonMap/EntitySystems/CP14StationAbyssSystem.cs @@ -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(OnStationPostInit); + } + + public override void Update(float frameTime) + { + base.Update(frameTime); + + var query = new EntityQueryEnumerator(); + 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 abyss, ref StationPostInitEvent args) + { + abyss.Comp.NextReloadTime = _timing.CurTime + _random.Next(abyss.Comp.MinReloadTime, abyss.Comp.MaxReloadTime); + ReloadAbyssNow(abyss); + } + + /// + /// Start process of removing old layers, and then generate new + /// + /// + public void ReloadAbyssNow(Entity abyss) + { + if (!TryComp(abyss, out var zLevelComp)) + return; + + foreach (var level in abyss.Comp.Levels) + { + var floor = _random.Pick(level.Value); + if (!_proto.TryIndex(floor, out var indexedZLevel)) + return; + var resPath = _random.Pick(indexedZLevel.Maps); + + _zLevels.SetZLevel((abyss, zLevelComp), level.Key, resPath, true); + } } } diff --git a/Content.Server/_CP14/StationDungeonMap/EntitySystems/CP14StationZLevelsSystem.cs b/Content.Server/_CP14/StationDungeonMap/EntitySystems/CP14StationZLevelsSystem.cs index f74b575082..c35e30c063 100644 --- a/Content.Server/_CP14/StationDungeonMap/EntitySystems/CP14StationZLevelsSystem.cs +++ b/Content.Server/_CP14/StationDungeonMap/EntitySystems/CP14StationZLevelsSystem.cs @@ -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() diff --git a/Content.Shared/_CP14/StationZLevels/CP14ZLevelPrototype.cs b/Content.Shared/_CP14/StationZLevels/CP14ZLevelPrototype.cs index 1d929a5ee9..3fd040b8c2 100644 --- a/Content.Shared/_CP14/StationZLevels/CP14ZLevelPrototype.cs +++ b/Content.Shared/_CP14/StationZLevels/CP14ZLevelPrototype.cs @@ -4,7 +4,7 @@ using Robust.Shared.Utility; namespace Content.Shared._CP14.StationZLevels; /// -/// 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 /// [Prototype("zLevel")] public sealed partial class CP14ZLevelPrototype : IPrototype