WinnerRelicLogic.lua 30 KB

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