using System;
using XGame.Framework.Components;
namespace FL.Battle.Components.AI
{
public interface IBattleEntityAIContext
{
IEntity Entity { get; }
StatesComponent States { get; }
MoveComponent Move { get; }
SkillComponent Skill { get; }
}
///
/// 战斗对象的通用AI
/// AI组件和具体的EntityView绑定,其他Component最好不要尝试获取AI组件
///
public class BattleEntityAI : Component
{
protected override void OnDispose()
{
}
public void MoveTo(MoveArgs args)
{
args.onComplete += () =>
{
Context.States.RemoveState(EEntityState.Moving);
};
Context.States.AddState(EEntityState.Moving);
Context.Move.MoveTo(args);
}
public void MoveToBattle(MoveArgs args, Action callback = null)
{
var entity = Context.Entity;
args.speed = entity.Attr.MoveSpeed;
args.timeScale = entity.Attr.MoveSpeedScale;
args.onComplete = () =>
{
Context.States.RemoveState(EEntityState.Moving);
PrepareBattle();
callback.SafeInvoke();
};
Context.States.AddState(EEntityState.Moving);
// 打断技能并重置cd
//Context.Skill.Stop(false);
Context.Move.MoveTo(args);
}
public void PrepareBattle()
{
Context.Skill.Prepare();
}
}
}