| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595 |
- --[[
- 数据说明
- unlockSkillMap = {
- [skillId] = {
- ['skillId'] = skillId,
- ['skillLv'] = skillLv,
- }
- }
- slotSkills = {
- [1] = {
- ['skillId'] = skillId,
- ['isUnlock'] = isUnlock,
- ['defaultSkillId'] = defaultSkillId,
- }
- }
- ]]
- local SkillData = class("SkillData")
- function SkillData:ctor()
- self.unlockSkillMap = nil
- self.slotSkills = nil
- self.advanceSkillMap = nil
- self.currPress = 0
- self.maxPress = 0
- end
- function SkillData:Clear()
- self.unlockSkillMap = nil
- self.slotSkills = nil
- self.advanceSkillMap = nil
- self.currPress = 0
- self.maxPress = 0
- end
- function SkillData:Destroy()
- if self.Clear then
- self:Clear()
- end
- self:UnRegisterNetEvents()
- end
- function SkillData:InitData(data)
- self:Clear()
- self:InitJobSkillData(data.job_skill_list)
- self:InitSlotSkillData(data.skill_list)
- end
- function SkillData:InitJobSkillData(jobSkillList, newSkills, upLevelSkills, downLevelSkills)
- local unlockSkillMap = self.unlockSkillMap
- if not self.advanceSkillMap then
- self.advanceSkillMap = {}
- end
- if not unlockSkillMap then
- unlockSkillMap = {}
- self.unlockSkillMap = unlockSkillMap
- end
- for i = 1, #jobSkillList do
- local jobSkillItem = jobSkillList[i]
- local unlockSkillList = jobSkillItem.unlock_skill_list
- if unlockSkillList then
- for j = 1, #unlockSkillList do
- local skillInfo = unlockSkillList[j]
- local skillId = skillInfo.key or 0
- local skillLv = skillInfo.value or 0
- local unlockSkillItem = unlockSkillMap[skillId]
- if unlockSkillItem then
- if unlockSkillItem.skillLv < skillLv then
- if upLevelSkills then
- table.insert(upLevelSkills, { skillType = Enum.SkillType.Active, skillId = skillId })
- end
- elseif unlockSkillItem.skillLv > skillLv then
- if downLevelSkills then
- table.insert(downLevelSkills, { skillType = Enum.SkillType.Active, skillId = skillId })
- end
- -- TODO: 2020-05-18 出现道具洗技能等级,所以这个Log没用了
- -- LogError('[Wboy] skill can not lv degradation ' .. tostring(skillId) .. ' ' .. tostring(unlockSkillItem.skillLv) .. ' ' .. tostring(skillLv))
- end
- else
- if newSkills then
- table.insert(newSkills, { skillType = Enum.SkillType.Active, skillId = skillId })
- end
- unlockSkillItem = {}
- unlockSkillMap[skillId] = unlockSkillItem
- local IsLeaderHero = math.floor(skillId / 10000) == 1
- local skillTreeCfgData
- if IsLeaderHero then
- skillTreeCfgData = ManagerContainer.CfgMgr:GetSkillTreeCfgById(skillId)
- else
- skillTreeCfgData = ManagerContainer.CfgMgr:GetParterSkillTreeCfgById(skillId)
- end
- if skillTreeCfgData and skillTreeCfgData.beforeSkill and skillTreeCfgData.beforeSkill ~= 0 then
- self.advanceSkillMap[skillId] = skillId
- if unlockSkillMap[skillTreeCfgData.beforeSkill] then
- unlockSkillMap[skillTreeCfgData.beforeSkill] = nil
- self.advanceSkillMap[skillTreeCfgData.beforeSkill] = nil
- if self.slotSkills and #self.slotSkills > 0 then
- for i = 1, #self.slotSkills do
- if self.slotSkills[i].skillId == skillTreeCfgData.beforeSkill then
- self.slotSkills[i].skillId = skillId
- end
- end
- end
- end
- end
- end
- unlockSkillItem.skillId = skillId
- unlockSkillItem.skillLv = skillLv
- end
- end
- end
- --刷新技能数据同时刷新压力值
- self:RefreshUnlockSkillPress()
- --刷新技能数据同时刷新勇气祝福等级
- self:RefreshNerveBenediction()
- end
- function SkillData:RefreshNerveBenediction()
- if not self.NerveBenedIction then
- self.NerveBenedIction = {}
- end
- local allCfgDatas = ManagerContainer.CfgMgr:GetAllSkillSuitNewCfg()
- for i = #allCfgDatas, 1, -1 do
- if not self.NerveBenedIction[i] then
- self.NerveBenedIction[i] = {}
- end
- self.NerveBenedIction[i].needNum = 0
- self.NerveBenedIction[i].currcount = 0
- local cfgData = allCfgDatas[i]
- local conditions = cfgData.TriggerConditions
- if conditions and #conditions > 0 then
- for j = 1, #conditions do
- local needLv = conditions[j][2]
- local needNum = conditions[j][1]
- self.NerveBenedIction[i].needNum = self.NerveBenedIction[i].needNum + needNum
- local currcount = 0
- for k, v in pairs(self.advanceSkillMap) do
- local skillLv = self:GetSkillLv(v)
- if skillLv >= needLv then
- currcount = currcount + 1
- end
- end
- self.NerveBenedIction[i].currcount = self.NerveBenedIction[i].currcount + currcount
- end
- if self.NerveBenedIction[i].currcount >= self.NerveBenedIction[i].needNum then
- self.NerveBenedIction[i].currcount = self.NerveBenedIction[i].needNum
- self.currNerveLv = i
- return
- end
- else
- self.currNerveLv = 1
- end
- end
- end
- function SkillData:GetCurrNerveLv()
- return self.currNerveLv or 0
- end
- function SkillData:GetNerveCurrDataById(id)
- return self.NerveBenedIction[id]
- end
- function SkillData:IsCanResetSkill(type)
- if type == 1 then --进阶技能重置
- for k, v in pairs(self.advanceSkillMap) do
- local skillLv = self:GetSkillLv(v)
- if skillLv > 1 then
- return true
- end
- end
- else --所有技能重置
- for k, v in pairs(self.unlockSkillMap) do
- if v.skillLv > 1 then
- return true
- end
- end
- end
- return false
- end
- function SkillData:InitSlotSkillData(slotSkillList)
- local slotSkills = {}
- for i = 1, #slotSkillList do
- local item = slotSkillList[i]
- local slotSkillItem = {}
- slotSkillItem.skillId = item.skill_id or 0
- slotSkillItem.isUnlock = (item.unlock and item.unlock > 0) and true or false
- slotSkillItem.defaultSkillId = item.default_skill_id or 0
- slotSkills[i] = slotSkillItem
- end
- self.slotSkills = slotSkills
- end
- function SkillData:OnJobSkillDataChange(data)
- local jobSkillList = data.job_skill_list
- local newSkills = {}
- local upLevelSkills = {}
- local downLevelSkills = {}
- self:InitJobSkillData(jobSkillList, newSkills, upLevelSkills, downLevelSkills)
- local isSlotChanged = false
- if not isSlotChanged and newSkills then
- for k,v in pairs(newSkills) do
- -- 是否槽位上填充了新技能
- if self:GetSkillIsAtSlot(v.skillId) then
- isSlotChanged = true
- break
- end
- end
- end
- if not isSlotChanged and upLevelSkills then
- for k,v in pairs(upLevelSkills) do
- -- 是否槽位上的技能升级了
- if self:GetSkillIsAtSlot(v.skillId) then
- isSlotChanged = true
- break
- end
- end
- end
- if not isSlotChanged and downLevelSkills then
- for k,v in pairs(downLevelSkills) do
- -- 是否槽位上的技能降级了
- if self:GetSkillIsAtSlot(v.skillId) then
- isSlotChanged = true
- break
- end
- end
- end
- return isSlotChanged, newSkills, upLevelSkills, downLevelSkills
- end
- --- 当单个技能槽位数据发生变化
- function SkillData:OnOneSkillSlotDataChange(data)
- local idx = data.idx
- local slotInfo = data.slot_info
- local item = self.slotSkills[idx]
- if not item then
- item = {}
- self.slotSkills[idx] = item
- end
- item.skillId = slotInfo.skill_id or 0
- item.isUnlock = (slotInfo.unlock and slotInfo.unlock > 0) and true or false
- item.defaultSkillId = slotInfo.default_skill_id or 0
- end
- --- 当技能槽位数据发生变化
- function SkillData:OnSkillSlotDataChange(data)
- local slots = data.slot_info
- for i = 1, #slots do
- local slot = slots[i]
- local item = self.slotSkills[i]
- if not item then
- item = {}
- self.slotSkills[i] = item
- end
- item.skillId = slot.skill_id or 0
- item.isUnlock = (slot.unlock and slot.unlock > 0) and true or false
- item.defaultSkillId = slot.default_skill_id or 0
- end
- end
- function SkillData:GetUnlockSkillMap()
- return self.unlockSkillMap
- end
- --- 获得技能是否解锁了
- ---@param skillId integer 技能Id
- function SkillData:GetIsUnlock(skillId)
- if self.unlockSkillMap then
- return self.unlockSkillMap[skillId] and true or false
- end
- return false
- end
- --- 获得技能等级
- ---@param skillId integer 技能Id
- function SkillData:GetSkillLv(skillId)
- if self.unlockSkillMap and self.unlockSkillMap[skillId] then
- return self.unlockSkillMap[skillId].skillLv or 0
- end
- return 0
- end
- --- 槽位的技能信息列表
- function SkillData:GetSlotSkills()
- return self.slotSkills
- end
- --- 技能是否已在槽位中
- ---@param skillId integer 技能Id
- function SkillData:GetSkillIsAtSlot(skillId)
- for i = 1, #self.slotSkills do
- local slotSkill = self.slotSkills[i]
- if slotSkill then
- if slotSkill.skillId == skillId and slotSkill.isUnlock then
- return true
- end
- end
- end
- return false
- end
- --- 获得槽位上的技能Id
- ---@param idx integer 槽位ID 1-4
- function SkillData:GetSlotSkillId(idx)
- local slotSkill = self.slotSkills[idx]
- if slotSkill then
- if not slotSkill.isUnlock then
- return 0
- end
- return slotSkill.skillId
- end
- return 0
- end
- --- 获得槽位是否解锁
- ---@param idx integer 槽位ID 1-4
- function SkillData:GetSlotIsUnlock(idx)
- local slotSkill = self.slotSkills[idx]
- if slotSkill then
- return slotSkill.isUnlock
- end
- return false
- end
- --- 获得槽位解锁的数量
- function SkillData:GetUnlockSlotNum()
- local num = 0
- for i = 1, #self.slotSkills do
- local slotSkill = self.slotSkills[i]
- if slotSkill.isUnlock then
- num = num + 1
- end
- end
- return num
- end
- --- 解锁的槽位上已放置的技能
- function SkillData:GetSlotVaildSkillNum()
- local num = 0
- for i = 1, #self.slotSkills do
- local slotSkill = self.slotSkills[i]
- if slotSkill.isUnlock and slotSkill.skillId > 0 then
- num = num + 1
- end
- end
- return num
- end
- --- 获得槽位上最低等级的技能等级
- function SkillData:GetSlotVaildSkillLowerLv()
- local lowerLv = nil
- local lowerId = nil
- for i = 1, #self.slotSkills do
- local slotSkill = self.slotSkills[i]
- if slotSkill.isUnlock and slotSkill.skillId > 0 then
- local lv = self:GetSkillLv(slotSkill.skillId)
- if lv > 0 then
- if not lowerLv or lowerLv > lv then
- lowerLv = lv
- lowerId = slotSkill.skillId
- end
- end
- end
- end
- return lowerLv, lowerId
- end
- --- 获得不在槽位中的所有解锁的主动技能
- function SkillData:GetUnlockSkillsExceptSlot()
- local slotSkillIds = {}
- for i = 1, #self.slotSkills do
- local slotSkill = self.slotSkills[i]
- if slotSkill.skillId and slotSkill.skillId > 0 then
- table.insert(slotSkillIds, slotSkill.skillId)
- end
- end
- local num = #slotSkillIds
- local isVaild = false
- local unlockSkills = {}
- if self.unlockSkillMap then
- for _, skillInfo in pairs(self.unlockSkillMap) do
- if skillInfo then
- local skillId = skillInfo.skillId
- isVaild = true
- for j = num, 1, -1 do
- if slotSkillIds[j] == skillId then
- table.remove(slotSkillIds, j)
- num = num - 1
- isVaild = false
- break
- end
- end
- if isVaild then
- table.insert(unlockSkills, skillId)
- end
- end
- end
- end
- return unlockSkills
- end
- function SkillData:GetUsedSkillParams()
- local len = #self.slotSkills
- local usedSkills = System.Array.CreateInstance(typeof(SkillParam), len)
- for i = 1, len do
- local skillParam = nil
- local slotSkill = self.slotSkills[i]
- if slotSkill then
- if slotSkill.skillId <= 0 or not slotSkill.isUnlock then
- skillParam = SkillParam.New(slotSkill.defaultSkillId, 1)
- else
- skillParam = SkillParam.New(slotSkill.skillId, self:GetSkillLv(slotSkill.skillId))
- end
- else
- skillParam = SkillParam.New(0, 0)
- end
- usedSkills[i - 1] = skillParam
- end
- return usedSkills
- end
- function SkillData:GetUsedSkills()
- local skills = {}
- for i = 1, #self.slotSkills do
- local slotSkill = self.slotSkills[i]
- if slotSkill then
- if slotSkill.skillId <= 0 or not slotSkill.isUnlock then
- skills[i] = { skillId = slotSkill.defaultSkillId, lv = 1 }
- else
- skills[i] = { skillId = slotSkill.skillId, lv = self:GetSkillLv(slotSkill.skillId) }
- end
- else
- skills[i] = { skillId = 0, lv = 0 }
- end
- end
- return skills
- end
- function SkillData:GetUnlockSkillAttrs()
- local attr = nil
- if self.unlockSkillMap then
- attr = {}
- local attrId, attrValue
- for _, skillInfo in pairs(self.unlockSkillMap) do
- if skillInfo then
- local skillId = skillInfo.skillId
- local skillLv = skillInfo.skillLv
- for i = skillLv, 1, -1 do
- local cfgId = CommonUtil.GetSkillUpEffectCfgIdByIdAndLv(skillId, i)
- local cfgData = ManagerContainer.CfgMgr:GetSkillUpEffectCfgById(cfgId)
- if cfgData then
- local addAttributes = cfgData.AddAttributes
- if addAttributes then
- for _, value in pairs(addAttributes) do
- attrId = value[1]
- attrValue = value[2]
- if attr[attrId] == nil then
- attr[attrId] = attrValue
- else
- attr[attrId] = attr[attrId] + attrValue
- end
- end
- end
- end
- end
- end
- end
- end
- self:GetAvanceSkillAttrs(attr)
- return attr
- end
- function SkillData:RefreshUnlockSkillPress()
- local currPress = 0
- local maxPress = 0
- if self.unlockSkillMap then
- local attrId, attrValue
- for _, skillInfo in pairs(self.unlockSkillMap) do
- if skillInfo then
- local skillId = skillInfo.skillId
- local skillLv = skillInfo.skillLv
- local skilltreeData = self:GetSkillTreeDataById(skillId)
- if skilltreeData and skilltreeData.PressPoint then
- local advancePress = self:GetAdvancePressByRecursion(skillId)
- maxPress = maxPress + skilltreeData.PressPoint * (skilltreeData.MaxLv - 1) + advancePress +skilltreeData.StartPressPoint
- end
- end
- end
- end
- self.maxPress = maxPress
- end
- function SkillData:GetMaxPress()
- return self.maxPress or 0
- end
- function SkillData:GetAdvancePressByRecursion(skillId)
- local maxPress = 0
- local skillcfg = self:GetSkillTreeDataById(skillId)
- if skillcfg and skillcfg.beforeSkill and skillcfg.beforeSkill ~= 0 then
- local beforeskillId = skillcfg.beforeSkill
- local beforeSkillcfg = self:GetSkillTreeDataById(beforeskillId)
- if beforeSkillcfg and beforeSkillcfg.StartPressPoint then
- local advancePress = 0
- if beforeskillId ~= skillId then
- local advancePress = self:GetAdvancePressByRecursion(beforeskillId)
- end
- maxPress = maxPress + skillcfg.StartPressPoint + advancePress
- end
- end
- return maxPress
- end
- -- 获取进阶技能属性列表
- function SkillData:GetAvanceSkillAttrs(attr,skillList)
- --判断是否是进阶技能 如果是 将之前进阶的所有属性加入属性列表
- if self.unlockSkillMap then
- for _, skillInfo in pairs(self.unlockSkillMap) do
- if skillInfo then
- self:GetAdvanceSkillAttrByRecursion(attr,skillList,skillInfo.skillId)
- end
- end
- end
- end
- function SkillData:GetSkillTreeDataById(skillId)
- local IsLeaderHero = math.floor(skillId / 10000) == 1
- local skillTreeCfgData
- if IsLeaderHero then
- skillTreeCfgData = ManagerContainer.CfgMgr:GetSkillTreeCfgById(skillId)
- else
- skillTreeCfgData = ManagerContainer.CfgMgr:GetParterSkillTreeCfgById(skillId)
- end
- return skillTreeCfgData
- end
- function SkillData:GetAdvanceSkillAttrByRecursion(attr,skillList,skillId)
- local attrId, attrValue
-
- local skillcfg = self:GetSkillTreeDataById(skillId)
- if skillcfg and skillcfg.beforeSkill and skillcfg.beforeSkill ~= 0 then
- local beforeskillId = skillcfg.beforeSkill
- local beforeSkillcfg = self:GetSkillTreeDataById(beforeskillId)
- if beforeSkillcfg then
- if skillList then
- skillList[#skillList + 1] = beforeskillId
- end
- local skillLv = beforeSkillcfg.MaxLv
- for i = skillLv, 1, -1 do
- local cfgId = CommonUtil.GetSkillUpEffectCfgIdByIdAndLv(beforeskillId, i)
- local cfgData = ManagerContainer.CfgMgr:GetSkillUpEffectCfgById(cfgId)
- if cfgData then
- local addAttributes = cfgData.AddAttributes
- if addAttributes then
- for _, value in pairs(addAttributes) do
- attrId = value[1]
- attrValue = value[2]
- if attr[attrId] == nil then
- attr[attrId] = attrValue
- else
- attr[attrId] = attr[attrId] + attrValue
- end
- end
- end
- end
- end
- end
- if beforeskillId ~= skillId then
- self:GetAdvanceSkillAttrByRecursion(attr,skillList,beforeskillId)
- end
- end
- end
- --- 检查技能等级变化,是否会导致属性变化
- function SkillData:CheckSkillChangeAttr(skillId, oldSkillLv, newSkillLv)
- if not skillId then return false end
- if oldSkillLv == newSkillLv then return false end
- if oldSkillLv == nil then oldSkillLv = 0 end
- if newSkillLv == nil then newSkillLv = 0 end
- local iterSign = 1
- if oldSkillLv > newSkillLv then iterSign = -1 end
- for lv = oldSkillLv + iterSign, newSkillLv, iterSign do
- local cfgId = CommonUtil.GetSkillUpEffectCfgIdByIdAndLv(skillId, lv)
- local cfgData = ManagerContainer.CfgMgr:GetSkillUpEffectCfgById(cfgId)
- if cfgData then
- return true
- end
- end
- return false
- end
- return SkillData
|