BattleMgr_Cmd.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209
  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 centerpos = GetCurBattleCenter();
  48. var rand = new Random();
  49. foreach (var id in units)
  50. {
  51. float r = (float)Math.Sqrt(rand.Next(2500)) + 10;
  52. double ang = rand.Next(22) / 180.0f * Math.PI + Math.PI*150f/180f;
  53. float x = centerpos.X + (float)(r * Math.Cos(ang));
  54. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  55. session.Call(new C2G_AddUnitsToMap()
  56. {
  57. UnitId = id,
  58. Force = 1,
  59. X = (int)x,
  60. Y = (int)y
  61. }).Coroutine();
  62. }
  63. break;
  64. case (int)KeyCode.F2:
  65. centerpos = GetCurBattleCenter();
  66. var units2 = new int[] { 102, 112, 122, 132 };
  67. rand = new Random();
  68. for (int i = 0; i < 2; i++)
  69. {
  70. var id = units2[rand.Next(units2.Length)];
  71. float r = (float)Math.Sqrt(rand.Next(3136)) + 10;
  72. double ang = rand.Next(20) / 180.0f * Math.PI + Math.PI * 76f / 180f;
  73. float x = centerpos.X + (float)(r * Math.Cos(ang));
  74. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  75. session.Call(new C2G_AddUnitsToMap()
  76. {
  77. UnitId = id,
  78. Force = 1,
  79. X = (int)x,
  80. Y = (int)y
  81. }).Coroutine();
  82. }
  83. break;
  84. case (int)KeyCode.F3:
  85. centerpos = GetCurBattleCenter();
  86. var units3 = new int[] { 103, 113, 123, 133 };
  87. rand = new Random();
  88. for (int i = 0; i < 1; i++)
  89. {
  90. var id = units3[rand.Next(units3.Length)];
  91. float r = (float)Math.Sqrt(rand.Next(2500)) + 10;
  92. double ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 78f / 180f + Math.PI;
  93. float x = centerpos.X + (float)(r * Math.Cos(ang));
  94. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  95. session.Call(new C2G_AddUnitsToMap()
  96. {
  97. UnitId = id,
  98. Force = 1,
  99. X = (int)x,
  100. Y = (int)y
  101. }).Coroutine();
  102. }
  103. break;
  104. case (int)KeyCode.F4:
  105. session.Call(new C2G_BattleNotify()
  106. {
  107. Message = BattleNotify.TiktokGift_1.ToString()
  108. }).Coroutine();
  109. break;
  110. case (int)KeyCode.F5:
  111. session.Call(new C2G_BattleNotify()
  112. {
  113. Message = BattleNotify.TiktokGift_10.ToString()
  114. }).Coroutine();
  115. break;
  116. case (int)KeyCode.F6:
  117. session.Call(new C2G_BattleNotify()
  118. {
  119. Message = BattleNotify.TiktokGift_52.ToString()
  120. }).Coroutine();
  121. break;
  122. case (int)KeyCode.F7:
  123. session.Call(new C2G_BattleNotify()
  124. {
  125. Message = BattleNotify.TiktokGift_99.ToString()
  126. }).Coroutine();
  127. break;
  128. case (int)KeyCode.F8:
  129. session.Call(new C2G_BattleNotify()
  130. {
  131. Message = BattleNotify.TiktokGift_199.ToString()
  132. }).Coroutine();
  133. break;
  134. case (int)KeyCode.F9:
  135. session.Call(new C2G_BattleNotify()
  136. {
  137. Message = BattleNotify.TiktokGift_520.ToString()
  138. }).Coroutine();
  139. break;
  140. case (int)KeyCode.F10:
  141. session.Call(new C2G_BattleNotify()
  142. {
  143. Message = BattleNotify.TiktokLike_energy.ToString()
  144. }).Coroutine();
  145. break;
  146. case (int)KeyCode.F11:
  147. EventSystem.Instance.Publish(ShowVipName.Clone(8));
  148. break;
  149. case (int)KeyCode.F12:
  150. EventSystem.Instance.Publish(TiktokGiftEvent.Clone(1, 13, "额滴个马", ""));
  151. break;
  152. }
  153. await ETTask.CompletedTask;
  154. //EventSystem.Instance.Publish<ShowOrHideHeadBar>();
  155. //EventSystem.Instance.Publish<SoundMuteEvent>();
  156. }
  157. //获得当前战场focus中心(当前塔位置)
  158. private Vector2 vecTemp = new Vector2();
  159. private Vector2 GetCurBattleCenter()
  160. {
  161. foreach(var tid in ConstGame.TowerTemplateIDs)
  162. {
  163. var tower = BattleMgr.Instance.GetUnitByTemplateID(tid);
  164. if(tower != null && !tower.IsDead)
  165. {
  166. vecTemp.X = tower.ZUnit.X;
  167. vecTemp.Y = tower.ZUnit.Y;
  168. return vecTemp;
  169. }
  170. }
  171. return new Vector2(0, 0);
  172. }
  173. }
  174. //发送战斗服指令相关
  175. public partial class BattleMgr
  176. {
  177. private bool autoFight;
  178. public bool AutoFight
  179. {
  180. get
  181. {
  182. return autoFight;
  183. }
  184. set
  185. {
  186. if(value == autoFight) return;
  187. else
  188. {
  189. autoFight = value;
  190. }
  191. }
  192. }
  193. public CommonAI.Zone.Action SetAutoFight(bool flag)
  194. {
  195. return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
  196. }
  197. }
  198. }