HechengLogic.lua 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. -- 统一英雄合成和英雄升星的入口,统一使用HeroLogic.heroJueXingDo()
  2. local UpNeedExcel = require("excel.upNeed")
  3. local HeroExcel = require("excel.hero")
  4. local Lang = require("common.Lang")
  5. local Util = require("common.Util")
  6. local Msg = require("core.Msg")
  7. local ObjHuman = require("core.ObjHuman")
  8. local Grid = require("bag.Grid")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local HeroGrid = require("hero.HeroGrid")
  11. local HeroLogic = require("hero.HeroLogic")
  12. local HeroDefine = require("hero.HeroDefine")
  13. local HeroAttrExcel = require("excel.hero").attr
  14. local CombatPosLogic = require("combat.CombatPosLogic")
  15. COND_TYPE_HEROID = 1 -- 指定id
  16. COND_TYPE_CAMPSTAR = 2 -- 指定阵营和星级
  17. local NORMAL_COND = {1,0,1}
  18. local NORMAL_CONDS = {}
  19. function getHechengConds(heroID, conds)
  20. Util.cleanTable(NORMAL_CONDS)
  21. NORMAL_COND[2] = heroID
  22. NORMAL_CONDS[1] = NORMAL_COND
  23. for _, cond in ipairs(conds) do
  24. NORMAL_CONDS[#NORMAL_CONDS + 1] = cond
  25. end
  26. return NORMAL_CONDS
  27. end
  28. -- 合成查询
  29. function hechengQuery(human, camp)
  30. local msgRet = Msg.gc.GC_HECHENG_QUERY
  31. msgRet.camp = camp
  32. local upStar = HeroDefine.ATTRHEROS
  33. local len = 0
  34. for heroID, v in pairs(upStar) do
  35. local mHeroConfig = HeroExcel.hero[heroID]
  36. if mHeroConfig and (mHeroConfig.camp == camp or camp == 0) then
  37. local nextAttrConfig = HeroDefine.getNextAttrConfig(heroID, mHeroConfig.star)
  38. if nextAttrConfig ~= nil then
  39. for _, attrID in pairs(v) do
  40. local attrConfig = HeroAttrExcel[attrID]
  41. if attrConfig then
  42. if attrConfig.jinjieshi < 1 and #attrConfig.cond > 0 then
  43. len = len + 1
  44. local net = msgRet.list[len]
  45. local conds = getHechengConds(heroID, attrConfig.cond)
  46. HeroGrid.makeHeroSimpleByID(net.heroSimple, nextAttrConfig.heroID)
  47. net.heroSimple.star = nextAttrConfig.star
  48. net.conditionList[0] = #conds
  49. for i = 1, #conds do
  50. HeroLogic.makeUpStarCond(net.conditionList[i], conds[i])
  51. end
  52. if len >= 10 then
  53. msgRet.isEnd = 0
  54. msgRet.list[0] = len
  55. Msg.send(msgRet, human.fd)
  56. len = 0
  57. end
  58. end
  59. end
  60. end
  61. end
  62. end
  63. end
  64. msgRet.isEnd = 1
  65. msgRet.list[0] = len
  66. Msg.send(msgRet, human.fd)
  67. sendHechengReds(human)
  68. end
  69. -- 检查材料符合不
  70. function checkCond(human, inputIDList, inputIndexList, condList)
  71. if inputIDList[0] ~= inputIndexList[0] then
  72. return
  73. end
  74. local indexTable = {}
  75. local indexStar = {}
  76. for i = 1, inputIDList[0] do
  77. local heroIndex = inputIndexList[i]
  78. local heroID = inputIDList[i]
  79. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  80. if not heroGrid then -- 不存在英雄
  81. return
  82. end
  83. if indexTable[heroIndex] then -- 重复id
  84. return
  85. end
  86. indexTable[heroIndex] = true
  87. if CombatPosLogic.isLastInCombat(human, heroGrid.uuid) then
  88. return
  89. end
  90. indexStar[i] = heroGrid.star
  91. end
  92. local judgeIndex = 0
  93. for _, cond in ipairs(condList) do
  94. local ctype = cond[1]
  95. if ctype == COND_TYPE_HEROID then
  96. local needHeroID = cond[2]
  97. local needHeroCnt = cond[3]
  98. local needHeroStar = cond[4] or HeroExcel.hero[needHeroID].star
  99. for i = 1, needHeroCnt do
  100. judgeIndex = judgeIndex + 1
  101. if judgeIndex > inputIDList[0] then
  102. return Broadcast.sendErr(human, Lang.HERO_HECHENG_ERR_MATERIAL)
  103. end
  104. local inputTargetID = inputIDList[judgeIndex]
  105. local inputTargetStar = indexStar[judgeIndex]
  106. if inputTargetID ~= needHeroID or inputTargetStar ~= needHeroStar then
  107. return Broadcast.sendErr(human, Lang.HERO_HECHENG_ERR_COND)
  108. end
  109. end
  110. elseif ctype == COND_TYPE_CAMPSTAR then
  111. local needHeroCamp = cond[2]
  112. local needHeroStar = cond[3]
  113. local needHeroCnt = cond[4]
  114. for j = 1, needHeroCnt do
  115. judgeIndex = judgeIndex + 1
  116. if judgeIndex > inputIDList[0] then
  117. return Broadcast.sendErr(human, Lang.HERO_HECHENG_ERR_MATERIAL)
  118. end
  119. local inputTargetID = inputIDList[judgeIndex]
  120. local inputHeroConfig = HeroExcel.hero[inputTargetID]
  121. if needHeroCamp ~= 0 and inputHeroConfig.camp ~= needHeroCamp then
  122. return Broadcast.sendErr(human, Lang.HERO_HECHENG_ERR_COND)
  123. end
  124. if indexStar[judgeIndex] ~= needHeroStar then
  125. return Broadcast.sendErr(human, Lang.HERO_HECHENG_ERR_COND)
  126. end
  127. end
  128. else
  129. assert(nil)
  130. end
  131. end
  132. return true
  133. end
  134. function isHeroRed(human, heroID, config)
  135. local conds = getHechengConds(heroID, config)
  136. local without = {}
  137. for _, cond in ipairs(conds) do
  138. local ctype = cond[1]
  139. local needCnt = cond[3]
  140. if not needCnt then return end
  141. if ctype == COND_TYPE_CAMPSTAR then
  142. needCnt = cond[4]
  143. end
  144. for i = 1, needCnt do
  145. local index = HeroLogic.selectJuexingGrid(human, ctype, cond, without)
  146. if not index then return end
  147. without[index] = true
  148. end
  149. end
  150. return true
  151. end
  152. function isCampRed(human, camp)
  153. local upStar = HeroDefine.ATTRHEROS
  154. for heroID, v in pairs(upStar) do
  155. local mHeroConfig = HeroExcel.hero[heroID]
  156. if mHeroConfig and mHeroConfig.camp == camp then
  157. for _, attrID in pairs(v) do
  158. local attrConfig = HeroAttrExcel[attrID]
  159. if attrConfig and attrConfig.jinjieshi < 1 and #attrConfig.cond > 0 and
  160. isHeroRed(human, heroID, attrConfig.cond) then
  161. return true
  162. end
  163. end
  164. end
  165. end
  166. end
  167. -- 红点
  168. function sendHechengReds(human)
  169. local msgRet = Msg.gc.GC_HECHENG_REDS
  170. msgRet.reds[0] = #HeroExcel.camp
  171. for camp = 1, msgRet.reds[0] do
  172. msgRet.reds[camp] = isCampRed(human, camp) and 1 or 0
  173. end
  174. --Msg.trace(msgRet)
  175. Msg.send(msgRet, human.fd)
  176. end