BattleMgr_Cmd.cs 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. private CommonLang.Geometry.Vector3 vecTmp = new CommonLang.Geometry.Vector3();
  16. private LaunchEffect effectTmp = new()
  17. {
  18. Name = "Icon_tiantianquan",
  19. BindBody = false,
  20. ScaleToBodySize = 8,
  21. EarthQuakeMS = 0,
  22. EffectTimeMS = 9999999
  23. };
  24. protected override async ETTask OnEvent(BattleFunc a)
  25. {
  26. Log.Debug($"Battle Func:{a.FuncIndex}");
  27. var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
  28. switch (a.FuncIndex)
  29. {
  30. case (int)KeyCode.F1:
  31. var units = new int[] { 101, 111, 121, 131 };
  32. var centerpos = GetCurBattleCenter();
  33. var rand = new Random();
  34. foreach (var id in units)
  35. {
  36. float r = (rand.Next(1000)) / 30.0f + 8;
  37. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  38. Log.Debug($"rand unit r({r}), ang({ang})");
  39. float x = centerpos.X + (float)(r * Math.Cos(ang));
  40. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  41. Log.Debug($"born unit: r:{r}, ang:{ang}---({x},{y})");
  42. session.Call(new C2G_AddUnitsToMap()
  43. {
  44. UnitId = id,
  45. Force = 1,
  46. X = (int)x,
  47. Y = (int)y
  48. }).Coroutine();
  49. }
  50. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'<font color=#fe3824>宝宝x</font>'进入了游戏,和大家一起守护家园!"));
  51. break;
  52. case (int)KeyCode.F2:
  53. centerpos = GetCurBattleCenter();
  54. vecTmp.Set(centerpos.X, centerpos.Y, 18);
  55. EventSystem.Instance.Publish(PlayEffectEvent.Static.Clone(effectTmp, 0, vecTmp, 1.57f));
  56. var units2 = new int[] { 102, 112, 122, 132 };
  57. rand = new Random();
  58. foreach (var id in units2)
  59. {
  60. float r = (rand.Next(1000)) / 30.0f + 8;
  61. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  62. Log.Debug($"rand unit r({r}), ang({ang})");
  63. float x = centerpos.X + (float)(r * Math.Cos(ang));
  64. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  65. session.Call(new C2G_AddUnitsToMap()
  66. {
  67. UnitId = id,
  68. Force = 1,
  69. X = (int)x,
  70. Y = (int)y
  71. }).Coroutine();
  72. }
  73. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'<font color=#fe2c55>宝宝x</font>'使用了'<font color=#fe3824>甜甜圈</font>',成功变形为'二级宝宝'"));
  74. break;
  75. case (int)KeyCode.F3:
  76. centerpos = GetCurBattleCenter();
  77. vecTmp.Set(centerpos.X, centerpos.Y, 18);
  78. EventSystem.Instance.Publish(PlayEffectEvent.Static.Clone(effectTmp, 0, vecTmp, 1.57f));
  79. var units3 = new int[] { 103, 113, 123, 133 };
  80. rand = new Random();
  81. foreach (var id in units3)
  82. {
  83. float r = (rand.Next(1000)) / 30.0f + 8;
  84. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  85. Log.Debug($"rand unit r({r}), ang({ang})");
  86. float x = centerpos.X + (float)(r * Math.Cos(ang));
  87. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  88. session.Call(new C2G_AddUnitsToMap()
  89. {
  90. UnitId = id,
  91. Force = 1,
  92. X = (int)x,
  93. Y = (int)y
  94. }).Coroutine();
  95. }
  96. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'<font color=#fe2c55>宝宝x</font>'使用了'<font color=#fe3824>甜甜圈</font>',成功变形为'三级宝宝'"));
  97. break;
  98. case (int)KeyCode.F4:
  99. session.Call(new C2G_TriggrBattleFunction()
  100. {
  101. TriggerID = 10111,
  102. Value1 = 0,
  103. Value2 = 0,
  104. Value3 = 0,
  105. Value4 = 0,
  106. Value5 = 0,
  107. Value6 = 0,
  108. }).Coroutine();
  109. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'<font color=#fe2c55>宝宝x</font>'使用了'<font color=#fe3824>能量电池</font>',全员满血,并增加攻击"));
  110. break;
  111. case (int)KeyCode.F5:
  112. session.Call(new C2G_TriggrBattleFunction()
  113. {
  114. TriggerID = 10111,
  115. Value1 = 0,
  116. Value2 = 0,
  117. Value3 = 0,
  118. Value4 = 0,
  119. Value5 = 0,
  120. Value6 = 0,
  121. }).Coroutine();
  122. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'<font color=#fe2c55>宝宝x</font>'使用了'<font color=#fe3824>恶魔炸弹</font>',召唤出地狱火岩"));
  123. break;
  124. case (int)KeyCode.F6:
  125. case (int)KeyCode.F7:
  126. case (int)KeyCode.F8:
  127. case (int)KeyCode.F9:
  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. }