AI_Attack.cs 1.3 KB

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