Browse Source

【优化】部分委托事件未清理

meijun 3 years ago
parent
commit
a96d3ce112

+ 121 - 108
XmdsServerCS/XmdsServerEdgeJS/Zone/XmdsZoneNode.cs

@@ -22,7 +22,7 @@ namespace XmdsServerEdgeJS.Zone
     {
         private readonly Logger log;
         private readonly ZoneService service;
-        private readonly string instanceID;        
+        private readonly string instanceID;
         private readonly ServerZoneNode node;
 
         //连斩生效时间
@@ -36,10 +36,10 @@ namespace XmdsServerEdgeJS.Zone
             node.SendToGameServer(name, param);
         }
 
-		public string GetBindGameSrvId()
-		{
-			return node.GetBindGameSrvId();
-		}
+        public string GetBindGameSrvId()
+        {
+            return node.GetBindGameSrvId();
+        }
 
         internal XmdsZoneNode(ZoneService svc, string instanceId, string gameServerId)
         {
@@ -75,11 +75,11 @@ namespace XmdsServerEdgeJS.Zone
             int killFullNum = (config.killFullNum != null) ? (int)(config.killFullNum) : 0;
             int killFullCollSec = (config.killFullCollSec != null) ? (int)(config.killFullCollSec) : 0;
 
-			GSCreateAreaData gsData = new GSCreateAreaData();
-			gsData.value1 = (config.value1 != null) ? ((int)(config.value1)) : 0;
-			gsData.value2 = (config.value2 != null) ? ((int)(config.value2)) : 0;
-			this.node.Start(instanceID, mapTemplateId , config.monsterHard, (byte)config.allowAutoGuard, config.calPKValue, 
-                averageLevel, floorRatio, propRatio, killInterval, killFullNum, killFullNum, config.usespaceDiv, 
+            GSCreateAreaData gsData = new GSCreateAreaData();
+            gsData.value1 = (config.value1 != null) ? ((int)(config.value1)) : 0;
+            gsData.value2 = (config.value2 != null) ? ((int)(config.value2)) : 0;
+            this.node.Start(instanceID, mapTemplateId, config.monsterHard, (byte)config.allowAutoGuard, config.calPKValue,
+                averageLevel, floorRatio, propRatio, killInterval, killFullNum, killFullNum, config.usespaceDiv,
                 (CommonAI.Data.SceneType)sceneType, gsData, (AreaType)areaType, isteam, canRiding);
             this.node.Zone.OnUnitDead += zone_onUnitDead;
             //this.node.Zone.OnGameOver += zone_onGameOver;
@@ -89,6 +89,7 @@ namespace XmdsServerEdgeJS.Zone
             this.node.Zone.OnTryPickItem += zone_onTryPickItem;
         }
 
+
         internal void Stop(Action<XmdsZoneNode> stopped)
         {
             if (node.IsDisposed)
@@ -100,21 +101,33 @@ namespace XmdsServerEdgeJS.Zone
                 node.OnZoneStop += (z) => { stopped(this); };
                 node.Stop();
             }
+
+
+            if(this.node != null && this.node.Zone != null)
+            {
+                this.node.Zone.OnUnitDead -= zone_onUnitDead;
+                //this.node.Zone.OnGameOver -= zone_onGameOver;
+                this.node.Zone.OnUnitGotInstanceItem -= zone_onUnitGotInstanceItem;
+                this.node.Zone.OnUnitPickUnit -= zone_onUnitPickUnit;
+                this.node.Zone.OnSendMessageToGS -= zone_onSendMessageToGS;
+                this.node.Zone.OnTryPickItem -= zone_onTryPickItem;
+            }
         }
+
         //------------------------------------------------------------------------------------------------------
 
         private HashMap<int, TVector2> _BornPlace = null;
-		private HashMap<String, TVector2> _BornPlaceExt = null;
+        private HashMap<String, TVector2> _BornPlaceExt = null;
 
