ManualAI.cs 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class ManualAI : CraftAI
  5. {
  6. public bool followTarget;
  7. // Update is called once per frame
  8. void FixedUpdate ()
  9. {
  10. if(owner.IsDead())
  11. {
  12. return;
  13. }
  14. if(battleController.isGameOver)
  15. {
  16. return;
  17. }
  18. if(CheckDead())
  19. {
  20. return;
  21. }
  22. if(owner.GetSwapManager().isPreparingSwap)
  23. {
  24. Debuger.Log("swap prapare time : "+owner.GetSwapManager().GetPreparingSwapTime());
  25. if(owner.GetSwapManager().IsReadySwap())
  26. {
  27. battleController.GetMessageManager().RequestSwap(owner.id, owner.GetSwapManager().GetTargetSwapId());
  28. owner.GetSwapManager().RequestedSwap();
  29. }
  30. }
  31. else if(GameTime.time-lastCheckTime >= checkTimeInterval)
  32. {
  33. lastCheckTime = GameTime.time;
  34. CheckAction();
  35. }
  36. }
  37. private void CheckAction()
  38. {
  39. if(owner.target != null)
  40. {
  41. float targetDis = NumberUtil.distanceVector3(owner.position, owner.target.position, true);
  42. Power attack = owner.GetPowerManager().GetAttack();
  43. if(!owner.target.CanShoot())
  44. {
  45. owner.target = null;
  46. }
  47. else if(targetDis > owner.viewRange)
  48. {
  49. owner.target = null;
  50. }
  51. else if(targetDis > attack.GetDistance())
  52. {
  53. if(!owner.isMoving)
  54. {
  55. Vector3 targetPos = owner.target.position;
  56. owner.MoveTo(targetPos.x, targetPos.z);
  57. }
  58. }
  59. else if(targetDis <= attack.GetDistance())
  60. {
  61. if(owner.isMoving && !owner.forceMove)
  62. owner.StopMove();
  63. owner.GetPowerManager().AttempUserPower(attack.GetId(), battleController);
  64. }
  65. }
  66. else
  67. {
  68. FindTarget();
  69. if(owner.target == null)
  70. {
  71. CheckOccupy();
  72. }
  73. }
  74. }
  75. protected override bool CheckOccupy ()
  76. {
  77. if(!base.CheckOccupy())
  78. return false;
  79. CrystalBase targetCrystal = battleController.GetMap().GetInRangeCrystalBase(owner.position);
  80. if(targetCrystal == null || targetCrystal.GetStation() != null)
  81. return false;
  82. List<BattleObject> list = map.GetBattleObjectByRange(targetCrystal.position, targetCrystal.range, TeamUtil.GetOpponentTeam(owner.team));
  83. if(list.Count > 0)
  84. return false;
  85. if(owner && targetCrystal != null)
  86. battleController.GetMessageManager().OccupyStation(owner, targetCrystal);
  87. return true;
  88. }
  89. }