Przeglądaj źródła

fix:buff/技能预览界面

chenbin 1 miesiąc temu
rodzic
commit
a78bcd7dd9

BIN
Assets/Res/Addressable/FGUI/Main/Main_fui.bytes


+ 1 - 1
Assets/Scripts/Business/Runtime/Battle/Buffs/Api/BuffEventDto.cs

@@ -14,7 +14,7 @@
     {
         public long ownerId;
         public int buffTableId;
-        public long partnerId;
+        public long partnerUID;
         /// <summary>
         /// 是否是技能
         /// false时为铭文

+ 22 - 5
Assets/Scripts/Business/Runtime/Battle/Skills/SkillComponent.cs

@@ -24,11 +24,6 @@ namespace FL.Battle.Components
     }
     public class SkillComponent : Component<ISkillContext>, IReset
     {
-        struct BuffSkillDto
-        {
-            public long skillId;
-            public long targetId;
-        }
 
         private const int NO_SKILL = -1;
         private Dictionary<int, ISkillActor> _usingActors;
@@ -108,6 +103,28 @@ namespace FL.Battle.Components
             return false;
         }
         /// <summary>
+        /// 返回技能的最小剩余时间
+        /// </summary>
+        /// <returns></returns>
+        public int GetMinCooldown()
+        {
+            if (_skillCDTimers.Count == 0)
+                return 0;
+            var remain = int.MaxValue;
+            foreach (var skillId in Context.Entity.ActiveSkillIds)
+            { // 有主动技能在队列里
+                if (_skillQueue.Contains(skillId))
+                    return 0;
+                if (_skillCDTimers.TryGetValue(skillId, out var timer))
+                {
+                    var temp = (timer as Timer).RemainTime;
+                    if (temp < remain)
+                        remain = temp;
+                }
+            }
+            return remain;
+        }
+        /// <summary>
         /// 冷却时间到的技能进入队列等待播放
         /// </summary>
         /// <param name="skillId"></param>

+ 1 - 1
Assets/Scripts/Business/Runtime/Data/Partners/PartnersService.cs

@@ -43,7 +43,7 @@ namespace FL.Data
         {
             if (PartnersData.Instance.IsReachedLimit)
             {
-                Log.Error($"随从已经达到出战数量上限.");
+                EventSingle.Instance.Notify(EventDefine.ShowTips, "随从已经达到出战数量上限.");
                 return;
             }
             var goneUpMap = PartnersData.Instance.GoneUpMap;

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

@@ -54,7 +54,15 @@
         /// <summary>
         /// buff预览
         /// </summary>
-        GameMainMapBuffPreview,
+        GameMainMapPreviewBuff,
+        /// <summary>
+        /// 请求预览Buff列表
+        /// </summary>
+        GameMainMapReqPreviewBuffs,
+        /// <summary>
+        /// 广播预览Buff列表
+        /// </summary>
+        GameMainMapPushPreviewBuffs,
         #endregion
         #region Battle.Component 2000 - 2999
         /// <summary>

+ 39 - 6
Assets/Scripts/Business/Runtime/FGUI/Main/BuffInfoListItem/MainBuffInfoListItemCtrl.cs

@@ -5,6 +5,8 @@
 /// created by cb 2024
 
 using FairyGUI;
+using FL.Battle.Buffs;
+using FL.Data;
 using XGame.Database;
 using XGame.Framework.UI;
 
@@ -36,13 +38,44 @@ namespace FL.FGUI
 
         #endregion
 
-        public void OnRefresh(int index, MainBuffItemData data)
+        public void OnRefresh(int index, BuffPreviewDto dto)
         {
-            var table = BuffTableRepo.Get(data.buffTableId);
-            VM.BuffIcon.url = table.Icon;
-            VM.BuffNameLabel.text = table.Name;
-            VM.BuffLayerPar.max = data.layerLimit;
-            VM.BuffLayerPar.value = data.layer;
+            var buffTable = BuffTableRepo.Get(dto.buffTableId);
+            VM.BuffIcon.url = buffTable.Icon;
+            VM.BuffNameLabel.text = buffTable.Name;
+            VM.BuffLayerPar.max = dto.layerLimit;
+            VM.BuffLayerPar.value = dto.layer;
+            string triggerName;
+            EQualityLevel quality;
+            if (dto.isSkill)
+            {
+                var skill = SkillTableRepo.Get(dto.skillId);
+                if (skill.BuffTie.Length == 2)
+                {
+                    var triBuff = BuffTableRepo.Get(skill.BuffTie[1]);
+                    triggerName = triBuff.Name;
+                }
+                else
+                {
+                    triggerName = skill.Name;
+                }
+                quality = (EQualityLevel)skill.Quality;
+            }
+            else
+            {
+                var epigraph = EpigraphTableRepo.Get(dto.skillId);
+                triggerName = epigraph.Name;
+                quality = epigraph.Quality;
+            }
+            VM.TriggerNameLabel.text = string.Format(StringDefine.common_bracket, triggerName);
+            VM.TriggerNameLabel.color = quality.ToEquipNameColor();
+            VM.TipsLabel.text = dto.layer == dto.layerLimit ? StringDefine.buff_preview_tips_attack : StringDefine.buff_preview_tips_coming;
+            //随从icon
+            if (PartnersData.Instance.PartnersMap.TryGetValue(dto.partnerUID, out var partner))
+            {
+                var partnerTable = PartnerTableRepo.Get(partner.TableId);
+                VM.PartnerIcon.url = partnerTable.Icon;
+            }
         }
     }
 }

