123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214 |
- using CommonAI.Zone;
- using CommonLang.Geometry;
- using ET.Client;
- using ET.EventType;
- using ET.Server;
- using System;
- using System.Collections.Generic;
- using UnityEngine;
- using Random = System.Random;
- using Vector2 = CommonLang.Geometry.Vector2;
- namespace ET
- {
- [Event]
- public class BattleFuncHandler : BEvent<BattleFunc>
- {
- protected override async ETTask OnEvent(BattleFunc a)
- {
- if(PlayerComponent.Instance == null || PlayerComponent.Instance.ClientScene() == null || PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>() == null)
- {
- return;
- }
- Log.Debug($"Battle Func:{a.FuncIndex}");
- var session = PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().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 rand = new Random();
- foreach (var id in units)
- {
- var pos = GetRandomPos();
- session.Call(new C2G_AddUnitsToMap()
- {
- UnitId = id,
- Force = 1,
- X = (int)pos.X,
- Y = (int)pos.Y
- }).Coroutine();
- }
- break;
- /*case (int)KeyCode.F2:
- var units2 = new int[] { 102, 112, 122, 132 };
- rand = new Random();
- for (int i = 0; i < 2; i++)
- {
- var pos = GetRandomPos();
- session.Call(new C2G_AddUnitsToMap()
- {
- UnitId = units2[rand.Next(units2.Length)],
- Force = 1,
- X = (int)pos.X,
- Y = (int)pos.Y
- }).Coroutine();
- }
- break;
- case (int)KeyCode.F3:
- var units3 = new int[] { 103, 113, 123, 133 };
- rand = new Random();
- for (int i = 0; i < 1; i++)
- {
- var pos = GetRandomPos();
- session.Call(new C2G_AddUnitsToMap()
- {
- UnitId = units3[rand.Next(units3.Length)],
- Force = 1,
- X = (int)pos.X,
- Y = (int)pos.Y
- }).Coroutine();
- }
- break;*/
- case (int)KeyCode.F2:
- session.Call(new C2G_BattleNotify() { Message = "test:1" }).Coroutine();
- break;
- case (int)KeyCode.F3:
- session.Call(new C2G_BattleNotify() { Message = "test:2" }).Coroutine();
- break;
- case (int)KeyCode.F4:
- session.Call(new C2G_BattleNotify() { Message = "test:3" }).Coroutine();
- break;
- case (int)KeyCode.F5:
- session.Call(new C2G_BattleNotify() { Message = "test:4" }).Coroutine();
- break;
- case (int)KeyCode.F6:
- session.Call(new C2G_BattleNotify() { Message = "test:5" }).Coroutine();
- break;
- case (int)KeyCode.F7:
- session.Call(new C2G_BattleNotify() { Message = "test:6" }).Coroutine();
- break;
- case (int)KeyCode.F8:
- session.Call(new C2G_BattleNotify() { Message = "test:7" }).Coroutine();
- break;
-
- }
- await ETTask.CompletedTask;
- //EventSystem.Instance.Publish<ShowOrHideHeadBar>();
- //EventSystem.Instance.Publish<SoundMuteEvent>();
- }
- //获得当前战场(当前塔位置),随机位置
- public static int BattleCenterIndex = 0;
- private Vector2 vecTemp = new Vector2();
- private Vector2 GetRandomPos()
- {
- Vector2[] TowerPos = { new Vector2(){ X = 103, Y = 197 }, new Vector2() { X = 190, Y = 133 }, new Vector2() { X = 104, Y = 69 } };
- var tower = TowerPos[BattleCenterIndex];
- var rand = new Random();
- float r;
- double ang;
- if(BattleCenterIndex == 0)
- {
- r = (float)Math.Sqrt(rand.Next(3025)) + 10;
- ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 77f / 180f + Math.PI;
- }
- else if(BattleCenterIndex == 1)
- {
- r = (float)Math.Sqrt(rand.Next(3136)) + 10;
- ang = rand.Next(20) / 180.0f * Math.PI + Math.PI * 76f / 180f;
- }
- else
- {
- r = (float)Math.Sqrt(rand.Next(2809)) + 10;
- ang = rand.Next(22) / 180.0f * Math.PI + Math.PI * 148f / 180f;
- }
- vecTemp.X = tower.X + (float)(r * Math.Cos(ang));
- vecTemp.Y = tower.Y - (float)(r * Math.Sin(ang));
- return vecTemp;
- }
- }
- //测试代码,检测当前战场中心
- [Event]
- public class Test1EventHandler : BEvent<CameraPlaybleEvent>
- {
- protected override async ETTask OnEvent(CameraPlaybleEvent a)
- {
- if (a.Playable == "Camera1_2")
- {
- BattleFuncHandler.BattleCenterIndex = 1;
- }
- else if (a.Playable == "Camera2_3")
- {
- BattleFuncHandler.BattleCenterIndex = 2;
- }
- await ETTask.CompletedTask;
- }
- }
- [Event]
- public class Test2EventHandler : BEvent<EventType.GameoverEvent>
- {
- protected override async ETTask OnEvent(EventType.GameoverEvent args)
- {
- BattleFuncHandler.BattleCenterIndex = 0;
- await ETTask.CompletedTask;
- }
- }
- //发送战斗服指令相关
- 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);
- }
- }
- }
|