yyl
2025-09-18 cb018a575005f873135fab3201d1bf6d408e2b6a
Main/System/Battle/Buff/BattleObjectBuffMgr.cs
@@ -6,11 +6,8 @@
public class BattleObjectBuffMgr
{
    // buffId, effectId, EffectPlayer
    private Dictionary<uint, Dictionary<int, BattleEffectPlayer>> buffEffectDict = new Dictionary<uint, Dictionary<int, BattleEffectPlayer>>();
    private Dictionary<int/*EffectId*/, KeyValuePair<BattleEffectPlayer, HashSet<uint/*BuffID*/>>> buffEffectDict = new Dictionary<int, KeyValuePair<BattleEffectPlayer, HashSet<uint>>>();
    //  buffId, buffdata
    private Dictionary<uint, HB428_tagSCBuffRefresh> buffDataDict = new Dictionary<uint, HB428_tagSCBuffRefresh>();
    private BattleObject battleObject;
@@ -25,17 +22,31 @@
    }
    //  增加buff
    public void AddBuff(HB428_tagSCBuffRefresh vNetData)
    public void Run()
    {
        // BuffBase buffBase = BuffFactory.CreateBuff(vNetData, battleObject);
        // if (null == buffBase)
        // {
        //     return;
        // }
        //  跟随BattleObject
        foreach (var kv in buffEffectDict)
        {
            // foreach (var kv2 in effectDict)
            {
                BattleEffectPlayer effectPlayer = kv.Value.Key;
                effectPlayer.transform.position = battleObject.heroRectTrans.position;
            }
        }
    }
        // buffBase.OnAdd();
    public void RemoveAllBuff()
    {
        foreach (var kv in buffEffectDict)
        {
            KeyValuePair<BattleEffectPlayer, HashSet<uint>> pair = kv.Value;
            battleObject.battleField.battleEffectMgr.RemoveEffect(kv.Key, pair.Key);
        }
        buffEffectDict.Clear();
        buffDataDict.Clear();
        battleObject.heroInfoBar.RefreshBuff(buffDataDict.Values.ToList());
    }
    //  删除buff
@@ -50,18 +61,24 @@
        if (buffData != null)
        {
            Dictionary<int, BattleEffectPlayer> effectDict = null;
            SkillConfig skillConfig = SkillConfig.Get((int)buffData.SkillID);
            if (buffEffectDict.TryGetValue(vNetData.BuffID, out effectDict))
            if (null == skillConfig || skillConfig.BuffEffect <= 0)
            {
                SkillConfig skillConfig = SkillConfig.Get((int)buffData.SkillID);
                if (null != skillConfig)
                return;
            }
            KeyValuePair<BattleEffectPlayer, HashSet<uint>> effectPair;
            if (buffEffectDict.TryGetValue(skillConfig.BuffEffect, out effectPair))
            {
                effectPair.Value.Remove(vNetData.BuffID);
                if (effectPair.Value.Count == 0)
                {
                    BattleEffectPlayer effectPlayer = null;
                    if (effectDict.TryGetValue(skillConfig.EffectId, out effectPlayer))
                    {
                        battleObject.battleField.battleEffectMgr.RemoveEffect(skillConfig.EffectId, effectPlayer);
                    }
                    //  没有这个buff了
                    battleObject.battleField.battleEffectMgr.RemoveEffect(skillConfig.BuffEffect, effectPair.Key);
                    buffEffectDict.Remove(skillConfig.BuffEffect);
                }
            }
        }
@@ -70,8 +87,17 @@
        battleObject.heroInfoBar.RefreshBuff(buffDataDict.Values.ToList());
    }
    //  刷新buff
    public void RefreshBuff(HB428_tagSCBuffRefresh vNetData)
    {
        SkillConfig skillConfig = SkillConfig.Get((int)vNetData.SkillID);
        if (null == skillConfig)
        {
            Debug.LogError("buff对应的技能不存在,skillId : " + vNetData.SkillID);
            return;
        }
        bool isNew = false;
        if (buffDataDict.ContainsKey(vNetData.BuffID))
        {
@@ -86,35 +112,31 @@
        if (isNew)
        {
            BuffMountAction buffMountAction = new BuffMountAction(battleObject.battleField, battleObject, vNetData, () =>
            {
                SkillConfig skillConfig = SkillConfig.Get((int)vNetData.SkillID);
                if (null != skillConfig && skillConfig.EffectId > 0)
            {
                if (null != skillConfig && skillConfig.BuffEffect > 0)
                {
                    // Dictionary<uint, Dictionary<int, BattleEffectPlayer>> buffEffectDict
                    Dictionary<int, BattleEffectPlayer> effectDict = null;
                    if (buffEffectDict.TryGetValue(vNetData.BuffID, out effectDict))
                    //  已经存在相同的buff特效
                    if (buffEffectDict.TryGetValue(skillConfig.BuffEffect, out KeyValuePair<BattleEffectPlayer, HashSet<uint>> pair))
                    {
                        //  存在这个buffid的特效字典
                        if (effectDict.ContainsKey(skillConfig.EffectId))
                        {
                            Debug.LogError("已存在同样的buff特效 " + skillConfig.EffectId);
                        }
                        else
                        {
                            BattleEffectPlayer effect = battleObject.battleField.battleEffectMgr.PlayEffect(battleObject, skillConfig.EffectId, battleObject.heroRectTrans, battleObject.Camp);
                            effectDict.Add(skillConfig.EffectId, effect);
                        }
                        pair.Value.Add(vNetData.BuffID);
                    }
                    else
                    {
                        effectDict = new Dictionary<int, BattleEffectPlayer>();
                        BattleEffectPlayer effect = battleObject.battleField.battleEffectMgr.PlayEffect(battleObject, skillConfig.EffectId, battleObject.heroRectTrans, battleObject.Camp);
                        effectDict.Add(skillConfig.EffectId, effect);
                        buffEffectDict.Add(vNetData.BuffID, effectDict);
                        BattleEffectPlayer effect = battleObject.battleField.battleEffectMgr.PlayEffect(battleObject, skillConfig.BuffEffect, battleObject.heroRectTrans, battleObject.Camp);
                        HashSet<uint> buffIdSet = new HashSet<uint>();
                        buffIdSet.Add(vNetData.BuffID);
                        buffEffectDict.Add(skillConfig.BuffEffect, new KeyValuePair<BattleEffectPlayer, HashSet<uint>>(effect, buffIdSet));
                    }
                }
                battleObject.heroInfoBar.RefreshBuff(buffDataDict.Values.ToList());
            });
            battleObject.battleField.recordPlayer.PlayRecord(buffMountAction);
        }
        else
        {
            //  已经存在的buff 刷新
            battleObject.heroInfoBar.RefreshBuff(buffDataDict.Values.ToList());
        }
    }
}