using CommonAI.Zone; using CommonLang.Geometry; using ET.Client; using ET.EventType; using ET.Server; using System; using UnityEngine; using Random = System.Random; using Vector2 = CommonLang.Geometry.Vector2; namespace ET { [Event] public class BattleFuncHandler : BEvent { protected override async ETTask OnEvent(BattleFunc a) { Log.Debug($"Battle Func:{a.FuncIndex}"); var session = PlayerComponent.Instance.ClientScene().GetComponent().Session; switch (a.FuncIndex) { case (int)BattleFunc.FUNC.ClientIsReady: session.Call(new C2G_BattleNotify() { Message = BattleNotify.ClientIsReady.ToString() }).Coroutine(); break; case (int)BattleFunc.FUNC.Start: session.Call(new C2G_BattleNotify() { Message = BattleNotify.StartRefreshMonster.ToString() }).Coroutine(); break; case (int)BattleFunc.FUNC.Start2: session.Call(new C2G_BattleNotify() { Message = BattleNotify.StartRefreshMonster2.ToString() }).Coroutine(); break; case (int)BattleFunc.FUNC.Start3: session.Call(new C2G_BattleNotify() { Message = BattleNotify.StartRefreshMonster3.ToString() }).Coroutine(); break; case (int)KeyCode.F1: var units = new int[] { 101, 111, 121, 131 }; var centerpos = GetCurBattleCenter(); var rand = new Random(); foreach (var id in units) { float r = (float)Math.Sqrt(rand.Next(2500)) + 10; double ang = rand.Next(22) / 180.0f * Math.PI + Math.PI*150f/180f; float x = centerpos.X + (float)(r * Math.Cos(ang)); float y = centerpos.Y - (float)(r * Math.Sin(ang)); session.Call(new C2G_AddUnitsToMap() { UnitId = id, Force = 1, X = (int)x, Y = (int)y }).Coroutine(); } break; case (int)KeyCode.F2: centerpos = GetCurBattleCenter(); var units2 = new int[] { 102, 112, 122, 132 }; rand = new Random(); for (int i = 0; i < 2; i++) { var id = units2[rand.Next(units2.Length)]; float r = (float)Math.Sqrt(rand.Next(3136)) + 10; double ang = rand.Next(20) / 180.0f * Math.PI + Math.PI * 76f / 180f; float x = centerpos.X + (float)(r * Math.Cos(ang)); float y = centerpos.Y - (float)(r * Math.Sin(ang)); session.Call(new C2G_AddUnitsToMap() { UnitId = id, Force = 1, X = (int)x, Y = (int)y }).Coroutine(); } break; case (int)KeyCode.F3: centerpos = GetCurBattleCenter(); var units3 = new int[] { 103, 113, 123, 133 }; rand = new Random(); for (int i = 0; i < 1; i++) { var id = units3[rand.Next(units3.Length)]; float r = (float)Math.Sqrt(rand.Next(2500)) + 10; double ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 78f / 180f + Math.PI; float x = centerpos.X + (float)(r * Math.Cos(ang)); float y = centerpos.Y - (float)(r * Math.Sin(ang)); session.Call(new C2G_AddUnitsToMap() { UnitId = id, Force = 1, X = (int)x, Y = (int)y }).Coroutine(); } break; case (int)KeyCode.F4: session.Call(new C2G_BattleNotify() { Message = BattleNotify.TiktokGift_1.ToString() }).Coroutine(); break; case (int)KeyCode.F5: session.Call(new C2G_BattleNotify() { Message = BattleNotify.TiktokGift_10.ToString() }).Coroutine(); break; case (int)KeyCode.F6: session.Call(new C2G_BattleNotify() { Message = BattleNotify.TiktokGift_52.ToString() }).Coroutine(); break; case (int)KeyCode.F7: session.Call(new C2G_BattleNotify() { Message = BattleNotify.TiktokGift_99.ToString() }).Coroutine(); break; case (int)KeyCode.F8: session.Call(new C2G_BattleNotify() { Message = BattleNotify.TiktokGift_199.ToString() }).Coroutine(); break; case (int)KeyCode.F9: session.Call(new C2G_BattleNotify() { Message = BattleNotify.TiktokGift_520.ToString() }).Coroutine(); break; case (int)KeyCode.F10: session.Call(new C2G_BattleNotify() { Message = BattleNotify.TiktokLike_energy.ToString() }).Coroutine(); break; case (int)KeyCode.F11: EventSystem.Instance.Publish(ShowVipName.Clone(8)); break; case (int)KeyCode.F12: EventSystem.Instance.Publish(TiktokGiftEvent.Clone(1, 13, "额滴个马", "")); break; } await ETTask.CompletedTask; //EventSystem.Instance.Publish(); //EventSystem.Instance.Publish(); } //获得当前战场focus中心(当前塔位置) private Vector2 vecTemp = new Vector2(); private Vector2 GetCurBattleCenter() { foreach(var tid in ConstGame.TowerTemplateIDs) { var tower = BattleMgr.Instance.GetUnitByTemplateID(tid); if(tower != null && !tower.IsDead) { vecTemp.X = tower.ZUnit.X; vecTemp.Y = tower.ZUnit.Y; return vecTemp; } } return new Vector2(0, 0); } } //发送战斗服指令相关 public partial class BattleMgr { private bool autoFight; public bool AutoFight { get { return autoFight; } set { if(value == autoFight) return; else { autoFight = value; } } } public CommonAI.Zone.Action SetAutoFight(bool flag) { return new UnitGuardAction(UnitMgr.Instance.ActorId, flag, CommonAI.XmdsConstConfig.AUTO_GUARD_MODE_POINT); } } }