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:
Leonid Pershin
2026-08-19 19:49:44 +03:00
parent 3c54f981b7
commit b135a9caad
42 changed files with 1134 additions and 59 deletions
+28 -5
View File
@@ -1,26 +1,49 @@
using Arch.Core;
using HSchool.Ai;
using HSchool.Content;
namespace HSchool.Simulation;
/// <summary>
/// Drains needs by <see cref="NeedDef.DecayPerHour"/> × simulated hours. Core ships decay at zero
/// so this is a no-op until something exists that can refill them.
/// Drains needs by <see cref="NeedDef.DecayPerHour"/> × simulated hours while the person is on
/// campus. Off campus, needs do not drain and <see cref="NeedDef.RestoredOffCampus"/> snaps to max
/// — sleep comes back overnight, hunger does not keep falling at home.
/// </summary>
public static class NeedDecay
{
private static readonly QueryDescription PeopleWithNeeds = new QueryDescription().WithAll<PersonNeeds>();
private static readonly QueryDescription PeopleWithNeeds =
new QueryDescription().WithAll<PersonNeeds, Presence>();
public static void Apply(World world, DefCatalog catalog, double gameMinutes)
{
if (gameMinutes <= 0 || !catalog.AnyNeedDecays)
if (gameMinutes <= 0 || (!catalog.AnyNeedDecays && !catalog.AnyNeedRestoredOffCampus))
{
return;
}
var hours = gameMinutes / 60d;
world.Query(in PeopleWithNeeds, (ref PersonNeeds needs) =>
world.Query(in PeopleWithNeeds, (ref PersonNeeds needs, ref Presence presence) =>
{
if (!presence.IsOnCampus)
{
foreach (var def in catalog.Needs.Values)
{
if (def.Abstract || !def.RestoredOffCampus || !needs.Values.ContainsKey(def.DefName))
{
continue;
}
needs.Values[def.DefName] = def.Max;
}
return;
}
if (!catalog.AnyNeedDecays)
{
return;
}
foreach (var def in catalog.Needs.Values)
{
if (def.Abstract || !needs.Values.TryGetValue(def.DefName, out var current))