2025-01-18 17:55:41 +03:00
|
|
|
using Content.Server.Chat.Systems;
|
2025-01-19 00:09:30 +03:00
|
|
|
using Content.Server.RoundEnd;
|
2025-01-18 17:55:41 +03:00
|
|
|
using Content.Shared._CP14.MagicEnergy;
|
2025-01-20 20:24:03 +03:00
|
|
|
using Content.Shared.GameTicking;
|
2025-01-19 00:09:30 +03:00
|
|
|
using Content.Shared.CCVar;
|
|
|
|
|
using Robust.Shared.Configuration;
|
2025-01-18 17:55:41 +03:00
|
|
|
using Robust.Shared.Audio;
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
|
|
|
|
namespace Content.Server._CP14.RoundEnd;
|
|
|
|
|
|
|
|
|
|
public sealed partial class CP14RoundEndSystem : EntitySystem
|
|
|
|
|
{
|
|
|
|
|
[Dependency] private readonly IGameTiming _timing = default!;
|
|
|
|
|
[Dependency] private readonly ChatSystem _chatSystem = default!;
|
2025-01-19 00:09:30 +03:00
|
|
|
[Dependency] private readonly RoundEndSystem _roundEnd = default!;
|
2025-04-15 23:09:49 +03:00
|
|
|
[Dependency] private readonly IConfigurationManager _cfg = default!;
|
2025-01-18 17:55:41 +03:00
|
|
|
|
|
|
|
|
private TimeSpan _roundEndMoment = TimeSpan.Zero;
|
|
|
|
|
|
2025-01-19 00:09:30 +03:00
|
|
|
//TODO: вообще нет поддержки нескольких кристаллов на карте.
|
2025-01-18 17:55:41 +03:00
|
|
|
public override void Initialize()
|
|
|
|
|
{
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
2025-03-09 23:29:20 +03:00
|
|
|
InitCbt();
|
|
|
|
|
|
2025-01-20 16:36:42 +03:00
|
|
|
SubscribeLocalEvent<CP14MagicContainerRoundFinisherComponent, CP14MagicEnergyLevelChangeEvent>(OnFinisherMagicEnergyLevelChange);
|
2025-03-13 13:30:52 +03:00
|
|
|
SubscribeLocalEvent<RoundRestartCleanupEvent>(OnRoundRestartCleanup);
|
2025-01-20 16:36:42 +03:00
|
|
|
}
|
|
|
|
|
|
2025-03-13 13:30:52 +03:00
|
|
|
private void OnRoundRestartCleanup(RoundRestartCleanupEvent ev)
|
2025-01-20 16:36:42 +03:00
|
|
|
{
|
|
|
|
|
_roundEndMoment = TimeSpan.Zero; //Reset timer, so it cant affect next round in any case
|
2025-01-18 17:55:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void Update(float frameTime)
|
|
|
|
|
{
|
|
|
|
|
base.Update(frameTime);
|
|
|
|
|
|
2025-03-09 23:29:20 +03:00
|
|
|
UpdateCbt(frameTime);
|
|
|
|
|
|
2025-01-18 17:55:41 +03:00
|
|
|
if (_roundEndMoment == TimeSpan.Zero)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
if (_roundEndMoment > _timing.CurTime)
|
|
|
|
|
return;
|
|
|
|
|
|
2025-03-13 13:30:52 +03:00
|
|
|
_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("cp14-round-end"),
|
2025-05-17 14:12:49 +03:00
|
|
|
announcementSound: new SoundPathSpecifier("/Audio/_CP14/Announce/event_boom.ogg"));
|
2025-03-09 23:29:20 +03:00
|
|
|
_roundEnd.EndRound();
|
2025-09-06 13:19:18 +03:00
|
|
|
_roundEndMoment = TimeSpan.Zero;
|
2025-01-18 17:55:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnFinisherMagicEnergyLevelChange(Entity<CP14MagicContainerRoundFinisherComponent> ent,
|
|
|
|
|
ref CP14MagicEnergyLevelChangeEvent args)
|
|
|
|
|
{
|
|
|
|
|
//Alarm 50% magic energy left
|
2025-01-20 16:36:42 +03:00
|
|
|
if (args.NewValue < args.OldValue && args.OldValue > args.MaxValue / 2 && args.NewValue <= args.MaxValue / 2)
|
2025-01-18 17:55:41 +03:00
|
|
|
{
|
|
|
|
|
_chatSystem.DispatchGlobalAnnouncement(
|
|
|
|
|
Loc.GetString("cp14-round-end-monolith-50"),
|
2025-05-17 14:12:49 +03:00
|
|
|
announcementSound: new SoundPathSpecifier("/Audio/_CP14/Announce/event_boom.ogg"));
|
2025-01-18 17:55:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//We initiate round end timer
|
|
|
|
|
if (_roundEndMoment == TimeSpan.Zero && args.NewValue == 0)
|
|
|
|
|
StartRoundEndTimer();
|
|
|
|
|
|
|
|
|
|
//Full charged - cancel roundEnd
|
|
|
|
|
if (_roundEndMoment != TimeSpan.Zero && args.NewValue == args.MaxValue)
|
|
|
|
|
CancelRoundEndTimer();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void StartRoundEndTimer()
|
|
|
|
|
{
|
2025-04-15 23:09:49 +03:00
|
|
|
var roundEndDelay = TimeSpan.FromMinutes(_cfg.GetCVar(CCVars.CP14RoundEndMinutes));
|
2025-01-18 17:55:41 +03:00
|
|
|
|
2025-01-19 00:09:30 +03:00
|
|
|
_roundEndMoment = _timing.CurTime + roundEndDelay;
|
|
|
|
|
|
|
|
|
|
var time = roundEndDelay.Minutes;
|
2025-01-18 17:55:41 +03:00
|
|
|
string unitsLocString;
|
2025-01-19 00:09:30 +03:00
|
|
|
if (roundEndDelay.TotalSeconds < 60)
|
2025-01-18 17:55:41 +03:00
|
|
|
{
|
2025-01-19 00:09:30 +03:00
|
|
|
time = roundEndDelay.Seconds;
|
2025-01-18 17:55:41 +03:00
|
|
|
unitsLocString = "eta-units-seconds";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2025-01-19 00:09:30 +03:00
|
|
|
time = roundEndDelay.Minutes;
|
2025-01-18 17:55:41 +03:00
|
|
|
unitsLocString = "eta-units-minutes";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
_chatSystem.DispatchGlobalAnnouncement(
|
|
|
|
|
Loc.GetString(
|
|
|
|
|
"cp14-round-end-monolith-discharged",
|
|
|
|
|
("time", time),
|
|
|
|
|
("units", Loc.GetString(unitsLocString))),
|
2025-05-17 14:12:49 +03:00
|
|
|
announcementSound: new SoundPathSpecifier("/Audio/_CP14/Announce/event_boom.ogg"));
|
2025-01-18 17:55:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CancelRoundEndTimer()
|
|
|
|
|
{
|
|
|
|
|
_roundEndMoment = TimeSpan.Zero;
|
|
|
|
|
|
|
|
|
|
_chatSystem.DispatchGlobalAnnouncement(Loc.GetString("cp14-round-end-monolith-recharged"),
|
2025-05-17 14:12:49 +03:00
|
|
|
announcementSound: new SoundPathSpecifier("/Audio/_CP14/Announce/event_boom.ogg"));
|
2025-01-18 17:55:41 +03:00
|
|
|
}
|
|
|
|
|
}
|