(client) feat:完成实体生成函数,修复行为树加载错误,改进Define打印缩进

This commit is contained in:
m0_75251201
2025-07-22 14:40:24 +08:00
parent 506d0a68a8
commit a6dfbd7c68
26 changed files with 835 additions and 527 deletions

View File

@ -8,7 +8,12 @@ namespace AI
{
public List<AIBase> children = new();
public virtual JobBase GetJob(Entity.Entity target)
public abstract JobBase GetJob(Entity.Entity target);
}
public class Selector : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
foreach (var aiBase in children)
{
@ -19,28 +24,7 @@ namespace AI
return null;
}
}
public class ContinuousMove : AIBase
{
override public JobBase GetJob(Entity.Entity target)
{
return null;
}
}
public class TrackPlayer : AIBase
{
}
public class RandomWander : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
return new WanderJob();
}
}
public class ConditionalAI : AIBase
public class ConditionalAI : Selector
{
// 条件函数,返回 true 表示满足条件
private Func<Entity.Entity, bool> condition;
@ -64,4 +48,56 @@ namespace AI
return null;
}
}
public class SequentialAI : Selector
{
private int currentIndex = 0; // 当前正在尝试的子节点索引
public override JobBase GetJob(Entity.Entity target)
{
// 如果当前索引超出了子节点范围,重置索引并返回 null
if (currentIndex >= children.Count)
{
ResetIndex();
return null;
}
// 获取当前子节点的任务
var currentChild = children[currentIndex];
var job = currentChild.GetJob(target);
// 移动到下一个子节点
currentIndex++;
return job;
}
// 重置当前索引(用于重新开始遍历)
private void ResetIndex()
{
currentIndex = 0;
}
}
public class ContinuousMove : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
return new MoveJob();
}
}
public class TrackPlayer : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
throw new NotImplementedException();
}
}
public class RandomWander : AIBase
{
public override JobBase GetJob(Entity.Entity target)
{
return new WanderJob();
}
}
}