+ 2 - 1
Assets/Scripts/Business/Runtime/FGUI/Main/BuffInfoListItem/MainBuffInfoListItemView.ListItem.cs

@@ -5,6 +5,7 @@
 /// created by cb 2024
 
 using FairyGUI;
+using FL.Battle.Buffs;
 
 namespace FL.FGUI
 {
@@ -14,7 +15,7 @@ namespace FL.FGUI
         void IGListItemHandle.OnRefresh(int index, object data)
         {
             ItemIndex = index;
-            Ctrl.OnRefresh(index, data as MainBuffItemData);
+            Ctrl.OnRefresh(index, (BuffPreviewDto)data);
         }
     }
 }

+ 5 - 15
Assets/Scripts/Business/Runtime/FGUI/Main/BuffPreviewPanel/MainBuffPreviewPanelCtrl.cs

@@ -5,6 +5,8 @@
 /// created by cb 2024
 
 using FairyGUI;
+using FL.Battle.Buffs;
+using System.Collections.Generic;
 using XGame.Framework.UI;
 
 namespace FL.FGUI
@@ -18,7 +20,7 @@ namespace FL.FGUI
         protected override void OnEnable(object intent)
         {
             AddUIListenres();
-            Mock();
+            RefreshList(intent as List<BuffPreviewDto>);
         }
         protected override void OnDisable()
         {
@@ -42,22 +44,10 @@ namespace FL.FGUI
 
         #endregion
 
-        private void Mock()
+        private void RefreshList(List<BuffPreviewDto> dtos)
         {
-            var count = 10;
-            var datas = new MainBuffItemData[count];
-            for(var i = 0; i < count; i++)
-            {
-                datas[i] = new MainBuffItemData()
-                {
-                    buffTableId = 20171101,
-                    layer = 4,
-                    layerLimit = 5,
-                };
-            }
             VM.BuffInfoList.ListType = EGListType.Virtual;
-            VM.BuffInfoList.BindDatas(datas);
-
+            VM.BuffInfoList.BindDatas(dtos);
         }
     }
 }

+ 11 - 4
Assets/Scripts/Business/Runtime/FGUI/Main/HomeBuffInfoNested/MainHomeBuffInfoNestedCtrl.cs

@@ -6,6 +6,7 @@
 
 using FairyGUI;
 using FL.Battle.Buffs;
+using System;
 using UnityEngine;
 using XGame.Database;
 using XGame.Framework.UI;
