BattleMgr_Cmd.cs 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  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. if(PlayerComponent.Instance == null || PlayerComponent.Instance.ClientScene() == null || PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>() == null)
  18. {
  19. return;
  20. }
  21. Log.Debug($"Battle Func:{a.FuncIndex}");
  22. var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
  23. switch (a.FuncIndex)
  24. {
  25. case (int)BattleFunc.FUNC.ClientIsReady:
  26. session.Call(new C2G_BattleNotify()
  27. {
  28. Message = BattleNotify.ClientIsReady.ToString()
  29. }).Coroutine();
  30. break;
  31. case (int)BattleFunc.FUNC.Start:
  32. session.Call(new C2G_BattleNotify()
  33. {
  34. Message = BattleNotify.StartRefreshMonster.ToString()
  35. }).Coroutine();
  36. break;
  37. case (int)BattleFunc.FUNC.Start2:
  38. session.Call(new C2G_BattleNotify()
  39. {
  40. Message = BattleNotify.StartRefreshMonster2.ToString()
  41. }).Coroutine();
  42. break;
  43. case (int)BattleFunc.FUNC.Start3:
  44. session.Call(new C2G_BattleNotify()
  45. {
  46. Message = BattleNotify.StartRefreshMonster3.ToString()
  47. }).Coroutine();
  48. break;
  49. case (int)KeyCode.F1:
  50. var units = new int[] { 101, 111, 121, 131 };
  51. var rand = new Random();
  52. foreach (var id in units)
  53. {
  54. var pos = GetRandomPos();
  55. session.Call(new C2G_AddUnitsToMap()
  56. {
  57. UnitId = id,
  58. Force = 1,
  59. X = (int)pos.X,
  60. Y = (int)pos.Y
  61. }).Coroutine();
  62. }
  63. break;
  64. case (int)KeyCode.F2:
  65. var units2 = new int[] { 102, 112, 122, 132 };
  66. rand = new Random();
  67. for (int i = 0; i < 2; i++)
  68. {
  69. var pos = GetRandomPos();
  70. session.Call(new C2G_AddUnitsToMap()
  71. {
  72. UnitId = units2[rand.Next(units2.Length)],
  73. Force = 1,
  74. X = (int)pos.X,
  75. Y = (int)pos.Y
  76. }).Coroutine();
  77. }
  78. break;
  79. case (int)KeyCode.F3:
  80. var units3 = new int[] { 103, 113, 123, 133 };
  81. rand = new Random();
  82. for (int i = 0; i < 1; i++)
  83. {
  84. var pos = GetRandomPos();
  85. session.Call(new C2G_AddUnitsToMap()
  86. {
  87. UnitId = units3[rand.Next(units3.Length)],
  88. Force = 1,
  89. X = (int)pos.X,
  90. Y = (int)pos.Y
  91. }).Coroutine();
  92. }
  93. break;
  94. case (int)KeyCode.F4:
  95. session.Call(new C2G_BattleNotify()
  96. {
  97. Message = BattleNotify.TiktokGift_1.ToString()
  98. }).Coroutine();
  99. break;
  100. case (int)KeyCode.F5:
  101. session.Call(new C2G_BattleNotify()
  102. {
  103. Message = BattleNotify.TiktokGift_10.ToString()
  104. }).Coroutine();
  105. break;
  106. case (int)KeyCode.F6:
  107. session.Call(new C2G_BattleNotify()
  108. {
  109. Message = BattleNotify.TiktokGift_52.ToString()
  110. }).Coroutine();
  111. break;
  112. case (int)KeyCode.F7:
  113. session.Call(new C2G_BattleNotify()
  114. {
  115. Message = BattleNotify.TiktokGift_99.ToString()
  116. }).Coroutine();
  117. break;
  118. case (int)KeyCode.F8:
  119. session.Call(new C2G_BattleNotify()
  120. {
  121. Message = BattleNotify.TiktokGift_199.ToString()
  122. }).Coroutine();
  123. break;
  124. case (int)KeyCode.F9:
  125. session.Call(new C2G_BattleNotify()
  126. {
  127. Message = BattleNotify.TiktokGift_520.ToString()
  128. }).Coroutine();
  129. break;
  130. case (int)KeyCode.F10:
  131. session.Call(new C2G_BattleNotify()
  132. {
  133. Message = BattleNotify.TiktokLike_energy.ToString()
  134. }).Coroutine();
  135. break;
  136. case (int)KeyCode.F11:
  137. EventSystem.Instance.Publish(ShowVipName.Clone(8));
  138. break;
  139. }
  140. await ETTask.CompletedTask;
  141. //EventSystem.Instance.Publish<ShowOrHideHeadBar>();
  142. //EventSystem.Instance.Publish<SoundMuteEvent>();
  143. }
  144. //获得当前战场(当前塔位置),随机位置
  145. public static int BattleCenterIndex = 0;
  146. private Vector2 vecTemp = new Vector2();
  147. private Vector2 GetRandomPos()
  148. {
  149. Vector2[] TowerPos = { new Vector2(){ X = 103, Y = 197 }, new Vector2() { X = 190, Y = 133 }, new Vector2() { X = 104, Y = 69 } };
  150. var tower = TowerPos[BattleCenterIndex];
  151. var rand = new Random();
  152. float r;
  153. double ang;
  154. if(BattleCenterIndex == 0)
  155. {
  156. r = (float)Math.Sqrt(rand.Next(2500)) + 10;
  157. ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 78f / 180f + Math.PI;
  158. }
  159. else if(BattleCenterIndex == 1)
  160. {
  161. r = (float)Math.Sqrt(rand.Next(3136)) + 10;
  162. ang = rand.Next(20) / 180.0f * Math.PI + Math.PI * 76f / 180f;
  163. }
  164. else
  165. {
  166. r = (float)Math.Sqrt(rand.Next(2500)) + 10;
  167. ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 150f / 180f;
  168. }
  169. vecTemp.X = tower.X + (float)(r * Math.Cos(ang));
  170. vecTemp.Y = tower.Y - (float)(r * Math.Sin(ang));
  171. return vecTemp;
  172. }
  173. }
  174. //测试代码,检测当前战场中心
  175. [Event]
  176. public class CameraPlaybleEventHandler : BEvent<CameraPlaybleEvent>
  177. {
  178. protected override async ETTask OnEvent(CameraPlaybleEvent a)
  179. {
  180. if (a.Playable == "Camera1_2")
  181. {
  182. BattleFuncHandler.BattleCenterIndex = 1;
  183. }
  184. else if (a.Playable == "Camera2_3")
  185. {
  186. BattleFuncHandler.BattleCenterIndex = 2;
  187. }
  188. await ETTask.CompletedTask;
  189. }
  190. }
  191. //发送战斗服指令相关
  192. public partial class BattleMgr
  193. {
  194. private bool autoFight;
  195. public bool AutoFight
  196. {
  197. get
  198. {
  199. return autoFight;
  200. }
  201. set
  202. {
  203. if(value == autoFight) return;
  204. else
  205. {
  206. autoFight = value;
  207. }
  208. }
  209. }
  210. public CommonAI.Zone.Action SetAutoFight(bool flag)
  211. {
  212. return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
  213. }
  214. }
  215. }