Browse Source

fix:圣兵一键上阵事件

chenbin 3 days ago
parent
commit
5df193517b

+ 6 - 5
Assets/Scripts/Business/Runtime/Battle/Enities/MonsterEntity.cs

@@ -3,11 +3,11 @@
     public class MonsterEntity : Entity
     {
         public override EEntityType EntityType => EEntityType.Monster;
-        /// <summary>
-        /// 出生坐标的索引
-        /// 死亡时需要归还该索引
-        /// </summary>
-        public int PositionIdx { get; set; }
+        ///// <summary>
+        ///// 出生坐标的索引
+        ///// 死亡时需要归还该索引
+        ///// </summary>
+        //public int PositionIdx { get; set; }
         /// <summary>
         /// 出生时延时
         /// 单位: 毫秒
@@ -18,5 +18,6 @@
         /// 0表示不用轨迹,默认直线
         /// </summary>
         public int BirthCurve { get; set; }
+        public bool IsBoss { get; set; }
     }
 }

+ 0 - 1
Assets/Scripts/Business/Runtime/FGUI/Item/GetItemPanel/ItemGetItemPanelCtrl.cs

@@ -10,7 +10,6 @@ using FL.Data.Items;
 using FL.Network;
 using System.Collections.Generic;
 using System.Linq;
-using System.Runtime.Remoting.Contexts;
 using XGame.Database;
 using XGame.Framework;
 using XGame.Framework.Time;

+ 1 - 1
Assets/Scripts/Business/Runtime/FGUI/Main/BossLaiXi/MainBossLaiXiView.cs

@@ -15,7 +15,7 @@ namespace FL.FGUI
     }
     public partial class MainBossLaiXiView : UIView
     {
-        public static UILayer Layer => UILayer.Popup;
+        public static UILayer Layer => UILayer.MapUI;
         protected override void AddController(IUIControllerGroup group)
         {
             group.Add(new MainBossLaiXiCtrl());

+ 10 - 1
Assets/Scripts/Business/Runtime/FGUI/UIExtensions.cs

@@ -1,4 +1,5 @@
-using XGame.Framework.UI;
+using XGame.Framework;
+using XGame.Framework.UI;
 
 namespace FL.FGUI
 {
@@ -8,5 +9,13 @@ namespace FL.FGUI
         {
             EventSingle.Instance.Notify(EventDefine.ShowTips, tips);
         }
+        public static void AddListener(this UIContext context, EventDefine eventId, EventDelegate handler)
+        {
+            EventSingle.Instance.AddListener(eventId, handler);
+        }
+        public static void RemoveListener(this UIContext context, EventDefine eventId, EventDelegate handler)
+        {
+            EventSingle.Instance.RemoveListener(eventId, handler);
+        }
     }
 }

+ 2 - 0
Assets/Scripts/Business/Runtime/Map/Entities/MonsterEntityView.cs

@@ -24,6 +24,8 @@ namespace FL.Map
         void ISkillContext.OnSkillStart(int skillId)
         {
             //TOTO 临时代码
+            if ((Entity as MonsterEntity).IsBoss)
+                return;
             if (States.IsState(EEntityState.MoveAI))
             {
                 Move.Pause();

+ 104 - 77
Assets/Scripts/Business/Runtime/Nodes/GameMain/MapComponent.cs

@@ -36,18 +36,18 @@ namespace FL.Nodes.GameMain
         private bool _isBossChallenge;
 
         private PlayerEntity _player;
-        /// <summary>
-        /// 怪物坐标相对出生点的偏移值
-        /// 怪物最多13个,分两排排列,索引如下
-        /// 二排   9 5 1 2 6 10
-        /// 一排 11 7 3 0 4 8 12
-        /// 0的左边偏移值为负数
-        /// </summary>
-        private Vector3 _monsterOffset = new Vector3(0.8f, 1.5f, 0);
-        /// <summary>
-        /// 空闲的怪物位置索引
-        /// </summary>
-        private List<int> _unusedIndexs;
+        ///// <summary>
+        ///// 怪物坐标相对出生点的偏移值
+        ///// 怪物最多13个,分两排排列,索引如下
+        ///// 二排   9 5 1 2 6 10
+        ///// 一排 11 7 3 0 4 8 12
+        ///// 0的左边偏移值为负数
+        ///// </summary>
+        //private Vector3 _monsterOffset = new Vector3(0.8f, 1.5f, 0);
+        ///// <summary>
+        ///// 空闲的怪物位置索引
+        ///// </summary>
+        //private List<int> _unusedIndexs;
         /// <summary>
         /// 怪物的实例对象
         /// </summary>
@@ -64,8 +64,10 @@ namespace FL.Nodes.GameMain
             EventSingle.Instance.AddListener(EventDefine.GameMainMapEndMask, OnMapEndMask);
             EventSingle.Instance.AddListener(EventDefine.PartnerDown, OnPartnerDown);
             EventSingle.Instance.AddListener(EventDefine.PartnerUp, OnPartnerUp);
+            EventSingle.Instance.AddListener(EventDefine.PartnerPlanChange, OnPartnersChanged);
+            EventSingle.Instance.AddListener(EventDefine.PartnerWearAll, OnPartnersChanged);
             EventSingle.Instance.AddListener(EventDefine.GameMainMapChallengeBoss, OnChallengeBoss);
-            InitMonsters();
+            //InitMonsters();
             StartMap(PlayerData.Instance.chapterId);
         }
 
@@ -75,6 +77,8 @@ namespace FL.Nodes.GameMain
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapEndMask, OnMapEndMask);
             EventSingle.Instance.RemoveListener(EventDefine.PartnerDown, OnPartnerDown);
             EventSingle.Instance.RemoveListener(EventDefine.PartnerUp, OnPartnerUp);
+            EventSingle.Instance.RemoveListener(EventDefine.PartnerPlanChange, OnPartnersChanged);
+            EventSingle.Instance.RemoveListener(EventDefine.PartnerWearAll, OnPartnersChanged);
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapChallengeBoss, OnChallengeBoss);
 
             _player = null;
