| | |
| | | using System; |
| | | using System.Collections.Generic; |
| | | using System.Linq; |
| | | using LitJson; |
| | | using Spine.Unity; |
| | | using UnityEngine; |
| | | |
| | | |
| | | public class BattleObjectBuffMgr |
| | | { |
| | | // private Dictionary<BuffBase, EffectPlayer> buffDict = new Dictionary<BuffBase, EffectPlayer>(); |
| | | |
| | | public Action onBuffChanged; |
| | | |
| | | public Action<int, bool> onIsControlChanged; |
| | | |
| | | private Dictionary<int/*EffectId*/, KeyValuePair<BattleEffectPlayer, HashSet<uint/*BuffID*/>>> buffEffectDict = new Dictionary<int, KeyValuePair<BattleEffectPlayer, HashSet<uint>>>(); |
| | | |
| | | private Dictionary<uint, HB428_tagSCBuffRefresh> buffDataDict = new Dictionary<uint, HB428_tagSCBuffRefresh>(); |
| | | |
| | | private BattleObject battleObject; |
| | | |
| | | private static Dictionary<string, List<int>> buffGroupStateDict = null; |
| | | |
| | | public Dictionary<int, bool> isControled = new Dictionary<int, bool>() |
| | | { |
| | | { BattleConst.HardControlGroup, false }, |
| | | { BattleConst.SoftControlGroup, false }, |
| | | { BattleConst.NormalAttackLimitGroup, false }, |
| | | { BattleConst.RageAttackLimitGroup, false }, |
| | | { BattleConst.PassiveSkillLimitGroup, false }, |
| | | }; |
| | | |
| | | public void Init(BattleObject _battleObject) |
| | | { |
| | | battleObject = _battleObject; |
| | | InitBuffGroupStateDict(); |
| | | } |
| | | |
| | | public void Release() |
| | | { |
| | | onBuffChanged = null; |
| | | buffGroupStateDict = null; |
| | | RemoveAllBuff(); |
| | | |
| | | } |
| | | |
| | | // 增加buff |
| | | public void AddBuff(HB428_tagSCBuffRefresh vNetData) |
| | | public void Run() |
| | | { |
| | | // BuffBase buffBase = BuffFactory.CreateBuff(vNetData, battleObject); |
| | | // if (null == buffBase) |
| | | // { |
| | | // return; |
| | | // } |
| | | |
| | | // buffBase.OnAdd(); |
| | | List<int> removeEffectList = new List<int>(); |
| | | // 跟随BattleObject |
| | | foreach (var kv in buffEffectDict) |
| | | { |
| | | BattleEffectPlayer effectPlayer = kv.Value.Key; |
| | | if (null != effectPlayer) |
| | | { |
| | | if (effectPlayer.isBindBone) |
| | | { |
| | | effectPlayer.FollowBoneXY(); |
| | | return; |
| | | } |
| | | int[] effectPos = effectPlayer.effectConfig.effectPos; |
| | | effectPlayer.transform.position = battleObject.heroRectTrans.position; |
| | | if (null != effectPos && effectPos.Length >= 2) |
| | | { |
| | | effectPlayer.rectTrans.anchoredPosition += new Vector2(effectPos[0], effectPos[1]); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | removeEffectList.Add(kv.Key); |
| | | } |
| | | } |
| | | |
| | | foreach (var effectId in removeEffectList) |
| | | { |
| | | buffEffectDict.Remove(effectId); |
| | | } |
| | | } |
| | | |
| | | 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(); |
| | | |
| | | OnBuffChanged(); |
| | | } |
| | | |
| | | // 删除buff |
| | | public void RemoveBuff(HB429_tagSCBuffDel vNetData) |
| | | { |
| | | var tempvNetData = vNetData; |
| | | BuffUnmountAction buffRemoveAction = new BuffUnmountAction(battleObject.battleField, new List<HB429_tagSCBuffDel>() { vNetData }, () => |
| | | { |
| | | HB428_tagSCBuffRefresh buffData = null; |
| | | |
| | | // buffBase.OnRemove(); |
| | | bool isRemove = false; |
| | | |
| | | if (buffDataDict.TryGetValue(tempvNetData.BuffID, out buffData)) |
| | | { |
| | | isRemove = true; |
| | | buffDataDict.Remove(tempvNetData.BuffID); |
| | | } |
| | | |
| | | if (!isRemove) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | bool isRemoveEffect = false; |
| | | |
| | | int remainCnt = -1; |
| | | |
| | | if (buffData != null) |
| | | { |
| | | SkillConfig skillConfig = SkillConfig.Get((int)buffData.SkillID); |
| | | |
| | | if (null == skillConfig || skillConfig.BuffEffect <= 0) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | KeyValuePair<BattleEffectPlayer, HashSet<uint>> effectPair; |
| | | |
| | | if (buffEffectDict.TryGetValue(skillConfig.BuffEffect, out effectPair)) |
| | | { |
| | | effectPair.Value.Remove(buffData.BuffID); |
| | | |
| | | remainCnt = effectPair.Value.Count; |
| | | |
| | | if (effectPair.Value.Count == 0) |
| | | { |
| | | // 没有这个buff了 |
| | | isRemoveEffect = true; |
| | | battleObject.battleField.battleEffectMgr.RemoveEffect(skillConfig.BuffEffect, effectPair.Key); |
| | | buffEffectDict.Remove(skillConfig.BuffEffect); |
| | | } |
| | | } |
| | | |
| | | if (buffGroupStateDict[BattleConst.HardControlGroup.ToString()].Contains(skillConfig.BuffState)) |
| | | { |
| | | BattleDebug.LogError("[BattleObjectBuffMgr]移除对象 " + battleObject.ObjID + " 的buff id " + tempvNetData.BuffID + " BuffState is " + skillConfig.BuffState + " 是否删除了字典内的内容 " + isRemove.ToString() + " 是否删除了特效 " + isRemoveEffect.ToString() + " pack uid 是 " + vNetData.packUID); |
| | | } |
| | | } |
| | | |
| | | // 不做表现 |
| | | OnBuffChanged(); |
| | | }); |
| | | |
| | | battleObject.battleField.recordPlayer.PlayRecord(buffRemoveAction); |
| | | |
| | | } |
| | | |
| | | // 刷新buff |
| | | public void RefreshBuff(HB428_tagSCBuffRefresh vNetData, bool insert = false) |
| | | { |
| | | if (battleObject.IsDead()) |
| | | { |
| | | Debug.LogError("给死亡对象刷新buff 检查服务器代码"); |
| | | RemoveAllBuff(); |
| | | return; |
| | | } |
| | | |
| | | SkillConfig skillConfig = SkillConfig.Get((int)vNetData.SkillID); |
| | | |
| | | if (null == skillConfig) |
| | | { |
| | | Debug.LogError("buff对应的技能不存在,skillId : " + vNetData.SkillID); |
| | | return; |
| | | } |
| | | |
| | | var tempvNetData = vNetData; |
| | | |
| | | if (tempvNetData.IsAdd != 0) |
| | | { |
| | | BuffMountAction buffMountAction = new BuffMountAction(battleObject.battleField, new List<HB428_tagSCBuffRefresh>() { tempvNetData }, () => |
| | | { |
| | | if (buffDataDict.ContainsKey(tempvNetData.BuffID)) |
| | | { |
| | | buffDataDict[tempvNetData.BuffID] = tempvNetData; |
| | | } |
| | | else |
| | | { |
| | | buffDataDict.Add(tempvNetData.BuffID, tempvNetData); |
| | | } |
| | | |
| | | if (battleObject.IsDead()) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (null != skillConfig && skillConfig.BuffEffect > 0) |
| | | { |
| | | // 已经存在相同的buff特效 |
| | | if (buffEffectDict.TryGetValue(skillConfig.BuffEffect, out KeyValuePair<BattleEffectPlayer, HashSet<uint>> pair)) |
| | | { |
| | | pair.Value.Add(tempvNetData.BuffID); |
| | | } |
| | | else |
| | | { |
| | | BattleEffectPlayer effect = battleObject.battleField.battleEffectMgr.PlayEffect(battleObject, skillConfig.BuffEffect, battleObject.heroRectTrans, battleObject.Camp); |
| | | |
| | | BoneFollower boneFollower = effect.AddMissingComponent<BoneFollower>(); |
| | | |
| | | effect.BindBone(battleObject.motionBase.skeletonAnim, effect.effectConfig.nodeName); |
| | | |
| | | HashSet<uint> buffIdSet = new HashSet<uint>(); |
| | | buffIdSet.Add(tempvNetData.BuffID); |
| | | buffEffectDict.Add(skillConfig.BuffEffect, new KeyValuePair<BattleEffectPlayer, HashSet<uint>>(effect, buffIdSet)); |
| | | } |
| | | |
| | | } |
| | | |
| | | if (skillConfig != null && buffGroupStateDict[BattleConst.HardControlGroup.ToString()].Contains(skillConfig.BuffState)) |
| | | { |
| | | BattleDebug.LogError("[BattleObjectBuffMgr]添加对象 " + battleObject.ObjID + " 的buff id " + tempvNetData.BuffID + " pack uid 是 " + tempvNetData.packUID + " BuffState is " + skillConfig.BuffState); |
| | | } |
| | | |
| | | OnBuffChanged(); |
| | | }); |
| | | if (insert) |
| | | { |
| | | battleObject.battleField.recordPlayer.ImmediatelyPlay(buffMountAction); |
| | | } |
| | | else |
| | | { |
| | | battleObject.battleField.recordPlayer.PlayRecord(buffMountAction); |
| | | } |
| | | } |
| | | else |
| | | { |
| | | if (buffDataDict.ContainsKey(tempvNetData.BuffID)) |
| | | { |
| | | buffDataDict[tempvNetData.BuffID] = tempvNetData; |
| | | } |
| | | else |
| | | { |
| | | buffDataDict.Add(tempvNetData.BuffID, tempvNetData); |
| | | } |
| | | // 已经存在的buff 刷新 |
| | | OnBuffChanged(); |
| | | } |
| | | } |
| | | |
| | | private void InitBuffGroupStateDict() |
| | | { |
| | | if (null == buffGroupStateDict) |
| | | { |
| | | FuncConfigConfig buffGroupStateConfig = FuncConfigConfig.Get("BuffStateGroup"); |
| | | buffGroupStateDict = JsonMapper.ToObject<Dictionary<string, List<int>>>(buffGroupStateConfig.Numerical1); |
| | | } |
| | | } |
| | | |
| | | private void OnBuffChanged() |
| | | { |
| | | |
| | | UpdateControlState(); |
| | | |
| | | battleObject.heroInfoBar.RefreshBuff(buffDataDict.Values.ToList()); |
| | | onBuffChanged?.Invoke(); |
| | | |
| | | // bool isUnderControl = false; |
| | | |
| | | // foreach (var kv in buffDataDict) |
| | | // { |
| | | // HB428_tagSCBuffRefresh hB428_TagSCBuffRefresh = kv.Value; |
| | | // SkillConfig skillConfig = SkillConfig.Get((int)hB428_TagSCBuffRefresh.SkillID); |
| | | // if (null != skillConfig && skillConfig.IsControlBuff()) |
| | | // { |
| | | // isUnderControl = true; |
| | | // break; |
| | | // } |
| | | // } |
| | | } |
| | | |
| | | private void UpdateControlState() |
| | | { |
| | | UpdateControlState(BattleConst.HardControlGroup); |
| | | UpdateControlState(BattleConst.SoftControlGroup); |
| | | UpdateControlState(BattleConst.NormalAttackLimitGroup); |
| | | UpdateControlState(BattleConst.RageAttackLimitGroup); |
| | | UpdateControlState(BattleConst.PassiveSkillLimitGroup); |
| | | } |
| | | |
| | | private void UpdateControlState(int groupType) |
| | | { |
| | | bool isChange = false; |
| | | bool curState = isControled[groupType]; |
| | | bool newState = IsUnderControl(groupType); |
| | | isControled[groupType] = newState; |
| | | isChange = curState != newState; |
| | | if (isChange) |
| | | { |
| | | onIsControlChanged?.Invoke(groupType, newState); |
| | | } |
| | | } |
| | | |
| | | private bool IsUnderControl(int groupType) |
| | | { |
| | | |
| | | foreach (var kv in buffDataDict) |
| | | { |
| | | HB428_tagSCBuffRefresh hB428_TagSCBuffRefresh = kv.Value; |
| | | SkillConfig skillConfig = SkillConfig.Get((int)hB428_TagSCBuffRefresh.SkillID); |
| | | |
| | | if (null != skillConfig) |
| | | { |
| | | int buffState = skillConfig.BuffState; |
| | | |
| | | if (buffGroupStateDict != null && buffGroupStateDict.TryGetValue(groupType.ToString(), out List<int> buffGroupState)) |
| | | { |
| | | if (buffGroupState.Contains(buffState)) |
| | | { |
| | | // if (groupType == 1) |
| | | // { |
| | | // // Debug.LogError("对象 " + battleObject.ObjID + " 受到了 " + skillConfig.SkillID + " 的控制效果,BuffState:" + buffState + " buffGroup :" + groupType + " buff id is " + hB428_TagSCBuffRefresh.BuffID + " ralate skill id is " + hB428_TagSCBuffRefresh.RelatedSkillID + " pack uid is " + hB428_TagSCBuffRefresh.packUID); |
| | | // } |
| | | return true; |
| | | } |
| | | } |
| | | } |
| | | } |
| | | |
| | | return false; |
| | | } |
| | | |
| | | public List<HB428_tagSCBuffRefresh> GetBuffList() |
| | | { |
| | | return buffDataDict.Values.ToList(); |
| | | } |
| | | |
| | | public void InsertBuff(HB428_tagSCBuffRefresh vNetData) |
| | | { |
| | | RefreshBuff(vNetData, true); |
| | | } |
| | | } |