HeroBook.lua 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. -----------------------------------------------------
  2. -- 英雄图鉴
  3. -----------------------------------------------------
  4. local Util = require("common.Util")
  5. local Msg = require("core.Msg")
  6. local HeroExcel = require("excel.hero")
  7. local HeroGrid = require("hero.HeroGrid")
  8. local HeroDefine = require("hero.HeroDefine")
  9. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  10. local Grid = require("bag.Grid")
  11. local BagLogic = require("bag.BagLogic")
  12. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  13. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  14. CAMP_2_MSGLIST = CAMP_2_MSGLIST or {}
  15. LIEZHUAN_REWARD_NO = 0 --不可领取
  16. LIEZHUAN_REWARD_CAN = 1 --可领取
  17. LIEZHUAN_REWARD_HAD = 2 --已领取
  18. CAMP_HEROS = {}
  19. CAMP_MAX = 5
  20. local function getHeros(camp)
  21. if CAMP_HEROS[camp] then return CAMP_HEROS[camp] end
  22. local Heros
  23. local heroCf
  24. for id,v in Util.pairsByKeys(HeroExcel.tujian) do
  25. heroCf = HeroExcel.hero[id]
  26. if not heroCf then
  27. assert(nil, "id err "..id)
  28. end
  29. CAMP_HEROS[heroCf.camp] = CAMP_HEROS[heroCf.camp] or {}
  30. CAMP_HEROS[heroCf.camp][id] = CAMP_HEROS[heroCf.camp][id] or {}
  31. Heros = CAMP_HEROS[heroCf.camp][id]
  32. Heros[#Heros + 1] = id
  33. end
  34. return CAMP_HEROS[camp]
  35. end
  36. local function getRewardStateByHeroID(human, heroID, star)
  37. local heroBookDB = human.db.heroBook
  38. if heroBookDB and
  39. heroBookDB.lieZhuanReward and
  40. heroBookDB.lieZhuanReward[heroID] and
  41. heroBookDB.lieZhuanReward[heroID][star] then
  42. return LIEZHUAN_REWARD_HAD
  43. end
  44. if isGet(human, heroID, star) then
  45. return LIEZHUAN_REWARD_CAN
  46. end
  47. return LIEZHUAN_REWARD_NO
  48. end
  49. local function isDotByHeroID(human,heroID, star)
  50. if human.db.lv < 9 then
  51. return false
  52. end
  53. local state = getRewardStateByHeroID(human,heroID, star)
  54. if state == LIEZHUAN_REWARD_CAN then
  55. return true
  56. end
  57. end
  58. local function getTuJianStar(human, heroID)
  59. -- 显示获取的最高星级
  60. local showStar
  61. local config = HeroExcel.tujian[heroID]
  62. if not config then return end
  63. local starList = config.star
  64. local index = 0
  65. for k, _star in ipairs(config.star) do
  66. local get = isGet(human, heroID, _star)
  67. if get then
  68. showStar = _star
  69. index = index + 1
  70. end
  71. end
  72. return showStar, index
  73. end
  74. local function getRewardStar(human, heroID)
  75. -- 显示获取的最高星级
  76. local star
  77. local config = HeroExcel.tujian[heroID]
  78. if not config then return end
  79. local starList = config.star
  80. local index = 0
  81. for k, _star in ipairs(config.star) do
  82. local state = getRewardStateByHeroID(human, heroID, _star)
  83. if state == LIEZHUAN_REWARD_CAN then
  84. star = _star
  85. index = k
  86. break
  87. end
  88. end
  89. if star == nil then
  90. for k, _star in ipairs(config.star) do
  91. local state = getRewardStateByHeroID(human, heroID, _star)
  92. if state == LIEZHUAN_REWARD_NO then
  93. star = _star
  94. index = k
  95. break
  96. end
  97. end
  98. end
  99. return star, index
  100. end
  101. function isGetHero(human, heroID)
  102. if not human then return end
  103. local heroCf = HeroExcel.hero[heroID]
  104. if not heroCf then return end
  105. return getRewardStateByHeroID(human, heroID, heroCf.star)
  106. end
  107. local function warperQuerySimpleCSList(human, heroID, showStar, listNet)
  108. local heroGrid = HeroGrid.getCacheHeroGridTujian(heroID)
  109. heroGrid.star = showStar
  110. HeroGrid.makeHeroSimple(listNet.heros, heroGrid, nil, human, nil, true)
  111. listNet.isDot = isDotByHeroID(human, heroID, showStar) and 1 or 0
  112. end
  113. function querySimple_CS(human, camp)
  114. local heros = getHeros(camp)
  115. local msgRet = Msg.gc.GC_HERO_BOOK_QUERY_CS
  116. msgRet.camp = camp
  117. msgRet.list[0] = 0
  118. local rewardState
  119. local listNet
  120. local len = 0
  121. for _id, heroIDs in pairs(heros) do
  122. len = len + 1
  123. local showStar = getTuJianStar(human, _id)
  124. listNet = msgRet.list[len]
  125. warperQuerySimpleCSList(human, heroIDs[1], showStar, listNet)
  126. if msgRet.list[0] >= HeroDefine.PAGE_HERO_COUNT then
  127. msgRet.list[0] = len
  128. Msg.send(msgRet, human.fd)
  129. page = page + 1
  130. end
  131. end
  132. msgRet.list[0] = len
  133. len = 0
  134. for index = 1, CAMP_MAX do
  135. local heros = getHeros(index)
  136. local setDot = 0
  137. for _id, heroIDs in pairs(heros) do
  138. local showStar = getTuJianStar(human, _id)
  139. local isDot = isDotByHeroID(human, heroIDs[1], showStar)
  140. if isDot == true then
  141. setDot = 1
  142. break
  143. end
  144. end
  145. len = len + 1
  146. msgRet.dot[len] = setDot
  147. end
  148. msgRet.dot[0] = len
  149. Msg.send(msgRet, human.fd)
  150. end
  151. function CG_HERO_BOOK_LIEZHUAN_QUERY(human, heroID)
  152. local config = HeroExcel.tujian[heroID]
  153. if not config then return end
  154. local nowStar = getTuJianStar(human, heroID)
  155. local showStar, index = getRewardStar(human, heroID)
  156. local heroGrid = HeroGrid.getCacheHeroGridTujian(heroID)
  157. if index == 0 then
  158. index = #config.star
  159. showStar = config.star[index]
  160. end
  161. local nextIndex = index
  162. if not config.star[nextIndex] then
  163. return
  164. end
  165. local nextStar = config.star[nextIndex] or showStar
  166. showStar = showStar or nextStar
  167. local msgRet = Msg.gc.GC_HERO_BOOK_LIEZHUAN_QUERY
  168. msgRet.id = heroID
  169. heroGrid.star = showStar
  170. HeroGrid.makeHeroDynamic(msgRet.data, heroGrid)
  171. msgRet.lieZhuanDesc = config.desc
  172. msgRet.rewardState = getRewardStateByHeroID(human, heroID, showStar)
  173. msgRet.nextStar = nextStar
  174. msgRet.curStar = nowStar or 0
  175. if msgRet.curStar > msgRet.nextStar then
  176. msgRet.curStar = msgRet.nextStar
  177. end
  178. local itemID = config.lieZhuanReward[index][1]
  179. local itemCnt = config.lieZhuanReward[index][2]
  180. Grid.makeItem(msgRet.lieZhuanReward, itemID, itemCnt)
  181. Msg.send(msgRet, human.fd)
  182. end
  183. function isGet(human, heroID, star)
  184. if not human.db.heroBook then return end
  185. local heroConfig = HeroExcel.hero[heroID]
  186. if not heroConfig then return end
  187. if not human.db.heroBook[heroID] then return end
  188. return human.db.heroBook[heroID][star]
  189. end
  190. function onAddHero(human, heroID, star)
  191. local heroConfig = HeroExcel.hero[heroID]
  192. if not heroConfig then return end
  193. local config = HeroExcel.tujian[heroID]
  194. if not config then return end
  195. human.db.heroBook = human.db.heroBook or {}
  196. human.db.heroBook[heroID] = human.db.heroBook[heroID] or {}
  197. for k, _star in ipairs(config.star) do
  198. if star >= _star and human.db.heroBook[heroID][_star] == nil then
  199. human.db.heroBook[heroID][_star] = true
  200. end
  201. end
  202. end
  203. function CG_HERO_BOOK_LIEZHUAN_GET(human, heroID)
  204. local heroConfig = HeroExcel.hero[heroID]
  205. if not heroConfig then return end
  206. local config = HeroExcel.tujian[heroID]
  207. if not config then return end
  208. local showStar, index = getRewardStar(human, heroID)
  209. if not showStar or not index then return end
  210. local rewardState = getRewardStateByHeroID(human, heroID, showStar)
  211. if rewardState ~= LIEZHUAN_REWARD_CAN then
  212. return
  213. end
  214. human.db.heroBook = human.db.heroBook or {}
  215. human.db.heroBook.lieZhuanReward = human.db.heroBook.lieZhuanReward or {}
  216. human.db.heroBook.lieZhuanReward[heroID] = human.db.heroBook.lieZhuanReward[heroID] or {}
  217. human.db.heroBook.lieZhuanReward[heroID][showStar] = true
  218. local itemID = config.lieZhuanReward[index][1]
  219. local itemCnt = config.lieZhuanReward[index][2]
  220. BagLogic.cleanMomentItemList()
  221. BagLogic.updateMomentItem(1, itemID,itemCnt)
  222. BagLogic.addMomentItemList(human, "hero_book_liezhuan")
  223. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_301)
  224. CG_HERO_BOOK_LIEZHUAN_QUERY(human, heroID)
  225. end
  226. function isDot(human)
  227. for camp = 1, CAMP_MAX do
  228. local heros = getHeros(camp)
  229. for _id, heroIDs in pairs(heros) do
  230. local showStar = getTuJianStar(human, _id)
  231. local isDot = isDotByHeroID(human, heroIDs[1], showStar)
  232. if isDot and isDot ~= 0 then
  233. return 1
  234. end
  235. end
  236. end
  237. return 0
  238. end
  239. function queryHeroBookById(human,heroID,star)
  240. local msgRet = Msg.gc.GC_HERO_BOOK_SINGLE_QUERY
  241. local heroGrid = HeroGrid.getCacheHeroGridTujian(heroID)
  242. heroGrid.star = star
  243. HeroGrid.makeHeroSimple(msgRet.hero, heroGrid, nil, human, nil, true)
  244. Msg.send(msgRet, human.fd)
  245. end