BattleMgr_Cmd.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. using CommonAI.Zone;
  2. using CommonLang.Geometry;
  3. using ET.Client;
  4. using ET.EventType;
  5. using ET.Server;
  6. using System;
  7. namespace ET
  8. {
  9. [Event(SceneType.None)]
  10. public class BattleFuncHandler : BEvent<BattleFunc>
  11. {
  12. public override void OnEvent(BattleFunc a)
  13. {
  14. Log.Debug($"Battle Func:{a.FuncIndex}");
  15. var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
  16. switch (a.FuncIndex)
  17. {
  18. case 2:
  19. var units = new int[] { 101, 111, 121, 131 };
  20. var centerpos = GetCurBattleCenter();
  21. var rand = new Random();
  22. foreach (var id in units)
  23. {
  24. float r = (rand.Next(1000)) / 30.0f + 8;
  25. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  26. Log.Debug($"rand unit r({r}), ang({ang})");
  27. float x = centerpos.X + (float)(r * Math.Cos(ang));
  28. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  29. Log.Debug($"born unit: r:{r}, ang:{ang}---({x},{y})");
  30. session.Call(new C2G_AddUnitsToMap()
  31. {
  32. UnitId = id,
  33. Force = 1,
  34. X = (int)x,
  35. Y = (int)y
  36. }).Coroutine();
  37. }
  38. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'宝宝一'进入了游戏,和大家一起守护家园!"));
  39. break;
  40. case 3:
  41. session.Call(new C2G_TriggrBattleFunction()
  42. {
  43. TriggerID = 10111,
  44. Value1 = 0,
  45. Value2 = 0,
  46. Value3 = 0,
  47. Value4 = 0,
  48. Value5 = 0,
  49. Value6 = 0,
  50. }).Coroutine();
  51. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("花园宝宝使用了道具‘电池’,释放出巨大能量"));
  52. break;
  53. case 4:
  54. var units2 = new int[] { 102, 112, 122, 132 };
  55. centerpos = GetCurBattleCenter();
  56. rand = new Random();
  57. foreach (var id in units2)
  58. {
  59. float r = (rand.Next(1000)) / 30.0f + 8;
  60. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  61. Log.Debug($"rand unit r({r}), ang({ang})");
  62. float x = centerpos.X + (float)(r * Math.Cos(ang));
  63. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  64. session.Call(new C2G_AddUnitsToMap()
  65. {
  66. UnitId = id,
  67. Force = 1,
  68. X = (int)x,
  69. Y = (int)y
  70. }).Coroutine();
  71. }
  72. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'宝宝一'使用了'甜甜圈道'成功变形为‘二级宝宝’"));
  73. break;
  74. case 5:
  75. var units3 = new int[] { 103, 113, 123, 133 };
  76. centerpos = GetCurBattleCenter();
  77. rand = new Random();
  78. foreach (var id in units3)
  79. {
  80. float r = (rand.Next(1000)) / 30.0f + 8;
  81. double ang = rand.Next(120) / 180.0f * Math.PI + Math.PI;
  82. Log.Debug($"rand unit r({r}), ang({ang})");
  83. float x = centerpos.X + (float)(r * Math.Cos(ang));
  84. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  85. session.Call(new C2G_AddUnitsToMap()
  86. {
  87. UnitId = id,
  88. Force = 1,
  89. X = (int)x,
  90. Y = (int)y
  91. }).Coroutine();
  92. }
  93. EventSystem.Instance.Publish(BattleMsgEvent.Static.Clone("'宝宝二'使用了'魔棒'道具,成功变形为‘三级宝宝’"));
  94. break;
  95. }
  96. }
  97. //获得当前战场focus中心(当前塔位置)
  98. private Vector2 vecTemp = new Vector2();
  99. private Vector2 GetCurBattleCenter()
  100. {
  101. foreach(var tid in ConstGame.TowerTemplateIDs)
  102. {
  103. var tower = BattleMgr.Instance.GetUnitByTemplateID(tid);
  104. if(tower != null && !tower.IsDead)
  105. {
  106. vecTemp.X = tower.ZUnit.X;
  107. vecTemp.Y = tower.ZUnit.Y;
  108. return vecTemp;
  109. }
  110. }
  111. return new Vector2(0, 0);
  112. }
  113. }
  114. //发送战斗服指令相关
  115. public partial class BattleMgr
  116. {
  117. private bool autoFight;
  118. public bool AutoFight
  119. {
  120. get
  121. {
  122. return autoFight;
  123. }
  124. set
  125. {
  126. if(value == autoFight) return;
  127. else
  128. {
  129. autoFight = value;
  130. }
  131. }
  132. }
  133. public CommonAI.Zone.Action SetAutoFight(bool flag)
  134. {
  135. return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
  136. }
  137. }
  138. }