Browse Source

fix:修复地图章节怪物提前被释放的问题

chenbin 1 month ago
parent
commit
07f4530d6d

+ 1 - 1
Assets/Scripts/Business/Runtime/Battle/Components/AI/AOEEntityAI.cs

@@ -180,7 +180,7 @@ namespace FL.Battle.Components.AI
             _aoeTimer = null;
             _stopTimer?.Cancel();
             _stopTimer = null;
-            EventSingle.Instance.Notify(EventDefine.GameMainMapRemoveView, Context.UID);
+            EventSingle.Instance.Notify(EventDefine.GameMainMapRemoveSimpleEntity, Context.UID);
         }
     }
 }

+ 1 - 1
Assets/Scripts/Business/Runtime/Battle/Components/AI/BulletAI.cs

@@ -343,7 +343,7 @@ namespace FL.Battle.Components.AI
             _skill = null;
             _skillVfxs = null;
             _lastTargetIds.Clear();
-            EventSingle.Instance.Notify(EventDefine.GameMainMapRemoveView, Context.UID);
+            EventSingle.Instance.Notify(EventDefine.GameMainMapRemoveSimpleEntity, Context.UID);
         }
 
     }

+ 1 - 1
Assets/Scripts/Business/Runtime/Battle/Components/AI/TrapAI.cs

@@ -128,7 +128,7 @@ namespace FL.Battle.Components.AI
                         target.Calculation.Damage(-_skill.Damage, Context.MasterId, _skill);
                     }
                 }
-                EventSingle.Instance.Notify(EventDefine.GameMainMapRemoveView, Context.UID);
+                EventSingle.Instance.Notify(EventDefine.GameMainMapRemoveSimpleEntity, Context.UID);
             };
             Context.Vfx.Play(vfxArgs);
         }

+ 1 - 3
Assets/Scripts/Business/Runtime/Battle/Enities/Entity.cs

@@ -1,7 +1,5 @@
-using FL.Data;
-using System;
+using System;
 using UnityEngine;
-using XGame.Database;
 
 namespace FL.Battle
 {

+ 1 - 1
Assets/Scripts/Business/Runtime/Event/EventDefine.cs

@@ -16,7 +16,7 @@
         /// <summary>
         /// 移除子弹、陷阱、召唤物等实例对象
         /// </summary>
-        GameMainMapRemoveView,
+        GameMainMapRemoveSimpleEntity,
         /// <summary>
         /// 血量变化
         /// </summary>

+ 1 - 2
Assets/Scripts/Business/Runtime/Map/TestMainMap/EntitiesComponent.Update.cs

@@ -61,8 +61,7 @@ namespace FL.Map.TestMainMap
             var elementBuffs = ListPool.Acquire<IBuff>();
             foreach (var ownerId in buffOwnerIds)
             {
-                if (_entityViewsMap.TryGetValue(ownerId, out var view) &&
-                    view is MonsterEntityView monster &&
+                if (_monsterMap.TryGetValue(ownerId, out var monster) &&
                     monster.IsDead == false &&
                     monster.Buffs.GetElementBuffs(ref elementBuffs))
                 {

+ 27 - 15
Assets/Scripts/Business/Runtime/Map/TestMainMap/EntitiesComponent.cs

@@ -30,12 +30,13 @@ namespace FL.Map.TestMainMap
         /// </summary>
         private const float MONSTER_POSITION_OFFSET = 6;
         private PlayerEntityView _player;
-        private Dictionary<long, PartnerEntityView> _partnerMap = new Dictionary<long, PartnerEntityView>();
+        private Dictionary<long, PartnerEntityView> _partnerMap = new();
+        private Dictionary<long, MonsterEntityView> _monsterMap = new();
         /// <summary>
         /// 地图实例对象,怪物、陷阱、召唤兽等
         /// key:UID
         /// </summary>
-        private Dictionary<long, IEntityView> _entityViewsMap = new Dictionary<long, IEntityView>();
+        private Dictionary<long, IEntityView> _entityViewsMap = new();
         private TargetSelector _selector;
         private ITimer _selectorTimer;
 
@@ -44,7 +45,7 @@ namespace FL.Map.TestMainMap
             InitSelector();
             EventSingle.Instance.AddListener(EventDefine.GameMainMapLoadEntities, OnLoadEntities);
             EventSingle.Instance.AddListener(EventDefine.GameMainMapRemoveEntity, OnRemoveEntity);
-            EventSingle.Instance.AddListener(EventDefine.GameMainMapRemoveView, OnRemoveEntity);
+            EventSingle.Instance.AddListener(EventDefine.GameMainMapRemoveSimpleEntity, OnRemoveSimpleEntity);
             EventSingle.Instance.AddListener(EventDefine.GameMainMapStartMask, OnStartMask);
             EventSingle.Instance.AddListener(EventDefine.GameMainMapGenBullet, OnGenBullet);
             EventSingle.Instance.AddListener(EventDefine.GameMainMapGenCommons, OnGenCommons);
@@ -56,7 +57,7 @@ namespace FL.Map.TestMainMap
         {
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapLoadEntities, OnLoadEntities);
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapRemoveEntity, OnRemoveEntity);
-            EventSingle.Instance.RemoveListener(EventDefine.GameMainMapRemoveView, OnRemoveEntity);
+            EventSingle.Instance.RemoveListener(EventDefine.GameMainMapRemoveSimpleEntity, OnRemoveSimpleEntity);
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapStartMask, OnStartMask);
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapGenBullet, OnGenBullet);
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapGenCommons, OnGenCommons);
@@ -71,9 +72,14 @@ namespace FL.Map.TestMainMap
                 Context.Asset.Recycle(partner);
             }
             _partnerMap.Clear();