-		public TVector2 r2b_get_getBornPlace(int areaId, string pointId)
+        public TVector2 r2b_get_getBornPlace(int areaId, string pointId)
         {
             lock (this)
             {
                 if (_BornPlace == null)
                 {
                     _BornPlace = new HashMap<int, TVector2>();
-					_BornPlaceExt = new HashMap<string, TVector2>();
-					List<DecorationData> Decorations = this.Node.SceneData.Decorations;
+                    _BornPlaceExt = new HashMap<string, TVector2>();
+                    List<DecorationData> Decorations = this.Node.SceneData.Decorations;
                     foreach (DecorationData decoration in Decorations)
                     {
                         foreach (AbilityData ability in decoration.Abilities)
@@ -125,20 +138,20 @@ namespace XmdsServerEdgeJS.Zone
                                 if (!string.IsNullOrEmpty(sceneAbility.NextScenePosition))
                                 {
                                     string[] pos = sceneAbility.NextScenePosition.Split(new Char[] { ',' });
-									TVector2 posInfo = new TVector2((float)Convert.ToSingle(pos[0]), (float)Convert.ToSingle(pos[1]));
+                                    TVector2 posInfo = new TVector2((float)Convert.ToSingle(pos[0]), (float)Convert.ToSingle(pos[1]));
 
-									_BornPlace.Put(sceneAbility.NextSceneID, posInfo);
-									_BornPlaceExt.Put(decoration.Name, posInfo);
-								}
+                                    _BornPlace.Put(sceneAbility.NextSceneID, posInfo);
+                                    _BornPlaceExt.Put(decoration.Name, posInfo);
+                                }
                             }
                         }
                     }
                 }
                 TVector2 ret;
