public bool ExcuteRelationship(List <BaseBuff> buffList, BuffCnf newCnf) { bool result = false; int length = buffList.Count; for (int i = length - 1; i >= 0; i--) { BaseBuff oldBuff = buffList[i]; if (!oldBuff.Info.CheckGroupById(newCnf.groupID)) { continue; } int newLv = newCnf.level; BuffInfo oldInfo = oldBuff.Info; int lvInfo = oldInfo.CheckLevel(newLv); if (lvInfo == BuffInfo.LESS) // 新buff等级低 { result = true; BuffLog.Log("新buff等级低 不处理,新Buff:[{0}],levell:[{1}],老Buff[{2}],level:[{3}]", newCnf.desc, newCnf.level, oldInfo.ToDes(), oldInfo.Level); break; } } return(result); }
public static BaseBuff Create(int buffId) { TestBuffFactoryMethod.CreateData(); BuffCnf buffObj = StaticCnf.FindData <BuffCnf>(buffId); BaseBuff buff = new BaseBuff(TestBuffFactoryMethod.info); return(buff); }
// 添加新Buff public void _internal_add_new_buff(BaseEntity caster, BuffCnf buffCnf) { BuffLog.Log("Attach Buff--> [{0}] add buff [{1}] ", _owner.ToDes(), buffCnf.desc); BaseBuff newBuff = _attach_buff(caster, buffCnf.id); /*//新Buff 默认情况下在OnAttach下会增加一层 TODO 剔除*/ bool result = newBuff.AddLayer(); // 触发回调 if (result) { newBuff.RaiseEvent(E_BuffEvent.BUFF_ADD_LAYER); } }
// buff 叠加 public void _internal_buff_overlap(BaseBuff oldBuff, BuffCnf buffCnf) { // 层级+1 bool result = oldBuff.AddLayer(); if (!result) { BuffLog.Log("Buff Add Layer 达到最大等级"); _internal_buff_refresh_time(oldBuff); return; } if (oldBuff.Info.RefreshOnAttach) { _internal_buff_refresh_time(oldBuff); } // 触发回调 // old_buff.RaiseEvent(E_BuffEvent.buff_add_layer); }
// 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个数量"); } }
// buff 覆盖 高等级覆盖低等级 public void _internal_buff_overlay(BaseEntity caster, BaseBuff oldBuff, BuffCnf buffCnf) { DetachBuff(oldBuff._bid); _internal_add_new_buff(caster, buffCnf); }