Persist talk opinions and pick topics by weight.
A finished circle never set Tick's peopleChanged bit, so people.json kept pre-talk numbers until morning drift. PickTopic compared a 0..total roll to a 0..1 cursor, so gossip almost never changed the subject. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -63,6 +63,22 @@ public class MorningOpinionsTests
|
||||
Assert.True(after < before);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void DriftToZero_DropsTheRecord()
|
||||
{
|
||||
using var school = OpenStaffed();
|
||||
var child = school.Roster!.People.First(person => person.IsStudent && !person.IsParent);
|
||||
var classmate = school.Roster.People.First(person =>
|
||||
person.IsStudent
|
||||
&& !person.Id.Equals(child.Id, StringComparison.Ordinal)
|
||||
&& !OpinionStore.FamilyMemberIds(school.Roster, child).Contains(person.Id));
|
||||
var drift = school.Catalog!.BehaviorRules!.OpinionDriftPerMorning;
|
||||
OpinionStore.Set(child, classmate.Id, Math.Min(2, drift));
|
||||
|
||||
Assert.True(MorningOpinions.Apply(school));
|
||||
Assert.False(child.Opinions.ContainsKey(classmate.Id));
|
||||
}
|
||||
|
||||
private static void AdvanceTo(School school, DateTime until)
|
||||
{
|
||||
while (school.Clock.Time < until)
|
||||
|
||||
@@ -151,6 +151,28 @@ public class TalkCircleTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void TalkCircleFinish_MarksTickPeopleChangedSoSaveWritesOpinions()
|
||||
{
|
||||
var (school, first, second) = TwoPupilsOnBreak();
|
||||
using (school)
|
||||
{
|
||||
OpinionStore.Set(first, second.Id, 10);
|
||||
PlaceAt(school, first.Id, "corridor-1");
|
||||
PlaceAt(school, second.Id, "corridor-1");
|
||||
Assert.True(school.TryStartAction(first.Id, TalkActions.Chat));
|
||||
|
||||
var peopleChanged = false;
|
||||
while (ActivityOf(school, first.Id) is not null)
|
||||
{
|
||||
peopleChanged |= school.Tick(0.2d, 5d);
|
||||
}
|
||||
|
||||
Assert.True(peopleChanged);
|
||||
Assert.NotEqual(10, OpinionStore.Get(first, second.Id));
|
||||
}
|
||||
}
|
||||
|
||||
private static (School School, Person First, Person Second) TwoPupilsWithPhonesOnBreak()
|
||||
{
|
||||
var (catalog, map) = Vanilla();
|
||||
|
||||
@@ -134,6 +134,53 @@ public class WhisperTests
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void CaughtWhisper_BecomesDisciplineTalkWithTeacher()
|
||||
{
|
||||
var (school, homeroom, firstId, secondId, teacherId) = TwoPupilsAndTeacher();
|
||||
using (school)
|
||||
{
|
||||
AdvanceTo(school, LessonStart);
|
||||
var converted = false;
|
||||
for (var i = 0; i < 24; i++)
|
||||
{
|
||||
school.Clock.JumpTo(LessonStart.AddMinutes(i));
|
||||
TalkCircleSystem.Interrupt(school, firstId);
|
||||
TalkCircleSystem.Interrupt(school, secondId);
|
||||
TalkCircleSystem.Interrupt(school, teacherId);
|
||||
var schoolClass = school.Roster!.Classes.First(row => row.PupilIds.Contains(firstId));
|
||||
foreach (var id in schoolClass.PupilIds)
|
||||
{
|
||||
PlaceAt(school, id, id == firstId || id == secondId ? homeroom : "corridor-1");
|
||||
}
|
||||
|
||||
PlaceAt(school, firstId, homeroom);
|
||||
PlaceAt(school, secondId, homeroom);
|
||||
PlaceAt(school, teacherId, homeroom);
|
||||
Assert.True(school.TryStartAction(firstId, TalkActions.Whisper));
|
||||
TalkCircleSystem.Apply(school, 0.2d);
|
||||
if (!school.DayLog.Any(row =>
|
||||
(row.PersonId == firstId || row.PersonId == secondId)
|
||||
&& row.Type.Equals(PersonLogTypes.TeacherInterrupted, StringComparison.Ordinal)
|
||||
&& row.Time == school.Clock.Time))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
Assert.Equal(TalkActions.TeacherTalk, ActivityOf(school, firstId));
|
||||
Assert.Equal(TalkActions.TeacherTalk, ActivityOf(school, teacherId));
|
||||
var circle = school.TalkCircleOf(firstId);
|
||||
Assert.NotNull(circle);
|
||||
Assert.Equal(TeacherTopics.Discipline, circle.TopicId);
|
||||
Assert.Contains(teacherId, circle.MemberIds);
|
||||
converted = true;
|
||||
break;
|
||||
}
|
||||
|
||||
Assert.True(converted);
|
||||
}
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void OrdinaryChat_DoesNotStartOnLesson()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user