@@ -21,12 +22,14 @@ namespace FL.FGUI
         protected override void OnEnable(object intent)
         {
             AddUIListenres();
-            EventSingle.Instance.AddListener(EventDefine.GameMainMapBuffPreview, OnBuffPreview);
+            EventSingle.Instance.AddListener(EventDefine.GameMainMapPreviewBuff, OnSinglePreviewBuff);
+            EventSingle.Instance.AddListener(EventDefine.GameMainMapPushPreviewBuffs, OnPreviewBuffs);
         }
         protected override void OnDisable()
         {
             RemoveUIListenres();
-            EventSingle.Instance.RemoveListener(EventDefine.GameMainMapBuffPreview, OnBuffPreview);
+            EventSingle.Instance.RemoveListener(EventDefine.GameMainMapPreviewBuff, OnSinglePreviewBuff);
+            EventSingle.Instance.RemoveListener(EventDefine.GameMainMapPushPreviewBuffs, OnPreviewBuffs);
         }
         #region UI事件
         private void AddUIListenres()
@@ -41,13 +44,13 @@ namespace FL.FGUI
         }
         private void OnClickBuffShowBtn(EventContext context)
         {
-            Context.UI.OpenAsync(UIKeys.MainBuffPreviewPanel);
+            EventSingle.Instance.Notify(EventDefine.GameMainMapReqPreviewBuffs);
         }
 
         #endregion
 
 
-        private void OnBuffPreview(int eventId, object args)
+        private void OnSinglePreviewBuff(int eventId, object args)
         {
             var dto = (BuffPreviewDto)args;
             var isShow = dto.buffTableId > 0;
@@ -85,5 +88,9 @@ namespace FL.FGUI
                 VM.TipsLabel.text = dto.layer == dto.layerLimit ? StringDefine.buff_preview_tips_attack : StringDefine.buff_preview_tips_coming;
             }
         }
+        private void OnPreviewBuffs(int eventId, object args)
+        {
+            Context.UI.OpenAsync(UIKeys.MainBuffPreviewPanel, args);
+        }
     }
 }

+ 110 - 24
Assets/Scripts/Business/Runtime/Map/TestMainMap/EntitiesComponent.Update.cs

@@ -1,4 +1,5 @@
 using FL.Battle.Buffs;
+using System;
 using System.Collections.Generic;
 using XGame.Framework;
 using XGame.Framework.Interfaces;
@@ -21,14 +22,48 @@ namespace FL.Map.TestMainMap
         {
             if (!_isElementBuffDirty) return;
             _isElementBuffDirty = false;
-            if (_buffOwnerIds == null || _buffOwnerIds.Count == 0) return;
+            CollectElementBuffs((elementBuffs, partners) =>
+            {
+                var isMatch = false;
+                if (elementBuffs != null)
+                {
+                    foreach (var buff in elementBuffs)
+                    {
+                        foreach (var partner in partners)
+                        {
+                            if (MatchTargetBuff(partner, buff))
+                            {
+                                isMatch = true;
+                                break;
+                            }
+                        }
+                        if (isMatch)
+                        {
+                            break;
+                        }
+                    }
+                }
+                if (!isMatch)
+                { // 没有匹配的项
+                    ResetBuffPreview();
+                }
+            });
+        }
+        private void CollectElementBuffs(Action<List<IBuff>, List<PartnerEntityView>> callback)
+        {
+            if (_buffOwnerIds == null || _buffOwnerIds.Count == 0)
+            {
+                callback.SafeInvoke(null, null);
+                return;
+            }
             var buffOwnerIds = ListPool.Acquire<long>();
             buffOwnerIds.AddRange(_buffOwnerIds);
             var elementBuffs = ListPool.Acquire<IBuff>();
             foreach (var ownerId in buffOwnerIds)
             {
-                if (_entityViewsMap.TryGetValue(ownerId, out var view) && 
-                    view is MonsterEntityView monster && 
+                if (_entityViewsMap.TryGetValue(ownerId, out var view) &&
+                    view is MonsterEntityView monster &&
+                    monster.IsDead == false &&
                     monster.Buffs.GetElementBuffs(ref elementBuffs))
                 {
                     continue;
@@ -42,61 +77,66 @@ namespace FL.Map.TestMainMap
                 var orderB = b.Layers * 1000 / b.LayerLimit;
                 return orderB - orderA;
             });
-            var isMatch = false;
-            foreach (var buff in elementBuffs)
+            // 随从 按照技能冷却时间排序
+            var partners = ListPool.Acquire<PartnerEntityView>();
+            partners.AddRange(_partnerMap.Values);
+            var skillCdMap = new Dictionary<long, int>();
+            partners.Sort((a, b) =>
             {
-                foreach (var partner in _partnerMap.Values)
+                var id_a = a.Entity.EntityId;
+                if (!skillCdMap.TryGetValue(id_a, out var cd_a))
                 {
-                    if (MatchTargetBuff(partner, buff))
-                    {
-                        isMatch = true;
-                        break;
-                    }
+                    cd_a = a.Skill.GetMinCooldown();
+                    skillCdMap.Add(id_a, cd_a);
                 }
-                if (isMatch)
+                var id_b = b.Entity.EntityId;
+                if (!skillCdMap.TryGetValue(id_b, out var cd_b))
                 {
-                    break;
+                    cd_b = a.Skill.GetMinCooldown();
+                    skillCdMap.Add(id_b, cd_b);
                 }
-            }
+                // 冷却时间短的排前面
+                return cd_a - cd_b;
+            });
+            //回调
+            callback.SafeInvoke(elementBuffs, partners);
+            //回收临时变量
+            ListPool.Recycle(partners);
             ListPool.Recycle(buffOwnerIds);
             ListPool.Recycle(elementBuffs);
-            if (!isMatch)
-            { // 没有匹配的项
-                ResetBuffPreview();
-            }
         }
         private bool MatchTargetBuff(PartnerEntityView partner, IBuff buff)
         {
             if (partner.Epigraphics.IsTargetBuff(buff.TableId, out var epigrapId))
             {
-                NotifyBuffPreview(buff, partner.Entity.EntityId, false, epigrapId);
+                NotifyBuffPreview(buff, partner.Entity.Attr.UID, false, epigrapId);
                 return true;
             }
             if (partner.Skill.FindSkillByElementType(buff.ElementType, out var skillId))
             {
-                NotifyBuffPreview(buff, partner.Entity.EntityId, true, skillId);
+                NotifyBuffPreview(buff, partner.Entity.Attr.UID, true, skillId);
                 return true;
             }
             return false;
         } 
