12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152 |
- 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; }
- }
- /// <summary>
- /// 战斗对象的通用AI
- /// AI组件和具体的EntityView绑定,其他Component最好不要尝试获取AI组件
- /// </summary>
- public class BattleEntityAI : Component<IBattleEntityAIContext>
- {
- 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();
- }
- }
- }
|