BattleMgr.cs 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639
  1. using CommonAI.Zone;
  2. using CommonAI.ZoneClient;
  3. using CommonLang;
  4. using CommonLang.Geometry;
  5. using ET.Client;
  6. using ET.EventType;
  7. using ET.Server;
  8. using Sirenix.Utilities;
  9. using System;
  10. using System.IO;
  11. using System.Linq;
  12. using System.Text.RegularExpressions;
  13. using XmdsCommon.Message;
  14. namespace ET
  15. {
  16. [FriendOf(typeof(UnitMgr))]
  17. public partial class BattleMgr : Singleton<BattleMgr>, ISingletonAwake, ISingletonUpdate, ILayerClient
  18. {
  19. public ZoneLayer Layer;
  20. private readonly MemoryStream writeBuffer = new MemoryStream(2048);
  21. private EventDispatcher<Event> eventHandler;
  22. private static CommonLang.Geometry.Vector3 vecTemp = new();
  23. private HashMap<int, BattleUnit> UnitTemplateIdHash = new();
  24. public void Awake()
  25. {
  26. eventHandler = new();
  27. registerEventHandler();
  28. Layer = TemplateManager.Factory.CreateClientZoneLayer(BattleResourceMgr.Instance.GameEditorTemplates, this);
  29. Layer.ActorSyncMode = SyncMode.ForceByServer;
  30. Layer.LayerInit += LayerEvent_Init;
  31. Layer.ObjectEnter += LayerEvent_ObjectEnter;
  32. Layer.ObjectLeave += LayerEvent_ObjectLeave;
  33. Layer.MessageReceived += (ZoneLayer _, CommonLang.Protocol.IMessage msg) => {
  34. if (msg is SyncPosEvent || msg is UnitForceSyncPosEvent || msg is LaunchSkill || msg is AddSpellEvent || msg is RemoveObjectEvent || msg is AddUnitEvent || msg is PlayerFocuseTargetEvent || msg is UnitFieldChangedEvent || msg is UnitEffectEvent || msg is UnitLaunchSkillEvent || msg is PlayerSkillStopEvent || msg is UnitHitEvent || msg is UnitLaunchBuffEvent)
  35. { }
  36. else
  37. {
  38. Log.Debug($"<<<BattleEvent: {msg}");
  39. }
  40. eventHandler.Notify(msg as Event);
  41. };
  42. Layer.DecorationChanged += (ZoneLayer _, ZoneEditorDecoration ed) => {
  43. Log.Error("not implements: DecorationChanged");
  44. };
  45. }
  46. public void Update(int timeMS)
  47. {
  48. //TODO: Send ping
  49. Layer.BeginUpdate(timeMS);
  50. Layer.Update();
  51. this.doUpdate();
  52. }
  53. //ILayerClient接口实现,供layer层调用
  54. //layer层在收到LockActorEvent消息后调用
  55. void ILayerClient.BattleReady(bool bok)
  56. {
  57. Log.Debug($"battle ready......{bok}");
  58. //TODO: 等GameObjectPool.cache完场景资源后,再play bgm
  59. var scnData = Layer.Data;
  60. if(!scnData.BGM.IsNullOrWhitespace() )
  61. {
  62. EventSystem.Instance.Publish<PlayBgm>(PlayBgm.Static.Clone(true, scnData.BGM));
  63. }
  64. }
  65. //ILayerClient接口实现,供layer层调用
  66. //layer层中需要发送消息到战斗服
  67. public void SendAction(CommonAI.Zone.Action action)
  68. {
  69. if(PlayerComponent.Instance == null)
  70. {
  71. Log.Error("playerComponent is null");
  72. return;
  73. }
  74. Log.Debug($">>>Send BattleMsg: {action.GetType()}");
  75. writeBuffer.Position = 0;
  76. if (BattleResourceMgr.Instance.BattleMsgDecoder.doEncode(writeBuffer, action))
  77. {
  78. PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session.Send(new BattleEventPushToServer() { data = writeBuffer.ToArray() });
  79. }
  80. }
  81. //客户端自己模拟创建消息,发送到zonelayer层处理
  82. public void PostMsg2Layer(CommonLang.Protocol.IMessage msg)
  83. {
  84. Layer.ProcessMessage(msg);
  85. }
  86. //layer层在处理好战斗服推送的ClientEnterScene消息后回调
  87. protected void LayerEvent_Init(CommonAI.ZoneClient.ZoneLayer layer)
  88. {
  89. Log.Debug($"OnLayerInit- scene template ID:{layer.Data.ID}");
  90. }
  91. //单位进入战斗
  92. protected void LayerEvent_ObjectEnter(ZoneLayer layer, ZoneObject obj)
  93. {
  94. var unit = BattleUnitFactory.Instance.Create(obj);
  95. if(unit != null )
  96. {
  97. UnitMgr.Instance.PutUnit(obj.ObjectID, unit);
  98. if (unit is BattleActor)
  99. {
  100. UnitMgr.Instance.Actor = unit as BattleActor;
  101. }
  102. unit.OnAwake(obj);
  103. if (unit is BattleUnit bu)
  104. {
  105. var tid = (obj as ZoneUnit).TemplateID;
  106. if (ConstGame.TowerTemplateIDs.Contains(tid))
  107. {
  108. if (UnitTemplateIdHash.ContainsKey((tid)))
  109. {
  110. Log.Error($"Already exist unit({tid}) @{obj.ObjectID}");
  111. return;
  112. }
  113. UnitTemplateIdHash.Add(tid, bu);
  114. }
  115. Log.Debug($"OnObjectEnter: {bu.ZUnit.TemplateID}@{obj.ObjectID}");
  116. }
  117. }
  118. }
  119. //单位离开战斗
  120. protected void LayerEvent_ObjectLeave(ZoneLayer layer, ZoneObject obj)
  121. {
  122. //Log.Debug($"OnObjectLeave: {obj.ObjectID}");
  123. var unit = UnitMgr.Instance.GetUnit(obj.ObjectID);
  124. if(unit == null)
  125. {
  126. Log.Error($"LayerEvent_ObjectLeave not exist:{obj.Name}:{obj.ObjectID}");
  127. return;
  128. }
  129. unit.OnSleep();
  130. UnitMgr.Instance.RemoveUnit(obj.ObjectID);
  131. if (unit is BattleUnit bu)
  132. {
  133. UnitTemplateIdHash.Remove(bu.ZUnit.TemplateID);
  134. }
  135. }
  136. public BattleUnit GetUnitByTemplateID(int tid)
  137. {
  138. return UnitTemplateIdHash.ContainsKey(tid) ? UnitTemplateIdHash[tid] : null;
  139. }
  140. public async ETTask ProcessLauncheffectTag(uint objectid, string tag)
  141. {
  142. //Effect支持Tag设置Event,格式:Event:事件名(事件参数)
  143. Match m = Regex.Match(tag, @"^@(\w+)\(([\w\d\s_,]+)\)");
  144. if (m.Groups.Count >= 3)
  145. {
  146. string name = m.Groups[1].Value;
  147. string param = m.Groups[2].Value;
  148. switch (name)
  149. {
  150. case "ChangeMode":
  151. var ps = param.Split(',');
  152. if (ps.Length > 1)
  153. {
  154. try
  155. {
  156. var delay = Convert.ToInt32(ps[1]);
  157. await TimerComponent.Instance.WaitAsync(delay);
  158. EventSystem.Instance.Publish(ChangeModeEvent.Static.Clone(objectid, ps[0]));
  159. }
  160. catch
  161. {
  162. Log.Error($"effect tag param error: {tag}");
  163. }
  164. }
  165. else
  166. {
  167. EventSystem.Instance.Publish(ChangeModeEvent.Static.Clone(objectid, param));
  168. }
  169. return;
  170. default:
  171. Log.Error($"effect unknow tag: {tag}");
  172. return;
  173. }
  174. }
  175. Log.Error($"effect illegal tag: {tag}");
  176. }
  177. private void registerEventHandler()
  178. {
  179. //actor===================
  180. eventHandler.AddListener<SetAutoBattleB2C>((ev) => {
  181. var isAutoFight = (ev as SetAutoBattleB2C).isAutoBattle != 0;
  182. Log.Debug($"AutoFight: {isAutoFight}");
  183. (UnitMgr.Instance.Actor.ZUnit as ZoneActor).IsGuard = isAutoFight;
  184. });
  185. eventHandler.AddListener<PlayerFocuseTargetEvent>((ev) =>
  186. {
  187. });
  188. eventHandler.AddListener<UnitHitBreak>((ev) =>
  189. {
  190. var e = ev as UnitHitBreak;
  191. var unit = UnitMgr.Instance.GetUnit(e.ObjectID);
  192. if (unit != null && unit is BattleUnit bunit)
  193. {
  194. var launcheffect = bunit.ZUnit.Info.HitBreakEffect;
  195. if (launcheffect != null)
  196. {
  197. EventSystem.Instance.Publish(PlayEffectEvent.Static.Clone(launcheffect, unit.Id, CommonLang.Geometry.Vector3.Zero));
  198. if(!launcheffect.Tag.IsNullOrWhitespace() )
  199. {
  200. ProcessLauncheffectTag(e.ObjectID, launcheffect.Tag).Coroutine();
  201. }
  202. }
  203. }
  204. });
  205. eventHandler.AddListener<ShowTipsEventB2C>((ev) =>
  206. {
  207. });
  208. eventHandler.AddListener<UnitDeadEvent>((ev) =>
  209. {
  210. var e = ev as UnitDeadEvent;
  211. Log.Debug($"Unit({e.object_id}) dead");
  212. EventSystem.Instance.Publish<PlayAnimatorEvent>(PlayAnimatorEvent.Static.Clone(
  213. e.ObjectID, AnimatorEventType.Dead));
  214. var unit = UnitMgr.Instance.GetUnit(e.ObjectID);
  215. if(unit != null && unit is BattleUnit bunit)
  216. {
  217. var launcheffect = bunit.ZUnit.Info.DeadActionEffect;
  218. if (launcheffect != null)
  219. {
  220. EventSystem.Instance.Publish<PlayEffectEvent>(PlayEffectEvent.Static.Clone(launcheffect, unit.Id, CommonLang.Geometry.Vector3.Zero));
  221. }
  222. }
  223. //TODO: 过几秒后,自行清理尸体
  224. });
  225. eventHandler.AddListener<UnitRebirthEvent>((ev) =>
  226. {
  227. });
  228. eventHandler.AddListener<UnitHitEvent>((ev) =>
  229. {
  230. var e = ev as UnitHitEvent;
  231. var unit = UnitMgr.Instance.GetUnit(e.ObjectID);
  232. if(unit == null)
  233. {
  234. Log.Warning($"Ignore unit({e.ObjectID}) on hit, not exist?");
  235. return;
  236. }
  237. if (e.dmgSrc == CommonAI.Data.DamageSource.RemedyPoison)
  238. {
  239. //伤害来源于叠毒BUFF
  240. e.client_state = (byte)UnitHitEventState.PoisonBuff;
  241. }
  242. //TODO: 显示伤害飘字
  243. LaunchEffect hitEffect = e.effect;
  244. if (hitEffect != null)
  245. {
  246. float roation = 0f;
  247. if (hitEffect.IsSyncSenderRotation)
  248. {
  249. //设置特效的rotation为施法者与受击连线方向的rotation
  250. var sender = UnitMgr.Instance.GetUnit(e.senderId);
  251. if (sender != null)
  252. {
  253. Vector3 difpos = new Vector3(unit.ZoneObject.X, unit.ZoneObject.Y, 0) - new Vector3(sender.ZoneObject.X, sender.ZoneObject.Y, 0);
  254. roation = (float)-Math.Atan2(-difpos.Y, difpos.X);
  255. }
  256. }
  257. if (hitEffect.BindBody)
  258. {
  259. vecTemp.Set(0, 0, 0);
  260. }
  261. else
  262. {
  263. vecTemp.Set(unit.ZoneObject.X, unit.ZoneObject.Y, unit.ZoneObject.Z);
  264. }
  265. EventSystem.Instance.Publish<PlayEffectEvent>(PlayEffectEvent.Static.Clone(hitEffect, e.ObjectID, vecTemp, roation));
  266. }
  267. });
  268. eventHandler.AddListener<PlayerPKModeChangeEventB2C>((ev) =>
  269. {
  270. //TODO:替代virtual层
  271. var e = ev as PlayerPKModeChangeEventB2C;
  272. Log.Debug($"PKMode: {e.CurMode}");
  273. });
  274. eventHandler.AddListener<PlayerBattlePropChangeEventB2C>((ev) =>
  275. {
  276. });
  277. eventHandler.AddListener<PlayerPKValueChangeEventB2C>((ev) =>
  278. {
  279. });
  280. eventHandler.AddListener<BuffActiveSkillEventB2C>((ev) =>
  281. {
  282. });
  283. eventHandler.AddListener<UnitEffectEvent>((ev) =>
  284. {
  285. var e = ev as UnitEffectEvent;
  286. vecTemp.Set(0,0,0);
  287. var unit = UnitMgr.Instance.GetUnit(e.object_id);
  288. if (unit != null && !e.effect.BindBody)
  289. {
  290. vecTemp.Set(unit.ZoneObject.X, unit.ZoneObject.Y, unit.ZoneObject.Z);
  291. }
  292. EventSystem.Instance.Publish(PlayEffectEvent.Static.Clone(e.effect, e.ObjectID, vecTemp));
  293. });
  294. eventHandler.AddListener<XmdsUnitPropEventB2C>((ev) =>
  295. {
  296. });
  297. //NPCCureEventB2C
  298. //MonsterSufferDamageInfoB2C
  299. //BattleHintNumberB2C
  300. //BattleFloatTipsEventB2C
  301. //BubbleTipsEventB2C
  302. //怪物归属权
  303. //MonsterHeirInfoChangeEventB2C
  304. eventHandler.AddListener<GameOverEvent>((ev) =>
  305. {
  306. var e = ev as GameOverEvent;
  307. EventSystem.Instance.Publish(GameoverEvent.Static.Clone(e.WinForce));
  308. });
  309. eventHandler.AddListener<CameraMoveToEvent>((ev) =>
  310. {
  311. var e = ev as CameraMoveToEvent;
  312. EventSystem.Instance.Publish(CameraEvent.Static.Clone(e.x, e.height, e.y, e.TimeMS, e.MoveSpeedSec));
  313. });
  314. eventHandler.AddListener<AddEffectEvent>((ev) => {
  315. var e = ev as AddEffectEvent;
  316. if(e.hostId == 0 || UnitMgr.Instance.HasUnit(e.hostId))
  317. {
  318. vecTemp.Set(e.x, e.y, 0);
  319. EventSystem.Instance.Publish(PlayEffectEvent.Static.Clone(e.effect, e.hostId, vecTemp));
  320. }
  321. });
  322. eventHandler.AddListener<ClientMsgEvent>((ev) =>
  323. {
  324. var e = ev as ClientMsgEvent;
  325. Log.Debug($">>>Battle client event: {e.Message}");
  326. });
  327. /*BubbleTalkEvent
  328. AddEffectEvent
  329. SyncEnvironmentVarEvent
  330. ScriptCommandEvent
  331. ScriptAddUnitEventsB2C
  332. ScriptRemoveUnitEventsB2C
  333. PlaySoundEventB2CForAll
  334. SyncFlagsEvent
  335. ChangeBGMEvent
  336. PlayDestoryEffect*/
  337. /*var e = msg as CommonAI.Zone.Event;
  338. if (e is ChatEvent)
  339. {
  340. var evt = (e as ChatEvent);
  341. var message = evt.Message;
  342. var evt_param = message.Split('|');
  343. if (evt_param.Length >= 2 && evt_param[0] == "Notice.Msg")
  344. {
  345. var dic = GameUtil.GetDBData("NoticeMsg", int.Parse(evt_param[1]));
  346. if (dic != null)
  347. {
  348. string result = "";
  349. if (evt_param.Length >= 3 && evt_param[2] != null)
  350. {
  351. //根据参数个数 依次填值
  352. string[] par = evt_param[2].Split('.');
  353. if (par != null && par.Length > 0)
  354. {
  355. switch (par.Length)
  356. {
  357. case 1:
  358. {
  359. result = Average(dic["MsgContent"] as string, par[0]);
  360. break;
  361. }
  362. case 2:
  363. {
  364. result = Average(dic["MsgContent"] as string, par[0], par[1]);
  365. break;
  366. }
  367. case 3:
  368. {
  369. result = Average(dic["MsgContent"] as string, par[0], par[1], par[2]);
  370. break;
  371. }
  372. case 4:
  373. {
  374. result = Average(dic["MsgContent"] as string, par[0], par[1], par[2], par[3]);
  375. break;
  376. }
  377. case 5:
  378. {
  379. result = Average(dic["MsgContent"] as string, par[0], par[1], par[2], par[3], par[4]);
  380. break;
  381. }
  382. }
  383. }
  384. }
  385. else
  386. {
  387. //没有参数
  388. result = (dic["MsgContent"] as string);
  389. }
  390. //
  391. EventManager.Fire("Event.OnEventHandler.star", new Dictionary<string, string>() {
  392. {"content", result}, {"keepTime", "" + (evt.KeepTimeMS/1000)}, {"content_is_text", "true"}
  393. });
  394. }
  395. else
  396. {
  397. YXJDebug.logError("config not exist >" + msg);
  398. }
  399. }
  400. else if (evt_param.Length == 2)
  401. {
  402. string funcName = "GlobalHooks." + evt_param[0];
  403. object[] param = evt_param[1].Split(',');
  404. //Client.GetMainState().GetFunction(funcName).LazyCall(param);
  405. if (param.Length == 0)
  406. Client.GetMainState().Call(funcName, Client.LogMiss);
  407. else if (param.Length == 1)
  408. Client.GetMainState().Call(funcName, param[0], Client.LogMiss);
  409. else if (param.Length == 2)
  410. Client.GetMainState().Call(funcName, param[0], param[1], Client.LogMiss);
  411. else if (param.Length == 3)
  412. Client.GetMainState().Call(funcName, param[0], param[1], param[2], Client.LogMiss);
  413. else if (param.Length == 4)
  414. Client.GetMainState().Call(funcName, param[0], param[1], param[2], param[3], Client.LogMiss);
  415. else if (param.Length == 5)
  416. Client.GetMainState().Call(funcName, param[0], param[1], param[2], param[3], param[4], Client.LogMiss);
  417. else
  418. {
  419. YXJDebug.logError("BattleClientBase.OnEventHandler Error!funcName is {0}", funcName);
  420. }
  421. }
  422. else
  423. {
  424. //位面进入退出效果
  425. if (msg == "EnterAOI")
  426. {
  427. var wwe = Camera.main.GetComponent<WaterWaveEffect>();
  428. if (wwe != null)
  429. {
  430. wwe.SetParam(40, -30, 3, 2);
  431. wwe.play();
  432. }
  433. //GameAlertManager.Instance.setAutoAnimiVisible(false);
  434. InAOI = true;
  435. }
  436. else if (msg == "LeaveAOI")
  437. {
  438. var wwe = Camera.main.GetComponent<WaterWaveEffect>();
  439. if (wwe != null)
  440. {
  441. wwe.SetParam(40, -30, 3, 2);
  442. wwe.play();
  443. }
  444. InAOI = false;
  445. }
  446. else
  447. {
  448. //普通chatevent
  449. EventManager.Fire("Event.OnEventHandler.star", new Dictionary<string, string>() {
  450. {"content", msg}, {"isImportant", "1"}, {"keepTime", "" + (evt.KeepTimeMS/1000)}
  451. });
  452. }
  453. }
  454. }
  455. else if (e is CommonAI.Zone.ZoneEvent)
  456. {
  457. if (e is BubbleTalkEvent)
  458. {
  459. BubbleTalkEvent evt = e as BubbleTalkEvent;
  460. if (evt.TalkInfos != null)
  461. {
  462. foreach (var info in evt.TalkInfos)
  463. {
  464. System.Action callback = delegate ()
  465. {
  466. if (info.TalkUnit == 0)
  467. {
  468. YXJDebug.logError("旁白气泡还没有实现>{0}", info.TalkContent);
  469. return;
  470. }
  471. ComAIUnit unit = GetUnitById(info.TalkUnit) as ComAIUnit;
  472. if (unit == null)
  473. {
  474. if (info.TalkContent != "bubblechat")
  475. {
  476. YXJDebug.logDebug(">BubbleTalkEvent unit not exist: {0}>>{1}", info.TalkUnit, info.TalkContent);
  477. }
  478. return;
  479. }
  480. if (info.TalkContent == "bubblechat")
  481. {
  482. UIBridgeManager.Instance.QuestUIBridge.BubbleTalkEventSend(unit);
  483. }
  484. else
  485. {
  486. var txt = ConfigMgr.Instance.TxtCfg.GetTextByKey("GameEditor_" + info.TalkContent);
  487. unit.AddBubbleChat(txt, info.TalkKeepTimeMS / 1000);
  488. }
  489. if (!string.IsNullOrEmpty(info.TalkActionType))
  490. {
  491. unit.PlayAnimationWhileIdle(info.TalkActionType);
  492. }
  493. };
  494. if (info.TalkDelayTimeMS > 0)
  495. {
  496. GameGlobal.Instance.StartCoroutine(WaitForSeconds(info.TalkDelayTimeMS / 1000, callback));
  497. }
  498. else
  499. {
  500. callback.Invoke();
  501. }
  502. }
  503. }
  504. }
  505. else if (e is AddEffectEvent && battleManager != null)
  506. {
  507. AddEffectEvent evt = e as AddEffectEvent;
  508. if (evt.hostId == 0 || GetUnitById(evt.hostId) != null)
  509. {
  510. Vector3 pos = battleManager.GetU3DPosByUnitCell(evt.x, evt.y);
  511. pos = ComAICell.AdjustHeight(pos);
  512. Quaternion rotation = Quaternion.Euler(0, evt.direction * Mathf.Rad2Deg + 90, 0);
  513. EffectPlayer.SetRotationOnetime(rotation); //--->这个功能加个参数不就好了 →_→
  514. EffectPlayer.Play(evt.effect, pos, false);
  515. }
  516. }
  517. else if (e is AddEffectEvent2 && battleManager != null)
  518. {
  519. AddEffectEvent2 evt = e as AddEffectEvent2;
  520. if (evt.hostId == 0 || GetUnitById(evt.hostId) != null)
  521. {
  522. Vector3 pos = battleManager.GetU3DPosByUnitCell(evt.x, evt.y);
  523. pos = ComAICell.AdjustHeight(pos);
  524. Vector3 targetPos = battleManager.GetU3DPosByUnitCell(evt.TargetX, evt.TargetY);
  525. EffectPlayer.PlayLocal(evt.effect, pos, false, 0, 0, 0, 0, evt.ET, targetPos, evt.FollowActor);
  526. }
  527. }
  528. else if (e is SyncEnvironmentVarEvent)
  529. {
  530. SyncEnvironmentVarEvent evt = e as SyncEnvironmentVarEvent;
  531. UIBridgeManager.Instance.BattleUIBridge.EnvironmentVarChange(evt.Key, evt.Value);
  532. }
  533. else if (e is ScriptCommandEvent)
  534. {
  535. ScriptCommandEvent evt = e as ScriptCommandEvent;
  536. string[] evt_param = evt.message.Split('|');
  537. if (evt_param.Length == 2)
  538. {
  539. object[] param = evt_param[1].Split(',');
  540. string funcName = "GlobalHooks." + evt_param[0];
  541. if (param.Length == 0)
  542. Client.GetMainState().Call(funcName, Client.LogMiss);
  543. else if (param.Length == 1)
  544. Client.GetMainState().Call(funcName, param[0], Client.LogMiss);
  545. else if (param.Length == 2)
  546. Client.GetMainState().Call(funcName, param[0], param[1], Client.LogMiss);
  547. else if (param.Length == 3)
  548. Client.GetMainState().Call(funcName, param[0], param[1], param[2], Client.LogMiss);
  549. else if (param.Length == 4)
  550. Client.GetMainState().Call(funcName, param[0], param[1], param[2], param[3], Client.LogMiss);
  551. else if (param.Length == 5)
  552. Client.GetMainState().Call(funcName, param[0], param[1], param[2], param[3], param[4], Client.LogMiss);
  553. else
  554. {
  555. YXJDebug.logError("BattleClientBase.OnEventHandler Error!funcName is {0}", funcName);
  556. }
  557. }
  558. }
  559. else if (e is LockActorEvent)
  560. {
  561. LockActorEvent evt = e as LockActorEvent;
  562. OnLockActorEvent(evt);
  563. }
  564. else if (e is ScriptAddUnitEventsB2C)
  565. {
  566. ScriptAddUnitEventsB2C evt = e as ScriptAddUnitEventsB2C;
  567. OnScriptAddUnitEvent(evt);
  568. }
  569. else if (e is ScriptRemoveUnitEventsB2C)
  570. {
  571. ScriptRemoveUnitEventsB2C evt = e as ScriptRemoveUnitEventsB2C;
  572. OnScriptRemoveUnitEvents(evt);
  573. }
  574. else if (e is PlaySoundEventB2CForAll)
  575. {
  576. PlaySoundEventB2CForAll evt = e as PlaySoundEventB2CForAll;
  577. XmdsSoundManager.GetXmdsInstance().PlaySound(evt.SoundName);
  578. }
  579. else if (e is SyncFlagsEvent && mDecoMgr != null)
  580. {
  581. mDecoMgr.LoadDecos();
  582. }
  583. else if (e is ChangeBGMEvent)
  584. {
  585. XmdsSoundManager.GetXmdsInstance().ChangeBGM((e as ChangeBGMEvent).FileName);
  586. }
  587. else if (e is PlayDestoryEffect)
  588. {
  589. if (EffectPlayer == null) return;
  590. PlayDestoryEffect destoryEffect = e as PlayDestoryEffect;
  591. Vector3 vec = new Vector3(destoryEffect.X, destoryEffect.Y, destoryEffect.Z);
  592. Quaternion rotation = Quaternion.Euler(0, destoryEffect.Direction * Mathf.Rad2Deg + 90, 0);
  593. LaunchEffect effect = new LaunchEffect();
  594. effect.Name = destoryEffect.EffectName;
  595. EffectPlayer.SetRotationOnetime(rotation);
  596. EffectPlayer.Play(effect, vec, true);
  597. }
  598. else
  599. {
  600. //YXJDebug.logInfo("OnEventHandler not implemented! {0}", e.ToString());
  601. }
  602. }*/
  603. }
  604. }
  605. }