BuffCtrl = {} local BuffTypeToConfigType = { [BuffName.PropertyChange] = 1, [BuffName.Control] = 2, [BuffName.DOT] = 3, [BuffName.HOT] = 4, [BuffName.Shield] = 5, [BuffName.Immune] = 6, [BuffName.Curse] = 7, [BuffName.KylinMark] = 8, [BuffName.Exile] = 9, } local function _GetPropChangeBuffCType(pName) for cType, pn in ipairs(BattlePropList) do if pn == pName then return cType end end end local function _GetBuffEffectConfig(buff) local bType = buff.type local cType = 1 if bType == BuffName.PropertyChange then cType = _GetPropChangeBuffCType(buff.propertyName) elseif bType == BuffName.HOT then cType = 1 elseif bType == BuffName.DOT then cType = buff.damageType elseif bType == BuffName.Brand then cType = buff.flag elseif bType == BuffName.Control then cType = buff.ctrlType elseif bType == BuffName.Shield then cType = buff.shieldType -- 无敌吸血盾特殊判断 if cType == ShieldTypeName.AllReduce and buff.shieldValue ~= 0 then cType = 4 end elseif bType == BuffName.Immune then cType = buff.immuneType elseif bType == BuffName.Curse then cType = buff.curseType elseif bType== BuffName.KylinMark then cType = 1 elseif bType== BuffName.Exile then cType = 1 end local type = BuffTypeToConfigType[bType] local config = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.BuffEffectConfig, "Type", type, "CType", cType) return config end function BuffCtrl.New(unit, buffRoot) local o = {} setmetatable(o, {__index = BuffCtrl}) o:ctor(unit, buffRoot) return o end function BuffCtrl:ctor(unit, buffRoot) -- LogPink("Buffctrl "..unit.camp.."|"..unit.role.position) self.owner = unit self.owner.role.Event:AddEvent(BattleEventName.BuffStart, self.OnBuffStart, self) self.owner.role.Event:AddEvent(BattleEventName.BuffCover, self.OnBuffCover, self) self.owner.role.Event:AddEvent(BattleEventName.BuffTrigger, self.OnBuffTrigger, self) self.owner.role.Event:AddEvent(BattleEventName.BuffEnd, self.OnBuffEnd, self) self.owner.role.Event:AddEvent(BattleEventName.BuffDodge, self.OnBuffDodge, self) self.owner.role.Event:AddEvent(BattleEventName.BuffRoundChange, self.OnBuffRoundChange, self) self.owner.role.Event:AddEvent(BattleEventName.BuffDurationChange, self.OnBuffRoundChange, self) self.buffRoot = buffRoot self.BuffIconList = {} self.BuffEffectList = {} end function BuffCtrl:Update() for k, v in pairs(self.BuffIconList) do v:Update() end end -- 加载并播放动画 function BuffCtrl:AddBuffEffect(buffName, isTrigger, offset) if not buffName or buffName == "" then return end if not self.BuffEffectList then self.BuffEffectList = {} end if not self.BuffEffectList[buffName] then self.BuffEffectList[buffName] = {} self.BuffEffectList[buffName].node = nil self.BuffEffectList[buffName].count = 0 end -- if not self.BuffEffectList[buffName].node then local sortingOrder if self.owner.camp == 0 then sortingOrder = self.owner.GameObject:GetComponent("Canvas").sortingOrder end local node = BattleManager.LoadAsset(buffName, sortingOrder) -- node.transform:SetParent(self.RootPanel.transform) -- node.transform.localScale = Vector3.one node.transform:SetParent(self.owner.GameObject.transform) node.transform.localScale = Vector3.one node.transform.localPosition = offset and Vector3.New(offset[1], offset[2], 0) or Vector3.zero--self.GameObject.transform.localPosition self.BuffEffectList[buffName].node = node end self.BuffEffectList[buffName].node:SetActive(false) self.BuffEffectList[buffName].node:SetActive(true) -- 触发特效不计数 if not isTrigger then self.BuffEffectList[buffName].count = self.BuffEffectList[buffName].count + 1 end end -- 卸载动画 function BuffCtrl:RemoveBuffEffect(buffName) if not buffName or buffName == "" then return end if not self.BuffEffectList then return end if not self.BuffEffectList[buffName] then return end if not self.BuffEffectList[buffName].node then return end -- 节点存在,数量不存在直接回收 if not self.BuffEffectList[buffName].count then poolManager:UnLoadAsset(buffName, self.BuffEffectList[buffName].node, PoolManager.AssetType.GameObject) self.BuffEffectList[buffName] = nil return end -- 引用数量减1 self.BuffEffectList[buffName].count = self.BuffEffectList[buffName].count - 1 if self.BuffEffectList[buffName].count <= 0 then poolManager:UnLoadAsset(buffName, self.BuffEffectList[buffName].node, PoolManager.AssetType.GameObject) self.BuffEffectList[buffName] = nil return end end -- 卸载所有动画 function BuffCtrl:RemoveAllBuffEffect() if not self.BuffEffectList then return end for name, v in pairs(self.BuffEffectList) do poolManager:UnLoadAsset(name, v.node, PoolManager.AssetType.GameObject) end self.BuffEffectList = {} end -- function BuffCtrl:AddBuffIcon(buff, icon) local currBuff=buff if not currBuff or not icon or icon == "" then return end if not self.BuffIconList then self.BuffIconList = {} end -- if not self.BuffIconList[buff.id] then -- local buffGO = BattlePool.GetItem(self.buffRoot.transform, BATTLE_POOL_TYPE.BUFF_VIEW) -- buffGO.transform.localScale = Vector3.one -- buffGO.transform.localPosition = Vector3.zero -- buffGO:SetActive(true) -- self.BuffIconList[buff.id] = BuffView.New(buffGO, buff, icon) -- else -- self.BuffIconList[buff.id].count = self.BuffIconList[buff.id].count + 1 -- self.BuffIconList[buff.id]:SetCount() -- end LogRed(buff.id) if not self.BuffIconList[currBuff.id] then --便利所有之前存在的buff图标,有同类型,同数值的叠加,否则新建 for key, value in pairs(self.BuffIconList) do local buffType=self.BuffIconList[key].buff.type if currBuff.type == self.BuffIconList[key].buff.type then if buffType == BuffName.PropertyChange then --属性 判断属性类型,属性值,属性修改类型 local b = self.BuffIconList[key].buff if self.BuffIconList[key].buffPropertyName == currBuff.propertyName and self.BuffIconList[key].buffCt == currBuff.changeType and self.BuffIconList[key].buffValue == currBuff.Value then self.BuffIconList[key]:SetCount(self.BuffIconList[key].count+1) return end --持续伤害类型,伤害系数 elseif buffType==BuffName.DOT then if self.BuffIconList[key].buffDamageType==currBuff.damageType and self.BuffIconList[key].buffDamageFactor==currBuff.damageFactor then self.BuffIconList[key]:SetCount(self.BuffIconList[key].count+1) return end --控制类型 elseif buffType == BuffName.Control then if self.BuffIconList[key].buffCtrlType==currBuff.ctrlType then self.BuffIconList[key]:SetCount(self.BuffIconList[key].count+1) return end elseif buffType == BuffName.HOT then if self.BuffIconList[key].healValue==currBuff.healValue then self.BuffIconList[key]:SetCount(self.BuffIconList[key].count+1) return end elseif buffType == BuffName.Immune then if self.BuffIconList[key].immuneType==currBuff.immuneType then self.BuffIconList[key]:SetCount(self.BuffIconList[key].count+1) return end elseif buffType == BuffName.Curse then if self.BuffIconList[key].curseType==currBuff.curseType then self.BuffIconList[key]:SetCount(self.BuffIconList[key].count+1) return end end end end end local buffGO = BattlePool.GetItem(self.buffRoot.transform, BATTLE_POOL_TYPE.BUFF_VIEW) buffGO.transform.localScale = Vector3.one buffGO.transform.localPosition = Vector3.zero buffGO:SetActive(true) self.BuffIconList[currBuff.id] = BuffView.New(buffGO, buff, icon) end function BuffCtrl:RemoveBuffIcon(buff) if not buff then return end if not self.BuffIconList then return end LogRed(buff.id.." type "..tostring(buff.type)) -- if self.BuffIconList[buff.id] then -- local count=self.BuffIconList[buff.id].count -- if count==1 then -- self.BuffIconList[buff.id]:Dispose() -- self.BuffIconList[buff.id] = nil -- else -- self.BuffIconList[buff.id]:SetCount(count-1) -- end -- return -- end --便利所有之前存在的buff图标,有同类型,同数值的叠加,否则新建 for key, value in pairs(self.BuffIconList) do local buffType = self.BuffIconList[key].buff.type local floor = self.BuffIconList[key].count if buff.type == buffType then if buffType == BuffName.PropertyChange then --属性 判断属性类型,属性值,属性修改类型 if self.BuffIconList[key].buffPropertyName==buff.propertyName and self.BuffIconList[key].buffValue==buff.Value and self.BuffIconList[key].buffCt==buff.changeType then if floor==1 then self.BuffIconList[key]:Dispose() self.BuffIconList[key] = nil else self.BuffIconList[key]:SetCount(floor-1) end return end --持续伤害类型,伤害系数 elseif buffType == BuffName.DOT then if self.BuffIconList[key].buffDamageType==buff.damageType and self.BuffIconList[key].buffDamageFactor==buff.damageFactor then if floor==1 then self.BuffIconList[key]:Dispose() self.BuffIconList[key] = nil else self.BuffIconList[key]:SetCount(floor-1) end return end --控制类型 elseif buffType == BuffName.Control then if self.BuffIconList[key].buffCtrlType==buff.ctrlType then if floor==1 then self.BuffIconList[key]:Dispose() self.BuffIconList[key] = nil else self.BuffIconList[key]:SetCount(floor-1) end return end elseif buffType == BuffName.HOT then if self.BuffIconList[key].healValue==buff.healValue then if floor==1 then self.BuffIconList[key]:Dispose() self.BuffIconList[key] = nil else self.BuffIconList[key]:SetCount(floor-1) end return end elseif buffType == BuffName.Immune then if self.BuffIconList[key].immuneType==buff.immuneType then if floor==1 then self.BuffIconList[key]:Dispose() self.BuffIconList[key] = nil else self.BuffIconList[key]:SetCount(floor-1) end return end elseif buffType == BuffName.Curse then if self.BuffIconList[key].curseType==buff.curseType then if floor==1 then self.BuffIconList[key]:Dispose() self.BuffIconList[key] = nil else self.BuffIconList[key]:SetCount(floor-1) end return end end end end end -- 卸载所有动画 function BuffCtrl:RemoveAllBuffIcon() if not self.BuffIconList then return end for id, v in pairs(self.BuffIconList) do v:Dispose() end self.BuffIconList = {} end function BuffCtrl:OnBuffStart(buff) --LogGreen("buff"..buff.type) -- 临时显示 if buff.type == BuffName.NoDead then self.owner.Floater:ImageBuffFloating("z_zhandou_bumie_zh") return end local eConfig = _GetBuffEffectConfig(buff) if not eConfig then return end if buff.type == BuffName.PropertyChange then if buff.changeType == 1 or buff.changeType == 2 then self:AddBuffEffect(eConfig.Hit) self:AddBuffEffect(eConfig.Continue, false, eConfig.ContinueOffset) --self.owner.Floater:TextBuffFloating(eConfig.DescColorType, GetLanguageStrById(eConfig.Describe)..Language[10237]) self.owner.Floater:ImageBuffFloating(eConfig.DescribeIcon,nil,nil,1) self:AddBuffIcon(buff, eConfig.Icon) SoundManager.PlaySound(SoundConfig.Sound_Buff) else self:AddBuffEffect(eConfig.DHit) self:AddBuffEffect(eConfig.DContinue) --self.owner.Floater:TextBuffFloating(eConfig.DDescColorType, GetLanguageStrById(eConfig.Describe)..Language[10238]) self.owner.Floater:ImageBuffFloating(eConfig.DescribeIcon,nil,nil,2) self:AddBuffIcon(buff, eConfig.DIcon) SoundManager.PlaySound(SoundConfig.Sound_DeBuff) end else self:AddBuffEffect(eConfig.Hit) self:AddBuffEffect(eConfig.Continue, false, eConfig.ContinueOffset) --一个伤害打死目标,同时被上buff 不显示buff提示(除非目标有不灭,死亡技能) change by:wangzhenxing,shihongyi 2021/7/7 if not self.owner.role:IsDead() or not self.owner.role:IsCanDead() or self.owner.role.isHaveNoDead then if eConfig.DescribeIcon and eConfig.DescribeIcon ~= "" then self.owner.Floater:ImageBuffFloating(eConfig.DescribeIcon) else self.owner.Floater:TextBuffFloating(eConfig.DescColorType, GetLanguageStrById(eConfig.Describe)) end self:AddBuffIcon(buff, eConfig.Icon) --else -- LogError("//////////") end end end -- function BuffCtrl:OnBuffDodge(buff) if buff.type == BuffName.Control and buff.caster.camp ~= self.owner.camp then self.owner.Floater:ImageBuffFloating("z_zhandou_dikangzi_zh") end end -- function BuffCtrl:OnBuffRoundChange(buff) if self.BuffIconList[buff.id] then self.BuffIconList[buff.id]:SetRound(buff) end end function BuffCtrl:OnBuffCover(buff) if self.BuffIconList[buff.id] then self.BuffIconList[buff.id]:SetLayer(buff) end end function BuffCtrl:OnBuffTrigger(buff) local eConfig = _GetBuffEffectConfig(buff) if not eConfig then return end if buff.type == BuffName.PropertyChange then if buff.changeType == 1 or buff.changeType == 2 then self:AddBuffEffect(eConfig.Trigger, true) else self:AddBuffEffect(eConfig.DTrigger, true) end else self:AddBuffEffect(eConfig.Trigger, true) end end function BuffCtrl:OnBuffEnd(buff) -- 临时显示 if buff.type == BuffName.NoDead then return end local eConfig = _GetBuffEffectConfig(buff) if not eConfig then return end if buff.type == BuffName.PropertyChange then if buff.changeType == 1 or buff.changeType == 2 then self:RemoveBuffEffect(eConfig.Hit) self:RemoveBuffEffect(eConfig.Continue) self:RemoveBuffEffect(eConfig.Trigger) self:RemoveBuffIcon(buff, eConfig.Icon) else self:RemoveBuffEffect(eConfig.DHit) self:RemoveBuffEffect(eConfig.DContinue) self:RemoveBuffEffect(eConfig.DTrigger) self:RemoveBuffIcon(buff, eConfig.DIcon) end else self:RemoveBuffEffect(eConfig.Hit) self:RemoveBuffEffect(eConfig.Continue) self:RemoveBuffEffect(eConfig.Trigger) self:RemoveBuffIcon(buff, eConfig.Icon) end end function BuffCtrl:Dispose() -- 回收所有buff相关效果 self:RemoveAllBuffEffect() self:RemoveAllBuffIcon() end return BuffCtrl