|
@@ -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)
|