HeroGem.lua 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  1. -- 宝石相关逻辑
  2. local Lang = require("common.Lang")
  3. local Msg = require("core.Msg")
  4. local BagLogic = require("bag.BagLogic")
  5. local LogDefine = require("common.LogDefine")
  6. local HeroLogic = require("hero.HeroLogic")
  7. local ObjHuman = require("core.ObjHuman")
  8. local HeroExcel = require("excel.hero")
  9. local Grid = require("bag.Grid")
  10. local Util = require("common.Util")
  11. local HeroDefine = require("hero.HeroDefine")
  12. --宝石最大等级
  13. local MAXGEMLEVEL = 10
  14. --一级宝石对装备基础属性的加成
  15. local BASEBONUS = 0.05
  16. --一级宝石对装备套装效果的加成,key为套装,value为加成比例
  17. local GEMTOEQUIPATTR = {
  18. [2] = 0.0025,
  19. [3] = 0.0025,
  20. [4] = 0.0025
  21. }
  22. --local inlayLog = "inlayGem"
  23. local upgradeLog = "upgradeGem"
  24. --组装下发给客户端的宝石数据
  25. function assembleData(sourceTb, targetTb, job, pos)
  26. --只生成单个数据
  27. local jobToGem = HeroDefine.HEROJOBTOGEM
  28. if pos then
  29. if sourceTb[pos] then
  30. targetTb.id = job and jobToGem[job] or 0
  31. targetTb.pos = pos
  32. targetTb.lv = sourceTb[pos].lv
  33. targetTb.maxLv = MAXGEMLEVEL
  34. if targetTb.lv < MAXGEMLEVEL then
  35. targetTb.upcost = math.ceil((targetTb.lv + 1) / 3 )
  36. else
  37. targetTb.upcost = 0 --宝石达到最高级时,消耗数量为0
  38. end
  39. else
  40. targetTb.id = job and jobToGem[job] or 0
  41. targetTb.pos = pos
  42. targetTb.lv = 0
  43. targetTb.maxLv = MAXGEMLEVEL
  44. targetTb.upcost = math.ceil(1 / 3 )
  45. end
  46. return
  47. end
  48. --所有数据
  49. for i = 1, HeroDefine.HEROGEMMAX do
  50. if sourceTb and sourceTb[i] then
  51. local lv = sourceTb[i].lv
  52. targetTb[i] = {
  53. id = job and jobToGem[job] or 0,
  54. pos = sourceTb[i].pos,
  55. lv = lv,
  56. maxLv = MAXGEMLEVEL,
  57. }
  58. if lv < MAXGEMLEVEL then
  59. targetTb[i].upcost = math.ceil((lv + 1) / 3 )
  60. else
  61. targetTb[i].upcost = 0 --宝石达到最高级时,消耗数量为0
  62. end
  63. else
  64. targetTb[i] = {
  65. id = job and jobToGem[job] or 0,
  66. pos = i,
  67. lv = 0,
  68. maxLv = MAXGEMLEVEL,
  69. }
  70. targetTb[i].upcost = math.ceil( 1/ 3 )
  71. end
  72. end
  73. end
  74. --宝石对装备加成
  75. --规则:只要有镶嵌宝石,那么就能对1-4孔位上装备的基础属性,装备套装效果有加成。
  76. function suitAttrBonus(heroGrid)
  77. local gemData = heroGrid.gem
  78. if not gemData then
  79. return
  80. end
  81. local sumLevel = 0
  82. for _, v in pairs(gemData) do
  83. sumLevel = sumLevel + v.lv
  84. end
  85. if sumLevel > 0 then
  86. local t = {}
  87. for k, v in pairs(GEMTOEQUIPATTR) do
  88. t[k] = v * sumLevel
  89. end
  90. --基础属性
  91. t.base = BASEBONUS * sumLevel
  92. return t
  93. end
  94. end
  95. --获取宝石数据,以ItemData格式下发
  96. function getGemData(human, heroID, heroIndex, pos)
  97. --位置是否超出装备位置
  98. if not pos or pos > HeroDefine.HEROGEMMAX then
  99. return
  100. end
  101. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  102. if not heroGrid then
  103. return
  104. end
  105. local heroCfg = HeroExcel.hero[heroID]
  106. if not heroCfg or not heroCfg.job then
  107. return
  108. end
  109. local itemId = HeroDefine.HEROJOBTOGEM[heroCfg.job]
  110. local itemCnt = 1
  111. --下发客户端
  112. local msgRet = Msg.gc.GC_HERO_GEM_LEVELUP_QUERY
  113. Grid.makeItem(msgRet.list, itemId, itemCnt)
  114. Msg.send(msgRet, human.fd)
  115. end
  116. --升级宝石
  117. function upgradeGem(human, heroID, heroIndex, pos)
  118. --位置是否超出装备位置
  119. if not pos or pos > HeroDefine.HEROGEMMAX then
  120. return
  121. end
  122. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  123. if not heroGrid then
  124. return
  125. end
  126. --有没有穿装备
  127. if not heroGrid.equip or not heroGrid.equip[pos] then
  128. return
  129. end
  130. local heroCfg = HeroExcel.hero[heroID]
  131. if not heroCfg or not heroCfg.job then
  132. return
  133. end
  134. local itemId = HeroDefine.HEROJOBTOGEM[heroCfg.job]
  135. if not itemId then
  136. return
  137. end
  138. --英雄数据中没有宝石那就是镶嵌操作
  139. local isGen = true
  140. local lv = 0
  141. local gemData = heroGrid.gem or {}
  142. if gemData[pos] then
  143. lv = gemData[pos].lv
  144. isGen = false
  145. end
  146. --已经最高级
  147. if lv == MAXGEMLEVEL then
  148. return
  149. end
  150. lv = lv + 1
  151. local itemCnt = math.ceil(lv / 3)
  152. --宝石数量是否足够
  153. if not BagLogic.checkItemCnt(human, itemId, itemCnt) then
  154. return
  155. end
  156. --扣除道具
  157. BagLogic.delItem(human, itemId, itemCnt, upgradeLog)
  158. --更新数据
  159. if isGen then
  160. gemData[pos] = {
  161. pos = pos,
  162. lv = lv,
  163. }
  164. heroGrid.gem = gemData
  165. else
  166. gemData[pos].lv = lv
  167. end
  168. ObjHuman.doCalcHero(human, heroIndex)
  169. HeroLogic.sendHeroBagDynamic(human, heroID, heroIndex)
  170. HeroLogic.refreshDot(human, heroGrid.uuid)
  171. --通知客户端
  172. local msgRet = Msg.gc.GC_HERO_GEM_UPGRADEGEM
  173. msgRet.gemData[0] = HeroDefine.HEROGEMMAX
  174. assembleData(gemData, msgRet.gemData, heroCfg.job, pos)
  175. Msg.send(msgRet, human.fd)
  176. --更新宝石加成
  177. local queryFunc = require("hero.HeroEquip").query
  178. queryFunc(human, heroID, heroIndex)
  179. end