local Msg = require("core.Msg") local CommonDB = require("common.CommonDB") local relicModule = require("excel.ServerRelic") local Grid = require("bag.Grid") local BagLogic = require("bag.BagLogic") local RoleAttr = require("role.RoleAttr") local ObjHuman = require("core.ObjHuman") local RoleDefine = require("role.RoleDefine") local Lang = require("common.Lang") local Broadcast = require("broadcast.Broadcast") local HuanJingTowerLogic = require("huanjingTower.HuanjingTowerLogic") local HeroConfig = require("excel.hero").hero local RoleSystemDefine = require("roleSystem.RoleSystemDefine") local HeroLogic = require("hero.HeroLogic") local RoleSystemLogic = require("roleSystem.RoleSystemLogic") local LOGTYPE = "WinnerRelic" local relicUpgradeConfig = relicModule.RelicUpgrade -- 获取升级配置表 local relicDataConfig = relicModule.RelicData -- 获取遗物数据表 local COND_TOWER_LEVEL = 500 --开启本系统需要通关恶魔之塔的层数 --[[ DB = {{ -- 激活状态 status ={ --{[1601] = 3,(star级别) --[1602] = 0, } -- 装备状态(整合到同一命名空间) --equipped = { [1601] = {heoidx, heoidx} -- }} ]] --判断是否开启圣者遗物 function isOpen(human) local towerLevel = HuanJingTowerLogic.getTowerLevel(human) if towerLevel >= COND_TOWER_LEVEL then return true end return false end -- 获取对应类型的遗物 local function generateCfgByType(type_m) local tbl = {} for relicId, relicCfg in pairs(relicDataConfig) do if relicCfg.nType == type_m then tbl[relicId] = relicCfg end end if not next(tbl) then return nil end return tbl end -- 填充协议 -- 红点判断 local function dotJudgment(human, cfgHtbl) local relicData = human.db.relicListData for relicId, relicCfg in pairs(cfgHtbl) do local nLevel = 0 if relicData and relicData.status and relicData.status[relicId] then nLevel = relicData.status[relicId] end if nLevel == 0 and nLevel <= 10 then if BagLogic.getItemCnt(human, relicCfg.nProp) >= 1 then return true end end end return false end local function AddTableAttr(tNode, tConfig, tConfig2) tNode[0] = 4 tNode[1].key = tConfig.HP tNode[1].value = tConfig2.nLife tNode[2].key = tConfig.ATK tNode[2].value= tConfig2.nAttack tNode[3].key = tConfig.DEF tNode[3].value = tConfig2.nDefense tNode[4].key = tConfig.SPEED tNode[4].value = tConfig2.nSpeed end function Listofrelics(human) local tMsgData = Msg.gc.GC_SACRED_RELIC_QUERY local RelicConfigs = tMsgData.SacredRelicConfigs local relicData = human.db.relicListData or {} --数据库 relicData.status = relicData.status or {} relicData.equipped = relicData.equipped or {} RelicConfigs[0] = 0 local len = 0 for relicId, relicCfg in pairs(relicDataConfig) do len = len + 1 RelicConfigs[0] = len local playerRelicData = (relicData and relicData.status and relicData.status[relicId]) or 0 -- 默认未激活 local currentStar = playerRelicData or 0 local msgEntry = RelicConfigs[len] -- 基础属性 msgEntry.id = relicId msgEntry.name = relicCfg.nName msgEntry.activateItem = relicCfg.nProp AddTableAttr(msgEntry.attr, RoleDefine, relicCfg) AddTableAttr(msgEntry.nextattr, RoleDefine, relicCfg) msgEntry.effectDesc = relicCfg.nEffectdescription local bonusValues = {} if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end msgEntry.effectData[0] = 4 msgEntry.effectNextData[0] = 4 msgEntry.effectMaxData[0] = 4 for i, bonusArray in ipairs(bonusValues) do local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0 local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0 local replaceValueMax = bonusArray and bonusArray[10] or 0 -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1) msgEntry.effectData[i] = replaceValue msgEntry.effectNextData[i] = replaceValueNext msgEntry.effectMaxData[i] = replaceValueMax end msgEntry.type = relicCfg.nType local nextStar = currentStar + 1 local costNum = nextStar <= 10 and relicUpgradeConfig and relicUpgradeConfig[nextStar] and relicUpgradeConfig[nextStar].CostNum or 0 Grid.makeItem(msgEntry.upGradeCost, relicCfg.nProp, costNum) msgEntry.upGradeCost.cnt = costNum or 0 msgEntry.starLevel = currentStar or 0 -- print("当前下发的遗物等级为:",currentStar) -- print("当前各种遗物的星级",msgEntry.starLevel) if relicUpgradeConfig and relicUpgradeConfig[currentStar] then msgEntry.equipLimit = relicUpgradeConfig[currentStar].EquipHeroNum or 0 else msgEntry.equipLimit = 0 end if relicData and relicData.equipped and relicData.equipped[relicId] then msgEntry.heroIdx[0] = #relicData.equipped[relicId] for idx, rid in ipairs(relicData.equipped[relicId]) do msgEntry.heroIdx[idx] = rid end else msgEntry.heroIdx = {} -- 先初始化为空表 msgEntry.heroIdx[0] = 0 end end Msg.send(tMsgData, human.fd) end function ActiveandUpgrade(human,relicId) print("开始激活圣者遗物11111111111111111") -- 基础校验 if not isOpen(human) then return Broadcast.sendErr(human, Lang.COMMOM_NOT_ENABLED) end local relicCfg = relicDataConfig[relicId] if not relicCfg then return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR) end human.db.relicListData = human.db.relicListData or {} human.db.relicListData.status = human.db.relicListData.status or {} local relicData=human.db.relicListData local playerRelicData = relicData and relicData.status and relicData.status[relicId] or 0 local currentStar = playerRelicData or 0 -- 检查是否已达到最大星级 if currentStar >=10 then return Broadcast.sendErr(human, Lang.COMMON_MAX_LEVEL) end local nextStar = currentStar +1 print("激活/升级,当前取得遗物的星级为",currentStar) print("激活/升级,当前遗物下一星级",nextStar) if nextStar > 10 or not relicUpgradeConfig or not relicUpgradeConfig[nextStar] then return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR) end local costItemId = relicCfg and relicCfg.nProp local costNum = relicUpgradeConfig and relicUpgradeConfig[nextStar] and relicUpgradeConfig[nextStar].CostNum or 0 if not costItemId or BagLogic.getItemCnt(human, costItemId) < costNum then return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH) end BagLogic.delItem(human, costItemId, costNum, LOGTYPE) --更新数据 playerRelicData = nextStar or 0 human.db.relicListData.status = human.db.relicListData.status or {} human.db.relicListData.status[relicId] = playerRelicData print("当前今激活或升级后存入数据库的星级",playerRelicData) --返回数据 local tMsgData = Msg.gc.GC_SACRED_RELIC_UPGRADE local RelicData = tMsgData.data or {} RelicData.id = relicId RelicData.name = relicCfg.nName RelicData.activateItem = relicCfg.nProp AddTableAttr(RelicData.attr, RoleDefine, relicCfg) AddTableAttr(RelicData.nextattr, RoleDefine, relicCfg) local bonusValues = {} RelicData.effectDesc = relicCfg.nEffectdescription if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end RelicData.effectData[0] = 4 RelicData.effectNextData[0] = 4 RelicData.effectMaxData[0] = 4 for i, bonusArray in ipairs(bonusValues) do local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0 local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0 local replaceValueMax = bonusArray and bonusArray[10] or 0 -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1) RelicData.effectData[i] = replaceValue RelicData.effectNextData[i] = replaceValueNext RelicData.effectMaxData[i] = replaceValueMax end RelicData.type = relicCfg.nType or {} local costNum = nextStar <= 10 and relicUpgradeConfig and relicUpgradeConfig[nextStar] and relicUpgradeConfig[nextStar].CostNum or 0 Grid.makeItem(RelicData.upGradeCost, relicCfg.nProp, costNum) RelicData.upGradeCost.cnt = costNum or 0 RelicData.starLevel = nextStar or 0 if relicUpgradeConfig and relicUpgradeConfig[nextStar] then RelicData.equipLimit = relicUpgradeConfig[nextStar].EquipHeroNum or 0 else RelicData.equipLimit = 0 end if relicData and relicData.equipped and relicData.equipped[relicId] then RelicData.heroIdx[0] = #relicData.equipped[relicId] for idx, rid in ipairs(relicData.equipped[relicId]) do RelicData.heroIdx[idx] = rid end else RelicData.heroIdx = {} -- 先初始化为空表 RelicData.heroIdx[0] = 0 end -- tMsgData = relicData Msg.send(tMsgData, human.fd) --重算战力 RoleAttr.cleanHeroAttrCache(human) RoleAttr.doCalc(human) ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI) --刷新红点,当所有可激活遗物均已被激活时 if not dotJudgment(human, relicDataConfig) then local dotID = 0 if relicCfg.nType == 1 then dotID = RoleSystemDefine.ROLE_SYS_ID_2022 elseif relicCfg.nType == 2 then dotID = RoleSystemDefine.ROLE_SYS_ID_2023 elseif relicCfg.nType == 3 then dotID = RoleSystemDefine.ROLE_SYS_ID_2024 end RoleSystemLogic.onDot(human, dotID) --刷新入口处 RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2021) end end -- 装备/卸下圣者遗物 function EquipeandRemove(human, heroID, heroIdx, relicId, operate) local relicCfg = relicDataConfig and relicDataConfig[relicId] local playerRelicData = human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[relicId] or 0 local currentStar = playerRelicData or 0 -- 检查系统是否开启 if not isOpen(human) then return Broadcast.sendErr(human, Lang.COMMON_NOT_OPEN) end --检查英雄是否存在 local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIdx) if not heroGrid then return Broadcast.sendErr(human, Lang.HERO_NOT_EXIST) end --检查英雄是否达到14星 if heroGrid.star < 14 then return Broadcast.sendErr(human, Lang.SACRED_RELIC_HERO_LEVEL_LIMIT) end -- 初始化遗物数据 human.db.relicListData = human.db.relicListData or {} local relicData =human.db.relicListData or {} -- 装备操作 local tMsgData = Msg.gc.GC_SACRED_RELIC_EQUIP local RelicData = tMsgData.olddata tMsgData.heroIdx = heroIdx RelicData.id = relicId RelicData.name = relicCfg.nName RelicData.activateItem = relicCfg.nProp AddTableAttr(RelicData.attr, RoleDefine, relicCfg) AddTableAttr(RelicData.nextattr, RoleDefine, relicCfg) RelicData.effectDesc = relicCfg.nEffectdescription local bonusValues = {} if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end RelicData.effectData[0] = 4 RelicData.effectNextData[0] = 4 RelicData.effectMaxData[0] = 4 for i, bonusArray in ipairs(bonusValues) do local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0 local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0 local replaceValueMax = bonusArray and bonusArray[10] or 0 -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1) RelicData.effectData[i] = replaceValue RelicData.effectNextData[i] = replaceValueNext RelicData.effectMaxData[i] = replaceValueMax end RelicData.type = relicCfg.nType local costNum = currentStar+1 <= 10 and relicUpgradeConfig and relicUpgradeConfig[currentStar+1] and relicUpgradeConfig[currentStar+1].CostNum or 0 Grid.makeItem(RelicData.upGradeCost, relicCfg.nProp, costNum) RelicData.upGradeCost.cnt = costNum or 0 RelicData.starLevel = currentStar or 0 if relicUpgradeConfig and relicUpgradeConfig[currentStar] then RelicData.equipLimit = relicUpgradeConfig[currentStar].EquipHeroNum or 0 else RelicData.equipLimit = 0 end -- 填充已装备英雄信息 if relicData and relicData.equipped and relicData.equipped[relicId] then RelicData.heroIdx[0] = #relicData.equipped[relicId] for idx, rid in ipairs(relicData.equipped[relicId]) do RelicData.heroIdx[idx] = rid end else RelicData.heroIdx = {} -- 先初始化为空表 RelicData.heroIdx[0] = 0 end if operate == 1 then print("当前进入装备操作") -- 如果当前英雄已经装备了遗物 human.db.relicListData.equipped = human.db.relicListData.equipped or {} human.db.relicListData.equipped[relicId] = human.db.relicListData.equipped[relicId] or {} -- 遍历找到对应的英雄索引并移除 for i, equippedHeroIdx in ipairs(human.db.relicListData.equipped[relicId]) do if equippedHeroIdx == heroIdx then table.remove(human.db.relicListData.equipped[relicId], i) break end end print("当前进入装备操作22222") heroGrid.relic = {} local LEN = human.db.relicListData and human.db.relicListData.equipped and human.db.relicListData.equipped[relicId] and #human.db.relicListData.equipped[relicId] local star = human.db and human.db.relicListData and human.db.relicListData[relicId] or 0 print("当前进入装备操作kkkkkkkkkkk",star) local NumLimit = relicUpgradeConfig and relicUpgradeConfig[star] and relicUpgradeConfig[star].EquipHeroNum or 0 if LEN and LEN >= 5 then return Broadcast.sendErr(human, Lang.SACRED_RELIC_HERO_LEVEL_LIMIT) end if not human.db.relicListData.equipped[relicId] then human.db.relicListData.equipped[relicId] = {} -- 初始化 end print("当前进入装备操作33333") if human.db.relicListData and human.db.relicListData.equipped and human.db.relicListData.equipped[relicId] then local alreadyExist = false for _, idx in ipairs(human.db.relicListData.equipped[relicId]) do if idx == heroIdx then alreadyExist = true break end end if not alreadyExist then table.insert(human.db.relicListData.equipped[relicId],heroIdx) print("成功装备遗物", relicId, "给英雄", heroIdx) else print("英雄已装备该遗物,无需重复操作", heroIdx, relicId) end end print("当前进入装备操作4444") heroGrid.relic = heroGrid.relic or {} heroGrid.relic.relicID = relicId heroGrid.relic.star = human.db.relicListData.status[relicId] or 0 print("当前遗物装备完毕",heroGrid.relic.relicID) else for idx,rid in pairs(human.db.relicListData.equipped[relicId]) do if rid == heroIdx then table.remove(human.db.relicListData.equipped[relicId],idx) break end return Broadcast.sendErr(human, Lang.SACRED_RELIC_HERO_LEVEL_LIMIT) end end -- 获取更新之后的数据 print("11111111111111111111111111111111ggg") local nRelicData = tMsgData.newdata nRelicData.id = relicId nRelicData.name = relicCfg.nName nRelicData.activateItem = relicCfg.nProp AddTableAttr(nRelicData.attr, RoleDefine, relicCfg) AddTableAttr(nRelicData.nextattr, RoleDefine, relicCfg) nRelicData.effectDesc = relicCfg.nEffectdescription local bonusValues = {} if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end nRelicData.effectData[0] = 4 nRelicData.effectNextData[0] = 4 nRelicData.effectMaxData[0] = 4 for i, bonusArray in ipairs(bonusValues) do local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0 local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0 local replaceValueMax = bonusArray and bonusArray[10] or 0 -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1) nRelicData.effectData[i] = replaceValue nRelicData.effectNextData[i] = replaceValueNext nRelicData.effectMaxData[i] = replaceValueMax end nRelicData.type = relicCfg.nType local costNum = currentStar+1 <= 10 and relicUpgradeConfig and relicUpgradeConfig[currentStar+1] and relicUpgradeConfig[currentStar+1].CostNum or 0 Grid.makeItem(RelicData.upGradeCost, relicCfg.nProp, costNum) nRelicData.upGradeCost.cnt = costNum or 0 nRelicData.starLevel = currentStar or 0 if relicUpgradeConfig and relicUpgradeConfig[currentStar] then nRelicData.equipLimit = relicUpgradeConfig[currentStar].EquipHeroNum or 0 else nRelicData.equipLimit = 0 end -- 填充已装备英雄信息 if relicData and relicData.equipped and relicData.equipped[relicId] then nRelicData.heroIdx[0] = #relicData.equipped[relicId] print("当前长度111111111111111111",nRelicData.heroIdx[0]) for idx, rid in ipairs(relicData.equipped[relicId]) do nRelicData.heroIdx[idx] = rid end else nRelicData.heroIdx = {} -- 先初始化为空表 nRelicData.heroIdx[0] = 0 end Msg.send(tMsgData, human.fd) --重算战力 HeroLogic.sendHeroBagUpdate(human,heroIdx) -- table.print_lua_table(tMsgData) print("圣者遗物装备完毕") RoleAttr.cleanHeroAttrCache(human) RoleAttr.doCalc(human) ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI) end -- 遗物对英雄属性加成 function doCalcHero(heroGrid,addAttrs) if not heroGrid or not heroGrid.relic then return end local relicid = heroGrid.relic and heroGrid.relic.relicID local star = heroGrid.relic and heroGrid.relic.star local Life,Attack,Defense,Speed = 0, 0, 0, 0 local relicData = relicDataConfig[relicid] Life = relicData and relicData.nLifeBonus and relicData.nLifeBonus[star] or 0 Attack = relicData and relicData.nAttackBonus and relicData.nAttackBonus[star] or 0 Life = relicData and relicData.nDefenseBonus and relicData.nDefenseBonus[star] or 0 Life = relicData and relicData.nSpeedBonus and relicData.nSpeedBonus[star] or 0 RoleAttr.updateValue(RoleDefine.HP,Life,addAttrs) RoleAttr.updateValue(RoleDefine.ATK,Attack,addAttrs) RoleAttr.updateValue(RoleDefine.DEF,Defense,addAttrs) RoleAttr.updateValue(RoleDefine.SPEED,Speed,addAttrs) end --红点 function isDot(human, dotConfig) if not isOpen(human) then return false end --入口处的红点判断 if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2021 then return dotJudgment(human, relicDataConfig) else --单个分页的红点 local RelicType = 0 if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2022 then RelicType = 1 elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2023 then RelicType = 2 elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2024 then RelicType = 3 end local cfgHtbl = generateCfgByType(RelicType) if not cfgHtbl then return 1 end return dotJudgment(human, cfgHtbl) end end