HeroGem.lua 5.7 KB

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