BattleMgr.cs 28 KB

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