Turns HolidayManager into an entity system, HolidaySystem.
This commit is contained in:
@@ -81,7 +81,6 @@ namespace Content.Server.Entry
|
||||
{
|
||||
base.PostInit();
|
||||
|
||||
IoCManager.Resolve<IHolidayManager>().Initialize();
|
||||
IoCManager.Resolve<ISandboxManager>().Initialize();
|
||||
IoCManager.Resolve<RecipeManager>().Initialize();
|
||||
IoCManager.Resolve<AlertManager>().Initialize();
|
||||
|
||||
@@ -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,21 +23,33 @@ namespace Content.Server.Holiday
|
||||
[ViewVariables]
|
||||
private bool _enabled = true;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
_configManager.OnValueChanged(CCVars.HolidaysEnabled, OnHolidaysEnableChange, true);
|
||||
|
||||
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnRunLevelChanged);
|
||||
}
|
||||
|
||||
public void RefreshCurrentHolidays()
|
||||
{
|
||||
_currentHolidays.Clear();
|
||||
|
||||
if (!_enabled) return;
|
||||
if (!_enabled)
|
||||
return;
|
||||
|
||||
var now = DateTime.Now;
|
||||
|
||||
foreach (var holiday in _prototypeManager.EnumeratePrototypes<HolidayPrototype>())
|
||||
{
|
||||
if(holiday.ShouldCelebrate(now))
|
||||
if (holiday.ShouldCelebrate(now))
|
||||
{
|
||||
_currentHolidays.Add(holiday);
|
||||
}
|
||||
}
|
||||
|
||||
RaiseLocalEvent(new HolidaysRefreshedEvent(_currentHolidays));
|
||||
}
|
||||
|
||||
public void DoGreet()
|
||||
{
|
||||
foreach (var holiday in _currentHolidays)
|
||||
@@ -71,13 +79,6 @@ namespace Content.Server.Holiday
|
||||
return _currentHolidays.Contains(prototype);
|
||||
}
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_configManager.OnValueChanged(CCVars.HolidaysEnabled, OnHolidaysEnableChange, true);
|
||||
|
||||
_entityManager.EventBus.SubscribeEvent<GameRunLevelChangedEvent>(EventSource.Local, this, OnRunLevelChanged);
|
||||
}
|
||||
|
||||
private void OnHolidaysEnableChange(bool enabled)
|
||||
{
|
||||
_enabled = enabled;
|
||||
@@ -103,4 +104,17 @@ namespace Content.Server.Holiday
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Event for when the list of currently active holidays has been refreshed.
|
||||
/// </summary>
|
||||
public class HolidaysRefreshedEvent : EntityEventArgs
|
||||
{
|
||||
public readonly IEnumerable<HolidayPrototype> Holidays;
|
||||
|
||||
public HolidaysRefreshedEvent(IEnumerable<HolidayPrototype> holidays)
|
||||
{
|
||||
Holidays = holidays;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<HolidayPrototype> GetCurrentHolidays();
|
||||
bool IsCurrentlyHoliday(string holiday);
|
||||
}
|
||||
}
|
||||
@@ -52,7 +52,6 @@ namespace Content.Server.IoC
|
||||
IoCManager.Register<IAdminManager, AdminManager>();
|
||||
IoCManager.Register<IDeviceNetwork, DeviceNetwork.DeviceNetwork>();
|
||||
IoCManager.Register<EuiManager, EuiManager>();
|
||||
IoCManager.Register<IHolidayManager, HolidayManager>();
|
||||
IoCManager.Register<IVoteManager, VoteManager>();
|
||||
IoCManager.Register<INpcBehaviorManager, NpcBehaviorManager>();
|
||||
IoCManager.Register<IPlayerLocator, PlayerLocator>();
|
||||
|
||||
@@ -27,7 +27,7 @@ namespace Content.Server.Jobs
|
||||
if (string.IsNullOrEmpty(Holiday) || string.IsNullOrEmpty(Prototype))
|
||||
return;
|
||||
|
||||
if (!IoCManager.Resolve<IHolidayManager>().IsCurrentlyHoliday(Holiday))
|
||||
if (!EntitySystem.Get<HolidaySystem>().IsCurrentlyHoliday(Holiday))
|
||||
return;
|
||||
|
||||
var entity = mob.EntityManager.SpawnEntity(Prototype, mob.Transform.Coordinates);
|
||||
|
||||
Reference in New Issue
Block a user