WinnerRelicLogic.lua 30 KB

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