WinnerRelicLogic.lua 27 KB

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