CatStation/Content.Server/Holiday/HolidaySystem.cs
Princess Cheeseballs 2c6ffecf62
Move GameTicker to Shared (#45834)
* Scope creep my ass

* why was this shit not pushed????

* gone...

* fix that

* review plus buildd

* asfsafsafsafsafas

* grug

* burber

* I'll fix this later

* shrimply die

* also this

* it's snerf or snuthin

* assaads

* round snend

* aaaa

* fix this shit for real

* actually, don't start GameRules until MapInit now that I think aboot it.

* forgot u

* don't actually need this part nullable

* Deffer comp removal

* one liner

* do that too

* chungus

* Honestly makes more sense here, plus WHY are we doing all that shit on "GameRuleAdded" rather than GameRuleStarted(?)

* deferred removal :V

* aaaaaaaaaaaaaaa

* whhop

* Whoop

* better

* landmine that I placed for myself then forgot about lmao

* cleanup

* FUCKING `!`

* gotovo

* amogus

* please don't check by metadata I beg

* waawsasfdfsasfa

* sfafsasfafsas

* fdsaasffsasfa

* code

* fix

* fasasffasfasfsad

* chungaas

* I may be stupid

* gra

* graaaaaaaaaaaaaaaaa

* comment

* gra

* clearing is not predicted and would require major refactors, so don't cache on client.

* lame shit :P

* last holes

* nukeopsfsafsasafsfafsa

* why  was that shit public bruh

* bubrbgwahrghfaka

* dynamic

* revert change that did nothing lmao
2026-09-16 19:34:19 +00:00

132 lines
3.8 KiB
C#

using System.Linq;
using Content.Server.Chat.Managers;
using Content.Server.GameTicking;
using Content.Shared.CCVar;
using Content.Shared.GameTicking;
using Content.Shared.Holiday;
using Robust.Shared.Configuration;
namespace Content.Server.Holiday
{
public sealed partial class HolidaySystem : EntitySystem
{
[Dependency] private IConfigurationManager _configManager = default!;
[Dependency] private IChatManager _chatManager = default!;
[Dependency] private SharedAppearanceSystem _appearance = default!;
[ViewVariables]
private readonly List<HolidayPrototype> _currentHolidays = new();
[ViewVariables]
private bool _enabled = true;
public override void Initialize()
{
Subs.CVar(_configManager, CCVars.HolidaysEnabled, OnHolidaysEnableChange);
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnRunLevelChanged);
SubscribeLocalEvent<HolidayVisualsComponent, ComponentInit>(OnVisualsInit);
}
public void RefreshCurrentHolidays()
{
_currentHolidays.Clear();
if (!_enabled)
{
RaiseLocalEvent(new HolidaysRefreshedEvent(Enumerable.Empty<HolidayPrototype>()));
return;
}
var now = DateTime.Now;
foreach (var holiday in ProtoMan.EnumeratePrototypes<HolidayPrototype>())
{
if (holiday.ShouldCelebrate(now))
{
_currentHolidays.Add(holiday);
}
}
RaiseLocalEvent(new HolidaysRefreshedEvent(_currentHolidays));
}
public void DoGreet()
{
foreach (var holiday in _currentHolidays)
{
_chatManager.DispatchServerAnnouncement(holiday.Greet());
}
}
public void DoCelebrate()
{
foreach (var holiday in _currentHolidays)
{
holiday.Celebrate();
}
}
public IEnumerable<HolidayPrototype> GetCurrentHolidays()
{
return _currentHolidays;
}
public bool IsCurrentlyHoliday(string holiday)
{
if (!ProtoMan.TryIndex(holiday, out HolidayPrototype? prototype))
return false;
return _currentHolidays.Contains(prototype);
}
private void OnHolidaysEnableChange(bool enabled)
{
_enabled = enabled;
RefreshCurrentHolidays();
}
private void OnRunLevelChanged(GameRunLevelChangedEvent eventArgs)
{
if (!_enabled)
return;
switch (eventArgs.New)
{
case GameRunLevel.PreRoundLobby:
RefreshCurrentHolidays();
break;
case GameRunLevel.InRound:
DoGreet();
DoCelebrate();
break;
case GameRunLevel.PostRound:
break;
}
}
private void OnVisualsInit(Entity<HolidayVisualsComponent> ent, ref ComponentInit args)
{
foreach (var (key, holidays) in ent.Comp.Holidays)
{
if (!holidays.Any(h => IsCurrentlyHoliday(h)))
continue;
_appearance.SetData(ent, HolidayVisuals.Holiday, key);
break;
}
}
}
/// <summary>
/// Event for when the list of currently active holidays has been refreshed.
/// </summary>
public sealed class HolidaysRefreshedEvent : EntityEventArgs
{
public readonly IEnumerable<HolidayPrototype> Holidays;
public HolidaysRefreshedEvent(IEnumerable<HolidayPrototype> holidays)
{
Holidays = holidays;
}
}
}