--Buff技相关(Buff技(BuffSkill) = 只会给自身添加buff,没有技能动画的技能,跟 技能(Skill) 不是一个东西 local FirstPersonEventDispatcher = require"Battle/Logic/Event/FirstPersonEventDispatcher" local BuffSkillComponent = class("BuffSkillComponent") local KEYPOSITION_BUFFSKILL2 = LuaConst.ESkillKeyPosition.BuffSkill2 local INIT_GODBEAST_CD = DataSheetManager.ConstData:GetDataByID("GodBeastInitialCD").IntValue * 1000 local FP = FP function BuffSkillComponent:initialize(entity) self.entity = entity self.buffSkillUpdateList = {} self.godBeastSkillCount = 0 self.curGodBeastSkillIndex = 0 self.godBeastDataList = nil self.buffSkillCdChangeDic = {} --key为buffSkillID,value为CD改变量 self.godBeastCdChange = 0 --神兽技能共用CD,所以CD change也是共用的(单位:毫秒) end function BuffSkillComponent:IsGodBeastSkill(data) return data and data.KeyPosition == KEYPOSITION_BUFFSKILL2 end function BuffSkillComponent:ChangeBuffSkillCd(buffSkillId, delta) local data = DataSheetManager.BuffSkillData:GetDataByID(buffSkillId) if self:IsGodBeastSkill(data) then self.godBeastCdChange = self.godBeastCdChange + delta for k,update in pairs(self.buffSkillUpdateList) do if self:IsGodBeastSkill(update.BuffSkillData) then update.CdChange = self.godBeastCdChange end end else self.buffSkillCdChangeDic[buffSkillId] = self.buffSkillCdChangeDic[buffSkillId] or 0 self.buffSkillCdChangeDic[buffSkillId] = self.buffSkillCdChangeDic[buffSkillId] + delta local update = self:GetBuffSkillUpdateByID(buffSkillId) if update then update.CdChange = self.buffSkillCdChangeDic[buffSkillId] end end end function BuffSkillComponent:AddBuffSkillById(buffSkillId) local data = DataSheetManager.BuffSkillData:GetDataByID(buffSkillId) local exsit = false for i,update in ipairs(self.buffSkillUpdateList) do if update.BuffSkillID == buffSkillId then exsit = true break elseif data.SkillGroup > 0 and update.BuffSkillData.SkillGroup == data.SkillGroup then exsit = true if update.BuffSkillData.GroupPriority < data.GroupPriority then --替换技能:当SkillGroup不为0且已存在时,GroupPriority更大的替换小的 local oldData = update.BuffSkillData update.BuffSkillID = data.ID update.BuffSkillData = data for i,v in ipairs(self.godBeastDataList) do if v.SkillGroup == data.SkillGroup then self.godBeastDataList[i] = data break end end if self.curGoldBeastData.ID == oldData.ID then self.curGoldBeastData = data end FirstPersonEventDispatcher.OnReplaceBuffSkill(self.entity, update, oldData, data) end end end if not exsit then if data then local update = RuntimeDataManager.New_BuffSkillUpdate() update.BuffSkillID = buffSkillId update.BuffSkillData = data if self:IsGodBeastSkill(data) then update.CD = INIT_GODBEAST_CD update.CdChange = self.godBeastCdChange else update.CdChange = self.buffSkillCdChangeDic[buffSkillId] or 0 end update.KeyPosition = data.KeyPosition table.insert(self.buffSkillUpdateList, update) if self:IsGodBeastSkill(data) then self:OnAddGodBeastSkill(data, update) end FirstPersonEventDispatcher.OnAddBuffSkill(self.entity, update) end -- else -- 正常情况,不报错了 -- logging.error(LTAG.ERROR, "HYW : 试图重复添加Buff技能 : ", buffSkillId) end end -- 修改内置cd (val 单位为 毫秒) function BuffSkillComponent:AddTriggerCD(val) self.StratagemTotalCD = self.StratagemTotalCD + val end function BuffSkillComponent:SwitchRightGodBeastSkill() self:SwitchGodBeastSkill(false, false) end function BuffSkillComponent:SwitchLeftGodBeastSkill() self:SwitchGodBeastSkill(false, true) end function BuffSkillComponent:SwitchGodBeastSkill(isInit, isPrevious) if self.godBeastSkillCount > 1 or isInit then if self.curGoldBeastData then --隐藏老按钮 self:GetBuffSkillUpdateByID(self.curGoldBeastData.ID).IsHiding = true end self.curGodBeastSkillIndex = self.curGodBeastSkillIndex + (isPrevious and -1 or 1) if self.curGodBeastSkillIndex > self.godBeastSkillCount then self.curGodBeastSkillIndex = 1 elseif self.curGodBeastSkillIndex <= 0 then self.curGodBeastSkillIndex = self.godBeastSkillCount end self.curGoldBeastData = self.godBeastDataList[self.curGodBeastSkillIndex] if self.curGoldBeastData then local updateData = self:GetBuffSkillUpdateByID(self.curGoldBeastData.ID, true) --显示新按钮 updateData.IsHiding = false FirstPersonEventDispatcher.OnSwitchGodBeastSkill(self.entity, updateData, self.curGoldBeastData, self.curGodBeastSkillIndex) end end end -- 获取计略的当前cd function BuffSkillComponent:GetStratagemCurCD() return self.StratagemCurCD end --获取计略的总cd function BuffSkillComponent:GetStratagemTotalCD() return self.StratagemTotalCD end function BuffSkillComponent:GetBuffSkillUpdateByID(buffSkillId, includeHiding) for i,update in ipairs(self.buffSkillUpdateList) do if update.BuffSkillData.ID == buffSkillId and (not update.IsHiding or includeHiding) then return update end end end function BuffSkillComponent:GetBuffSkillUpdateByKeyPosition(keyPos, includeHiding) for i,update in ipairs(self.buffSkillUpdateList) do if update.BuffSkillData.KeyPosition == keyPos and (not update.IsHiding or includeHiding) then return update end end end function BuffSkillComponent:OnAddGodBeastSkill(data, updateData) self.godBeastSkillCount = self.godBeastSkillCount + 1 local isFirst = false if not self.godBeastDataList then self.godBeastDataList = {} isFirst = true end updateData.IsHiding = true self.godBeastDataList[self.godBeastSkillCount] = data if isFirst then self:SwitchGodBeastSkill(true) end end function BuffSkillComponent:OnSwitchHero(fromEntity) local fromBuffSkillComp = fromEntity.components.buffSkill for i,fromUpdateData in ipairs(fromBuffSkillComp.buffSkillUpdateList) do if self:IsGodBeastSkill(fromUpdateData.BuffSkillData) then for j,myUpdateData in ipairs(self.buffSkillUpdateList) do if self:IsGodBeastSkill(myUpdateData.BuffSkillData) then if myUpdateData.BuffSkillData.SkillGroup == fromUpdateData.BuffSkillData.SkillGroup then myUpdateData.CD = fromUpdateData.CD myUpdateData.CdChange = fromUpdateData.CdChange end end end end end for k,v in pairs(fromBuffSkillComp.buffSkillCdChangeDic) do --pairs safe 仅数据拷贝 self.buffSkillCdChangeDic[k] = v self.godBeastCdChange = fromBuffSkillComp.godBeastCdChange end end return BuffSkillComponent