-				if(pointId != null && _BornPlaceExt.TryGetValue(pointId, out ret))
-				{
-					return ret;
-				}
+                if (pointId != null && _BornPlaceExt.TryGetValue(pointId, out ret))
+                {
+                    return ret;
+                }
                 else if (_BornPlace.TryGetValue(areaId, out ret))
                 {
                     return ret;
@@ -195,13 +208,13 @@ namespace XmdsServerEdgeJS.Zone
             if (obj is InstancePlayer)
             {
                 string uuid = (obj as InstancePlayer).PlayerUUID;
-				var eventParam = new
-				{
-					eventName = "interActiveItem",
-					playerId = uuid,
-					itemId = pickable.Info.TemplateID,
-					x = obj.X,
-					y = obj.Y
+                var eventParam = new
+                {
+                    eventName = "interActiveItem",
+                    playerId = uuid,
+                    itemId = pickable.Info.TemplateID,
+                    x = obj.X,
+                    y = obj.Y
                 };
                 node.SendToGameServer(EventType.playerEvent.ToString(), eventParam);
             }
@@ -218,14 +231,14 @@ namespace XmdsServerEdgeJS.Zone
 
             if (dropitem != null)
             {
-				var eventParam = new
-				{
-					eventName = "pickItem",
-					instanceId = zone.UUID,
-					playerId = uuid,
-					itemId = dropitem.ObjID,
-					isGuard = player.IsGuard,
-					objectId = item.Info.ID,
+                var eventParam = new
+                {
+                    eventName = "pickItem",
+                    instanceId = zone.UUID,
+                    playerId = uuid,
+                    itemId = dropitem.ObjID,
+                    isGuard = player.IsGuard,
+                    objectId = item.Info.ID,
                     //type = prop.ItemType,
                     //templateID = it.Info.TemplateID
                 };
@@ -233,20 +246,20 @@ namespace XmdsServerEdgeJS.Zone
                 //u.queueEvent(new UnitGotInstanceItemEvent(u.ID, this.ID));
             }
             else
-			{
-				dynamic eventParam = new
-				{
-					eventName = "interActiveItem",
-					playerId = uuid,
-					itemId = item.Info.TemplateID,
-					objId = item.ID,
-					type = prop.ItemType,
-					isRemove = item.IsPickAll(),
-					x = item.X,
-					y = item.Y
-				};
-				node.SendToGameServer(EventType.playerEvent.ToString(), eventParam);
-			}
+            {
+                dynamic eventParam = new
+                {
+                    eventName = "interActiveItem",
+                    playerId = uuid,
+                    itemId = item.Info.TemplateID,
+                    objId = item.ID,
+                    type = prop.ItemType,
+                    isRemove = item.IsPickAll(),
+                    x = item.X,
+                    y = item.Y
+                };
+                node.SendToGameServer(EventType.playerEvent.ToString(), eventParam);
+            }
         }
 
 
@@ -325,20 +338,20 @@ namespace XmdsServerEdgeJS.Zone
             int tpID = obj.Info.TemplateID;
             //击杀助攻列表.
             List<string> atkAssistantList = null;
-			if (type == 0 && obj is XmdsInstanceMonster)
-			{
-				tpID = (obj as XmdsInstanceMonster).MonsterID;
-				if (tpID <= 0)
-				{
-					tpID = obj.Info.TemplateID;
-					log.Info("zone_onUnitDead单位id异常:" + obj.Info.TemplateID + ", " + obj.Info.Name + ", obj: " + obj + ", " + zone.GetSceneID());
-				}
-				atkAssistantList = (obj.Virtual as XmdsVirtual).mHateSystem.GetAtkAssistantList();
-			}
-			else if(type == 1)
-			{
-				atkAssistantList = (obj.Virtual as XmdsVirtual).mHateSystem.GetAtkAssistantList();
-			}
+            if (type == 0 && obj is XmdsInstanceMonster)
+            {
+                tpID = (obj as XmdsInstanceMonster).MonsterID;
+                if (tpID <= 0)
+                {
+                    tpID = obj.Info.TemplateID;
+                    log.Info("zone_onUnitDead单位id异常:" + obj.Info.TemplateID + ", " + obj.Info.Name + ", obj: " + obj + ", " + zone.GetSceneID());
+                }
+                atkAssistantList = (obj.Virtual as XmdsVirtual).mHateSystem.GetAtkAssistantList();
+            }
+            else if (type == 1)
+            {
+                atkAssistantList = (obj.Virtual as XmdsVirtual).mHateSystem.GetAtkAssistantList();
+            }
 
             if (type != 2 && playerIds.Count == 0 && (atkAssistantList == null || atkAssistantList.Count == 0))
             {
@@ -353,43 +366,43 @@ namespace XmdsServerEdgeJS.Zone
             int aLevel = 0;
             string aName = "";
             string sceneType = "";
-			if(attacker != null)
-			{
-				if (attacker is XmdsInstanceMonster)
-				{
-					MonsterVisibleDataB2C mvd = attacker.GenSyncUnitInfo().VisibleInfo as MonsterVisibleDataB2C;
-					sceneType = (attacker.Virtual as XmdsVirtual).GetCurSceneType();
-
-					aID = attacker.Info.TemplateID;
-					aQColor = (int)mvd.Qcolor;
-					aName = mvd.DisplayName;
-					aLevel = attacker.GenSyncUnitInfo().Level;
-				}
-				else if (attacker.IsPlayerUnit && obj.IsMonster)
-				{
-					InstanceUnit attackerUnit = attacker.IsPet ? attacker.Virtual.GetMasterUnit() : attacker;
-					if (attackerUnit != null)
-					{
-						attackerUnit.Virtual.DispatchKillOtherEvent(attackerUnit.Virtual, obj.Virtual);
-					}
-					else
-					{
-						log.Warn("zone_onUnitDead: 找不到人形攻击者:" + attacker.Info.ID + ", " + zone.GetSceneID());
-					}
-				}
-			}         
-			
-			//连斩数计算
-			if(zone is EditorScene)
-			{
-				EditorScene scene = zone as EditorScene;
-				if(scene != null && scene.Data.killInterval > 0 && attacker != null)
-				{
+            if (attacker != null)
+            {
+                if (attacker is XmdsInstanceMonster)
+                {
+                    MonsterVisibleDataB2C mvd = attacker.GenSyncUnitInfo().VisibleInfo as MonsterVisibleDataB2C;
+                    sceneType = (attacker.Virtual as XmdsVirtual).GetCurSceneType();
+
+                    aID = attacker.Info.TemplateID;
+                    aQColor = (int)mvd.Qcolor;
+                    aName = mvd.DisplayName;
+                    aLevel = attacker.GenSyncUnitInfo().Level;
+                }
+                else if (attacker.IsPlayerUnit && obj.IsMonster)
+                {
+                    InstanceUnit attackerUnit = attacker.IsPet ? attacker.Virtual.GetMasterUnit() : attacker;
+                    if (attackerUnit != null)
+                    {
+                        attackerUnit.Virtual.DispatchKillOtherEvent(attackerUnit.Virtual, obj.Virtual);
+                    }
+                    else
+                    {
+                        log.Warn("zone_onUnitDead: 找不到人形攻击者:" + attacker.Info.ID + ", " + zone.GetSceneID());
+                    }
+                }
+            }
+
+            //连斩数计算
+            if (zone is EditorScene)
+            {
+                EditorScene scene = zone as EditorScene;
+                if (scene != null && scene.Data.killInterval > 0 && attacker != null)
+                {
                     long curTime = CommonLang.CUtils.localTimeMS;
 
                     if (continueKillsValidTime < curTime && attacker.Statistic != null &&
-						curTime - attacker.Statistic.preKillTime < scene.Data.killInterval)
-					{
+                        curTime - attacker.Statistic.preKillTime < scene.Data.killInterval)
+                    {
                         attacker.updateContinueKills();
 
                         //如果连斩有上限,并且达到上限后有一定冷却时间
@@ -397,17 +410,17 @@ namespace XmdsServerEdgeJS.Zone
                         {
                             attacker.Statistic.continueKills = 0;
                             this.continueKillsValidTime = curTime + scene.Data.killMaxCoolTime * 1000;
-                        }						
+                        }
                     }
                     else
                     {
                         attacker.resetContinueKills();
                     }
-					attacker.Statistic.preKillTime = curTime;
-                }				
-			}
+                    attacker.Statistic.preKillTime = curTime;
+                }
+            }
 
-			XmdsVirtual vir = (obj.Virtual as XmdsVirtual);
+            XmdsVirtual vir = (obj.Virtual as XmdsVirtual);
             XmdsHateSystem zhs = vir.GetHateSystem() as XmdsHateSystem;
             InstancePlayer belongPlayer = zhs.GetHeirs() as InstancePlayer;
             //Console.Write("attacker objId:" + aID + "   aQColor:" + aQColor + " aName " + aName + " aLevel  " + aLevel);
@@ -443,13 +456,13 @@ namespace XmdsServerEdgeJS.Zone
 
             if (obj.IsPlayer)
             {
-                log.Warn("玩家死亡:" + (obj == null ? "null" : obj.PlayerUUID)+ ", 攻击者:" +
+                log.Warn("玩家死亡:" + (obj == null ? "null" : obj.PlayerUUID) + ", 攻击者:" +
                     (attacker == null ? "null" : (attacker.PlayerUUID + ", " + attacker.Info.ID)) + ", Scene:" + zone.GetSceneID());
             }
             node.SendToGameServer(EventType.areaEvent.ToString(), eventParam);
         }
 
-		
-		#endregion
-	}
+
+        #endregion
+    }
 }

