AI_Attack.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. namespace ET.Client
  2. {
  3. public class AI_Attack: AAIHandler
  4. {
  5. public override int Check(AIComponent aiComponent, AIConfig aiConfig)
  6. {
  7. long sec = TimeHelper.ClientNow() / 1000 % 15;
  8. if (sec >= 10)
  9. {
  10. return 0;
  11. }
  12. return 1;
  13. }
  14. public override async ETTask Execute(AIComponent aiComponent, AIConfig aiConfig, ETCancellationToken cancellationToken)
  15. {
  16. Scene clientScene = aiComponent.DomainScene();
  17. Unit myUnit = UnitHelper.GetMyUnitFromClientScene(clientScene);
  18. if (myUnit == null)
  19. {
  20. return;
  21. }
  22. // 停在当前位置
  23. clientScene.GetComponent<SessionComponent>().Session.Send(new C2M_Stop());
  24. Log.Debug("开始攻击");
  25. for (int i = 0; i < 100000; ++i)
  26. {
  27. Log.Debug($"攻击: {i}次");
  28. // 因为协程可能被中断,任何协程都要传入cancellationToken,判断如果是中断则要返回
  29. await TimerComponent.Instance.WaitAsync(1000, cancellationToken);
  30. if (cancellationToken.IsCancel())
  31. {
  32. return;
  33. }
  34. }
  35. }
  36. }
  37. }