Implement phase 35 dress appropriateness and school rules.
Adds outfit evaluation, morning home dressing, locker-room ChangeClothes with day-log events, PE/weather AI goals, dress-rules API, and tests.
This commit is contained in:
@@ -0,0 +1,76 @@
|
||||
using HSchool.Ai;
|
||||
using HSchool.Content;
|
||||
using HSchool.People;
|
||||
using HSchool.Schedule;
|
||||
|
||||
namespace HSchool.Simulation;
|
||||
|
||||
/// <summary>Applies pending dress rules and home morning outfits at six in the morning.</summary>
|
||||
internal static class MorningDress
|
||||
{
|
||||
private static readonly Arch.Core.QueryDescription Identities =
|
||||
new Arch.Core.QueryDescription().WithAll<PersonIdentity, Presence>();
|
||||
|
||||
public static bool Apply(School school)
|
||||
{
|
||||
if (school.Catalog is null || school.Roster is null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var isWorkday = SchoolDay.IsWorkday(school.Catalog, school.Clock.Time, school.SchoolWeekDays);
|
||||
var changed = false;
|
||||
if (isWorkday && school.DressRules.HasPending)
|
||||
{
|
||||
school.DressRules = school.DressRules.ApplyPending();
|
||||
changed = true;
|
||||
}
|
||||
|
||||
var offCampus = OffCampusIds(school);
|
||||
foreach (var person in school.Roster.People)
|
||||
{
|
||||
if (!offCampus.Contains(person.Id))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var schoolClass = ClassOf(school, person);
|
||||
var subjects = isWorkday
|
||||
? ApparelDresser.TodaySubjects(school, person, schoolClass)
|
||||
: [];
|
||||
changed |= ApparelDresser.RedressPerson(
|
||||
school,
|
||||
person,
|
||||
ApparelMode.Everyday,
|
||||
includeHome: true,
|
||||
todaySubjects: subjects,
|
||||
logChanges: false);
|
||||
}
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
private static HashSet<string> OffCampusIds(School school)
|
||||
{
|
||||
var ids = new HashSet<string>(StringComparer.Ordinal);
|
||||
var world = school.World;
|
||||
world.Query(in Identities, (ref PersonIdentity identity, ref Presence presence) =>
|
||||
{
|
||||
if (!presence.IsOnCampus)
|
||||
{
|
||||
ids.Add(identity.Id);
|
||||
}
|
||||
});
|
||||
return ids;
|
||||
}
|
||||
|
||||
private static SchoolClass? ClassOf(School school, Person person)
|
||||
{
|
||||
if (person.ClassId is null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return school.Roster?.Classes.FirstOrDefault(row => row.Id.Equals(person.ClassId, StringComparison.Ordinal));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user