Shield = Buff:New() -- 无敌吸血盾的免疫状态 --local immune0 = nil --local onRoleBeHit=nil -- function Shield:immune0(buff) -- return buff.type == BuffName.Control or buff.isDeBuff or buff.type == BuffName.DOT or (buff.caster~=nil and buff.caster.camp~=self.target.camp and buff.type~= BuffName.Exile) -- end --初始化Buff,通过传入一些自定义参数控制成长相关的数值 function Shield:SetData(...) self.shieldType, -- 护盾类型(1 固定减伤盾 2 百分比减伤盾 3 无敌盾 5.反伤盾 ) self.shieldValue, -- 护盾值(固定减伤盾:减伤值 百分比减伤盾:减伤百分比 无敌盾:吸血率) self.dmgReboundFactor = ... --伤害反弹系数 self.damageSum = 0 --记录承受的伤害 self.isBuff = true self.atk=nil --每次扣除护盾时,记录破盾的对象 self.cover = self.shieldType ~= ShieldTypeName.NormalReduce -- 除固定减伤盾外都不能叠加 -- 刷新排序等级 self.sort = 4 self.triggerNum=0 self.onRoleBeHit=function(atkRole, damage, bCrit, finalDmg, damageType, skill) --damagetype为3 是 舍身济世分摊伤害 if damageType==3 then return end if skill then --技能造成的直接伤害 local rDamage = math.floor(damage*self.shieldValue) if rDamage ~= 0 then self.triggerNum=self.triggerNum+1 BattleUtil.ApplyDamage(nil,self.target,atkRole, rDamage) if self.triggerNum>=self.dmgReboundFactor then self.disperse=true end end end end self.immune0=function(buff) return buff.type == BuffName.Control or buff.isDeBuff or buff.type == BuffName.DOT or (buff.caster.camp~=self.target.camp and buff.type~= BuffName.Exile) end end --初始化后调用一次 function Shield:OnStart() self.target.shield:Add(self) if self.shieldType == ShieldTypeName.AllReduce then self.target.buffFilter:Add(self.immune0) -- 清除所有负面buff BattleLogic.BuffMgr:ClearBuff(self.target, function (buff) return buff.type == BuffName.Control or buff.type == BuffName.DOT or buff.caster.camp~=self.target.camp end) elseif self.shieldType == ShieldTypeName.ThornsReduce then self.target.Event:AddEvent(BattleEventName.RoleBeHit,self.onRoleBeHit,nil,nil,self.target) elseif self.shieldType == ShieldTypeName.ImmuneReduce then self.target.buffFilter:Add(self.immune0) end end --间隔N帧触发,返回true时表示继续触发,返回false立刻触发OnEnd function Shield:OnTrigger() return true end -- 计算护盾 function Shield:CountShield(damage, atkRole,skill) self.atk = atkRole local isImmuneAllReduceShield=false local finalDamage = damage if self.shieldType == ShieldTypeName.NormalReduce then if damage < self.shieldValue then self.shieldValue = self.shieldValue - damage self.damageSum = self.damageSum + damage else self.damageSum = self.damageSum + self.shieldValue finalDamage = damage - self.shieldValue self.shieldValue = 0 self.disperse = true end elseif self.shieldType == ShieldTypeName.RateReduce then --减伤盾只减伤直接伤害,和史弘毅对接的 2020/11/14 by王振兴 if skill then local reduceDamage = math.floor(BattleUtil.ErrorCorrection(damage * self.shieldValue)) finalDamage = damage - reduceDamage self.damageSum = self.damageSum + reduceDamage else finalDamage=damage end elseif self.shieldType == ShieldTypeName.AllReduce then --攻击者免疫无敌盾 isImmuneAllReduceShield=atkRole.isImmuneAllReduceShield --特殊处理 白骨精附加的普攻不会必定暴击 if atkRole.roleId==10091 and skill and skill.type==BattleSkillType.Normal and skill.isAdd then isImmuneAllReduceShield=false end if isImmuneAllReduceShield and skill then finalDamage=damage else finalDamage = 0 end --TODO 计算吸血 if self.shieldValue ~= 0 then local treatValue = math.floor(BattleUtil.ErrorCorrection(damage * self.shieldValue)) BattleUtil.ApplyTreat(self.target, self.target, treatValue) end elseif self.shieldType == ShieldTypeName.ThornsReduce then finalDamage=damage end -- -- self.caster.Event:DispatchEvent(BattleEventName.ShildTrigger, self) self.target.Event:DispatchEvent(BattleEventName.ShildTrigger, self,isImmuneAllReduceShield) BattleLogic.Event:DispatchEvent(BattleEventName.ShildTrigger, self) return finalDamage end --计算无敌盾 function Shield:CountAllReduce(damage,atkRole,skill) local finalDamage = damage local isImmuneAllReduceShield=false if self.shieldType == ShieldTypeName.AllReduce then --攻击者免疫无敌盾 isImmuneAllReduceShield=atkRole.isImmuneAllReduceShield --特殊处理 白骨精附加的普攻不会必定暴击 if atkRole.roleId==10091 and skill and skill.type==BattleSkillType.Normal and skill.isAdd then isImmuneAllReduceShield=false end if atkRole.roleId==10091 and skill and skill.type==BattleSkillType.Special and skill.isAdd and not skill.isTriggerJudge then isImmuneAllReduceShield=false end if isImmuneAllReduceShield and skill then finalDamage=damage else finalDamage = 0 end end return finalDamage end -- 提前计算护盾吸收伤害 function Shield:PreCountShield(damage) local finalDamage = damage if self.shieldType == ShieldTypeName.NormalReduce then if damage > self.shieldValue then finalDamage = damage - self.shieldValue end elseif self.shieldType == ShieldTypeName.RateReduce then local reduceDamage = math.floor(BattleUtil.ErrorCorrection(damage * self.shieldValue)) finalDamage = damage - reduceDamage elseif self.shieldType == ShieldTypeName.AllReduce then finalDamage = 0 elseif self.shieldType == ShieldTypeName.ThornsReduce then finalDamage=damage end return finalDamage end -- 改变护盾值(固定减伤盾:减伤值 百分比减伤盾:减伤百分比 无敌盾:吸血率) function Shield:ChangeShieldValue(type, value) -- 计算 local finalValue = BattleUtil.ErrorCorrection(BattleUtil.CountValue(self.shieldValue, value, type)) self.shieldValue = finalValue -- 发送事件 self.caster.Event:DispatchEvent(BattleEventName.ShildValueChange, self) end --效果结束时调用一次 function Shield:OnEnd() -- 计算反伤 if self.shieldType == ShieldTypeName.NormalReduce then for i = 1, self.target.shield.size do if self.target.shield.buffer[i] == self then local dd = math.floor(self.dmgReboundFactor * self.damageSum) if dd > 0 and self.atk then BattleUtil.ApplyDamage(nil, self.target, self.atk, dd) end -- local arr = RoleManager.Query(function (r) return r.camp ~= self.target.camp end) -- for j = 1, #arr do -- end self.target.shield:Remove(i) break end end elseif self.shieldType == ShieldTypeName.RateReduce then for i = 1, self.target.shield.size do if self.target.shield.buffer[i] == self then self.target.shield:Remove(i) break end end elseif self.shieldType == ShieldTypeName.AllReduce or self.shieldType==ShieldTypeName.ImmuneReduce then -- 移除免疫效果 for i = 1, self.target.buffFilter.size do if self.target.buffFilter.buffer[i] == self.immune0 then self.target.buffFilter:Remove(i) break end end for i = 1, self.target.shield.size do if self.target.shield.buffer[i] == self then self.target.shield:Remove(i) break end end elseif self.shieldType == ShieldTypeName.ThornsReduce then self.target.Event:RemoveEvent(BattleEventName.RoleBeHit,self.onRoleBeHit,nil,nil,self.target) for i = 1, self.target.shield.size do if self.target.shield.buffer[i] == self then self.target.shield:Remove(i) break end end end BattleLogic.Event:DispatchEvent(BattleEventName.ShieldBuffEnd, self) end --只有当cover字段为true时触发,返回true则被新效果覆盖 function Shield:OnCover(newBuff) return true end -- 比较buff function Shield:OnCompare(buff) return self.shieldType == buff.shieldType end return Shield