BattleMgr.cs 28 KB

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