-        private void NotifyBuffPreview(IBuff buff, long partnerId, bool isSkill, int skillId)
+        private void NotifyBuffPreview(IBuff buff, long partnerUID, bool isSkill, int skillId)
         {
             _buffPreview = new BuffPreviewDto()
             {
                 ownerId = buff.OwnerId,
                 buffTableId = buff.TableId,
-                partnerId = partnerId,
+                partnerUID = partnerUID,
                 isSkill = isSkill,
                 skillId = skillId,
                 layer = buff.Layers,
                 layerLimit = buff.LayerLimit,
             };
-            EventSingle.Instance.Notify(EventDefine.GameMainMapBuffPreview, _buffPreview);
+            EventSingle.Instance.Notify(EventDefine.GameMainMapPreviewBuff, _buffPreview);
         }
         private void ResetBuffPreview()
         {
             _buffPreview = default;
-            EventSingle.Instance.Notify(EventDefine.GameMainMapBuffPreview, _buffPreview);
+            EventSingle.Instance.Notify(EventDefine.GameMainMapPreviewBuff, _buffPreview);
         }
         private void OnAddBuff(int eventId, object args)
         {
@@ -114,6 +154,52 @@ namespace FL.Map.TestMainMap
                _isElementBuffDirty = true;
             }
         }
