Enhance protocol and simulation features with activity tracking and behavior definitions
- Updated protocol documentation to include new `activity` and `activityLabel` fields in the person card response, reflecting real-time activity status. - Introduced `BehaviorDef` to define behavior rules, including need thresholds and lesson skill gains, enhancing AI decision-making. - Revised the `DefCatalog` to incorporate behavior definitions and updated validation logic to ensure proper behavior handling. - Enhanced the simulation to manage presence and activity states, allowing for more dynamic interactions within the school environment. - Updated tests to validate the new activity tracking and behavior functionalities, ensuring robust performance and reliability. - Improved localization strings to support new activity and behavior features, enhancing user experience.
This commit is contained in:
@@ -59,6 +59,8 @@ internal sealed record PersonCardResponse(
|
||||
IReadOnlyList<LabeledStatResponse> Skills,
|
||||
IReadOnlyList<DefLabelResponse> Traits,
|
||||
IReadOnlyList<NeedStatResponse> Needs,
|
||||
string? Activity,
|
||||
string? ActivityLabel,
|
||||
PersonFamilyResponse Family);
|
||||
|
||||
internal sealed record LabeledStatResponse(string Id, string Label, string Value);
|
||||
|
||||
@@ -14,6 +14,9 @@ internal static class PersonCardReader
|
||||
private static readonly QueryDescription IdentityAndNeeds =
|
||||
new QueryDescription().WithAll<PersonIdentity, PersonNeeds>();
|
||||
|
||||
private static readonly QueryDescription IdentityAndActivity =
|
||||
new QueryDescription().WithAll<PersonIdentity, PersonActivity>();
|
||||
|
||||
public static PersonCardResponse? Read(School school, string personId, string locale)
|
||||
{
|
||||
var roster = school.Roster;
|
||||
@@ -42,6 +45,17 @@ internal static class PersonCardReader
|
||||
}
|
||||
|
||||
var needs = LiveNeeds(school.World, personId) ?? person.Needs;
|
||||
var activityId = LiveActivity(school.World, personId);
|
||||
string? activityLabel = null;
|
||||
if (activityId is not null && catalog is not null && catalog.Actions.TryGetValue(activityId, out var action))
|
||||
{
|
||||
activityLabel = catalog.Label(locale, action);
|
||||
}
|
||||
else if (activityId is not null)
|
||||
{
|
||||
activityLabel = activityId;
|
||||
}
|
||||
|
||||
return new PersonCardResponse(
|
||||
person.Id,
|
||||
person.Name.Full,
|
||||
@@ -61,6 +75,8 @@ internal static class PersonCardReader
|
||||
Skills(person, catalog, locale),
|
||||
Traits(person, catalog, locale),
|
||||
Needs(needs, catalog, locale),
|
||||
activityId,
|
||||
activityLabel,
|
||||
Family(roster, person));
|
||||
}
|
||||
|
||||
@@ -77,6 +93,20 @@ internal static class PersonCardReader
|
||||
return found;
|
||||
}
|
||||
|
||||
private static string? LiveActivity(World world, string personId)
|
||||
{
|
||||
string? found = null;
|
||||
var query = IdentityAndActivity;
|
||||
world.Query(in query, (ref PersonIdentity identity, ref PersonActivity activity) =>
|
||||
{
|
||||
if (identity.Id.Equals(personId, StringComparison.Ordinal) && activity.IsActive)
|
||||
{
|
||||
found = activity.ActionId;
|
||||
}
|
||||
});
|
||||
return found;
|
||||
}
|
||||
|
||||
private static IReadOnlyList<LabeledStatResponse> Body(Person person, DefCatalog? catalog, string locale)
|
||||
{
|
||||
var rows = new List<LabeledStatResponse>();
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
[
|
||||
{
|
||||
"defName": "EatLunch",
|
||||
"room": "Cafeteria",
|
||||
"thing": "Chair",
|
||||
"minutes": 15,
|
||||
"need": "Hunger",
|
||||
"needGain": 0.5,
|
||||
"roles": ["student", "staff"],
|
||||
"weight": 0,
|
||||
},
|
||||
{
|
||||
"defName": "UseToilet",
|
||||
"room": "Restroom",
|
||||
"minutes": 4,
|
||||
"need": "Toilet",
|
||||
"needGain": 1,
|
||||
"roles": ["student", "staff"],
|
||||
"weight": 0,
|
||||
},
|
||||
{
|
||||
"defName": "RecessRest",
|
||||
"room": "Corridor",
|
||||
"minutes": 10,
|
||||
"roles": ["student", "staff"],
|
||||
"weight": 2,
|
||||
},
|
||||
{
|
||||
"defName": "Chat",
|
||||
"room": "Corridor",
|
||||
"minutes": 8,
|
||||
"need": "Social",
|
||||
"needGain": 0.4,
|
||||
"roles": ["student", "staff"],
|
||||
"weight": 3,
|
||||
},
|
||||
{
|
||||
"defName": "WalkCorridor",
|
||||
"room": "Corridor",
|
||||
"minutes": 3,
|
||||
"roles": ["student", "staff"],
|
||||
"weight": 1,
|
||||
},
|
||||
{
|
||||
"defName": "WalkYard",
|
||||
"room": "SchoolYard",
|
||||
"minutes": 5,
|
||||
"roles": ["student", "staff"],
|
||||
"weight": 1,
|
||||
},
|
||||
]
|
||||
@@ -1 +1 @@
|
||||
{ "defName": "Sit" }
|
||||
{ "defName": "Sit", "abstract": true }
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"defName": "Behavior",
|
||||
// A need at or below this is urgent. Phase 21 turns that into a goal weight.
|
||||
"needThreshold": 0.35,
|
||||
// Skill points a lesson adds per game hour, before traits and need state.
|
||||
"lessonSkillPerHour": 0.05,
|
||||
// Inclusive extra commute minutes. 0–6 matches the previous hardcoded roll so
|
||||
// the same seed still arrives at the same minute.
|
||||
"commuteSlackMin": 0,
|
||||
"commuteSlackMax": 6,
|
||||
"switchMargin": 0.15,
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
[
|
||||
{ "defName": "Sleep", "initial": 1, "decayPerHour": 0, "min": 0, "max": 1 },
|
||||
{ "defName": "Hunger", "initial": 1, "decayPerHour": 0, "min": 0, "max": 1 },
|
||||
{ "defName": "Toilet", "initial": 1, "decayPerHour": 0, "min": 0, "max": 1 },
|
||||
{ "defName": "Social", "initial": 1, "decayPerHour": 0, "min": 0, "max": 1 },
|
||||
{ "defName": "Sleep", "initial": 1, "decayPerHour": 0.05, "min": 0, "max": 1, "restoredOffCampus": true },
|
||||
{ "defName": "Hunger", "initial": 1, "decayPerHour": 0.1, "min": 0, "max": 1 },
|
||||
{ "defName": "Toilet", "initial": 1, "decayPerHour": 0.15, "min": 0, "max": 1 },
|
||||
{ "defName": "Social", "initial": 1, "decayPerHour": 0.08, "min": 0, "max": 1 },
|
||||
]
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
{
|
||||
"Sit": "Sit",
|
||||
"EatLunch": "Lunch",
|
||||
"UseToilet": "Restroom",
|
||||
"RecessRest": "Recess",
|
||||
"Chat": "Chat",
|
||||
"WalkCorridor": "Walk the corridor",
|
||||
"WalkYard": "Walk the yard",
|
||||
"Behavior": "Behavior rules",
|
||||
"Chair": "Chair",
|
||||
"DirectorsChair": "Principal's chair",
|
||||
"Desk": "Desk",
|
||||
|
||||
@@ -1,5 +1,12 @@
|
||||
{
|
||||
"Sit": "Сесть",
|
||||
"EatLunch": "Обед",
|
||||
"UseToilet": "Туалет",
|
||||
"RecessRest": "Перемена",
|
||||
"Chat": "Разговор",
|
||||
"WalkCorridor": "Прогулка по коридору",
|
||||
"WalkYard": "Прогулка во дворе",
|
||||
"Behavior": "Правила поведения",
|
||||
"Chair": "Стул",
|
||||
"DirectorsChair": "Кресло директора",
|
||||
"Desk": "Стол",
|
||||
|
||||
Reference in New Issue
Block a user