BattleMgr_Cmd.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  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() { Message = BattleNotify.ClientIsReady.ToString() }).Coroutine();
  23. session.Call(new C2G_BattleNotify()
  24. {
  25. Message = BattleNotify.StartRefreshMonster.ToString()
  26. }).Coroutine();
  27. break;
  28. case (int)KeyCode.F1:
  29. var units = new int[] { 101, 111, 121, 131 };
  30. var centerpos = GetCurBattleCenter();
  31. var rand = new Random();
  32. foreach (var id in units)
  33. {
  34. float r = rand.Next(1000) / 30.0f + 8;
  35. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  36. //Log.Debug($"rand unit r({r}), ang({ang})");
  37. float x = centerpos.X + (float)(r * Math.Cos(ang));
  38. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  39. //Log.Debug($"born unit: r:{r}, ang:{ang}---({x},{y})");
  40. session.Call(new C2G_AddUnitsToMap()
  41. {
  42. UnitId = id,
  43. Force = 1,
  44. X = (int)x,
  45. Y = (int)y
  46. }).Coroutine();
  47. }
  48. //EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'<font color=#fe3824>宝宝x</font>'进入了游戏,和大家一起守护家园!"));
  49. break;
  50. case (int)KeyCode.F2:
  51. centerpos = GetCurBattleCenter();
  52. var units2 = new int[] { 102, 112, 122, 132 };
  53. rand = new Random();
  54. for (int i = 0; i < 2; i++)
  55. {
  56. var id = units2[rand.Next(units2.Length)];
  57. float r = rand.Next(1000) / 30.0f + 8;
  58. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  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. //EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'<font color=#fe2c55>宝宝x</font>'使用了'<font color=#fe3824>甜甜圈</font>',成功变形为'二级宝宝'"));
  70. break;
  71. case (int)KeyCode.F3:
  72. centerpos = GetCurBattleCenter();
  73. var units3 = new int[] { 103, 113, 123, 133 };
  74. rand = new Random();
  75. for (int i = 0; i < 1; i++)
  76. {
  77. var id = units3[rand.Next(units3.Length)];
  78. float r = rand.Next(1000) / 30.0f + 8;
  79. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  80. float x = centerpos.X + (float)(r * Math.Cos(ang));
  81. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  82. session.Call(new C2G_AddUnitsToMap()
  83. {
  84. UnitId = id,
  85. Force = 1,
  86. X = (int)x,
  87. Y = (int)y
  88. }).Coroutine();
  89. }
  90. //EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'<font color=#fe2c55>宝宝x</font>'使用了'<font color=#fe3824>甜甜圈</font>',成功变形为'三级宝宝'"));
  91. break;
  92. case (int)KeyCode.F4:
  93. session.Call(new C2G_BattleNotify()
  94. {
  95. Message = BattleNotify.TiktokGift_1.ToString()
  96. }).Coroutine();
  97. break;
  98. case (int)KeyCode.F5:
  99. session.Call(new C2G_BattleNotify()
  100. {
  101. Message = BattleNotify.TiktokGift_10.ToString()
  102. }).Coroutine();
  103. break;
  104. case (int)KeyCode.F6:
  105. session.Call(new C2G_BattleNotify()
  106. {
  107. Message = BattleNotify.TiktokGift_52.ToString()
  108. }).Coroutine();
  109. break;
  110. case (int)KeyCode.F7:
  111. session.Call(new C2G_BattleNotify()
  112. {
  113. Message = BattleNotify.TiktokGift_99.ToString()
  114. }).Coroutine();
  115. break;
  116. case (int)KeyCode.F8:
  117. session.Call(new C2G_BattleNotify()
  118. {
  119. Message = BattleNotify.TiktokGift_199.ToString()
  120. }).Coroutine();
  121. break;
  122. case (int)KeyCode.F9:
  123. session.Call(new C2G_BattleNotify()
  124. {
  125. Message = BattleNotify.TiktokGift_520.ToString()
  126. }).Coroutine();
  127. break;
  128. case (int)KeyCode.F10:
  129. break;
  130. }
  131. await ETTask.CompletedTask;
  132. }
  133. //获得当前战场focus中心(当前塔位置)
  134. private Vector2 vecTemp = new Vector2();
  135. private Vector2 GetCurBattleCenter()
  136. {
  137. foreach(var tid in ConstGame.TowerTemplateIDs)
  138. {
  139. var tower = BattleMgr.Instance.GetUnitByTemplateID(tid);
  140. if(tower != null && !tower.IsDead)
  141. {
  142. vecTemp.X = tower.ZUnit.X;
  143. vecTemp.Y = tower.ZUnit.Y;
  144. return vecTemp;
  145. }
  146. }
  147. return new Vector2(0, 0);
  148. }
  149. }
  150. //发送战斗服指令相关
  151. public partial class BattleMgr
  152. {
  153. private bool autoFight;
  154. public bool AutoFight
  155. {
  156. get
  157. {
  158. return autoFight;
  159. }
  160. set
  161. {
  162. if(value == autoFight) return;
  163. else
  164. {
  165. autoFight = value;
  166. }
  167. }
  168. }
  169. public CommonAI.Zone.Action SetAutoFight(bool flag)
  170. {
  171. return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
  172. }
  173. }
  174. }