HeroTenZhiHuan.lua 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. -- 十星英雄置换 神将置换
  2. -- 拒绝潜规则
  3. local HeroExcel = require("excel.hero")
  4. local UpNeedExcel = require("excel.upNeed")
  5. local Lang = require("common.Lang")
  6. local Util = require("common.Util")
  7. local Msg = require("core.Msg")
  8. local ObjHuman = require("core.ObjHuman")
  9. local Grid = require("bag.Grid")
  10. local BagLogic = require("bag.BagLogic")
  11. local ItemDefine = require("bag.ItemDefine")
  12. local Broadcast = require("broadcast.Broadcast")
  13. local HeroLogic = require("hero.HeroLogic")
  14. local HeroGrid = require("hero.HeroGrid")
  15. local HeroEquip = require("hero.HeroEquip")
  16. local HeroDefine = require("hero.HeroDefine")
  17. local FenjieLogic = require("hecheng.FenjieLogic")
  18. local FuwenLogic = require("fuwen.FuwenLogic")
  19. local SkinLogic = require("skin.SkinLogic")
  20. MATERIAL1_NEED_STAR = 10 -- 材料1,需要10星以上的英雄
  21. MATERIAL2_NEED_STAR = 5 -- 材料2,需要5星的英雄
  22. local MAX_LEN = 100
  23. -- 可否作为材料1
  24. -- 得大于10星
  25. function canBeMaterial1(heroID, star)
  26. if not heroID or not star then return end
  27. local heroConfig = HeroExcel.hero[heroID]
  28. if not heroConfig then return end
  29. if star < MATERIAL1_NEED_STAR then
  30. return
  31. end
  32. local attrConfig = HeroDefine.getAttrConfig(heroID, star)
  33. return attrConfig
  34. end
  35. -- 可否作为材料2
  36. function canBeMaterial2(heroID)
  37. if not heroID then return end
  38. local heroConfig = HeroExcel.hero[heroID]
  39. if not heroConfig then return end
  40. if heroConfig.star ~= MATERIAL2_NEED_STAR then
  41. return
  42. end
  43. -- 能否找到10-13星的目标英雄
  44. for starI = MATERIAL1_NEED_STAR, HeroLogic.HERO_MAX_STAR do
  45. local attrConfig = HeroDefine.getAttrConfig(heroID, starI)
  46. if not attrConfig then
  47. return
  48. end
  49. end
  50. return heroConfig
  51. end
  52. -- 发送魂匣信息给前端
  53. function query(human)
  54. local material2List = {}
  55. for index,heroGrid in pairs(human.db.heroBag) do
  56. if index ~= 0 and canBeMaterial2(heroGrid.id) then
  57. material2List[heroGrid.id] = true
  58. end
  59. end
  60. local msgRet = Msg.gc.GC_HERO_TEN_ZHIHUAN_QUERY
  61. Grid.makeItem(msgRet.needItem, ItemDefine.ITEM_MONTHACT_TENSTAR_ID, 1)
  62. msgRet.canHeroId[0] = 0
  63. for heroID in pairs(material2List) do
  64. if msgRet.canHeroId[0] >= MAX_LEN then
  65. break
  66. end
  67. msgRet.canHeroId[0] = msgRet.canHeroId[0] + 1
  68. msgRet.canHeroId[msgRet.canHeroId[0]] = heroID
  69. end
  70. msgRet.material1Star = MATERIAL1_NEED_STAR
  71. msgRet.material2Star = MATERIAL2_NEED_STAR
  72. msgRet.needMaterial2Cnts[0] = 0
  73. msgRet.needItemCnts[0] = 0
  74. for i = MATERIAL1_NEED_STAR, HeroLogic.HERO_MAX_STAR do
  75. local config = UpNeedExcel.zhihuan[i]
  76. -- 消耗5星英雄数量
  77. msgRet.needMaterial2Cnts[0] = msgRet.needMaterial2Cnts[0] + 1
  78. msgRet.needMaterial2Cnts[msgRet.needMaterial2Cnts[0]] = config and config.needHeroCnt or 0
  79. -- 消耗道具数量
  80. msgRet.needItemCnts[0] = msgRet.needItemCnts[0] + 1
  81. msgRet.needItemCnts[msgRet.needItemCnts[0]] = config and config.useItem[2] or 0
  82. end
  83. --Msg.trace(msgRet)
  84. Msg.send(msgRet, human.fd)
  85. end
  86. function zhihuan(human, material2ID, heroIndexList)
  87. local heroConfig = canBeMaterial2(material2ID)
  88. if not heroConfig then
  89. return Broadcast.sendErr(human, Lang.TENSTAR_ERR_NOTENSTAR)
  90. end
  91. local materialList = {}
  92. local material2Cnt = 0
  93. local material1Star = 0
  94. for i = 1, heroIndexList[0] do
  95. local heroIndex = heroIndexList[i]
  96. local heroID = HeroLogic.getHeroIdByIndex(human, heroIndex)
  97. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  98. if not heroID or not heroGrid or materialList[heroIndex] then -- 不存在或重复材料不允许!
  99. return Broadcast.sendErr(human, Lang.TENSTAR_ERR_MATERIAL)
  100. end
  101. materialList[heroIndex] = true
  102. if heroID == material2ID then
  103. material2Cnt = material2Cnt + 1
  104. else
  105. local material1Config = canBeMaterial1(heroID, heroGrid.star)
  106. if not material1Config then
  107. return Broadcast.sendErr(human, Lang.TENSTAR_ERR_MATERIAL)
  108. end
  109. local materialHeroConfig = HeroExcel.hero[material1Config.heroID]
  110. if materialHeroConfig.camp ~= materialHeroConfig.camp then
  111. return Broadcast.sendErr(human, Lang.TENSTAR_ERR_CAMP)
  112. end
  113. material1Star = math.max(material1Star, material1Config.star)
  114. end
  115. end
  116. local config = UpNeedExcel.zhihuan[material1Star]
  117. if not config then
  118. return Broadcast.sendErr(human, Lang.TENSTAR_ERR_SIZE)
  119. end
  120. -- 物品检查
  121. local useItemID = config.useItem[1]
  122. local useItemCnt = config.useItem[2]
  123. if BagLogic.getItemCnt(human, useItemID) < useItemCnt then
  124. local itemName = ItemDefine.getValue(useItemID, "name")
  125. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, itemName))
  126. end
  127. local needMaterial2Cnt = config.needHeroCnt
  128. if material2Cnt ~= needMaterial2Cnt then
  129. return Broadcast.sendErr(human, Lang.TENSTAR_ERR_SIZE)
  130. end
  131. local attrConfig = HeroDefine.getAttrConfig(material2ID, material1Star)
  132. if not attrConfig then return end
  133. -- 扣物品
  134. BagLogic.delItem(human, useItemID, useItemCnt, "tenStar_displace")
  135. local fuwenTb = nil
  136. local equipTb = nil
  137. local newHeroGrid = nil
  138. local outItems = {}
  139. for heroIndex in pairs(materialList) do
  140. local heroID = HeroLogic.getHeroIdByIndex(human, heroIndex)
  141. if heroID == material2ID then
  142. HeroEquip.putOffQuick(human, heroID, heroIndex, true)
  143. FuwenLogic.putOffQuick(human, heroID, heroIndex, true)
  144. local inputIDList = {[0]=1, [1]=heroID}
  145. local inputIndexList = {[0]=1, [1]=heroIndex}
  146. outItems[#outItems + 1] = FenjieLogic.fenjie(human, FenjieLogic.FENJIE_DO_TENSTAR, inputIDList, inputIndexList, nil, "tenStar_displace")
  147. else
  148. equipTb,fuwenTb = HeroEquip.getEquipAndFuwenByHeroIndex(human,heroID,heroIndex)
  149. newHeroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  150. HeroLogic.delHeroByIndex(human, heroIndex, "tenStar_displace")
  151. end
  152. end
  153. BagLogic.sendItemGetList3(human, outItems, "tenStar_displace")
  154. newHeroGrid.id = attrConfig.heroID
  155. local tHeroCof = HeroExcel.hero[attrConfig.heroID]
  156. if tHeroCof then
  157. newHeroGrid.head = tHeroCof.head
  158. newHeroGrid.body = tHeroCof.body
  159. print("[zhihuan] 置换新英雄先更换为原先的皮肤 heroID = "..attrConfig.heroID.." head = ".. tHeroCof.head.." body = "..tHeroCof.body)
  160. end
  161. local newIndex = HeroLogic.addHeroByGrid(human, newHeroGrid, "tenStar_displace")
  162. if equipTb ~= nil then
  163. for i = 1,ItemDefine.EQUIP_MAX_CNT do
  164. if i ~= ItemDefine.EQUIP_SUBTYPE_SHUIJIN and equipTb[i] ~= nil then
  165. HeroEquip.putOn(human, attrConfig.heroID, newIndex, equipTb[i])
  166. end
  167. end
  168. end
  169. if fuwenTb ~= nil then
  170. for i = 1,2 do
  171. if fuwenTb[i] ~= nil then
  172. FuwenLogic.putOn(human, attrConfig.heroID, newIndex, fuwenTb[i],i)
  173. end
  174. end
  175. end
  176. SkinLogic.OnLoginCheckEquipSkin(human, true)
  177. -- 发送给前端用来显示获得的英雄
  178. local msgRet = Msg.gc.GC_HERO_TEN_ZHIHUAN
  179. HeroGrid.makeHeroSimple(msgRet.heroSimple, newHeroGrid, newIndex, human)
  180. Msg.send(msgRet, human.fd)
  181. end