BattleMgr_Cmd.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  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 System.Collections.Generic;
  8. using UnityEngine;
  9. using Random = System.Random;
  10. using Vector2 = CommonLang.Geometry.Vector2;
  11. namespace ET
  12. {
  13. [Event]
  14. public class BattleFuncHandler : BEvent<BattleFunc>
  15. {
  16. protected override async ETTask OnEvent(BattleFunc a)
  17. {
  18. if(PlayerComponent.Instance == null || PlayerComponent.Instance.ClientScene() == null || PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>() == null)
  19. {
  20. return;
  21. }
  22. Log.Debug($"Battle Func:{a.FuncIndex}");
  23. var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
  24. switch (a.FuncIndex)
  25. {
  26. case (int)BattleFunc.FUNC.ClientIsReady:
  27. session.Call(new C2G_BattleNotify()
  28. {
  29. Message = BattleNotify.ClientIsReady.ToString()
  30. }).Coroutine();
  31. break;
  32. case (int)BattleFunc.FUNC.Start:
  33. session.Call(new C2G_BattleNotify()
  34. {
  35. Message = BattleNotify.StartRefreshMonster.ToString()
  36. }).Coroutine();
  37. break;
  38. case (int)BattleFunc.FUNC.Start2:
  39. session.Call(new C2G_BattleNotify()
  40. {
  41. Message = BattleNotify.StartRefreshMonster2.ToString()
  42. }).Coroutine();
  43. break;
  44. case (int)BattleFunc.FUNC.Start3:
  45. session.Call(new C2G_BattleNotify()
  46. {
  47. Message = BattleNotify.StartRefreshMonster3.ToString()
  48. }).Coroutine();
  49. break;
  50. case (int)KeyCode.F1:
  51. session.Call(new C2G_BattleNotify() { Message = "test:8" }).Coroutine();
  52. break;
  53. case (int)KeyCode.F2:
  54. session.Call(new C2G_BattleNotify() { Message = "test:1" }).Coroutine();
  55. break;
  56. case (int)KeyCode.F3:
  57. session.Call(new C2G_BattleNotify() { Message = "test:2" }).Coroutine();
  58. break;
  59. case (int)KeyCode.F4:
  60. session.Call(new C2G_BattleNotify() { Message = "test:3" }).Coroutine();
  61. break;
  62. case (int)KeyCode.F5:
  63. session.Call(new C2G_BattleNotify() { Message = "test:4" }).Coroutine();
  64. break;
  65. case (int)KeyCode.F6:
  66. session.Call(new C2G_BattleNotify() { Message = "test:5" }).Coroutine();
  67. break;
  68. case (int)KeyCode.F7:
  69. session.Call(new C2G_BattleNotify() { Message = "test:6" }).Coroutine();
  70. break;
  71. case (int)KeyCode.F8:
  72. session.Call(new C2G_BattleNotify() { Message = "test:7" }).Coroutine();
  73. break;
  74. }
  75. await ETTask.CompletedTask;
  76. //EventSystem.Instance.Publish<ShowOrHideHeadBar>();
  77. //EventSystem.Instance.Publish<SoundMuteEvent>();
  78. }
  79. //获得当前战场(当前塔位置),随机位置
  80. public static int BattleCenterIndex = 0;
  81. private Vector2 vecTemp = new Vector2();
  82. private Vector2 GetRandomPos()
  83. {
  84. Vector2[] TowerPos = { new Vector2(){ X = 103, Y = 197 }, new Vector2() { X = 190, Y = 133 }, new Vector2() { X = 104, Y = 69 } };
  85. var tower = TowerPos[BattleCenterIndex];
  86. var rand = new Random();
  87. float r;
  88. double ang;
  89. if(BattleCenterIndex == 0)
  90. {
  91. r = (float)Math.Sqrt(rand.Next(3025)) + 10;
  92. ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 77f / 180f + Math.PI;
  93. }
  94. else if(BattleCenterIndex == 1)
  95. {
  96. r = (float)Math.Sqrt(rand.Next(3136)) + 10;
  97. ang = rand.Next(20) / 180.0f * Math.PI + Math.PI * 76f / 180f;
  98. }
  99. else
  100. {
  101. r = (float)Math.Sqrt(rand.Next(2809)) + 10;
  102. ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 148f / 180f;
  103. }
  104. vecTemp.X = tower.X + (float)(r * Math.Cos(ang));
  105. vecTemp.Y = tower.Y - (float)(r * Math.Sin(ang));
  106. return vecTemp;
  107. }
  108. }
  109. //测试代码,检测当前战场中心
  110. [Event]
  111. public class Test1EventHandler : BEvent<CameraPlaybleEvent>
  112. {
  113. protected override async ETTask OnEvent(CameraPlaybleEvent a)
  114. {
  115. if (a.Playable == "Camera1_2")
  116. {
  117. BattleFuncHandler.BattleCenterIndex = 1;
  118. }
  119. else if (a.Playable == "Camera2_3")
  120. {
  121. BattleFuncHandler.BattleCenterIndex = 2;
  122. }
  123. await ETTask.CompletedTask;
  124. }
  125. }
  126. [Event]
  127. public class Test2EventHandler : BEvent<EventType.GameoverEvent>
  128. {
  129. protected override async ETTask OnEvent(EventType.GameoverEvent args)
  130. {
  131. BattleFuncHandler.BattleCenterIndex = 0;
  132. await ETTask.CompletedTask;
  133. }
  134. }
  135. //发送战斗服指令相关
  136. public partial class BattleMgr
  137. {
  138. private bool autoFight;
  139. public bool AutoFight
  140. {
  141. get
  142. {
  143. return autoFight;
  144. }
  145. set
  146. {
  147. if(value == autoFight) return;
  148. else
  149. {
  150. autoFight = value;
  151. }
  152. }
  153. }
  154. public CommonAI.Zone.Action SetAutoFight(bool flag)
  155. {
  156. return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
  157. }
  158. }
  159. }