// BUG 2018.10.22 针对Buff之间的关系,抽象出一个接口, // 提供给外部 caster(释放buff者)给自身owner添加Buff 处理buff之间的相互关系 重叠/替换/抵消 public void AttachBuff(BaseEntity caster, int buffId) { BuffLog.Assert(!_owner.AttributeProp.IsDead(), "目标[{0}]已经死亡,无法添加Buff:[{1}]", _owner.ToDes(), buffId); if (_owner.AttributeProp.IsDead()) { return; } // 1.根据Id查找对应的ID BuffCnf newCnf = BuffHelper.FindBuffById(buffId); BuffLog.Log("Attach Buff [{0}]", newCnf.desc); // 2.检测buff之间的 关系 int count = 0; int length = _buffList.Count; for (int i = length - 1; i >= 0; i--) { BaseBuff oldBuff = _buffList[i]; if (!oldBuff.Info.CheckGroupById(newCnf.groupID)) { continue; } count++; // TODO BUG逻辑有一定的问题,如果注释掉下面一行代码 //if (count != 1) continue; int newLv = newCnf.level; // 1/0/-1 1=本buff等级更高,0=等级相等,-1=本buff等级会第一点 BuffInfo oldInfo = oldBuff.Info; int lvInfo = oldInfo.CheckLevel(newLv); if (lvInfo == BuffInfo.LESS) // 新buff等级低 { BuffLog.Log("新buff等级低 不处理,新Buff:[{0}],levell:[{1}],老Buff[{2}],level:[{3}]", newCnf.desc, newCnf.level, oldInfo.ToDes(), oldInfo.Level); continue; } if (lvInfo == BuffInfo.EQUAL && oldInfo.Multilayer) // 等级相等,可层级叠加 { BuffLog.Log("Buff:[{0}],等级相等,可层级叠加", oldInfo.ToDes()); _internal_buff_overlap(oldBuff, newCnf); } else if (lvInfo == BuffInfo.EQUAL && !oldInfo.Multilayer) // 等级相等,不可叠加 { BuffLog.Log("Buff:[{0}],等级相等,不可叠加", oldInfo.ToDes()); _internal_buff_refresh_time(oldBuff); } else // 新buff等级高 { BuffLog.Log("Buff:[{0}],新Buff等级高,覆盖", oldInfo.ToDes()); _internal_buff_overlay(caster, _buffList[i], newCnf); } _update_attr(0); //让在update中发挥作用的buff马上生效 } if (count == 0) { _internal_add_new_buff(caster, newCnf); } else if (count > 1) { LogManager.Error("Buff Group Id 超过1个数量"); } }