+ 13 - 9
XmdsVSPlugins/XmdsCommonZone/Zones/Zone91002.cs

@@ -30,7 +30,19 @@ namespace XmdsCommonZone.Zones
         public Zone91002(TemplateManager templates, InstanceZoneListener listener, SceneData data, GSCreateAreaData gsData, string bindGameSrvId)
             : base(templates, listener, data, gsData, bindGameSrvId)
         {
-            AddEvents();
+            OnUnitDead += Zone91002_OnUnitDead;
+            OnUnitAdded += Zone91002_OnUnitAdded;
+            OnUnitRebirth += Zone91002_OnUnitRebirth;
+            OnUnitRemoved += Zone91002_OnUnitRemoved;
+        }
+
+        protected override void Disposing()
+        {
+            base.Disposing();
+            OnUnitDead -= Zone91002_OnUnitDead;
+            OnUnitAdded -= Zone91002_OnUnitAdded;
+            OnUnitRebirth -= Zone91002_OnUnitRebirth;
+            OnUnitRemoved -= Zone91002_OnUnitRemoved;
         }
 
         private void FightBuff_Tick(TimeTaskMS task)
@@ -53,14 +65,6 @@ namespace XmdsCommonZone.Zones
             AddTimePeriodicMS(CheckIntervalMS, FightBuff_Tick);
         }
 
