BattleMgr_Cmd.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  1. using CommonAI.Zone;
  2. using CommonLang.Geometry;
  3. using ET.Client;
  4. using ET.EventType;
  5. using ET.Server;
  6. using System;
  7. using UnityEngine;
  8. using Random = System.Random;
  9. using Vector2 = CommonLang.Geometry.Vector2;
  10. namespace ET
  11. {
  12. [Event]
  13. public class BattleFuncHandler : BEvent<BattleFunc>
  14. {
  15. protected override async ETTask OnEvent(BattleFunc a)
  16. {
  17. Log.Debug($"Battle Func:{a.FuncIndex}");
  18. var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
  19. switch (a.FuncIndex)
  20. {
  21. case (int)BattleFunc.FUNC.Start:
  22. session.Call(new C2G_BattleNotify()
  23. {
  24. Message = BattleNotify.StartRefreshMonster.ToString()
  25. }).Coroutine();
  26. break;
  27. case (int)KeyCode.F1:
  28. var units = new int[] { 101, 111, 121, 131 };
  29. var centerpos = GetCurBattleCenter();
  30. var rand = new Random();
  31. foreach (var id in units)
  32. {
  33. float r = (float)Math.Sqrt(rand.Next(2304)) + 12;
  34. double ang = rand.Next(40) / 180.0f * Math.PI + Math.PI/2.0f + Math.PI;
  35. //Log.Debug($"rand unit r({r}), ang({ang})");
  36. float x = centerpos.X + (float)(r * Math.Cos(ang));
  37. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  38. //Log.Debug($"born unit: r:{r}, ang:{ang}---({x},{y})");
  39. session.Call(new C2G_AddUnitsToMap()
  40. {
  41. UnitId = id,
  42. Force = 1,
  43. X = (int)x,
  44. Y = (int)y
  45. }).Coroutine();
  46. }
  47. break;
  48. case (int)KeyCode.F2:
  49. centerpos = GetCurBattleCenter();
  50. var units2 = new int[] { 102, 112, 122, 132 };
  51. rand = new Random();
  52. for (int i = 0; i < 2; i++)
  53. {
  54. var id = units2[rand.Next(units2.Length)];
  55. float r = (float)Math.Sqrt(rand.Next(2304)) + 12;
  56. double ang = rand.Next(40) / 180.0f * Math.PI + Math.PI / 2.0f + Math.PI;
  57. float x = centerpos.X + (float)(r * Math.Cos(ang));
  58. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  59. session.Call(new C2G_AddUnitsToMap()
  60. {
  61. UnitId = id,
  62. Force = 1,
  63. X = (int)x,
  64. Y = (int)y
  65. }).Coroutine();
  66. }
  67. break;
  68. case (int)KeyCode.F3:
  69. centerpos = GetCurBattleCenter();
  70. var units3 = new int[] { 103, 113, 123, 133 };
  71. rand = new Random();
  72. for (int i = 0; i < 1; i++)
  73. {
  74. var id = units3[rand.Next(units3.Length)];
  75. float r = (float)Math.Sqrt(rand.Next(2304)) + 12;
  76. double ang = rand.Next(40) / 180.0f * Math.PI + Math.PI / 2.0f + Math.PI;
  77. float x = centerpos.X + (float)(r * Math.Cos(ang));
  78. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  79. session.Call(new C2G_AddUnitsToMap()
  80. {
  81. UnitId = id,
  82. Force = 1,
  83. X = (int)x,
  84. Y = (int)y
  85. }).Coroutine();
  86. }
  87. break;
  88. case (int)KeyCode.F4:
  89. session.Call(new C2G_BattleNotify()
  90. {
  91. Message = BattleNotify.TiktokGift_1.ToString()
  92. }).Coroutine();
  93. break;
  94. case (int)KeyCode.F5:
  95. session.Call(new C2G_BattleNotify()
  96. {
  97. Message = BattleNotify.TiktokGift_10.ToString()
  98. }).Coroutine();
  99. break;
  100. case (int)KeyCode.F6:
  101. session.Call(new C2G_BattleNotify()
  102. {
  103. Message = BattleNotify.TiktokGift_52.ToString()
  104. }).Coroutine();
  105. break;
  106. case (int)KeyCode.F7:
  107. session.Call(new C2G_BattleNotify()
  108. {
  109. Message = BattleNotify.TiktokGift_99.ToString()
  110. }).Coroutine();
  111. break;
  112. case (int)KeyCode.F8:
  113. session.Call(new C2G_BattleNotify()
  114. {
  115. Message = BattleNotify.TiktokGift_199.ToString()
  116. }).Coroutine();
  117. break;
  118. case (int)KeyCode.F9:
  119. session.Call(new C2G_BattleNotify()
  120. {
  121. Message = BattleNotify.TiktokGift_520.ToString()
  122. }).Coroutine();
  123. break;
  124. case (int)KeyCode.F10:
  125. break;
  126. }
  127. await ETTask.CompletedTask;
  128. }
  129. //获得当前战场focus中心(当前塔位置)
  130. private Vector2 vecTemp = new Vector2();
  131. private Vector2 GetCurBattleCenter()
  132. {
  133. foreach(var tid in ConstGame.TowerTemplateIDs)
  134. {
  135. var tower = BattleMgr.Instance.GetUnitByTemplateID(tid);
  136. if(tower != null && !tower.IsDead)
  137. {
  138. vecTemp.X = tower.ZUnit.X;
  139. vecTemp.Y = tower.ZUnit.Y;
  140. return vecTemp;
  141. }
  142. }
  143. return new Vector2(0, 0);
  144. }
  145. }
  146. //发送战斗服指令相关
  147. public partial class BattleMgr
  148. {
  149. private bool autoFight;
  150. public bool AutoFight
  151. {
  152. get
  153. {
  154. return autoFight;
  155. }
  156. set
  157. {
  158. if(value == autoFight) return;
  159. else
  160. {
  161. autoFight = value;
  162. }
  163. }
  164. }
  165. public CommonAI.Zone.Action SetAutoFight(bool flag)
  166. {
  167. return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
  168. }
  169. }
  170. }