-            foreach (var item in _entityViewsMap)
+            foreach(var monster in _monsterMap.Values)
             {
-                Context.Asset.Recycle(item.Value);
+                Context.Asset.Recycle(monster);
+            }
+            _monsterMap.Clear();
+            foreach (var entity in _entityViewsMap.Values)
+            {
+                Context.Asset.Recycle(entity);
             }
             _entityViewsMap.Clear();
             ClearElementBuffs();
@@ -160,7 +166,7 @@ namespace FL.Map.TestMainMap
                         }
                         entityView.Entity = monster;
                         entityView.Entity = monster;
-                        _entityViewsMap.Add(monster.EntityId, entityView);
+                        _monsterMap.Add(monster.EntityId, entityView);
                         _selector.Register(entityView);
                         entityView.Selector = _selector;
                         Context.MapUI.AddEntity(entityView);
@@ -210,7 +216,7 @@ namespace FL.Map.TestMainMap
                     var tarPosition = entity.BirthPosition;
                     tarPosition.y += (-dto.monsterMoveDistance + MONSTER_POSITION_OFFSET);
                     tarPosition = Context.VM.EnemyRoot.TransformPoint(tarPosition);
-                    var entityView = _entityViewsMap[entity.EntityId] as MonsterEntityView;
+                    var entityView = _monsterMap[entity.EntityId];
                     entityView.CommonAI.MoveToBattle(tarPosition, dto.monsterMoveDelay);
                 }
             });
@@ -220,14 +226,11 @@ namespace FL.Map.TestMainMap
         private void OnRemoveEntity(int eventId, object args)
         {
             var entityId = (long)args;
-            if (_entityViewsMap.TryGetValue(entityId, out var entityView))
+            if (_monsterMap.TryGetValue(entityId, out var monster))
             {
-                _entityViewsMap.Remove(entityId);
-                if (entityView is ITarget target)
-                {
-                    _selector?.Unregister(target);
-                }
-                Context.Asset.Recycle(entityView);
+                _monsterMap.Remove(entityId);
+                _selector?.Unregister(monster);
+                Context.Asset.Recycle(monster);
                 RemoveElementBuff(entityId);
                 return;
             }
@@ -246,6 +249,15 @@ namespace FL.Map.TestMainMap
                 Context.VM.Camera.Target = null;
             }
         }
+        private void OnRemoveSimpleEntity(int eventId, object args)
+        {
+            var entityId = (long)args;
+            if (_entityViewsMap.TryGetValue(entityId, out var entityView))
+            {
+                _entityViewsMap.Remove(entityId);
+                Context.Asset.Recycle(entityView);
+            }
+        }
         #endregion
 
         #region 目标选择