WinnerRelicLogic.lua 31 KB

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