@@ -86,23 +90,23 @@ namespace FL.Nodes.GameMain
             _isBossFailed = false;
             _isBossChallenge = false;
             _monsterMap?.Clear();
-            _unusedIndexs?.Clear();
+            //_unusedIndexs?.Clear();
 
             Context.Map.Close(_currentMap);
             _currentMap = null;
         }
 
-        private void InitMonsters()
-        {
-            if (_unusedIndexs == null)
-                _unusedIndexs = new List<int>();
-            else
-                _unusedIndexs.Clear();
-            for (var i = 0; i < 13; i++)
-            {
-                _unusedIndexs.Add(i);
-            }
-        }
+        //private void InitMonsters()
+        //{
+        //    if (_unusedIndexs == null)
+        //        _unusedIndexs = new List<int>();
+        //    else
+        //        _unusedIndexs.Clear();
+        //    for (var i = 0; i < 13; i++)
+        //    {
+        //        _unusedIndexs.Add(i);
+        //    }
+        //}
         private void StartMap(int chapterId)
         {
             _chapterId = chapterId;
@@ -316,58 +320,58 @@ namespace FL.Nodes.GameMain
             position.x += (index % cols) * offset;
             return position;
         }
-        /// <summary>
-        /// 获取怪物的出生坐标和索引
-        /// </summary>
-        /// <param name="position"></param>
-        /// <param name="positionIdx"></param>
-        /// <returns></returns>
-        private Vector3 GetMonsterBirth(Vector3 position, out int positionIdx)
-        {
-            if (_unusedIndexs.Count > 0)
-            {
-                positionIdx = _unusedIndexs[0];
-                _unusedIndexs.RemoveAt(0);
-            }
-            else
-            {
-                positionIdx = 0;
-            }
-            if (positionIdx == 0)
-            {
-                return position;
-            }
-            var offset = Vector3.zero;
-            var xMultiple = (positionIdx + 1) / 2;
-            offset.x = _monsterOffset.x * xMultiple;
-            if (positionIdx % 2 != 0)
-            { // 索引为奇数的在左边
-                offset.x = -offset.x;
-            }
-            if (xMultiple % 2 != 0)
-            { // 倍数为奇数的在上面
-                offset.y = _monsterOffset.y;
-            }
-            var target = position + offset;
-            // 随机偏移xy(-0.2, 0.2)
-            target.x += Random.Range(-0.25f, 0.25f);
-            target.y += Random.Range(-0.25f, 0.25f);
-            return target;
-        }
-        private void PushMonstPositionIdx(int positionIdx)
-        {
-            if (_unusedIndexs.Contains(positionIdx))
-                return; // 避免重复记录
-            for (var i = 0; i < _unusedIndexs.Count; i++)
-            {
-                if (positionIdx < _unusedIndexs[i] && (i == 0 || positionIdx > _unusedIndexs[i - 1]))
-                { // 小于当前索引的值 且 大于(i - 1 )的值
-                    _unusedIndexs.Insert(i, positionIdx);
-                    return;
-                }
-            }
-            _unusedIndexs.Add(positionIdx);
-        }
+        ///// <summary>
+        ///// 获取怪物的出生坐标和索引
+        ///// </summary>
+        ///// <param name="position"></param>
+        ///// <param name="positionIdx"></param>
+        ///// <returns></returns>
+        //private Vector3 GetMonsterBirth(Vector3 position, out int positionIdx)
+        //{
+        //    if (_unusedIndexs.Count > 0)
+        //    {
+        //        positionIdx = _unusedIndexs[0];
+        //        _unusedIndexs.RemoveAt(0);
+        //    }
+        //    else
+        //    {
+        //        positionIdx = 0;
+        //    }
+        //    if (positionIdx == 0)
+        //    {
+        //        return position;
+        //    }
+        //    var offset = Vector3.zero;
+        //    var xMultiple = (positionIdx + 1) / 2;
+        //    offset.x = _monsterOffset.x * xMultiple;
+        //    if (positionIdx % 2 != 0)
+        //    { // 索引为奇数的在左边
+        //        offset.x = -offset.x;
+        //    }
+        //    if (xMultiple % 2 != 0)
+        //    { // 倍数为奇数的在上面
+        //        offset.y = _monsterOffset.y;
+        //    }
+        //    var target = position + offset;
+        //    // 随机偏移xy(-0.2, 0.2)
+        //    target.x += Random.Range(-0.25f, 0.25f);
+        //    target.y += Random.Range(-0.25f, 0.25f);
+        //    return target;
+        //}
+        //private void PushMonstPositionIdx(int positionIdx)
+        //{
+        //    if (_unusedIndexs.Contains(positionIdx))
+        //        return; // 避免重复记录
+        //    for (var i = 0; i < _unusedIndexs.Count; i++)
+        //    {
+        //        if (positionIdx < _unusedIndexs[i] && (i == 0 || positionIdx > _unusedIndexs[i - 1]))
+        //        { // 小于当前索引的值 且 大于(i - 1 )的值
+        //            _unusedIndexs.Insert(i, positionIdx);
+        //            return;
+        //        }
+        //    }
+        //    _unusedIndexs.Add(positionIdx);
+        //}
         private MonsterEntity[] GenMonsters()
         {
             var chapter = ChapterTableRepo.Get(_chapterId);
@@ -421,6 +425,7 @@ namespace FL.Nodes.GameMain
                     entity.BirthPosition = position;
                     entity.BirthDelay = row * chapter.Interval + (isBossPart ? 1000 : 0); // boss额外加1000毫秒延迟
                     entity.BirthCurve = curve;
+                    entity.IsBoss = monsterTab.Type == 2;
                     monsters[i] = entity;
                 }
                 return monsters;
