BuffCtrl = {} local BuffTypeToConfigType = { [BuffName.PropertyChange] = 1, [BuffName.Control] = 2, [BuffName.DOT] = 3, [BuffName.HOT] = 4, [BuffName.Shield] = 5, [BuffName.Immune] = 6, [BuffName.Curse] = 7, } 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 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) if not buff 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 end function BuffCtrl:RemoveBuffIcon(buff) if not buff then return end if not self.BuffIconList then return end if self.BuffIconList[buff.id] then self.BuffIconList[buff.id]:Dispose() self.BuffIconList[buff.id] = nil 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:TextBuffFloating(2, Language[10280]) 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, eConfig.Describe..Language[10281]) 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, eConfig.Describe..Language[10282]) self:AddBuffIcon(buff, eConfig.DIcon) SoundManager.PlaySound(SoundConfig.Sound_DeBuff) end else self:AddBuffEffect(eConfig.Hit) self:AddBuffEffect(eConfig.Continue, false, eConfig.ContinueOffset) if eConfig.DescribeIcon and eConfig.DescribeIcon ~= "" then self.owner.Floater:ImageBuffFloating(eConfig.DescribeIcon) else self.owner.Floater:TextBuffFloating(eConfig.DescColorType, eConfig.Describe) end self:AddBuffIcon(buff, eConfig.Icon) 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") 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