* auto doggy

* fix

* fix
This commit is contained in:
Ed
2025-03-09 23:29:20 +03:00
committed by GitHub
parent 759260c2ba
commit 66058ffc49
9 changed files with 105 additions and 38 deletions

View File

@@ -0,0 +1,68 @@
using Content.Server.GameTicking;
using Content.Shared.CCVar;
using Robust.Shared.Audio;
using Robust.Shared.Console;
namespace Content.Server._CP14.RoundEnd;
public sealed partial class CP14RoundEndSystem
{
[Dependency] private readonly IConsoleHost _consoleHost = default!;
[Dependency] private readonly GameTicker _ticker = default!;
private TimeSpan _nextUpdateTime = TimeSpan.Zero;
private readonly TimeSpan _updateFrequency = TimeSpan.FromSeconds(45f);
private bool _enabled;
private void InitCbt()
{
_enabled = _configManager.GetCVar(CCVars.CP14ClosedBetaTest);
_configManager.OnValueChanged(CCVars.CP14ClosedBetaTest, _ => { _enabled = _configManager.GetCVar(CCVars.CP14ClosedBetaTest); }, true);
}
// Вы можете сказать: Эд, ты ебанулся? Это же лютый щиткод!
// И я вам отвечу: Да. Но сама система ограничения времени работы сервера - временная штука на этап разработки, которая будет удалена. Мне просто лень каждый раз запускать и выключать сервер ручками.
private void UpdateCbt(float _)
{
if (!_enabled)
return;
if (_nextUpdateTime > _timing.CurTime)
return;
_nextUpdateTime = _timing.CurTime + _updateFrequency;
DateTime nowMoscow = DateTime.UtcNow.AddHours(3);
//Disable any round timers
if (nowMoscow.Hour is < 18 or > 20)
{
if (_ticker.RunLevel == GameRunLevel.InRound)
_roundEnd.EndRound();
if (!_ticker.Paused)
_ticker.TogglePause();
}
else
{
if (_ticker.Paused)
_ticker.TogglePause();
}
if (nowMoscow.Hour == 17 && nowMoscow.Minute == 45)
{
_consoleHost.ExecuteCommand("shutdown"); //Restart server, load updates and other
}
if (nowMoscow.Hour == 20 && nowMoscow.Minute == 45)
{
_chatSystem.DispatchGlobalAnnouncement("ВНИМАНИЕ: Сервер автоматически завершит раунд через 15 минут", announcementSound: new SoundPathSpecifier("/Audio/Effects/beep1.ogg"), sender: "Сервер");
}
if (nowMoscow.Hour == 21 && nowMoscow.Minute == 02)
{
_consoleHost.ExecuteCommand("golobby");
_consoleHost.ExecuteCommand("set-motd Плейтест на сегодня уже закончен. Следующий запуск в 18:00 МСК.");
}
}
}

View File

@@ -15,7 +15,6 @@ public sealed partial class CP14RoundEndSystem : EntitySystem
{
[Dependency] private readonly IGameTiming _timing = default!;
[Dependency] private readonly ChatSystem _chatSystem = default!;
[Dependency] private readonly GameTicker _gameTicker = default!;
[Dependency] private readonly CP14DemiplaneSystem _demiplane = default!;
[Dependency] private readonly RoundEndSystem _roundEnd = default!;
[Dependency] private readonly IConfigurationManager _configManager = default!;
@@ -27,6 +26,8 @@ public sealed partial class CP14RoundEndSystem : EntitySystem
{
base.Initialize();
InitCbt();
SubscribeLocalEvent<CP14MagicContainerRoundFinisherComponent, CP14MagicEnergyLevelChangeEvent>(OnFinisherMagicEnergyLevelChange);
SubscribeNetworkEvent<RoundEndMessageEvent>(OnRoundEndMessage);
}
@@ -34,19 +35,25 @@ public sealed partial class CP14RoundEndSystem : EntitySystem
private void OnRoundEndMessage(RoundEndMessageEvent ev)
{
_roundEndMoment = TimeSpan.Zero; //Reset timer, so it cant affect next round in any case
_demiplane.DeleteAllDemiplanes(safe: false);
_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("cp14-round-end"),
announcementSound: new SoundPathSpecifier("/Audio/_CP14/Ambience/event_boom.ogg"));
}
public override void Update(float frameTime)
{
base.Update(frameTime);
UpdateCbt(frameTime);
if (_roundEndMoment == TimeSpan.Zero)
return;
if (_roundEndMoment > _timing.CurTime)
return;
EndRound();
_roundEnd.EndRound();
}
private void OnFinisherMagicEnergyLevelChange(Entity<CP14MagicContainerRoundFinisherComponent> ent,
@@ -103,16 +110,4 @@ public sealed partial class CP14RoundEndSystem : EntitySystem
_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("cp14-round-end-monolith-recharged"),
announcementSound: new SoundPathSpecifier("/Audio/_CP14/Ambience/event_boom.ogg"));
}
private void EndRound()
{
if (_gameTicker.RunLevel != GameRunLevel.InRound)
return;
_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("cp14-round-end"),
announcementSound: new SoundPathSpecifier("/Audio/_CP14/Ambience/event_boom.ogg"));
_roundEndMoment = TimeSpan.Zero;
_roundEnd.EndRound();
_demiplane.DeleteAllDemiplanes(safe: false);
}
}