+        private void OnRequestBuffList(int eventId, object args)
+        {
+            var buffPreviewDtos = new List<BuffPreviewDto>();
+            CollectElementBuffs((elementBuffs, partners) =>
+            {
+                if (elementBuffs != null)
+                {
+                    foreach (var buff in elementBuffs)
+                    {
+                        foreach (var partner in partners)
+                        {
+                            var partnerUID = partner.Entity.Attr.UID;
+                            if (partner.Epigraphics.IsTargetBuff(buff.TableId, out var epigrapId))
+                            {
+                                var dto = new BuffPreviewDto()
+                                {
+                                    ownerId = buff.OwnerId,
+                                    buffTableId = buff.TableId,
+                                    partnerUID = partnerUID,
+                                    isSkill = false,
+                                    skillId = epigrapId,
+                                    layer = buff.Layers,
+                                    layerLimit = buff.LayerLimit,
+                                };
+                                buffPreviewDtos.Add(dto);
+                            }
+                            if (partner.Skill.FindSkillByElementType(buff.ElementType, out var skillId))
+                            {
+                                var dto = new BuffPreviewDto()
+                                {
+                                    ownerId = buff.OwnerId,
+                                    buffTableId = buff.TableId,
+                                    partnerUID = partnerUID,
+                                    isSkill = true,
+                                    skillId = skillId,
+                                    layer = buff.Layers,
+                                    layerLimit = buff.LayerLimit,
+                                };
+                                buffPreviewDtos.Add(dto);
+                            }
+                        }
+                    }
+                }
+                EventSingle.Instance.Notify(EventDefine.GameMainMapPushPreviewBuffs, buffPreviewDtos);
+            });
+        }
         private void RemoveElementBuff(long ownerId)
         {
             if (_buffPreview.ownerId == ownerId)

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

@@ -10,7 +10,6 @@ using XGame;
 using XGame.Database;
 using XGame.Framework.Asyncs;
 using XGame.Framework.Components;
-using XGame.Framework.Interfaces;
 using XGame.Framework.Map;
 using XGame.Framework.Time;
 
@@ -51,8 +50,8 @@ namespace FL.Map.TestMainMap
             EventSingle.Instance.AddListener(EventDefine.GameMainMapGenCommons, OnGenCommons);
             EventSingle.Instance.AddListener(EventDefine.GameMainMapAddBuff, OnAddBuff);
             EventSingle.Instance.AddListener(EventDefine.GameMainMapRemoveBuff, OnRemoveBuff);
+            EventSingle.Instance.AddListener(EventDefine.GameMainMapReqPreviewBuffs, OnRequestBuffList);
         }
-
         protected override void OnDisable()
         {
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapLoadEntities, OnLoadEntities);
@@ -63,6 +62,7 @@ namespace FL.Map.TestMainMap
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapGenCommons, OnGenCommons);
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapAddBuff, OnAddBuff);
             EventSingle.Instance.RemoveListener(EventDefine.GameMainMapRemoveBuff, OnRemoveBuff);
+            EventSingle.Instance.RemoveListener(EventDefine.GameMainMapReqPreviewBuffs, OnRequestBuffList);
             ClearSelector();
             Context.VM.Camera.Target = null;
             Context.Asset.Recycle(_player);

+ 11 - 0
Assets/Scripts/Framework/Runtime/Time/Impl/Timer.cs

@@ -189,6 +189,17 @@ namespace XGame.Framework.Time
         }
         public int TimeAxis => _timeAxis;
         /// <summary>
+        /// 下一次回调的剩余时间
+        /// </summary>
+        public int RemainTime
+        {
+            get
+            {
+                var interval = _passTimes == 0 ? _delay : _interval;
+                return interval - _timeAxis;
+            }
+        }
+        /// <summary>
         /// 只对Running状态的定时器有效
         /// </summary>
         /// <param name="delay"></param>

+ 2 - 2
fl-fgui-project/assets/Main/BuffInfoListItem.xml

@@ -12,8 +12,8 @@
       <gearDisplay controller="BgCtrl" pages="1"/>
     </image>
     <image id="n8_sbc1" name="n8" src="sbc18w" fileName="images/Daojudikuang.png" xy="16,4"/>
-    <loader id="n2_huso" name="PartnerBgIcon" xy="16,4" size="216,114" touchable="false"/>
-    <loader id="n1_huso" name="PartnerIcon" xy="16,4" size="216,114" touchable="false"/>
+    <loader id="n2_huso" name="PartnerBgIcon" xy="16,4" pivot="0.5,0.5" size="216,114" touchable="false" fill="scaleFree"/>
+    <loader id="n1_huso" name="PartnerIcon" xy="67,-47" pivot="0.5,0.5" size="114,216" rotation="90" touchable="false" fill="scaleFree"/>
     <loader id="n4_huso" name="BuffIcon" xy="425,17" size="78,78" touchable="false" fill="scaleFree"/>
     <component id="n5_huso" name="BuffLayerPar" src="huso8u" fileName="Components/BuffInfoPar.xml" xy="524,64" size="171,25" touchable="false">
       <ProgressBar value="4" max="5"/>