BattleMgr_Cmd.cs 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using CommonAI.Zone;
  2. using CommonLang.Geometry;
  3. using ET.Client;
  4. using ET.EventType;
  5. using ET.Server;
  6. using System;
  7. namespace ET
  8. {
  9. [Event(SceneType.None)]
  10. public class BattleFuncHandler : BEvent<BattleFunc>
  11. {
  12. public override void OnEvent(BattleFunc a)
  13. {
  14. Log.Debug($"Battle Func:{a.FuncIndex}");
  15. var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
  16. switch (a.FuncIndex)
  17. {
  18. case 2:
  19. var units = new int[] { 101, 111, 121, 131 };
  20. var centerpos = GetCurBattleCenter();
  21. var rand = new Random();
  22. foreach (var id in units)
  23. {
  24. float r = (rand.Next(1000)) / 100.0f + 5;
  25. double ang = rand.Next(180) / 180.0f * Math.PI + Math.PI;
  26. Log.Debug($"rand unit r({r}), ang({ang})");
  27. float x = centerpos.X + (float)(r * Math.Cos(ang));
  28. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  29. session.Call(new C2G_AddUnitsToMap()
  30. {
  31. UnitId = id,
  32. Force = 1,
  33. X = (int)x,
  34. Y = (int)y
  35. }).Coroutine();
  36. }
  37. break;
  38. case 3:
  39. session.Call(new C2G_TriggrBattleFunction()
  40. {
  41. TriggerID = 10111,
  42. Value1 = 0,
  43. Value2 = 0,
  44. Value3 = 0,
  45. Value4 = 0,
  46. Value5 = 0,
  47. Value6 = 0,
  48. }).Coroutine();
  49. break;
  50. case 4:
  51. var units2 = new int[] { 102, 112, 122, 132 };
  52. centerpos = GetCurBattleCenter();
  53. rand = new Random();
  54. foreach (var id in units2)
  55. {
  56. float r = (rand.Next(1000)) / 100.0f + 5;
  57. double ang = rand.Next(180) / 180.0f * Math.PI + Math.PI;
  58. Log.Debug($"rand unit r({r}), ang({ang})");
  59. float x = centerpos.X + (float)(r * Math.Cos(ang));
  60. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  61. session.Call(new C2G_AddUnitsToMap()
  62. {
  63. UnitId = id,
  64. Force = 1,
  65. X = (int)x,
  66. Y = (int)y
  67. }).Coroutine();
  68. }
  69. break;
  70. case 5:
  71. var units3 = new int[] { 103, 113, 123, 133 };
  72. centerpos = GetCurBattleCenter();
  73. rand = new Random();
  74. foreach (var id in units3)
  75. {
  76. float r = (rand.Next(1000)) / 100.0f + 5;
  77. double ang = rand.Next(180) / 180.0f * Math.PI + Math.PI;
  78. Log.Debug($"rand unit r({r}), ang({ang})");
  79. float x = centerpos.X + (float)(r * Math.Cos(ang));
  80. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  81. session.Call(new C2G_AddUnitsToMap()
  82. {
  83. UnitId = id,
  84. Force = 1,
  85. X = (int)x,
  86. Y = (int)y
  87. }).Coroutine();
  88. }
  89. break;
  90. }
  91. }
  92. //获得当前战场focus中心(当前塔位置)
  93. private Vector2 vecTemp = new Vector2();
  94. private Vector2 GetCurBattleCenter()
  95. {
  96. foreach(var tid in ConstGame.TowerTemplateIDs)
  97. {
  98. var tower = BattleMgr.Instance.GetUnitByTemplateID(tid);
  99. if(tower != null && !tower.IsDead)
  100. {
  101. vecTemp.X = tower.ZUnit.X;
  102. vecTemp.Y = tower.ZUnit.Y;
  103. return vecTemp;
  104. }
  105. }
  106. return new Vector2(0, 0);
  107. }
  108. }
  109. //发送战斗服指令相关
  110. public partial class BattleMgr
  111. {
  112. private bool autoFight;
  113. public bool AutoFight
  114. {
  115. get
  116. {
  117. return autoFight;
  118. }
  119. set
  120. {
  121. if(value == autoFight) return;
  122. else
  123. {
  124. autoFight = value;
  125. }
  126. }
  127. }
  128. public CommonAI.Zone.Action SetAutoFight(bool flag)
  129. {
  130. return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
  131. }
  132. }
  133. }