-        private void AddEvents()
-        {
-            OnUnitDead += Zone91002_OnUnitDead;
-            OnUnitAdded += Zone91002_OnUnitAdded;
-            OnUnitRebirth += Zone91002_OnUnitRebirth;
-            OnUnitRemoved += Zone91002_OnUnitRemoved;
-        }
-
         private void Zone91002_OnUnitRemoved(InstanceZone zone, InstanceUnit obj)
         {
         }

+ 18 - 15
XmdsVSPlugins/XmdsCommonZone/Zones/ZoneIntervalRebirthMonster.cs

@@ -34,17 +34,26 @@ namespace XmdsCommonZone.Zones
         public ZoneIntervalRebirthMonster(TemplateManager templates, InstanceZoneListener listener, SceneData data, GSCreateAreaData gsData, string bindGameSrvId)
             : base(templates, listener, data, gsData, bindGameSrvId)
         {
-            AddEvents();
+            OnInit += ZoneIntervalRebirthMonster_OnInit;
+            OnUnitDead += ZoneIntervalRebirthMonster_OnUnitDead;
+        }
+
+        protected override void Disposing()
+        {
+            base.Disposing();
+
+            OnInit -= ZoneIntervalRebirthMonster_OnInit;
+            OnUnitDead -= ZoneIntervalRebirthMonster_OnUnitDead;
         }
 
-        /// <summary>
-        /// 从游戏服初始化场景数据
-        /// </summary>
-        /// <param name="timeOpenCloseList">从00点到当前的毫秒数{openTime, closeTime, openTime, closeTime ...}</param>
-        /// <param name="monsterIdProbabilityList">monsterId,万分比概率{monsterId, probability, monsterId, probability ...}</param>
-        /// <param name="createMonsterIntervalMS">创建Monster的时间间隔,单位毫秒</param>
-        /// <param name="maxMonsterCount">创建monster的最大个数</param>
-        public void InitSceneDataFromGameServer(int[] timeOpenCloseList, int[] monsterIdProbabilityList, int createMonsterIntervalMS, int maxMonsterNum)
+            /// <summary>
+            /// 从游戏服初始化场景数据
+            /// </summary>
+            /// <param name="timeOpenCloseList">从00点到当前的毫秒数{openTime, closeTime, openTime, closeTime ...}</param>
+            /// <param name="monsterIdProbabilityList">monsterId,万分比概率{monsterId, probability, monsterId, probability ...}</param>
+            /// <param name="createMonsterIntervalMS">创建Monster的时间间隔,单位毫秒</param>
+            /// <param name="maxMonsterCount">创建monster的最大个数</param>
+            public void InitSceneDataFromGameServer(int[] timeOpenCloseList, int[] monsterIdProbabilityList, int createMonsterIntervalMS, int maxMonsterNum)
         {
             Debug.Assert(!initedFromServer, "ZoneIntervalRebirthMonster.InitSceneDataFromGameServer already call, can not call it twice");
             initedFromServer = true;
@@ -133,12 +142,6 @@ namespace XmdsCommonZone.Zones
             return 3600000 * 24 - time + timeOpenCloseList[0];
         }
 
-        private void AddEvents()
-        {
-            OnInit += ZoneIntervalRebirthMonster_OnInit;
-            OnUnitDead += ZoneIntervalRebirthMonster_OnUnitDead;
-        }
-
         private void ZoneIntervalRebirthMonster_OnInit(InstanceZone zone)
         {
             Log.Error("ZoneIntervalRebirthMonster.ZoneIntervalRebirthMonster_OnInit");