Grow lesson skills only when the assigned teacher is standing in the room.

The timetable already named a teacher; learning ignored whether they were in the toilet, still walking, or not a person at all.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
Leonid Pershin
2026-08-20 08:33:28 +03:00
co-authored by Cursor
parent 936d6fb04f
commit fbc32f2bfc
9 changed files with 312 additions and 18 deletions
+32 -2
View File
@@ -8,10 +8,14 @@ namespace HSchool.Simulation;
/// <summary>
/// Grows skills for people who are actually in the lesson: at the room, not walking, not off
/// doing something else. The formula lives in <see cref="HSchool.Ai.LessonLearning"/>.
/// doing something else, and with the assigned teacher standing there. The formula lives in
/// <see cref="HSchool.Ai.LessonLearning"/>.
/// </summary>
internal static class LessonLearningSystem
{
private static readonly QueryDescription Places =
new QueryDescription().WithAll<PersonIdentity, Presence>();
private static readonly QueryDescription People =
new QueryDescription().WithAll<PersonIdentity, PersonSkills, PersonTraits, PersonNeeds, PersonRoles, Presence, PersonActivity>();
@@ -38,11 +42,19 @@ internal static class LessonLearningSystem
var weekday = SchoolDay.WeekdayIndex(school.Clock.Time);
var catalog = school.Catalog;
var world = school.World;
var places = new Dictionary<string, Presence>(StringComparer.Ordinal);
world.Query(
in Places,
(ref PersonIdentity identity, ref Presence presence) =>
{
places[identity.Id] = presence;
});
world.Query(
in People,
(ref PersonIdentity identity, ref PersonSkills skills, ref PersonTraits traits, ref PersonNeeds needs, ref PersonRoles roles, ref Presence presence, ref PersonActivity activity) =>
{
if (activity.IsActive || presence.NodeId is null || presence.Path.Length > 0 || presence.RemainingMinutes > 0)
if (activity.IsActive || !IsStanding(presence))
{
return;
}
@@ -56,12 +68,19 @@ internal static class LessonLearningSystem
var lesson = CurrentLesson(school, person, weekday, slot.Index);
if (lesson is null
|| presence.NodeId is null
|| !presence.NodeId.Equals(lesson.RoomId, StringComparison.Ordinal)
|| !catalog.Subjects.TryGetValue(lesson.Subject, out var subject))
{
return;
}
if (!TeacherStandingIn(places, lesson.TeacherId, lesson.RoomId))
{
school.TryLogLessonOnce(personId, PersonLogTypes.LessonNoTeacher, lesson.Subject);
return;
}
var hunger = needs.Values.GetValueOrDefault("Hunger", 1f);
foreach (var share in subject.Skills)
{
@@ -87,6 +106,17 @@ internal static class LessonLearningSystem
});
}
private static bool IsStanding(Presence presence) =>
presence.NodeId is not null && presence.Path.Length == 0 && presence.RemainingMinutes <= 0;
private static bool TeacherStandingIn(
Dictionary<string, Presence> places,
string teacherId,
string roomId) =>
places.TryGetValue(teacherId, out var teacher) && IsStanding(teacher)
&& teacher.NodeId is not null
&& teacher.NodeId.Equals(roomId, StringComparison.Ordinal);
private static LessonPlacement? CurrentLesson(School school, Person person, int weekday, int period)
{
foreach (var lesson in Duty.LessonsToday(person, ClassOf(school, person), school.Timetable, weekday))