WinnerRelicLogic.lua 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687
  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. -- print("[GC_SACRED_RELIC_QUERY] 回复中的装备的遗物ID relicId = "..relicId)
  173. -- table.print_lua_table(relicData.equipped)
  174. msgEntry.heroIdx[0] = #relicData.equipped[relicId]
  175. for idx, rid in ipairs(relicData.equipped[relicId]) do
  176. msgEntry.heroIdx[idx] = rid
  177. end
  178. else
  179. msgEntry.heroIdx = {} -- 先初始化为空表
  180. msgEntry.heroIdx[0] = 0
  181. end
  182. end
  183. Msg.send(tMsgData, human.fd)
  184. end
  185. function ActiveandUpgrade(human,relicId)
  186. -- print("开始激活圣者遗物")
  187. local relicCfg = relicDataConfig[relicId]
  188. if not relicCfg then
  189. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  190. end
  191. human.db.relicListData = human.db.relicListData or {}
  192. human.db.relicListData.status = human.db.relicListData.status or {}
  193. local relicData=human.db.relicListData
  194. local playerRelicData = relicData and relicData.status and relicData.status[relicId] or 0
  195. local currentStar = playerRelicData or 0
  196. -- 检查是否已达到最大星级
  197. if currentStar >=10 then
  198. return Broadcast.sendErr(human, Lang.COMMON_MAX_LEVEL)
  199. end
  200. local nextStar = currentStar +1
  201. if nextStar > 10 or not relicUpgradeConfig or not relicUpgradeConfig[nextStar] then
  202. return Broadcast.sendErr(human, Lang.COMMON_COMFIG_ERROR)
  203. end
  204. local costItemId = relicCfg and relicCfg.nProp
  205. local costNum = relicUpgradeConfig and relicUpgradeConfig[nextStar] and relicUpgradeConfig[nextStar].CostNum or 0
  206. if not costItemId or BagLogic.getItemCnt(human, costItemId) < costNum then
  207. return Broadcast.sendErr(human, Lang.COMMON_ITEM_NOT_ENOUGH)
  208. end
  209. BagLogic.delItem(human, costItemId, costNum, LOGTYPE)
  210. --更新数据
  211. playerRelicData = nextStar or 0
  212. human.db.relicListData.status = human.db.relicListData.status or {}
  213. human.db.relicListData.status[relicId] = playerRelicData
  214. --返回数据
  215. local tMsgData = Msg.gc.GC_SACRED_RELIC_UPGRADE
  216. local RelicData = tMsgData.data or {}
  217. RelicData.id = relicId
  218. RelicData.name = relicCfg.nName
  219. RelicData.activateItem = relicCfg.nProp
  220. AddTableAttr(RelicData.attr, RoleDefine, relicCfg, nextStar)
  221. AddTableAttr2(RelicData.nextattr, RoleDefine, relicCfg)
  222. local bonusValues = {}
  223. RelicData.effectDesc = relicCfg.nEffectdescription
  224. if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end
  225. if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end
  226. if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end
  227. if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end
  228. RelicData.effectData[0] = 4
  229. RelicData.effectNextData[0] = 4
  230. RelicData.effectMaxData[0] = 4
  231. for i, bonusArray in ipairs(bonusValues) do
  232. local replaceValue = nextStar > 0 and bonusArray[nextStar] or 0
  233. local replaceValueNext = nextStar + 1 > 0 and nextStar + 1 <= 10 and bonusArray[nextStar+1] or 0
  234. local replaceValueMax = bonusArray and bonusArray[10] or 0
  235. -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1)
  236. RelicData.effectData[i] = replaceValue
  237. RelicData.effectNextData[i] = replaceValueNext
  238. RelicData.effectMaxData[i] = replaceValueMax
  239. end
  240. RelicData.type = relicCfg.nType or {}
  241. local costNum = nextStar+1 <= 10 and relicUpgradeConfig and relicUpgradeConfig[nextStar+1] and relicUpgradeConfig[nextStar+1].CostNum or 0
  242. Grid.makeItem(RelicData.upGradeCost, relicCfg.nProp, costNum)
  243. RelicData.upGradeCost.cnt = costNum or 0
  244. RelicData.starLevel = nextStar or 0
  245. if relicUpgradeConfig and relicUpgradeConfig[nextStar] then
  246. RelicData.equipLimit = relicUpgradeConfig[nextStar].EquipHeroNum or 0
  247. else
  248. RelicData.equipLimit = 0
  249. end
  250. if relicData and relicData.equipped and relicData.equipped[relicId] then
  251. RelicData.heroIdx[0] = #relicData.equipped[relicId]
  252. for idx, rid in ipairs(relicData.equipped[relicId]) do
  253. RelicData.heroIdx[idx] = rid
  254. local heroID = HeroLogic.getHeroIdByIndex(human, rid)
  255. local heroGrid = HeroLogic.getHeroGrid(human, heroID, rid)
  256. if heroGrid and heroGrid.relic and heroGrid.relilc.star then
  257. heroGrid.relilc.star = nextStar or 0
  258. end
  259. end
  260. else
  261. RelicData.heroIdx = {} -- 先初始化为空表
  262. RelicData.heroIdx[0] = 0
  263. end
  264. if nextStar == 1 then
  265. -- 激活
  266. TriggerLogic.PublishEvent(TriggerDefine.YIWU_ACTIVATE, human.db._id, relicId, 1)
  267. end
  268. -- 总星数
  269. TriggerLogic.PublishEvent(TriggerDefine.YIWU_ALLSTAR, human.db._id, 1)
  270. --更新英雄身上穿的遗物的星级
  271. -- tMsgData = relicData
  272. Msg.send(tMsgData, human.fd)
  273. --重算战力
  274. RoleAttr.cleanHeroAttrCache(human)
  275. RoleAttr.doCalc(human)
  276. ObjHuman.sendAttr(human, RoleDefine.ZHANDOULI)
  277. --刷新红点,
  278. nextStar = nextStar + 1
  279. costNum = nextStar <= 10 and relicUpgradeConfig and relicUpgradeConfig[nextStar] and relicUpgradeConfig[nextStar].CostNum or 0
  280. if nextStar > 10 or BagLogic.getItemCnt(human, costItemId) < costNum then
  281. local dotID = 0
  282. if relicCfg.nType == 1 then
  283. dotID = RoleSystemDefine.ROLE_SYS_ID_2022
  284. elseif relicCfg.nType == 2 then
  285. dotID = RoleSystemDefine.ROLE_SYS_ID_2023
  286. elseif relicCfg.nType == 3 then
  287. dotID = RoleSystemDefine.ROLE_SYS_ID_2024
  288. end
  289. RoleSystemLogic.onDot(human, dotID)
  290. --刷新入口处
  291. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2021)
  292. end
  293. Listofrelics(human)
  294. end
  295. function putmsg(human,RelicData,relicCfg,oldid,isexist)
  296. -- print("当前进入给old赋值")
  297. local relicId = oldid
  298. if isexist then
  299. RelicData.id = oldid
  300. else
  301. RelicData.id = 0
  302. end
  303. local relicData =human.db.relicListData or {}
  304. local playerRelicData = human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[oldid] or 0
  305. local currentStar = playerRelicData or 0
  306. RelicData.name = relicCfg.nName
  307. RelicData.activateItem = relicCfg.nProp
  308. AddTableAttr(RelicData.attr, RoleDefine, relicCfg, currentStar)
  309. AddTableAttr2(RelicData.nextattr, RoleDefine, relicCfg)
  310. RelicData.effectDesc = relicCfg.nEffectdescription
  311. local bonusValues = {}
  312. if relicCfg.nLifeBonus then table.insert(bonusValues, relicCfg.nLifeBonus) end
  313. if relicCfg.nAttackBonus then table.insert(bonusValues, relicCfg.nAttackBonus) end
  314. if relicCfg.nDefenseBonus then table.insert(bonusValues, relicCfg.nDefenseBonus) end
  315. if relicCfg.nSpeedBonus then table.insert(bonusValues, relicCfg.nSpeedBonus) end
  316. RelicData.effectData[0] = 4
  317. RelicData.effectNextData[0] = 4
  318. RelicData.effectMaxData[0] = 4
  319. for i, bonusArray in ipairs(bonusValues) do
  320. local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0
  321. local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0
  322. local replaceValueMax = bonusArray and bonusArray[10] or 0
  323. -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1)
  324. RelicData.effectData[i] = replaceValue
  325. RelicData.effectNextData[i] = replaceValueNext
  326. RelicData.effectMaxData[i] = replaceValueMax
  327. end
  328. RelicData.type = relicCfg.nType
  329. local costNum = currentStar+1 <= 10 and relicUpgradeConfig and relicUpgradeConfig[currentStar+1] and relicUpgradeConfig[currentStar+1].CostNum or 0
  330. Grid.makeItem(RelicData.upGradeCost, relicCfg.nProp, costNum)
  331. RelicData.upGradeCost.cnt = costNum or 0
  332. RelicData.starLevel = currentStar or 0
  333. if relicUpgradeConfig and relicUpgradeConfig[currentStar] then
  334. RelicData.equipLimit = relicUpgradeConfig[currentStar].EquipHeroNum or 0
  335. else
  336. RelicData.equipLimit = 0
  337. end
  338. -- 填充已装备英雄信息
  339. if relicData and relicData.equipped and relicData.equipped[relicId] then
  340. RelicData.heroIdx[0] = #relicData.equipped[relicId]
  341. for idx, rid in ipairs(relicData.equipped[relicId]) do
  342. RelicData.heroIdx[idx] = rid
  343. end
  344. else
  345. RelicData.heroIdx = {} -- 先初始化为空表
  346. RelicData.heroIdx[0] = 0
  347. end
  348. -- print("当前结束old赋值")
  349. end
  350. -- 装备/卸下圣者遗物
  351. function EquipeandRemove(human, heroID, heroIdx, relicId, operate)
  352. local relicCfg = relicDataConfig and relicDataConfig[relicId]
  353. local playerRelicData = human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[relicId] or 0
  354. local currentStar = playerRelicData or 0
  355. -- 检查系统是否开启
  356. if not isOpen(human) then
  357. return Broadcast.sendErr(human, Lang.COMMON_NOT_OPEN)
  358. end
  359. --检查英雄是否存在
  360. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIdx)
  361. if not heroGrid then
  362. return Broadcast.sendErr(human, Lang.HERO_NOT_EXIST)
  363. end
  364. --检查英雄是否达到14星
  365. if heroGrid.star < 14 then
  366. return Broadcast.sendErr(human, Lang.SACRED_RELIC_HERO_LEVEL_LIMIT)
  367. end
  368. -- 初始化遗物数据
  369. human.db.relicListData = human.db.relicListData or {}
  370. local relicData =human.db.relicListData or {}
  371. -- 装备操作
  372. local tMsgData = Msg.gc.GC_SACRED_RELIC_EQUIP
  373. local RelicData = tMsgData.olddata
  374. tMsgData.heroIdx = heroIdx
  375. local oldcfg = relicCfg
  376. local oldid = relicId
  377. local isexist, nIndex = false, -1
  378. if human.db and human.db.relicListData and human.db.relicListData.equipped then
  379. for id, heroList in pairs(human.db.relicListData.equipped) do
  380. for idx, heroid in pairs(heroList) do
  381. if heroid == heroIdx then
  382. oldcfg = relicDataConfig and relicDataConfig[id]
  383. oldid = id
  384. isexist = true
  385. nIndex = idx
  386. break
  387. end
  388. end
  389. if isexist then
  390. break
  391. end
  392. end
  393. end
  394. putmsg(human,RelicData,oldcfg,oldid,isexist)
  395. if operate == 1 then
  396. local LEN = human.db.relicListData and human.db.relicListData.equipped and human.db.relicListData.equipped[relicId] and #human.db.relicListData.equipped[relicId]
  397. local star = human.db and human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[relicId] or 0
  398. local NumLimit = relicUpgradeConfig and relicUpgradeConfig[star] and relicUpgradeConfig[star].EquipHeroNum or 0
  399. if LEN and LEN >= NumLimit then
  400. return Broadcast.sendErr(human, Lang.RELIC_EQUIP_LIMIT)
  401. end
  402. -- print("当前进入装备操作")
  403. -- 如果当前英雄已经装备了遗物
  404. human.db.relicListData.equipped = human.db.relicListData.equipped or {}
  405. human.db.relicListData.equipped[relicId] = human.db.relicListData.equipped[relicId] or {}
  406. if heroGrid and heroGrid.relic and heroGrid.relic.star and heroGrid.relic.star >0 then
  407. -- 遍历找到对应的英雄索引并移除
  408. if isexist and -1 ~= nIndex then
  409. table.remove(relicData.equipped[oldid],nIndex)
  410. RelicData.heroIdx[0] = #relicData.equipped[oldid]
  411. for idx, rid in ipairs(relicData.equipped[oldid]) do
  412. RelicData.heroIdx[idx] = rid
  413. end
  414. else
  415. RelicData.heroIdx = {} -- 先初始化为空表
  416. RelicData.heroIdx[0] = 0
  417. end
  418. end
  419. heroGrid.relic = {}
  420. if not human.db.relicListData.equipped[relicId] then
  421. human.db.relicListData.equipped[relicId] = {} -- 初始化
  422. end
  423. if human.db.relicListData and human.db.relicListData.equipped and human.db.relicListData.equipped[relicId] then
  424. for _, idx in ipairs(human.db.relicListData.equipped[relicId]) do
  425. if idx == heroIdx then
  426. return
  427. end
  428. end
  429. table.insert(human.db.relicListData.equipped[relicId],heroIdx)
  430. -- print("成功装备遗物", relicId, "给英雄", heroIdx)
  431. end
  432. heroGrid.relic = heroGrid.relic or {}
  433. heroGrid.relic.relicID = relicId
  434. heroGrid.relic.star = human.db.relicListData and human.db.relicListData.status and human.db.relicListData.status[relicId] or 0
  435. -- print("成功装备遗物", relicId, "给英雄", heroIdx,"当前遗物星级为",heroGrid.relic.star)
  436. else
  437. if human.db.relicListData and human.db.relicListData.equipped and human.db.relicListData.equipped[relicId] then
  438. for idx,rid in pairs(human.db.relicListData.equipped[relicId]) do
  439. if rid == heroIdx then
  440. table.remove(human.db.relicListData.equipped[relicId],idx)
  441. break
  442. end
  443. end
  444. else
  445. return Broadcast.sendErr(human, Lang.RELIC_HERO_NO_EQUPPED)
  446. end
  447. heroGrid.relic = {}
  448. end
  449. --获取更新之后的数据
  450. local nRelicData = tMsgData.newdata
  451. if operate == 0 then
  452. nRelicData.id = 0
  453. else
  454. nRelicData.id = relicId
  455. end
  456. tMsgData.heroIdx = heroIdx
  457. nRelicData.name = relicCfg.nName
  458. nRelicData.activateItem = relicCfg.nProp
  459. AddTableAttr(nRelicData.attr, RoleDefine, relicCfg, currentStar)
  460. AddTableAttr2(nRelicData.nextattr, RoleDefine, relicCfg)
  461. nRelicData.effectDesc = relicCfg.nEffectdescription
  462. local nbonusValues = {}
  463. if relicCfg.nLifeBonus then table.insert(nbonusValues, relicCfg.nLifeBonus) end
  464. if relicCfg.nAttackBonus then table.insert(nbonusValues, relicCfg.nAttackBonus) end
  465. if relicCfg.nDefenseBonus then table.insert(nbonusValues, relicCfg.nDefenseBonus) end
  466. if relicCfg.nSpeedBonus then table.insert(nbonusValues, relicCfg.nSpeedBonus) end
  467. nRelicData.effectData[0] = 4
  468. nRelicData.effectNextData[0] = 4
  469. nRelicData.effectMaxData[0] = 4
  470. for i, bonusArray in ipairs(nbonusValues) do
  471. local replaceValue = currentStar > 0 and bonusArray[currentStar] or 0
  472. local replaceValueNext = currentStar + 1 > 0 and currentStar + 1 <= 10 and bonusArray[currentStar+1] or 0
  473. local replaceValueMax = bonusArray and bonusArray[10] or 0
  474. -- effectDesc = string.gsub(effectDesc, "X%%", tostring(replaceValue).."%%", 1)
  475. nRelicData.effectData[i] = replaceValue
  476. nRelicData.effectNextData[i] = replaceValueNext
  477. nRelicData.effectMaxData[i] = replaceValueMax
  478. end
  479. nRelicData.type = relicCfg.nType
  480. local costNum = currentStar+1 <= 10 and relicUpgradeConfig and relicUpgradeConfig[currentStar+1] and relicUpgradeConfig[currentStar+1].CostNum or 0
  481. Grid.makeItem(nRelicData.upGradeCost, relicCfg.nProp, costNum)
  482. nRelicData.upGradeCost.cnt = costNum or 0
  483. nRelicData.starLevel = currentStar or 0
  484. if relicUpgradeConfig and relicUpgradeConfig[currentStar] then
  485. nRelicData.equipLimit = relicUpgradeConfig[currentStar].EquipHeroNum or 0
  486. else
  487. nRelicData.equipLimit = 0
  488. end
  489. -- 填充已装备英雄信息
  490. if relicData and relicData.equipped and relicData.equipped[relicId] then
  491. nRelicData.heroIdx[0] = #relicData.equipped[relicId]
  492. for idx, rid in ipairs(relicData.equipped[relicId]) do
  493. nRelicData.heroIdx[idx] = rid
  494. end
  495. else
  496. nRelicData.heroIdx = {} -- 先初始化为空表
  497. nRelicData.heroIdx[0] = 0
  498. end
  499. -- table.print_lua_table(tMsgData)
  500. Msg.send(tMsgData, human.fd)
  501. --重算战力
  502. HeroLogic.sendHeroBagUpdate(human,heroIdx)
  503. -- print("圣者遗物装备完毕")
  504. ObjHuman.doCalcHero(human, heroIdx)
  505. HeroLogic.sendHeroBagDynamic(human, heroID, heroIdx)
  506. HeroLogic.refreshDot(human, heroGrid.uuid)
  507. end
  508. -- 遗物对英雄属性加成
  509. function doCalcHero(human,heroGrid,addAttrs)
  510. local Life,Attack,Defense,Speed = 0, 0, 0, 0
  511. local reliData = human and human.db and human.db.relicListData and human.db.relicListData.status
  512. if not reliData then
  513. return
  514. end
  515. for relicId, star in pairs(human.db.relicListData.status) do
  516. local relicData = relicDataConfig and relicDataConfig[relicId]
  517. Life = relicData and relicData.nLife or 0
  518. Attack = relicData and relicData.nAttack or 0
  519. Defense = relicData and relicData.nDefense or 0
  520. Speed = relicData and relicData.nSpeed or 0
  521. star = star or 1
  522. RoleAttr.updateValue(RoleDefine.HP,Life * star,addAttrs)
  523. RoleAttr.updateValue(RoleDefine.ATK,Attack * star,addAttrs)
  524. RoleAttr.updateValue(RoleDefine.DEF,Defense * star,addAttrs)
  525. RoleAttr.updateValue(RoleDefine.SPEED,Speed * star,addAttrs)
  526. end
  527. end
  528. --红点
  529. function isDot(human, dotConfig)
  530. if not isOpen(human) then
  531. return false
  532. end
  533. --入口处的红点判断
  534. if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2021 then
  535. return dotJudgment(human, relicDataConfig)
  536. else
  537. -- print("当前进红点分页111111 id = "..dotConfig.id)
  538. --单个分页的红点
  539. local RelicType = 0
  540. if dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2022 then
  541. RelicType = 1
  542. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2023 then
  543. RelicType = 2
  544. elseif dotConfig.id == RoleSystemDefine.ROLE_SYS_ID_2024 then
  545. RelicType = 3
  546. end
  547. local cfgHtbl = generateCfgByType(RelicType)
  548. if not cfgHtbl then
  549. return false
  550. end
  551. return dotJudgment(human, cfgHtbl)
  552. end
  553. end
  554. function WinnerRelic_GetSkillID(nRelicID, nStar)
  555. local tConfig = relicDataConfig[nRelicID]
  556. if nil == tConfig then
  557. return 0
  558. end
  559. return tConfig.skillID[nStar] or 0
  560. end
  561. --对应遗物加成描述中的第一个x
  562. function WinnerRelic_GetRateLife(nRelicID, nStar)
  563. local tConfig = relicDataConfig[nRelicID]
  564. if nil == tConfig then
  565. return 0
  566. end
  567. return tConfig.nLifeBonus[nStar]
  568. end
  569. --对应遗物加成描述中的第二个x
  570. function WinnerRelic_GetRateAttack(nRelicID, nStar)
  571. local tConfig = relicDataConfig[nRelicID]
  572. if nil == tConfig then
  573. return 0
  574. end
  575. return tConfig.nAttackBonus[nStar]
  576. end
  577. --对应遗物加成描述中的第三个x
  578. function WinnerRelic_GetRateDef(nRelicID, nStar)
  579. local tConfig = relicDataConfig[nRelicID]
  580. if nil == tConfig then
  581. return 0
  582. end
  583. return tConfig.nDefenseBonus[nStar]
  584. end
  585. --对应遗物加成描述中的第四个x
  586. function WinnerRelic_GetRateSpeed(nRelicID, nStar)
  587. local tConfig = relicDataConfig[nRelicID]
  588. if nil == tConfig then
  589. return 0
  590. end
  591. return tConfig.nSpeedBonus[nStar]
  592. end
  593. -- 英雄重置或转换取消圣遗物
  594. function WinnerRelic_CancelWinner(human, tHeroGrid, nHeroIndex)
  595. local tRelicData = human.db.relicListData
  596. if not tRelicData then
  597. return
  598. end
  599. if not tHeroGrid.relic or nil == _G.next(tHeroGrid.relic) then
  600. return
  601. end
  602. local nRelicID = tHeroGrid.relic.relicID
  603. if not tRelicData.equipped or not tRelicData.equipped[nRelicID] then
  604. return
  605. end
  606. for i, v in ipairs(tRelicData.equipped[nRelicID]) do
  607. if v == nHeroIndex then
  608. table.remove(tRelicData.equipped[nRelicID], i)
  609. --print("[WinnerRelic_CancelWinner] 移除了对应的英雄index nRelicID = "..nRelicID.." nHeroIndex = "..nHeroIndex.." i = "..i)
  610. break
  611. end
  612. end
  613. -- table.print_lua_table(tRelicData.equipped[nRelicID])
  614. -- print("[WinnerRelic_CancelWinner]打印当前遗物装备数据")
  615. end
  616. function onLogin(human)
  617. local tRelicData = human.db.relicListData
  618. if not tRelicData then
  619. return
  620. end
  621. if not tRelicData.equipped then
  622. return
  623. end
  624. for nRelicID, tHeroIndex in pairs(tRelicData.equipped) do
  625. local nLen = #tHeroIndex
  626. for i = nLen, 1, -1 do
  627. local nHeroIndex = tHeroIndex[i]
  628. local nHeroID = HeroLogic.getHeroIdByIndex(human, nHeroIndex)
  629. local tHeroGrid = HeroLogic.getHeroGrid(human, nHeroID, nHeroIndex)
  630. -- 不存在对应的 herogrid了
  631. if not tHeroGrid then
  632. table.remove(tRelicData.equipped[nRelicID], i)
  633. else
  634. local nHeroStar = tHeroGrid.star
  635. if WINNERRELIC_HEROSTAR > nHeroStar then
  636. -- 先取消穿戴
  637. if tHeroGrid.relic and nil ~= _G.next(tHeroGrid.relic) then
  638. tHeroGrid.relic = {}
  639. end
  640. -- 移除记录的数据
  641. table.remove(tRelicData.equipped[nRelicID], i)
  642. end
  643. end
  644. end
  645. end
  646. end