From 1380d5107a6b2e70d92c1556bc22871f0521eee2 Mon Sep 17 00:00:00 2001 From: ud18010 Date: Thu, 30 Jul 2026 13:19:45 +0800 Subject: [PATCH] feat: add actor behavior example config --- .../Config/ActorBehavior/fighter_buff.json | 23 ++++++++++++++ .../Config/ActorBehavior/fighter_flyobj.json | 27 +++++++++++++++++ .../Config/ActorBehavior/fighter_skill.json | 30 +++++++++++++++++++ .../BehaviorConfigCatalogTests.cs | 30 +++++++++++++++++++ 4 files changed, 110 insertions(+) create mode 100644 Client/Assets/Resources/Config/ActorBehavior/fighter_buff.json create mode 100644 Client/Assets/Resources/Config/ActorBehavior/fighter_flyobj.json create mode 100644 Client/Assets/Resources/Config/ActorBehavior/fighter_skill.json diff --git a/Client/Assets/Resources/Config/ActorBehavior/fighter_buff.json b/Client/Assets/Resources/Config/ActorBehavior/fighter_buff.json new file mode 100644 index 00000000..2c6fc5a5 --- /dev/null +++ b/Client/Assets/Resources/Config/ActorBehavior/fighter_buff.json @@ -0,0 +1,23 @@ +{ + "type": "fighter", + "version": 1, + "buffs": [ + { + "id": "slow_01", + "duration": 3.0, + "tickInterval": 1.0, + "repeatCount": 3, + "stacking": "RefreshDuration", + "logicEffects": [ + { + "id": "slow_tick", + "shape": "Locked", + "target": "Owner", + "effects": [ + { "type": "Attribute", "attribute": "moveSpeed", "value": -0.2 } + ] + } + ] + } + ] +} diff --git a/Client/Assets/Resources/Config/ActorBehavior/fighter_flyobj.json b/Client/Assets/Resources/Config/ActorBehavior/fighter_flyobj.json new file mode 100644 index 00000000..8f8f3995 --- /dev/null +++ b/Client/Assets/Resources/Config/ActorBehavior/fighter_flyobj.json @@ -0,0 +1,27 @@ +{ + "type": "fighter", + "version": 1, + "flyObjects": [ + { + "id": "blade_wave", + "duration": 1.5, + "movement": { "kind": "Line", "speed": 6.0 }, + "collision": { "shape": "Sphere", "radius": 0.4, "hitLimit": 1 }, + "timeline": [ + { "time": 0.0, "kind": "Effect", "prefab": "Assets/Game/Art/Effect/blade_wave.prefab", "duration": 1.5 }, + { "time": 0.0, "kind": "LogicEffect", "effectId": "blade_wave_hit", "trigger": "OnCollision" } + ], + "logicEffects": [ + { + "id": "blade_wave_hit", + "shape": "Locked", + "target": "HitActor", + "effects": [ + { "type": "Attribute", "attribute": "hp", "value": -20 }, + { "type": "Buff", "buffId": "slow_01" } + ] + } + ] + } + ] +} diff --git a/Client/Assets/Resources/Config/ActorBehavior/fighter_skill.json b/Client/Assets/Resources/Config/ActorBehavior/fighter_skill.json new file mode 100644 index 00000000..fcfb338c --- /dev/null +++ b/Client/Assets/Resources/Config/ActorBehavior/fighter_skill.json @@ -0,0 +1,30 @@ +{ + "type": "fighter", + "version": 1, + "behaviors": [ + { + "id": "slash", + "duration": 0.8, + "canBeInterrupted": true, + "input": "DirectionOrTarget", + "timeline": [ + { "time": 0.0, "kind": "Animation", "animation": "slash_01", "duration": 0.8 }, + { "time": 0.12, "kind": "Effect", "prefab": "Assets/Game/Art/Effect/slash.prefab", "duration": 0.5 }, + { "time": 0.25, "kind": "LogicEffect", "effectId": "slash_hit" }, + { "time": 0.32, "kind": "Projectile", "flyObjectId": "blade_wave" } + ], + "logicEffects": [ + { + "id": "slash_hit", + "shape": "Sector", + "radius": 2.4, + "angle": 90, + "target": "Enemy", + "effects": [ + { "type": "Attribute", "attribute": "hp", "value": -30 } + ] + } + ] + } + ] +} diff --git a/Server/Framework.Shared.Tests/ActorBehavior/BehaviorConfigCatalogTests.cs b/Server/Framework.Shared.Tests/ActorBehavior/BehaviorConfigCatalogTests.cs index 7028fe94..3a279805 100644 --- a/Server/Framework.Shared.Tests/ActorBehavior/BehaviorConfigCatalogTests.cs +++ b/Server/Framework.Shared.Tests/ActorBehavior/BehaviorConfigCatalogTests.cs @@ -44,6 +44,36 @@ namespace XWorld.Framework.Tests.ActorBehavior Assert.Contains("missing_wave", ex.Message); } + + [Fact] + public void ExampleConfigFiles_LoadFromRepository() + { + string root = FindRepoRoot(); + string dir = System.IO.Path.Combine(root, "Client", "Assets", "Resources", "Config", "ActorBehavior"); + + BehaviorConfigCatalog catalog = BehaviorConfigCatalog.LoadFromJson( + "fighter", + System.IO.File.ReadAllText(System.IO.Path.Combine(dir, "fighter_skill.json")), + System.IO.File.ReadAllText(System.IO.Path.Combine(dir, "fighter_flyobj.json")), + System.IO.File.ReadAllText(System.IO.Path.Combine(dir, "fighter_buff.json"))); + + Assert.True(catalog.Behaviors.ContainsKey("slash")); + } + + private static string FindRepoRoot() + { + string? dir = AppContext.BaseDirectory; + while (dir != null) + { + string gitPath = System.IO.Path.Combine(dir, ".git"); + if (System.IO.Directory.Exists(gitPath) || System.IO.File.Exists(gitPath)) + { + return dir; + } + dir = System.IO.Directory.GetParent(dir)?.FullName; + } + throw new InvalidOperationException("repo root not found"); + } } internal static class TestBehaviorJson