BattleMgr_Cmd.cs 8.0 KB

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