CraftAI.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. public class CraftAI : AI
  5. {
  6. public bool followTarget;
  7. protected float lastCheckOccupyTime;
  8. protected float checkOccupyInterval = 3f;
  9. protected Craft owner
  10. {
  11. get{
  12. return _owner as Craft;
  13. }
  14. }
  15. protected virtual bool CheckOccupy()
  16. {
  17. if(GameTime.time - lastCheckOccupyTime > checkOccupyInterval)
  18. {
  19. lastCheckOccupyTime = GameTime.time;
  20. return true;
  21. }
  22. return false;
  23. }
  24. public void AttempGetItem(MapItem mapItem)
  25. {
  26. if(!CanSendMessage())
  27. {
  28. return;
  29. }
  30. if(!owner.IsHero())
  31. return;
  32. if(mapItem is FlagItem)
  33. DealFlag(mapItem as FlagItem);
  34. else
  35. battleController.GetMessageManager().GetItem(player, owner.id, mapItem.id);
  36. }
  37. private void DealFlag(FlagItem flagItem)
  38. {
  39. if (flagItem.linkedCraftId >= 0)
  40. return;
  41. if(flagItem.team == owner.team)
  42. {
  43. if(flagItem.IsInBase())
  44. {
  45. FlagItem oppFlagItem = battleController.GetMap().GetFlag(TeamUtil.GetOpponentTeam(flagItem.team));
  46. if(oppFlagItem.linkedCraftId == owner.id)
  47. battleController.GetMessageManager().CaptureFlag(player, owner);
  48. }
  49. else
  50. {
  51. battleController.GetMessageManager().ReturnFlag(player, owner, flagItem);
  52. }
  53. }
  54. else
  55. battleController.GetMessageManager().GetFlag(player, owner, flagItem);
  56. }
  57. protected void FindMaxThreatTarget()
  58. {
  59. if(map.HasFlag())
  60. {
  61. FlagItem myFlag = map.GetFlag(owner.team);
  62. if(myFlag.linkedCraftId != -1)
  63. {
  64. owner.target = map.GetBattleObject(myFlag.linkedCraftId);
  65. return;
  66. }
  67. }
  68. else if(map.id == MapData.MapID.Challenge)
  69. {
  70. List<CrystalBase> list = battleController.GetMap().GetCrystalBaseList();
  71. for(int i=0; i<list.Count; i++)
  72. {
  73. Station station = list[i].GetStation();
  74. if(station != null && station.team != owner.team)
  75. {
  76. owner.target = station;
  77. return;
  78. }
  79. }
  80. }
  81. int id = owner.GetThreadManager().GetMaxThreatId();
  82. BattleObject battleObj = battleController.GetMap().GetBattleObject(id);
  83. if(battleObj != null)
  84. {
  85. if(battleObj.IsDead())
  86. {
  87. owner.GetThreadManager().RemoveThreat(id);
  88. }
  89. else
  90. {
  91. owner.target = battleObj;
  92. }
  93. }
  94. }
  95. }