BattleEntityAI.cs 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using System;
  2. using XGame.Framework.Components;
  3. namespace FL.Battle.Components.AI
  4. {
  5. public interface IBattleEntityAIContext
  6. {
  7. IEntity Entity { get; }
  8. StatesComponent States { get; }
  9. MoveComponent Move { get; }
  10. SkillComponent Skill { get; }
  11. }
  12. /// <summary>
  13. /// 战斗对象的通用AI
  14. /// AI组件和具体的EntityView绑定,其他Component最好不要尝试获取AI组件
  15. /// </summary>
  16. public class BattleEntityAI : Component<IBattleEntityAIContext>
  17. {
  18. protected override void OnDispose()
  19. {
  20. }
  21. public void MoveTo(MoveArgs args)
  22. {
  23. args.onComplete += () =>
  24. {
  25. Context.States.RemoveState(EEntityState.Moving);
  26. };
  27. Context.States.AddState(EEntityState.Moving);
  28. Context.Move.MoveTo(args);
  29. }
  30. public void MoveToBattle(MoveArgs args, Action callback = null)
  31. {
  32. var entity = Context.Entity;
  33. args.speed = entity.Attr.MoveSpeed;
  34. args.timeScale = entity.Attr.MoveSpeedScale;
  35. args.onComplete = () =>
  36. {
  37. Context.States.RemoveState(EEntityState.Moving);
  38. PrepareBattle();
  39. callback.SafeInvoke();
  40. };
  41. Context.States.AddState(EEntityState.Moving);
  42. // 打断技能并重置cd
  43. //Context.Skill.Stop(false);
  44. Context.Move.MoveTo(args);
  45. }
  46. public void PrepareBattle()
  47. {
  48. Context.Skill.Prepare();
  49. }
  50. }
  51. }