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:
@@ -0,0 +1,87 @@
|
||||
namespace HSchool.Content.Tests;
|
||||
|
||||
public class ActionDefTests
|
||||
{
|
||||
private readonly CatalogLoader _loader = new();
|
||||
|
||||
[Fact]
|
||||
public void ConcreteAction_WithoutRoom_FailsLoad()
|
||||
{
|
||||
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
||||
[CatalogLoader.CorePackId],
|
||||
[
|
||||
PackDocuments.Def(
|
||||
CatalogLoader.CorePackId,
|
||||
"actions",
|
||||
"eat",
|
||||
"""{ "defName": "Eat", "minutes": 15, "need": "Hunger", "needGain": 0.5 }"""),
|
||||
PackDocuments.Def(
|
||||
CatalogLoader.CorePackId,
|
||||
"needs",
|
||||
"hunger",
|
||||
"""{ "defName": "Hunger", "initial": 1, "decayPerHour": 0, "min": 0, "max": 1 }"""),
|
||||
]));
|
||||
|
||||
Assert.Contains("Eat", ex.Message, StringComparison.Ordinal);
|
||||
Assert.Contains("room", ex.Message, StringComparison.OrdinalIgnoreCase);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConcreteAction_UnknownNeed_FailsLoad()
|
||||
{
|
||||
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
||||
[CatalogLoader.CorePackId],
|
||||
[
|
||||
PackDocuments.Def(
|
||||
CatalogLoader.CorePackId,
|
||||
"rooms",
|
||||
"cafeteria",
|
||||
"""{ "defName": "Cafeteria", "travelMinutes": 1 }"""),
|
||||
PackDocuments.Def(
|
||||
CatalogLoader.CorePackId,
|
||||
"actions",
|
||||
"eat",
|
||||
"""
|
||||
{ "defName": "EatLunch", "room": "Cafeteria", "minutes": 15, "need": "Snacks", "needGain": 0.5 }
|
||||
"""),
|
||||
]));
|
||||
|
||||
Assert.Contains("EatLunch", ex.Message, StringComparison.Ordinal);
|
||||
Assert.Contains("Snacks", ex.Message, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void ConcreteAction_UnknownThing_FailsLoad()
|
||||
{
|
||||
var ex = Assert.Throws<ContentLoadException>(() => _loader.Load(
|
||||
[CatalogLoader.CorePackId],
|
||||
[
|
||||
PackDocuments.Def(
|
||||
CatalogLoader.CorePackId,
|
||||
"rooms",
|
||||
"cafeteria",
|
||||
"""{ "defName": "Cafeteria", "travelMinutes": 1 }"""),
|
||||
PackDocuments.Def(
|
||||
CatalogLoader.CorePackId,
|
||||
"actions",
|
||||
"eat",
|
||||
"""
|
||||
{ "defName": "EatLunch", "room": "Cafeteria", "thing": "Stool", "minutes": 15 }
|
||||
"""),
|
||||
]));
|
||||
|
||||
Assert.Contains("EatLunch", ex.Message, StringComparison.Ordinal);
|
||||
Assert.Contains("Stool", ex.Message, StringComparison.Ordinal);
|
||||
}
|
||||
|
||||
[Fact]
|
||||
public void AbstractAction_DoesNotNeedARoom()
|
||||
{
|
||||
var catalog = _loader.Load(
|
||||
[CatalogLoader.CorePackId],
|
||||
[PackDocuments.Def(CatalogLoader.CorePackId, "actions", "sit", """{ "defName": "Sit", "abstract": true }""")]);
|
||||
|
||||
Assert.True(catalog.Actions["Sit"].Abstract);
|
||||
Assert.Null(catalog.Actions["Sit"].Room);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user