Files
h-school/src/HSchool.Server/Game/WorkerCommand.cs
T

130 lines
4.2 KiB
C#

using HSchool.Content;
using HSchool.People;
using HSchool.Server.Api;
using HSchool.Server.Net;
using HSchool.Simulation;
namespace HSchool.Server.Game;
/// <summary>
/// Work item for one school's worker. The supervisor never touches that school's <c>World</c>;
/// it only posts these.
/// </summary>
internal abstract record WorkerCommand
{
internal sealed record Open(GameClient Client) : WorkerCommand;
internal sealed record Close(uint PlayerId) : WorkerCommand;
internal sealed record SetRunning(bool Running) : WorkerCommand;
internal sealed record SetSpeed(byte SpeedIndex) : WorkerCommand;
internal sealed record SkipEmpty : WorkerCommand;
internal sealed record DismissNotice(uint Id) : WorkerCommand;
internal sealed record DismissNoticeHttp(uint Id, TaskCompletionSource Result) : WorkerCommand;
/// <summary>Test/dev post onto the school board. Looks up an EventDef by name.</summary>
internal sealed record PostNotice(
string DefName,
string PersonKey,
string Kind,
TaskCompletionSource<PostedNotice?> Result) : WorkerCommand;
internal sealed record GetNoticePortraitTarget(
uint NoticeId,
TaskCompletionSource<NoticePortraitTarget> Result) : WorkerCommand;
internal sealed record Dump(TaskCompletionSource<SchoolLiveDump?> Result) : WorkerCommand;
internal sealed record GetPerson(
string PersonId,
string Locale,
TaskCompletionSource<PersonCardResult> Result) : WorkerCommand;
internal sealed record GetPortraitBuildInput(
string PersonId,
string Locale,
TaskCompletionSource<PortraitBuildInputResult> Result) : WorkerCommand;
internal sealed record GetPersonLog(
string PersonId,
string Locale,
PersonLogQuery Query,
TaskCompletionSource<PersonLogResult> Result) : WorkerCommand;
internal sealed record HireStaff(
string PersonId,
string Position,
TaskCompletionSource<StaffingOutcome> Result) : WorkerCommand;
internal sealed record AssignSubject(
string PersonId,
string Subject,
TaskCompletionSource<StaffingOutcome> Result) : WorkerCommand;
internal sealed record UnassignSubject(
string PersonId,
string Subject,
TaskCompletionSource<StaffingOutcome> Result) : WorkerCommand;
internal sealed record PinLesson(
string ClassId,
string Subject,
string RoomId,
int Day,
int Period,
TaskCompletionSource<TimetableOutcome> Result) : WorkerCommand;
internal sealed record UnpinLesson(
string ClassId,
string Subject,
int Day,
int Period,
TaskCompletionSource<TimetableOutcome> Result) : WorkerCommand;
internal sealed record GetDressRules(TaskCompletionSource<DressRulesOutcome> Result) : WorkerCommand;
internal sealed record SetDressRules(
DressRulePair? PendingStudents,
DressRulePair? PendingStaff,
TaskCompletionSource<DressRulesOutcome> Result) : WorkerCommand;
internal sealed record GetSpeechRules(TaskCompletionSource<SpeechRulesOutcome> Result) : WorkerCommand;
internal sealed record SetSpeechRules(
string? PendingStudents,
string? PendingStaff,
TaskCompletionSource<SpeechRulesOutcome> Result) : WorkerCommand;
}
internal sealed record PostedNotice(uint Id, string DefName, bool Pause);
internal enum NoticePortraitTargetError
{
None,
UnknownSchool,
UnknownNotice,
CannotGenerate,
}
internal sealed record NoticePortraitTarget(
NoticePortraitTargetError Error,
string PersonId,
PortraitKind Kind)
{
public static NoticePortraitTarget UnknownSchool { get; } =
new(NoticePortraitTargetError.UnknownSchool, "", PortraitKind.Full);
public static NoticePortraitTarget UnknownNotice { get; } =
new(NoticePortraitTargetError.UnknownNotice, "", PortraitKind.Full);
public static NoticePortraitTarget CannotGenerate { get; } =
new(NoticePortraitTargetError.CannotGenerate, "", PortraitKind.Full);
public static NoticePortraitTarget Ok(string personId, PortraitKind kind) =>
new(NoticePortraitTargetError.None, personId, kind);
}