WinnerRelicLogic.lua 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619
  1. local Msg = require("core.Msg")
  2. local CommonDB = require("common.CommonDB")
  3. local relicModule = require("excel.ServerRelic")
  4. local Grid = require("bag.Grid")
  5. local BagLogic = require("bag.BagLogic")
  6. local RoleAttr = require("role.RoleAttr")
  7. local ObjHuman = require("core.ObjHuman")
  8. local RoleDefine = require("role.RoleDefine")
  9. local Lang = require("common.Lang")
  10. local Broadcast = require("broadcast.Broadcast")
  11. local HuanJingTowerLogic = require("huanjingTower.HuanjingTowerLogic")
  12. local HeroConfig = require("excel.hero").hero
  13. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  14. local HeroLogic = require("hero.HeroLogic")
  15. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  16. local Util = require("common.Util")
  17. local TriggerDefine = require("trigger.TriggerDefine")
  18. local TriggerLogic = require("trigger.TriggerLogic")
  19. local LOGTYPE = "WinnerRelic"
  20. local relicUpgradeConfig = relicModule.RelicUpgrade -- 获取升级配置表
  21. local relicDataConfig = relicModule.RelicData -- 获取遗物数据表
  22. local COND_TOWER_LEVEL = 500 --开启本系统需要通关恶魔之塔的层数
  23. --[[
  24. DB =
  25. {{
  26. -- 激活状态
  27. status ={
  28. --{[1601] = 3,(star级别)
  29. --[1602] = 0,
  30. }
  31. -- 装备状态(整合到同一命名空间)
  32. --equipped = {
  33. [1601] = {heoidx, heoidx}
  34. -- }}
  35. ]]
  36. --判断是否开启圣者遗物
  37. local function isOpen(human)
  38. local towerLevel = HuanJingTowerLogic.getTowerLevel(human)
  39. if towerLevel >= COND_TOWER_LEVEL then
  40. return true
  41. end
  42. return false
  43. end
  44. -- 获取对应类型的遗物
  45. local function generateCfgByType(type_m)
  46. local tbl = {}
  47. for relicId, relicCfg in pairs(relicDataConfig) do
  48. if relicCfg.nType == type_m then
  49. tbl[relicId] = relicCfg
  50. end
  51. end
  52. if not next(tbl) then
  53. return nil
  54. end
  55. return tbl
  56. end
  57. -- 红点判断
  58. local function dotJudgment(human, cfgHtbl)
  59. -- print("当前进入遗物类型红点判断")
  60. local relicData = human.db.relicListData
  61. for relicId, relicCfg in pairs(cfgHtbl) do
  62. local nLevel = 0
  63. if relicData and relicData.status and relicData.status[relicId] then
  64. nLevel = relicData.status[relicId]
  65. end
  66. -- print("当前遗物等级",nLevel)
  67. if nLevel == nil or nLevel == 0 then
  68. if BagLogic.getItemCnt(human, relicCfg.nProp) >= 1 then
  69. return true
  70. end
  71. elseif nLevel +1 <= 10 then
  72. local num = relicUpgradeConfig and relicUpgradeConfig[nLevel +1] and relicUpgradeConfig[nLevel +1].CostNum or 0
  73. if BagLogic.getItemCnt(human, relicCfg.nProp) >= num then
  74. return true
  75. end
  76. end
  77. end
  78. -- print("当前不包含红点")
  79. return false
  80. end
  81. local function AddTableAttr(tNode, tConfig, tConfig2,tstar)
  82. tNode[0] = 4
  83. tNode[1].key = tConfig.HP
  84. tNode[1].value = tConfig2.nLife* tstar
  85. tNode[2].key = tConfig.ATK
  86. tNode[2].value= tConfig2.nAttack*tstar
  87. tNode[3].key = tConfig.DEF
  88. tNode[3].value = tConfig2.nDefense*tstar
  89. tNode[4].key = tConfig.SPEED
  90. tNode[4].value = tConfig2.nSpeed*tstar
  91. end
  92. local function AddTableAttr2(tNode, tConfig, tConfig2)
  93. tNode[0] = 4
  94. tNode[1].key = tConfig.HP
  95. tNode[1].value = tConfig2.nLife
  96. tNode[2].key = tConfig.ATK
  97. tNode[2].value= tConfig2.nAttack
  98. tNode[3].key = tConfig.DEF
  99. tNode[3].value = tConfig2.nDefense
  100. tNode[4].key = tConfig.SPEED
  101. tNode[4].value = tConfig2.nSpeed
  102. end
  103. -- 获取所有圣遗物的总星级
  104. local function WinnerRelic_GetAllStar(human)
  105. local nAllStar = 0
  106. if not human.db.relicListData or not human.db.relicListData.status then
  107. return nAllStar
  108. end
  109. local tDBData = human.db.relicListData.status
  110. for relicId, _ in pairs(relicDataConfig) do
  111. if tDBData[relicId] then
  112. nAllStar = nAllStar + tDBData[relicId]
  113. end
  114. end
  115. return nAllStar
  116. end
  117. function Listofrelics(human)
  118. -- if not isOpen(human) then
  119. -- return Broadcast.sendErr(human, Lang.COMMON_NOT_OPEN)
  120. -- end
  121. local tMsgData = Msg.gc.GC_SACRED_RELIC_QUERY
  122. tMsgData.nAllStar = WinnerRelic_GetAllStar(human)
  123. local RelicConfigs = tMsgData.SacredRelicConfigs
  124. local relicData = human.db.relicListData or {} --数据库
  125. relicData.status = relicData.status or {}
  126. relicData.equipped = relicData.equipped or {}
  127. RelicConfigs[0] = 0
  128. local len = 0
  129. for relicId, relicCfg in pairs(relicDataConfig) do
  130. len = len + 1
  131. RelicConfigs[0] = len
  132. local playerRelicData = (relicData and relicData.status and relicData.status[relicId]) or 0 -- 默认未激活
  133. local currentStar = playerRelicData or 0
  134. local msgEntry = RelicConfigs[len]
  135. -- 基础属性
  136. msgEntry.id = relicId
  137. msgEntry.name = relicCfg.nName
  138. msgEntry.activateItem = relicCfg.nProp
  139. AddTableAttr(msgEntry.attr, RoleDefine, relicCfg, currentStar)
  140. AddTableAttr2(msgEntry.nextattr, RoleDefine, relicCfg)
  141. msgEntry.effectDesc = relicCfg.nEffectdescription
  142. local bonusValues = {}
  143. if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end
  144. if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end
  145. if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end
  146. if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end
  147. msgEntry.effectData[0] = 4
  148. msgEntry.effectNextData[0] = 4
  149. msgEntry.effectMaxData[0] = 4
  150. for i, bonusArray in ipairs(bonusValues) do
  151. local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0
  152. local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0
  153. local replaceValueMax = bonusArray and bonusArray[10] or 0
  154. -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1)
  155. msgEntry.effectData[i] = replaceValue
  156. msgEntry.effectNextData[i] = replaceValueNext
  157. msgEntry.effectMaxData[i] = replaceValueMax
  158. end
  159. msgEntry.type = relicCfg.nType
  160. local nextStar = currentStar + 1
  161. local costNum = nextStar <= 10 and relicUpgradeConfig and relicUpgradeConfig[nextStar] and relicUpgradeConfig[nextStar].CostNum or 0
  162. Grid.makeItem(msgEntry.upGradeCost, relicCfg.nProp, costNum)
  163. msgEntry.upGradeCost.cnt = costNum or 0
  164. msgEntry.starLevel = currentStar or 0
  165. if relicUpgradeConfig and relicUpgradeConfig[currentStar] then
  166. msgEntry.equipLimit = relicUpgradeConfig[currentStar].EquipHeroNum or 0
  167. else
  168. msgEntry.equipLimit = 0
  169. end
  170. if relicData and relicData.equipped and relicData.equipped[relicId] then
  171. msgEntry.heroIdx[0] = #relicData.equipped[relicId]
  172. for idx, rid in ipairs(relicData.equipped[relicId]) do
  173. msgEntry.heroIdx[idx] = rid
  174. end
  175. else
  176. msgEntry.heroIdx = {} -- 先初始化为空表
  177. msgEntry.heroIdx[0] = 0
  178. end
  179. end
  180. Msg.send(tMsgData, human.fd)
  181. end
  182. function ActiveandUpgrade(human,relicId)
  183. -- print("开始激活圣者遗物")
  184. local relicCfg = relicDataConfig[relicId]
  185. if not relicCfg then
  186. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  187. end
  188. human.db.relicListData = human.db.relicListData or {}
  189. human.db.relicListData.status = human.db.relicListData.status or {}
  190. local relicData=human.db.relicListData
  191. local playerRelicData = relicData and relicData.status and relicData.status[relicId] or 0
  192. local currentStar = playerRelicData or 0
  193. -- 检查是否已达到最大星级
  194. if currentStar >=10 then
  195. return Broadcast.sendErr(human, Lang.COMMON_MAX_LEVEL)
  196. end
  197. local nextStar = currentStar +1
  198. if nextStar > 10 or not relicUpgradeConfig or not relicUpgradeConfig[nextStar] then
  199. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  200. end
  201. local costItemId = relicCfg and relicCfg.nProp
  202. local costNum = relicUpgradeConfig and relicUpgradeConfig[nextStar] and relicUpgradeConfig[nextStar].CostNum or 0
  203. if not costItemId or BagLogic.getItemCnt(human, costItemId) < costNum then
  204. return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH)
  205. end
  206. BagLogic.delItem(human, costItemId, costNum, LOGTYPE)
  207. --更新数据
  208. playerRelicData = nextStar or 0
  209. human.db.relicListData.status = human.db.relicListData.status or {}
  210. human.db.relicListData.status[relicId] = playerRelicData
  211. --返回数据
  212. local tMsgData = Msg.gc.GC_SACRED_RELIC_UPGRADE
  213. local RelicData = tMsgData.data or {}
  214. RelicData.id = relicId
  215. RelicData.name = relicCfg.nName
  216. RelicData.activateItem = relicCfg.nProp
  217. AddTableAttr(RelicData.attr, RoleDefine, relicCfg, nextStar)
  218. AddTableAttr2(RelicData.nextattr, RoleDefine, relicCfg)
  219. local bonusValues = {}
  220. RelicData.effectDesc = relicCfg.nEffectdescription
  221. if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end
  222. if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end
  223. if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end
  224. if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end
  225. RelicData.effectData[0] = 4
  226. RelicData.effectNextData[0] = 4
  227. RelicData.effectMaxData[0] = 4
  228. for i, bonusArray in ipairs(bonusValues) do
  229. local replaceValue = nextStar > 0 and bonusArray[nextStar] or 0
  230. local replaceValueNext = nextStar + 1 > 0 and nextStar + 1 <= 10 and bonusArray[nextStar+1] or 0
  231. local replaceValueMax = bonusArray and bonusArray[10] or 0
  232. -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1)
  233. RelicData.effectData[i] = replaceValue
  234. RelicData.effectNextData[i] = replaceValueNext
  235. RelicData.effectMaxData[i] = replaceValueMax
  236. end
  237. RelicData.type = relicCfg.nType or {}
  238. local costNum = nextStar+1 <= 10 and relicUpgradeConfig and relicUpgradeConfig[nextStar+1] and relicUpgradeConfig[nextStar+1].CostNum or 0
  239. Grid.makeItem(RelicData.upGradeCost, relicCfg.nProp, costNum)
  240. RelicData.upGradeCost.cnt = costNum or 0
  241. RelicData.starLevel = nextStar or 0
  242. if relicUpgradeConfig and relicUpgradeConfig[nextStar] then
  243. RelicData.equipLimit = relicUpgradeConfig[nextStar].EquipHeroNum or 0
  244. else
  245. RelicData.equipLimit = 0
  246. end
  247. if relicData and relicData.equipped and relicData.equipped[relicId] then
  248. RelicData.heroIdx[0] = #relicData.equipped[relicId]
  249. for idx, rid in ipairs(relicData.equipped[relicId]) do
  250. RelicData.heroIdx[idx] = rid
  251. local heroID = HeroLogic.getHeroIdByIndex(human, rid)
  252. local heroGrid = HeroLogic.getHeroGrid(human, heroID, rid)
  253. if heroGrid and heroGrid.relic and heroGrid.relilc.star then
  254. heroGrid.relilc.star = nextStar or 0
  255. end
  256. end
  257. else
  258. RelicData.heroIdx = {} -- 先初始化为空表
  259. RelicData.heroIdx[0] = 0
  260. end
  261. if nextStar == 1 then
  262. -- 激活
  263. TriggerLogic.PublishEvent(TriggerDefine.YIWU_ACTIVATE, human.db._id, relicId, 1)
  264. end
  265. -- 总星数
  266. TriggerLogic.PublishEvent(TriggerDefine.YIWU_ALLSTAR, human.db._id, 1)
  267. --更新英雄身上穿的遗物的星级
  268. -- tMsgData = relicData
  269. Msg.send(tMsgData, human.fd)
  270. --重算战力
  271. RoleAttr.cleanHeroAttrCache(human)
  272. RoleAttr.doCalc(human)
  273. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  274. --刷新红点,
  275. nextStar = nextStar + 1
  276. costNum = nextStar <= 10 and relicUpgradeConfig and relicUpgradeConfig[nextStar] and relicUpgradeConfig[nextStar].CostNum or 0
  277. if nextStar > 10 or BagLogic.getItemCnt(human, costItemId) < costNum then
  278. local dotID = 0
  279. if relicCfg.nType == 1 then
  280. dotID = RoleSystemDefine.ROLE_SYS_ID_2022
  281. elseif relicCfg.nType == 2 then
  282. dotID = RoleSystemDefine.ROLE_SYS_ID_2023
  283. elseif relicCfg.nType == 3 then
  284. dotID = RoleSystemDefine.ROLE_SYS_ID_2024
  285. end
  286. RoleSystemLogic.onDot(human, dotID)
  287. --刷新入口处
  288. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2021)
  289. end
  290. Listofrelics(human)
  291. end
  292. function putmsg(human,RelicData,relicCfg,oldid,isexist)
  293. -- print("当前进入给old赋值")
  294. local relicId = oldid
  295. if isexist then
  296. RelicData.id = oldid
  297. else
  298. RelicData.id = 0
  299. end
  300. local relicData =human.db.relicListData or {}
  301. local playerRelicData = human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[oldid] or 0
  302. local currentStar = playerRelicData or 0
  303. RelicData.name = relicCfg.nName
  304. RelicData.activateItem = relicCfg.nProp
  305. AddTableAttr(RelicData.attr, RoleDefine, relicCfg, currentStar)
  306. AddTableAttr2(RelicData.nextattr, RoleDefine, relicCfg)
  307. RelicData.effectDesc = relicCfg.nEffectdescription
  308. local bonusValues = {}
  309. if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end
  310. if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end
  311. if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end
  312. if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end
  313. RelicData.effectData[0] = 4
  314. RelicData.effectNextData[0] = 4
  315. RelicData.effectMaxData[0] = 4
  316. for i, bonusArray in ipairs(bonusValues) do
  317. local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0
  318. local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0
  319. local replaceValueMax = bonusArray and bonusArray[10] or 0
  320. -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1)
  321. RelicData.effectData[i] = replaceValue
  322. RelicData.effectNextData[i] = replaceValueNext
  323. RelicData.effectMaxData[i] = replaceValueMax
  324. end
  325. RelicData.type = relicCfg.nType
  326. local costNum = currentStar+1 <= 10 and relicUpgradeConfig and relicUpgradeConfig[currentStar+1] and relicUpgradeConfig[currentStar+1].CostNum or 0
  327. Grid.makeItem(RelicData.upGradeCost, relicCfg.nProp, costNum)
  328. RelicData.upGradeCost.cnt = costNum or 0
  329. RelicData.starLevel = currentStar or 0
  330. if relicUpgradeConfig and relicUpgradeConfig[currentStar] then
  331. RelicData.equipLimit = relicUpgradeConfig[currentStar].EquipHeroNum or 0
  332. else
  333. RelicData.equipLimit = 0
  334. end
  335. -- 填充已装备英雄信息
  336. if relicData and relicData.equipped and relicData.equipped[relicId] then
  337. RelicData.heroIdx[0] = #relicData.equipped[relicId]
  338. for idx, rid in ipairs(relicData.equipped[relicId]) do
  339. RelicData.heroIdx[idx] = rid
  340. end
  341. else
  342. RelicData.heroIdx = {} -- 先初始化为空表
  343. RelicData.heroIdx[0] = 0
  344. end
  345. -- print("当前结束old赋值")
  346. end
  347. -- 装备/卸下圣者遗物
  348. function EquipeandRemove(human, heroID, heroIdx, relicId, operate)
  349. local relicCfg = relicDataConfig and relicDataConfig[relicId]
  350. local playerRelicData = human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[relicId] or 0
  351. local currentStar = playerRelicData or 0
  352. -- 检查系统是否开启
  353. if not isOpen(human) then
  354. return Broadcast.sendErr(human, Lang.COMMON_NOT_OPEN)
  355. end
  356. --检查英雄是否存在
  357. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIdx)
  358. if not heroGrid then
  359. return Broadcast.sendErr(human, Lang.HERO_NOT_EXIST)
  360. end
  361. --检查英雄是否达到14星
  362. if heroGrid.star < 14 then
  363. return Broadcast.sendErr(human, Lang.SACRED_RELIC_HERO_LEVEL_LIMIT)
  364. end
  365. -- 初始化遗物数据
  366. human.db.relicListData = human.db.relicListData or {}
  367. local relicData =human.db.relicListData or {}
  368. -- 装备操作
  369. local tMsgData = Msg.gc.GC_SACRED_RELIC_EQUIP
  370. local RelicData = tMsgData.olddata
  371. tMsgData.heroIdx = heroIdx
  372. local oldcfg = relicCfg
  373. local oldid = relicId
  374. local isexist, nIndex = false, -1
  375. if human.db and human.db.relicListData and human.db.relicListData.equipped then
  376. for id, heroList in pairs(human.db.relicListData.equipped) do
  377. for idx, heroid in pairs(heroList) do
  378. if heroid == heroIdx then
  379. oldcfg = relicDataConfig and relicDataConfig[id]
  380. oldid = id
  381. isexist = true
  382. nIndex = idx
  383. break
  384. end
  385. end
  386. if isexist then
  387. break
  388. end
  389. end
  390. end
  391. putmsg(human,RelicData,oldcfg,oldid,isexist)
  392. if operate == 1 then
  393. local LEN = human.db.relicListData and human.db.relicListData.equipped and human.db.relicListData.equipped[relicId] and #human.db.relicListData.equipped[relicId]
  394. local star = human.db and human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[relicId] or 0
  395. local NumLimit = relicUpgradeConfig and relicUpgradeConfig[star] and relicUpgradeConfig[star].EquipHeroNum or 0
  396. if LEN and LEN >= NumLimit then
  397. return Broadcast.sendErr(human, Lang.RELIC_EQUIP_LIMIT)
  398. end
  399. -- print("当前进入装备操作")
  400. -- 如果当前英雄已经装备了遗物
  401. human.db.relicListData.equipped = human.db.relicListData.equipped or {}
  402. human.db.relicListData.equipped[relicId] = human.db.relicListData.equipped[relicId] or {}
  403. if heroGrid and heroGrid.relic and heroGrid.relic.star and heroGrid.relic.star >0 then
  404. -- 遍历找到对应的英雄索引并移除
  405. if isexist and -1 ~= nIndex then
  406. table.remove(relicData.equipped[oldid],nIndex)
  407. RelicData.heroIdx[0] = #relicData.equipped[oldid]
  408. for idx, rid in ipairs(relicData.equipped[oldid]) do
  409. RelicData.heroIdx[idx] = rid
  410. end
  411. else
  412. RelicData.heroIdx = {} -- 先初始化为空表
  413. RelicData.heroIdx[0] = 0
  414. end
  415. end
  416. heroGrid.relic = {}
  417. if not human.db.relicListData.equipped[relicId] then
  418. human.db.relicListData.equipped[relicId] = {} -- 初始化
  419. end
  420. if human.db.relicListData and human.db.relicListData.equipped and human.db.relicListData.equipped[relicId] then
  421. for _, idx in ipairs(human.db.relicListData.equipped[relicId]) do
  422. if idx == heroIdx then
  423. return
  424. end
  425. end
  426. table.insert(human.db.relicListData.equipped[relicId],heroIdx)
  427. -- print("成功装备遗物", relicId, "给英雄", heroIdx)
  428. end
  429. heroGrid.relic = heroGrid.relic or {}
  430. heroGrid.relic.relicID = relicId
  431. heroGrid.relic.star = human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[relicId] or 0
  432. -- print("成功装备遗物", relicId, "给英雄", heroIdx,"当前遗物星级为",heroGrid.relic.star)
  433. else
  434. if human.db.relicListData and human.db.relicListData.equipped and human.db.relicListData.equipped[relicId] then
  435. for idx,rid in pairs(human.db.relicListData.equipped[relicId]) do
  436. if rid == heroIdx then
  437. table.remove(human.db.relicListData.equipped[relicId],idx)
  438. break
  439. end
  440. end
  441. else
  442. return Broadcast.sendErr(human, Lang.RELIC_HERO_NO_EQUPPED)
  443. end
  444. heroGrid.relic = {}
  445. end
  446. --获取更新之后的数据
  447. local nRelicData = tMsgData.newdata
  448. if operate == 0 then
  449. nRelicData.id = 0
  450. else
  451. nRelicData.id = relicId
  452. end
  453. tMsgData.heroIdx = heroIdx
  454. nRelicData.name = relicCfg.nName
  455. nRelicData.activateItem = relicCfg.nProp
  456. AddTableAttr(nRelicData.attr, RoleDefine, relicCfg, currentStar)
  457. AddTableAttr2(nRelicData.nextattr, RoleDefine, relicCfg)
  458. nRelicData.effectDesc = relicCfg.nEffectdescription
  459. local nbonusValues = {}
  460. if relicCfg.nLifeBonus then table.insert(nbonusValues, relicCfg.nLifeBonus) end
  461. if relicCfg.nAttackBonus then table.insert(nbonusValues, relicCfg.nAttackBonus) end
  462. if relicCfg.nDefenseBonus then table.insert(nbonusValues, relicCfg.nDefenseBonus) end
  463. if relicCfg.nSpeedBonus then table.insert(nbonusValues, relicCfg.nSpeedBonus) end
  464. nRelicData.effectData[0] = 4
  465. nRelicData.effectNextData[0] = 4
  466. nRelicData.effectMaxData[0] = 4
  467. for i, bonusArray in ipairs(nbonusValues) do
  468. local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0
  469. local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0
  470. local replaceValueMax = bonusArray and bonusArray[10] or 0
  471. -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1)
  472. nRelicData.effectData[i] = replaceValue
  473. nRelicData.effectNextData[i] = replaceValueNext
  474. nRelicData.effectMaxData[i] = replaceValueMax
  475. end
  476. nRelicData.type = relicCfg.nType
  477. local costNum = currentStar+1 <= 10 and relicUpgradeConfig and relicUpgradeConfig[currentStar+1] and relicUpgradeConfig[currentStar+1].CostNum or 0
  478. Grid.makeItem(nRelicData.upGradeCost, relicCfg.nProp, costNum)
  479. nRelicData.upGradeCost.cnt = costNum or 0
  480. nRelicData.starLevel = currentStar or 0
  481. if relicUpgradeConfig and relicUpgradeConfig[currentStar] then
  482. nRelicData.equipLimit = relicUpgradeConfig[currentStar].EquipHeroNum or 0
  483. else
  484. nRelicData.equipLimit = 0
  485. end
  486. -- 填充已装备英雄信息
  487. if relicData and relicData.equipped and relicData.equipped[relicId] then
  488. nRelicData.heroIdx[0] = #relicData.equipped[relicId]
  489. for idx, rid in ipairs(relicData.equipped[relicId]) do
  490. nRelicData.heroIdx[idx] = rid
  491. end
  492. else
  493. nRelicData.heroIdx = {} -- 先初始化为空表
  494. nRelicData.heroIdx[0] = 0
  495. end
  496. -- table.print_lua_table(tMsgData)
  497. Msg.send(tMsgData, human.fd)
  498. --重算战力
  499. HeroLogic.sendHeroBagUpdate(human,heroIdx)
  500. -- print("圣者遗物装备完毕")
  501. ObjHuman.doCalcHero(human, heroIdx)
  502. HeroLogic.sendHeroBagDynamic(human, heroID, heroIdx)
  503. HeroLogic.refreshDot(human, heroGrid.uuid)
  504. end
  505. -- 遗物对英雄属性加成
  506. function doCalcHero(human,heroGrid,addAttrs)
  507. local Life,Attack,Defense,Speed = 0, 0, 0, 0
  508. local reliData = human and human.db and human.db.relicListData and human.db.relicListData.status
  509. if not reliData then
  510. return
  511. end
  512. for relicId, star in pairs(human.db.relicListData.status) do
  513. local relicData = relicDataConfig and relicDataConfig[relicId]
  514. Life = relicData and relicData.nLife or 0
  515. Attack = relicData and relicData.nAttack or 0
  516. Defense = relicData and relicData.nDefense or 0
  517. Speed = relicData and relicData.nSpeed or 0
  518. star = star or 1
  519. RoleAttr.updateValue(RoleDefine.HP,Life * star,addAttrs)
  520. RoleAttr.updateValue(RoleDefine.ATK,Attack * star,addAttrs)
  521. RoleAttr.updateValue(RoleDefine.DEF,Defense * star,addAttrs)
  522. RoleAttr.updateValue(RoleDefine.SPEED,Speed * star,addAttrs)
  523. end
  524. end
  525. --红点
  526. function isDot(human, dotConfig)
  527. if not isOpen(human) then
  528. return false
  529. end
  530. --入口处的红点判断
  531. if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2021 then
  532. return dotJudgment(human, relicDataConfig)
  533. else
  534. -- print("当前进红点分页111111 id = "..dotConfig.id)
  535. --单个分页的红点
  536. local RelicType = 0
  537. if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2022 then
  538. RelicType = 1
  539. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2023 then
  540. RelicType = 2
  541. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2024 then
  542. RelicType = 3
  543. end
  544. local cfgHtbl = generateCfgByType(RelicType)
  545. if not cfgHtbl then
  546. return false
  547. end
  548. return dotJudgment(human, cfgHtbl)
  549. end
  550. end
  551. function WinnerRelic_GetSkillID(nRelicID, nStar)
  552. local tConfig = relicDataConfig[nRelicID]
  553. if nil == tConfig then
  554. return 0
  555. end
  556. return tConfig.skillID[nStar] or 0
  557. end
  558. --对应遗物加成描述中的第一个x
  559. function WinnerRelic_GetRateLife(nRelicID, nStar)
  560. local tConfig = relicDataConfig[nRelicID]
  561. if nil == tConfig then
  562. return 0
  563. end
  564. return tConfig.nLifeBonus[nStar]
  565. end
  566. --对应遗物加成描述中的第二个x
  567. function WinnerRelic_GetRateAttack(nRelicID, nStar)
  568. local tConfig = relicDataConfig[nRelicID]
  569. if nil == tConfig then
  570. return 0
  571. end
  572. return tConfig.nAttackBonus[nStar]
  573. end
  574. --对应遗物加成描述中的第三个x
  575. function WinnerRelic_GetRateDef(nRelicID, nStar)
  576. local tConfig = relicDataConfig[nRelicID]
  577. if nil == tConfig then
  578. return 0
  579. end
  580. return tConfig.nDefenseBonus[nStar]
  581. end
  582. --对应遗物加成描述中的第四个x
  583. function WinnerRelic_GetRateSpeed(nRelicID, nStar)
  584. local tConfig = relicDataConfig[nRelicID]
  585. if nil == tConfig then
  586. return 0
  587. end
  588. return tConfig.nSpeedBonus[nStar]
  589. end