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:
Leonid Pershin
2026-08-20 13:34:34 +03:00
co-authored by Cursor
parent 8d07b3606d
commit b38d0bb628
9 changed files with 298 additions and 2 deletions
@@ -0,0 +1,56 @@
namespace HSchool.People.Tests;
public class OpinionStoreTests
{
[Fact]
public void SetZero_RemovesTheEntry()
{
var person = Blank("a");
Assert.True(OpinionStore.Set(person, "b", 12));
Assert.Equal(12, OpinionStore.Get(person, "b"));
Assert.True(OpinionStore.Set(person, "b", 0));
Assert.Null(OpinionStore.Get(person, "b"));
Assert.False(person.Opinions.ContainsKey("b"));
}
[Fact]
public void Set_ClampsToMinusOneHundredAndOneHundred()
{
var person = Blank("a");
OpinionStore.Set(person, "b", 500);
Assert.Equal(100, person.Opinions["b"]);
OpinionStore.Set(person, "b", -500);
Assert.Equal(-100, person.Opinions["b"]);
}
private static Person Blank(string id)
{
var cases = new CaseTable
{
Nom = id,
Gen = id,
Dat = id,
Acc = id,
Ins = id,
Pre = id,
};
return new Person
{
Id = id,
FamilyId = "f",
Female = false,
BirthDate = new DateTime(2000, 1, 1, 0, 0, 0, DateTimeKind.Utc),
Name = new PersonName(id, id, id, cases, cases, cases),
IsStudent = true,
IsStaff = false,
IsParent = false,
Numbers = new Dictionary<string, int>(StringComparer.Ordinal),
Choices = new Dictionary<string, string>(StringComparer.Ordinal),
Skills = new Dictionary<string, int>(StringComparer.Ordinal),
Traits = [],
Needs = new Dictionary<string, float>(StringComparer.Ordinal),
Opinions = new Dictionary<string, int>(StringComparer.Ordinal),
};
}
}