@@ -487,6 +492,28 @@ namespace FL.Nodes.GameMain
             dto.partners = partners;
             EventSingle.Instance.Notify(EventDefine.GameMainMapLoadEntities, dto);
         }
+        private void OnPartnersChanged(int eventId, object args)
+        {
+            //TODO 临时代码
+            if (_partnerMap == null) return;
+            var partnerIds = _partnerMap.Keys.ToList();
+            _partnerMap.Clear();
+            foreach (var partnerId in partnerIds)
+            {
+                EventSingle.Instance.Notify(EventDefine.GameMainMapRemoveEntity, partnerId);
+            }
+            var chapter = ChapterTableRepo.Get(_chapterId);
+            var map = MapTableRepo.Get(chapter.Map);
+            var dto = new LoadEntitiesDto();
+            dto.chapterId = _chapterId;
+            //战斗位置
+            dto.battlePosition = GetBattlePosition(map, chapter.Part);// map.BattlePositions[chapter.Part - 1].ToVector3();
+            var partners = GenPartners(dto.battlePosition);
+            AddPartners(partners);
+            dto.partners = partners;
+            EventSingle.Instance.Notify(EventDefine.GameMainMapLoadEntities, dto);
+
+        }
         private void OnChallengeBoss(int eventId, object args)
         {
             CombatFailed(true);