|
@@ -0,0 +1,393 @@
|
|
|
+using CommonAI.Zone;
|
|
|
+using CommonAI.ZoneClient;
|
|
|
+using CommonLang;
|
|
|
+using ET.Client;
|
|
|
+using Microsoft.Cci;
|
|
|
+using System;
|
|
|
+using System.Collections.Generic;
|
|
|
+using System.Data;
|
|
|
+using System.IO;
|
|
|
+using System.Net;
|
|
|
+using System.Runtime.InteropServices.ComTypes;
|
|
|
+using XmdsCommon.Message;
|
|
|
+
|
|
|
+namespace ET
|
|
|
+{
|
|
|
+ public class BattleMgr : Singleton<BattleMgr>, ISingletonUpdate, ILayerClient
|
|
|
+ {
|
|
|
+ private bool isInited = false;
|
|
|
+ public ZoneLayer Layer;
|
|
|
+ private readonly MemoryStream writeBuffer = new MemoryStream(2048);
|
|
|
+
|
|
|
+ public async ETTask InitAsync()
|
|
|
+ {
|
|
|
+ Layer = TemplateManager.Factory.CreateClientZoneLayer(BattleResourceMgr.Instance.GameEditorTemplates, this);
|
|
|
+
|
|
|
+ Layer.LayerInit += OnLayerInit;
|
|
|
+ Layer.ObjectEnter += OnObjectEnter;
|
|
|
+ Layer.ObjectLeave += OnObjectLeave;
|
|
|
+ Layer.PlayerLeave += RemovePlayerInfo;
|
|
|
+ //Layer.MessageReceived += xxLayer_MessageReceived;
|
|
|
+ Layer.DecorationChanged += Layer_DecorationChanged;
|
|
|
+ isInited = true;
|
|
|
+
|
|
|
+ await ETTask.CompletedTask;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void Update()
|
|
|
+ {
|
|
|
+ if (!isInited) return;
|
|
|
+
|
|
|
+ //TODO: Send ping
|
|
|
+ Layer.Update();
|
|
|
+ }
|
|
|
+
|
|
|
+ void ILayerClient.BattleReady(bool bok)
|
|
|
+ {
|
|
|
+ Log.Debug("battle ready.......");
|
|
|
+ //throw new System.NotImplementedException();
|
|
|
+ }
|
|
|
+
|
|
|
+ //layer层中需要发送消息到战斗服
|
|
|
+ public void SendAction(CommonAI.Zone.Action action)
|
|
|
+ {
|
|
|
+ if(PlayerComponent.Instance == null)
|
|
|
+ {
|
|
|
+ Log.Error("playerComponent is null");
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ writeBuffer.Position = 0;
|
|
|
+ if (BattleResourceMgr.Instance.BattleMsgDecoder.doEncode(writeBuffer, action))
|
|
|
+ {
|
|
|
+ var param = new BattleEventPushToServer() { data = writeBuffer.ToArray() };
|
|
|
+ PlayerComponent.Instance.ClientScene().GetComponent<SessionComponent>().Session.Send(param);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //客户端自己模拟创建消息,发送到zonelayer层处理
|
|
|
+ public void PostMsg2Layer(IMessage msg)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void OnLayerInit(CommonAI.ZoneClient.ZoneLayer layer)
|
|
|
+ {
|
|
|
+ Log.Debug("OnLayerInit");
|
|
|
+ }
|
|
|
+
|
|
|
+ //单位进入战斗
|
|
|
+ protected void OnObjectEnter(ZoneLayer layer, ZoneObject obj)
|
|
|
+ {
|
|
|
+ Log.Debug($"OnObjectEnter: {obj.Name}");
|
|
|
+ }
|
|
|
+
|
|
|
+ //单位离开战斗
|
|
|
+ protected void OnObjectLeave(ZoneLayer layer, ZoneObject obj)
|
|
|
+ {
|
|
|
+ Log.Debug($"OnObjectLeave: {obj.Name}");
|
|
|
+ }
|
|
|
+ public void RemovePlayerInfo(ZoneLayer layer, ZoneObject obj)
|
|
|
+ {
|
|
|
+ Log.Debug($"RemovePlayerInfo: {obj.Name}");
|
|
|
+ /*ComAICell cell = null;
|
|
|
+ if (allUnits.TryGetValue(obj.ObjectID, out cell))
|
|
|
+ {
|
|
|
+ if (!(cell is ComAIPlayer)) return;
|
|
|
+ var player = cell as ComAIPlayer;
|
|
|
+ var info = player.GetVirtual().GetBaseInfo();
|
|
|
+ if (info == null || string.IsNullOrEmpty(info.uuid) || !allPlayers.ContainsKey(info.uuid)) return;
|
|
|
+ grassStealth.DelPlayer(player);
|
|
|
+ allPlayers.Remove(info.uuid);
|
|
|
+ if (UnitLoadOkCallBack.ContainsKey(info.uuid)) UnitLoadOkCallBack.Remove(info.uuid);
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+
|
|
|
+ protected void Layer_DecorationChanged(CommonAI.ZoneClient.ZoneLayer layer, CommonAI.ZoneClient.ZoneEditorDecoration ed)
|
|
|
+ {
|
|
|
+ Log.Debug("Layer_DecorationChanged");
|
|
|
+ /*DataMgr.Instance.RegionManager.OnDecorationChanged(ed);
|
|
|
+ if (mDecoMgr != null)
|
|
|
+ {
|
|
|
+ mDecoMgr.OnStateChange(ed);
|
|
|
+ }*/
|
|
|
+ }
|
|
|
+ /*private void OnEventHandler(CommonAI.Zone.Event e)
|
|
|
+{
|
|
|
+ if (e is SyncPosEvent || e is Pong)
|
|
|
+ {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (e is ChatEvent)
|
|
|
+ {
|
|
|
+ var evt = (e as ChatEvent);
|
|
|
+ var msg = evt.Message;
|
|
|
+ var evt_param = msg.Split('|');
|
|
|
+ if (evt_param.Length >= 2 && evt_param[0] == "Notice.Msg")
|
|
|
+ {
|
|
|
+ var dic = GameUtil.GetDBData("NoticeMsg", int.Parse(evt_param[1]));
|
|
|
+ if (dic != null)
|
|
|
+ {
|
|
|
+ string result = "";
|
|
|
+ if (evt_param.Length >= 3 && evt_param[2] != null)
|
|
|
+ {
|
|
|
+ //根据参数个数 依次填值
|
|
|
+ string[] par = evt_param[2].Split('.');
|
|
|
+ if (par != null && par.Length > 0)
|
|
|
+ {
|
|
|
+ switch (par.Length)
|
|
|
+ {
|
|
|
+ case 1:
|
|
|
+ {
|
|
|
+ result = Average(dic["MsgContent"] as string, par[0]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 2:
|
|
|
+ {
|
|
|
+ result = Average(dic["MsgContent"] as string, par[0], par[1]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 3:
|
|
|
+ {
|
|
|
+ result = Average(dic["MsgContent"] as string, par[0], par[1], par[2]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 4:
|
|
|
+ {
|
|
|
+ result = Average(dic["MsgContent"] as string, par[0], par[1], par[2], par[3]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ case 5:
|
|
|
+ {
|
|
|
+ result = Average(dic["MsgContent"] as string, par[0], par[1], par[2], par[3], par[4]);
|
|
|
+ break;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //没有参数
|
|
|
+ result = (dic["MsgContent"] as string);
|
|
|
+ }
|
|
|
+ //
|
|
|
+ EventManager.Fire("Event.OnEventHandler.star", new Dictionary<string, string>() {
|
|
|
+ {"content", result}, {"keepTime", "" + (evt.KeepTimeMS/1000)}, {"content_is_text", "true"}
|
|
|
+ });
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ YXJDebug.logError("config not exist >" + msg);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (evt_param.Length == 2)
|
|
|
+ {
|
|
|
+ string funcName = "GlobalHooks." + evt_param[0];
|
|
|
+ object[] param = evt_param[1].Split(',');
|
|
|
+ //Client.GetMainState().GetFunction(funcName).LazyCall(param);
|
|
|
+ if (param.Length == 0)
|
|
|
+ Client.GetMainState().Call(funcName, Client.LogMiss);
|
|
|
+ else if (param.Length == 1)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], Client.LogMiss);
|
|
|
+ else if (param.Length == 2)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], param[1], Client.LogMiss);
|
|
|
+ else if (param.Length == 3)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], param[1], param[2], Client.LogMiss);
|
|
|
+ else if (param.Length == 4)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], param[1], param[2], param[3], Client.LogMiss);
|
|
|
+ else if (param.Length == 5)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], param[1], param[2], param[3], param[4], Client.LogMiss);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ YXJDebug.logError("BattleClientBase.OnEventHandler Error!funcName is {0}", funcName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //位面进入退出效果
|
|
|
+ if (msg == "EnterAOI")
|
|
|
+ {
|
|
|
+ var wwe = Camera.main.GetComponent<WaterWaveEffect>();
|
|
|
+ if (wwe != null)
|
|
|
+ {
|
|
|
+ wwe.SetParam(40, -30, 3, 2);
|
|
|
+ wwe.play();
|
|
|
+ }
|
|
|
+ //GameAlertManager.Instance.setAutoAnimiVisible(false);
|
|
|
+ InAOI = true;
|
|
|
+ }
|
|
|
+ else if (msg == "LeaveAOI")
|
|
|
+ {
|
|
|
+ var wwe = Camera.main.GetComponent<WaterWaveEffect>();
|
|
|
+ if (wwe != null)
|
|
|
+ {
|
|
|
+ wwe.SetParam(40, -30, 3, 2);
|
|
|
+ wwe.play();
|
|
|
+ }
|
|
|
+ InAOI = false;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //普通chatevent
|
|
|
+ EventManager.Fire("Event.OnEventHandler.star", new Dictionary<string, string>() {
|
|
|
+ {"content", msg}, {"isImportant", "1"}, {"keepTime", "" + (evt.KeepTimeMS/1000)}
|
|
|
+ });
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (e is CommonAI.Zone.ZoneEvent)
|
|
|
+ {
|
|
|
+ if (e is BubbleTalkEvent)
|
|
|
+ {
|
|
|
+ BubbleTalkEvent evt = e as BubbleTalkEvent;
|
|
|
+ if (evt.TalkInfos != null)
|
|
|
+ {
|
|
|
+ foreach (var info in evt.TalkInfos)
|
|
|
+ {
|
|
|
+ System.Action callback = delegate ()
|
|
|
+ {
|
|
|
+ if (info.TalkUnit == 0)
|
|
|
+ {
|
|
|
+ YXJDebug.logError("旁白气泡还没有实现>{0}", info.TalkContent);
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ ComAIUnit unit = GetUnitById(info.TalkUnit) as ComAIUnit;
|
|
|
+ if (unit == null)
|
|
|
+ {
|
|
|
+ if (info.TalkContent != "bubblechat")
|
|
|
+ {
|
|
|
+ YXJDebug.logDebug(">BubbleTalkEvent unit not exist: {0}>>{1}", info.TalkUnit, info.TalkContent);
|
|
|
+ }
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (info.TalkContent == "bubblechat")
|
|
|
+ {
|
|
|
+ UIBridgeManager.Instance.QuestUIBridge.BubbleTalkEventSend(unit);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ var txt = ConfigMgr.Instance.TxtCfg.GetTextByKey("GameEditor_" + info.TalkContent);
|
|
|
+ unit.AddBubbleChat(txt, info.TalkKeepTimeMS / 1000);
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!string.IsNullOrEmpty(info.TalkActionType))
|
|
|
+ {
|
|
|
+ unit.PlayAnimationWhileIdle(info.TalkActionType);
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ if (info.TalkDelayTimeMS > 0)
|
|
|
+ {
|
|
|
+ GameGlobal.Instance.StartCoroutine(WaitForSeconds(info.TalkDelayTimeMS / 1000, callback));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ callback.Invoke();
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (e is AddEffectEvent && battleManager != null)
|
|
|
+ {
|
|
|
+ AddEffectEvent evt = e as AddEffectEvent;
|
|
|
+ if (evt.hostId == 0 || GetUnitById(evt.hostId) != null)
|
|
|
+ {
|
|
|
+ Vector3 pos = battleManager.GetU3DPosByUnitCell(evt.x, evt.y);
|
|
|
+ pos = ComAICell.AdjustHeight(pos);
|
|
|
+ Quaternion rotation = Quaternion.Euler(0, evt.direction * Mathf.Rad2Deg + 90, 0);
|
|
|
+ EffectPlayer.SetRotationOnetime(rotation); //--->这个功能加个参数不就好了 →_→
|
|
|
+ EffectPlayer.Play(evt.effect, pos, false);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (e is AddEffectEvent2 && battleManager != null)
|
|
|
+ {
|
|
|
+ AddEffectEvent2 evt = e as AddEffectEvent2;
|
|
|
+ if (evt.hostId == 0 || GetUnitById(evt.hostId) != null)
|
|
|
+ {
|
|
|
+ Vector3 pos = battleManager.GetU3DPosByUnitCell(evt.x, evt.y);
|
|
|
+ pos = ComAICell.AdjustHeight(pos);
|
|
|
+ Vector3 targetPos = battleManager.GetU3DPosByUnitCell(evt.TargetX, evt.TargetY);
|
|
|
+ EffectPlayer.PlayLocal(evt.effect, pos, false, 0, 0, 0, 0, evt.ET, targetPos, evt.FollowActor);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (e is SyncEnvironmentVarEvent)
|
|
|
+ {
|
|
|
+ SyncEnvironmentVarEvent evt = e as SyncEnvironmentVarEvent;
|
|
|
+ UIBridgeManager.Instance.BattleUIBridge.EnvironmentVarChange(evt.Key, evt.Value);
|
|
|
+ }
|
|
|
+ else if (e is ScriptCommandEvent)
|
|
|
+ {
|
|
|
+ ScriptCommandEvent evt = e as ScriptCommandEvent;
|
|
|
+ string[] evt_param = evt.message.Split('|');
|
|
|
+ if (evt_param.Length == 2)
|
|
|
+ {
|
|
|
+ object[] param = evt_param[1].Split(',');
|
|
|
+ string funcName = "GlobalHooks." + evt_param[0];
|
|
|
+ if (param.Length == 0)
|
|
|
+ Client.GetMainState().Call(funcName, Client.LogMiss);
|
|
|
+ else if (param.Length == 1)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], Client.LogMiss);
|
|
|
+ else if (param.Length == 2)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], param[1], Client.LogMiss);
|
|
|
+ else if (param.Length == 3)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], param[1], param[2], Client.LogMiss);
|
|
|
+ else if (param.Length == 4)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], param[1], param[2], param[3], Client.LogMiss);
|
|
|
+ else if (param.Length == 5)
|
|
|
+ Client.GetMainState().Call(funcName, param[0], param[1], param[2], param[3], param[4], Client.LogMiss);
|
|
|
+ else
|
|
|
+ {
|
|
|
+ YXJDebug.logError("BattleClientBase.OnEventHandler Error!funcName is {0}", funcName);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ else if (e is LockActorEvent)
|
|
|
+ {
|
|
|
+ LockActorEvent evt = e as LockActorEvent;
|
|
|
+ OnLockActorEvent(evt);
|
|
|
+ }
|
|
|
+ else if (e is ScriptAddUnitEventsB2C)
|
|
|
+ {
|
|
|
+ ScriptAddUnitEventsB2C evt = e as ScriptAddUnitEventsB2C;
|
|
|
+ OnScriptAddUnitEvent(evt);
|
|
|
+ }
|
|
|
+ else if (e is ScriptRemoveUnitEventsB2C)
|
|
|
+ {
|
|
|
+ ScriptRemoveUnitEventsB2C evt = e as ScriptRemoveUnitEventsB2C;
|
|
|
+ OnScriptRemoveUnitEvents(evt);
|
|
|
+ }
|
|
|
+ else if (e is PlaySoundEventB2CForAll)
|
|
|
+ {
|
|
|
+ PlaySoundEventB2CForAll evt = e as PlaySoundEventB2CForAll;
|
|
|
+ XmdsSoundManager.GetXmdsInstance().PlaySound(evt.SoundName);
|
|
|
+ }
|
|
|
+ else if (e is SyncFlagsEvent && mDecoMgr != null)
|
|
|
+ {
|
|
|
+ mDecoMgr.LoadDecos();
|
|
|
+ }
|
|
|
+ else if (e is ChangeBGMEvent)
|
|
|
+ {
|
|
|
+ XmdsSoundManager.GetXmdsInstance().ChangeBGM((e as ChangeBGMEvent).FileName);
|
|
|
+ }
|
|
|
+ else if (e is PlayDestoryEffect)
|
|
|
+ {
|
|
|
+ if (EffectPlayer == null) return;
|
|
|
+ PlayDestoryEffect destoryEffect = e as PlayDestoryEffect;
|
|
|
+ Vector3 vec = new Vector3(destoryEffect.X, destoryEffect.Y, destoryEffect.Z);
|
|
|
+ Quaternion rotation = Quaternion.Euler(0, destoryEffect.Direction * Mathf.Rad2Deg + 90, 0);
|
|
|
+ LaunchEffect effect = new LaunchEffect();
|
|
|
+ effect.Name = destoryEffect.EffectName;
|
|
|
+ EffectPlayer.SetRotationOnetime(rotation);
|
|
|
+ EffectPlayer.Play(effect, vec, true);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ //YXJDebug.logInfo("OnEventHandler not implemented! {0}", e.ToString());
|
|
|
+ }
|
|
|
+ }
|
|
|
+}*/
|
|
|
+ }
|
|
|
+}
|
|
|
+
|