diff --git a/Content.Server/Entry/EntryPoint.cs b/Content.Server/Entry/EntryPoint.cs index 446f543b77..7ad42dbabd 100644 --- a/Content.Server/Entry/EntryPoint.cs +++ b/Content.Server/Entry/EntryPoint.cs @@ -81,7 +81,6 @@ namespace Content.Server.Entry { base.PostInit(); - IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); IoCManager.Resolve().Initialize(); diff --git a/Content.Server/Holiday/HolidayManager.cs b/Content.Server/Holiday/HolidaySystem.cs similarity index 77% rename from Content.Server/Holiday/HolidayManager.cs rename to Content.Server/Holiday/HolidaySystem.cs index 16c6772850..d611e1746a 100644 --- a/Content.Server/Holiday/HolidayManager.cs +++ b/Content.Server/Holiday/HolidaySystem.cs @@ -2,8 +2,6 @@ using System; using System.Collections.Generic; using Content.Server.Chat.Managers; using Content.Server.GameTicking; -using Content.Server.Holiday.Interfaces; -using Content.Shared; using Content.Shared.CCVar; using Robust.Shared.Configuration; using Robust.Shared.GameObjects; @@ -13,12 +11,10 @@ using Robust.Shared.ViewVariables; namespace Content.Server.Holiday { - // ReSharper disable once ClassNeverInstantiated.Global - public class HolidayManager : IHolidayManager, IEntityEventSubscriber + public class HolidaySystem : EntitySystem { [Dependency] private readonly IConfigurationManager _configManager = default!; [Dependency] private readonly IPrototypeManager _prototypeManager = default!; - [Dependency] private readonly IEntityManager _entityManager = default!; [Dependency] private readonly IChatManager _chatManager = default!; [ViewVariables] @@ -27,19 +23,31 @@ namespace Content.Server.Holiday [ViewVariables] private bool _enabled = true; + public override void Initialize() + { + _configManager.OnValueChanged(CCVars.HolidaysEnabled, OnHolidaysEnableChange, true); + + SubscribeLocalEvent(OnRunLevelChanged); + } + public void RefreshCurrentHolidays() { _currentHolidays.Clear(); - if (!_enabled) return; + if (!_enabled) + return; var now = DateTime.Now; foreach (var holiday in _prototypeManager.EnumeratePrototypes()) { - if(holiday.ShouldCelebrate(now)) + if (holiday.ShouldCelebrate(now)) + { _currentHolidays.Add(holiday); + } } + + RaiseLocalEvent(new HolidaysRefreshedEvent(_currentHolidays)); } public void DoGreet() @@ -71,13 +79,6 @@ namespace Content.Server.Holiday return _currentHolidays.Contains(prototype); } - public void Initialize() - { - _configManager.OnValueChanged(CCVars.HolidaysEnabled, OnHolidaysEnableChange, true); - - _entityManager.EventBus.SubscribeEvent(EventSource.Local, this, OnRunLevelChanged); - } - private void OnHolidaysEnableChange(bool enabled) { _enabled = enabled; @@ -103,4 +104,17 @@ namespace Content.Server.Holiday } } } + + /// + /// Event for when the list of currently active holidays has been refreshed. + /// + public class HolidaysRefreshedEvent : EntityEventArgs + { + public readonly IEnumerable Holidays; + + public HolidaysRefreshedEvent(IEnumerable holidays) + { + Holidays = holidays; + } + } } diff --git a/Content.Server/Holiday/Interfaces/IHolidayManager.cs b/Content.Server/Holiday/Interfaces/IHolidayManager.cs deleted file mode 100644 index 1211f3d9f2..0000000000 --- a/Content.Server/Holiday/Interfaces/IHolidayManager.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System.Collections.Generic; - -namespace Content.Server.Holiday.Interfaces -{ - public interface IHolidayManager - { - void Initialize(); - void RefreshCurrentHolidays(); - void DoGreet(); - void DoCelebrate(); - IEnumerable GetCurrentHolidays(); - bool IsCurrentlyHoliday(string holiday); - } -} diff --git a/Content.Server/IoC/ServerContentIoC.cs b/Content.Server/IoC/ServerContentIoC.cs index 56e3d0ac45..2723693706 100644 --- a/Content.Server/IoC/ServerContentIoC.cs +++ b/Content.Server/IoC/ServerContentIoC.cs @@ -52,7 +52,6 @@ namespace Content.Server.IoC IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); - IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); IoCManager.Register(); diff --git a/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs b/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs index e7f4e5c625..cea9a1df19 100644 --- a/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs +++ b/Content.Server/Jobs/GiveItemOnHolidaySpecial.cs @@ -27,7 +27,7 @@ namespace Content.Server.Jobs if (string.IsNullOrEmpty(Holiday) || string.IsNullOrEmpty(Prototype)) return; - if (!IoCManager.Resolve().IsCurrentlyHoliday(Holiday)) + if (!EntitySystem.Get().IsCurrentlyHoliday(Holiday)) return; var entity = mob.EntityManager.SpawnEntity(Prototype, mob.Transform.Coordinates);