Add EventDef notices, morning and lesson bells, and info toasts.
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -165,6 +165,7 @@ internal sealed partial class SchoolWorker
|
||||
{
|
||||
PublishSnapshot();
|
||||
BroadcastClock();
|
||||
EmitWorldEvents(school);
|
||||
MaybeBroadcastPresence(school);
|
||||
}
|
||||
|
||||
@@ -244,6 +245,7 @@ internal sealed partial class SchoolWorker
|
||||
PublishSnapshot();
|
||||
Persist();
|
||||
BroadcastClock();
|
||||
EmitWorldEvents(school);
|
||||
BroadcastPresence();
|
||||
_presenceAge = 0;
|
||||
}
|
||||
@@ -489,4 +491,48 @@ internal sealed partial class SchoolWorker
|
||||
var length = ProtocolCodec.WritePresence(frame, message);
|
||||
client.TrySendReliable(frame.AsMemory(0, length));
|
||||
}
|
||||
|
||||
private void EmitWorldEvents(School school)
|
||||
{
|
||||
var catalog = school.Catalog;
|
||||
if (catalog is null)
|
||||
{
|
||||
school.DrainWorldEvents();
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var fact in school.DrainWorldEvents())
|
||||
{
|
||||
foreach (var def in catalog.Events.Values)
|
||||
{
|
||||
if (def.Abstract
|
||||
|| !def.Trigger.Equals(fact.Trigger, StringComparison.Ordinal)
|
||||
|| !def.Severity.Equals(EventSeverities.Info, StringComparison.Ordinal))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
BroadcastNotice(new ServerNoticeMessage(
|
||||
++_nextNoticeId,
|
||||
def.DefName,
|
||||
NoticeSeverity.Info,
|
||||
def.Pause,
|
||||
(uint)Math.Max(0, def.TtlMs)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void BroadcastNotice(in ServerNoticeMessage message)
|
||||
{
|
||||
var frame = new byte[ProtocolCodec.NoticeSize(message)];
|
||||
var length = ProtocolCodec.WriteNotice(frame, message);
|
||||
var payload = frame.AsMemory(0, length);
|
||||
foreach (var client in _clients.All)
|
||||
{
|
||||
if (client.IsReady && client.OpenSchoolId == _id)
|
||||
{
|
||||
client.TrySendReliable(payload);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user