BattleMgr_Cmd.cs 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. asyncHandler(a.FuncIndex);
  16. }
  17. //获得当前战场focus中心(当前塔位置)
  18. private Vector2 vecTemp = new Vector2();
  19. private Vector2 GetCurBattleCenter()
  20. {
  21. foreach(var tid in ConstGame.TowerTemplateIDs)
  22. {
  23. var tower = BattleMgr.Instance.GetUnitByTemplateID(tid);
  24. if(tower != null && !tower.IsDead)
  25. {
  26. vecTemp.X = tower.ZUnit.X;
  27. vecTemp.Y = tower.ZUnit.Y;
  28. return vecTemp;
  29. }
  30. }
  31. return new Vector2(0, 0);
  32. }
  33. private void asyncHandler(BattleFunc.Index index)
  34. {
  35. var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session;
  36. switch (index)
  37. {
  38. case BattleFunc.Index.Func2:
  39. var units = new int[] {105, 108, 111, 117};
  40. var centerpos = GetCurBattleCenter();
  41. var rand = new Random();
  42. foreach (var id in units)
  43. {
  44. float r = (rand.Next(1000)) / 100.0f + 5;
  45. double ang = rand.Next(180) / 180.0f * Math.PI + Math.PI;
  46. Log.Debug($"rand unit r({r}), ang({ang})");
  47. float x = centerpos.X + (float)(r * Math.Cos(ang));
  48. float y = centerpos.Y - (float)(r * Math.Sin(ang));
  49. session.Call(new C2G_AddUnitsToMap()
  50. {
  51. UnitId = id,
  52. Force = 1,
  53. X = (int)x,
  54. Y = (int)y
  55. }).Coroutine();
  56. }
  57. break;
  58. default:
  59. break;
  60. }
  61. }
  62. }
  63. //发送战斗服指令相关
  64. public partial class BattleMgr
  65. {
  66. private bool autoFight;
  67. public bool AutoFight
  68. {
  69. get
  70. {
  71. return autoFight;
  72. }
  73. set
  74. {
  75. if(value == autoFight) return;
  76. else
  77. {
  78. autoFight = value;
  79. }
  80. }
  81. }
  82. public CommonAI.Zone.Action SetAutoFight(bool flag)
  83. {
  84. return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT);
  85. }
  86. }
  87. }