130 lines
5.1 KiB
C#
130 lines
5.1 KiB
C#
using System.Linq;
|
|
using NUnit.Framework;
|
|
using UnityEngine;
|
|
using XGame.ActorBehavior;
|
|
using XGame.VirtualInput;
|
|
using XWorld.Framework.ActorBehavior;
|
|
|
|
public sealed class LobbyActorBehaviorRuntimeTests
|
|
{
|
|
[Test]
|
|
public void RegisterSelfActor_DefaultsCatalogToFighter()
|
|
{
|
|
var runtime = new LobbyActorBehaviorRuntime();
|
|
runtime.RegisterCatalog(CreateFighterCatalog());
|
|
|
|
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
|
|
|
|
Assert.That(runtime.SwitchActorCatalog(10, LobbyActorBehaviorRuntime.DefaultCatalogType), Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void Skill1Tap_StartsQuantao01AndEmitsPresentationEvents()
|
|
{
|
|
var runtime = new LobbyActorBehaviorRuntime();
|
|
runtime.RegisterCatalog(CreateFighterCatalog());
|
|
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
|
|
|
|
BehaviorStartResult result = runtime.HandleActionButton(
|
|
CreateButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Tap, Vector2.zero),
|
|
10,
|
|
Vector3.forward);
|
|
|
|
BehaviorEvent[] events = runtime.DrainEvents().ToArray();
|
|
Assert.That(result.Success, Is.True);
|
|
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.TimelineAnimation && e.Animation == "140_skill01a_qt"), Is.True);
|
|
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.TimelineEffect && e.Prefab.Contains("9110004_zhujue_quantao_skill01a")), Is.True);
|
|
}
|
|
|
|
[Test]
|
|
public void PrimaryTap_DoesNotStartQuantao01()
|
|
{
|
|
var runtime = new LobbyActorBehaviorRuntime();
|
|
runtime.RegisterCatalog(CreateFighterCatalog());
|
|
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
|
|
|
|
BehaviorStartResult result = runtime.HandleActionButton(
|
|
CreateButtonEvent(ActionButtonId.Primary, ActionButtonPhase.Tap, Vector2.zero),
|
|
10,
|
|
Vector3.forward);
|
|
|
|
Assert.That(result.Success, Is.False);
|
|
Assert.That(result.Error, Is.EqualTo("button ignored"));
|
|
Assert.That(runtime.DrainEvents().Any(e => e.BehaviorId == LobbyActorBehaviorRuntime.SecondaryABehaviorId), Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void Skill1Release_DoesNotStartQuantao01Again()
|
|
{
|
|
var runtime = new LobbyActorBehaviorRuntime();
|
|
runtime.RegisterCatalog(CreateFighterCatalog());
|
|
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
|
|
|
|
BehaviorStartResult result = runtime.HandleActionButton(
|
|
CreateButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Release, Vector2.right),
|
|
10,
|
|
Vector3.forward);
|
|
|
|
Assert.That(result.Success, Is.False);
|
|
Assert.That(result.Error, Is.EqualTo("button ignored"));
|
|
Assert.That(runtime.DrainEvents().Any(e => e.BehaviorId == LobbyActorBehaviorRuntime.SecondaryABehaviorId), Is.False);
|
|
}
|
|
|
|
[Test]
|
|
public void Skill1Tap_DoesNotRestartWhileSkillIsActive()
|
|
{
|
|
var runtime = new LobbyActorBehaviorRuntime();
|
|
runtime.RegisterCatalog(CreateFighterCatalog());
|
|
runtime.RegisterOrUpdateActor(10, Vector3.zero, Vector3.forward);
|
|
|
|
BehaviorStartResult first = runtime.HandleActionButton(
|
|
CreateButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Tap, Vector2.zero),
|
|
10,
|
|
Vector3.forward);
|
|
runtime.DrainEvents();
|
|
|
|
BehaviorStartResult second = runtime.HandleActionButton(
|
|
CreateButtonEvent(ActionButtonId.Skill1, ActionButtonPhase.Tap, Vector2.zero),
|
|
10,
|
|
Vector3.forward);
|
|
|
|
BehaviorEvent[] events = runtime.DrainEvents().ToArray();
|
|
Assert.That(first.Success, Is.True);
|
|
Assert.That(second.Success, Is.False);
|
|
Assert.That(second.Error, Is.EqualTo("actor already has active behavior"));
|
|
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.BehaviorStopped), Is.False);
|
|
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.BehaviorStarted), Is.False);
|
|
Assert.That(events.Any(e => e.Kind == BehaviorEventKind.TimelineAnimation), Is.False);
|
|
}
|
|
|
|
private static ActionButtonEvent CreateButtonEvent(ActionButtonId buttonId, ActionButtonPhase phase, Vector2 direction)
|
|
{
|
|
return new ActionButtonEvent(buttonId, phase, Vector2.zero, Vector2.zero, direction, direction.magnitude, 0f, false, 1);
|
|
}
|
|
|
|
private static BehaviorConfigCatalog CreateFighterCatalog()
|
|
{
|
|
return BehaviorConfigCatalog.LoadFromJson(
|
|
"fighter",
|
|
@"{
|
|
""type"": ""fighter"",
|
|
""version"": 1,
|
|
""behaviors"": [
|
|
{
|
|
""id"": ""quantao01"",
|
|
""duration"": 1.0,
|
|
""canBeInterrupted"": true,
|
|
""input"": ""DirectionOrTarget"",
|
|
""timeline"": [
|
|
{ ""time"": 0.0, ""kind"": ""Animation"", ""animation"": ""140_skill01a_qt"", ""duration"": 1.0 },
|
|
{ ""time"": 0.0, ""kind"": ""Effect"", ""prefab"": ""Assets/Game/Art/Effect/Prefab/skill/9110004_zhujue_quantao_skill01a.prefab"", ""duration"": 1.0 }
|
|
],
|
|
""logicEffects"": []
|
|
}
|
|
]
|
|
}",
|
|
@"{ ""type"": ""fighter"", ""version"": 1, ""flyObjects"": [] }",
|
|
@"{ ""type"": ""fighter"", ""version"": 1, ""buffs"": [] }");
|
|
}
|
|
}
|