feat(ai): AiRuntime 条件转换+IsControllable让位门+状态计时+trace+Reset
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using BaseGames.AI;
|
||||
|
||||
namespace BaseGames.Tests.EditMode.AI
|
||||
{
|
||||
public sealed class FakeSensor : ISensor
|
||||
{
|
||||
public bool Sees; public float LostForValue; public Vector2 Last;
|
||||
public bool SeesPlayer() => Sees;
|
||||
public bool InRange(float range) => Sees; // 简化:可见即在范围
|
||||
public bool LostFor(float seconds) => LostForValue >= seconds;
|
||||
public Vector2 LastKnown => Last;
|
||||
}
|
||||
|
||||
public sealed class FakeMover : IMover
|
||||
{
|
||||
public List<string> Calls = new List<string>();
|
||||
public void MoveTo(Vector2 t) => Calls.Add("MoveTo");
|
||||
public void FacePlayer() => Calls.Add("FacePlayer");
|
||||
public void Stop() => Calls.Add("Stop");
|
||||
public void WalkRandom() => Calls.Add("WalkRandom");
|
||||
public void LookAround() => Calls.Add("LookAround");
|
||||
}
|
||||
|
||||
public sealed class FakeCombat : ICombatant
|
||||
{
|
||||
public string Running; public List<string> Used = new List<string>();
|
||||
public bool UseAbility(string id) { Used.Add(id); Running = id; return true; }
|
||||
public bool IsAbilityRunning(string id = null) => id == null ? Running != null : Running == id;
|
||||
public bool NoAbilityRunning => Running == null;
|
||||
public bool CanUseAbility(string id) => true;
|
||||
}
|
||||
|
||||
public sealed class FakeVitals : IActorVitals
|
||||
{
|
||||
public bool Alive = true; public bool Controllable = true; public float Hp = 1f;
|
||||
public bool IsAlive => Alive;
|
||||
public bool IsControllable => Controllable;
|
||||
public float HpPercent => Hp;
|
||||
public bool HpBelow(float ratio) => Hp < ratio;
|
||||
}
|
||||
|
||||
public sealed class FakeAiContext : IAiContext
|
||||
{
|
||||
public FakeSensor S = new FakeSensor();
|
||||
public FakeMover M = new FakeMover();
|
||||
public FakeCombat C = new FakeCombat();
|
||||
public FakeVitals V = new FakeVitals();
|
||||
public Blackboard BB = new Blackboard();
|
||||
public ISensor Sensor => S;
|
||||
public IMover Mover => M;
|
||||
public ICombatant Combat => C;
|
||||
public IActorVitals Vitals => V;
|
||||
public Blackboard Blackboard => BB;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user