XianzhiLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393
  1. -- 英雄召唤+英雄置换
  2. -- 每次抽奖会额外赠送卷轴和珠子
  3. local Lang = require("common.Lang")
  4. local Msg = require("core.Msg")
  5. local XianzhiExcel = require("excel.xianzhi")
  6. local HeroExcel = require("excel.hero")
  7. local ItemDefine = require("bag.ItemDefine")
  8. local BagLogic = require("bag.BagLogic")
  9. local HeroLogic = require("hero.HeroLogic")
  10. local Grid = require("bag.Grid")
  11. local HeroGrid = require("hero.HeroGrid")
  12. local HeroBook = require("hero.HeroBook")
  13. local Broadcast = require("broadcast.Broadcast")
  14. local HeroDefine = require("hero.HeroDefine")
  15. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  16. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  17. local Util = require("common.Util")
  18. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  19. local DrawCardLogic = require("drawCard.DrawCardLogic")
  20. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  21. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  22. local HeroGrowUp = require("absAct.HeroGrowUp")
  23. local YunYingLogic = require("yunying.YunYingLogic")
  24. function detail(human, camp)
  25. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  26. if not xianzhiConfig then return end
  27. local msgRet = Msg.gc.GC_XIANZHI_DETAIL
  28. local cnt = 0
  29. local bf = false
  30. local itemCnt = 0
  31. for heroID,heroConfig in pairs(HeroExcel.hero) do
  32. bf = false
  33. itemCnt = heroConfig.star == 5 and 50 or 30
  34. if camp == 4 then
  35. if (heroConfig.camp == 4 or heroConfig.camp == 5) and heroConfig.seerLv ~= 0 then
  36. bf = true
  37. end
  38. else
  39. if heroConfig.camp == camp and heroConfig.seerLv ~= 0 then
  40. bf = true
  41. end
  42. end
  43. if bf then
  44. cnt = cnt + 1
  45. Grid.makeItem(msgRet.item[cnt], heroID, itemCnt)
  46. end
  47. end
  48. for j = 1, #xianzhiConfig.zhaohuan do
  49. local tempConfig = xianzhiConfig.zhaohuan[j]
  50. if cnt > 50 then
  51. break
  52. end
  53. if j == #xianzhiConfig.zhaohuan or j == #xianzhiConfig.zhaohuan - 1 then
  54. else
  55. for k, v in ipairs(tempConfig[1]) do
  56. cnt = cnt + 1
  57. local minCnt = tempConfig[2][1]
  58. local maxCnt = tempConfig[2][2]
  59. Grid.makeItem(msgRet.item[cnt], v[1], minCnt)
  60. end
  61. end
  62. end
  63. msgRet.item[0] = cnt
  64. Msg.send(msgRet, human.fd)
  65. end
  66. -- 召唤
  67. function zhaohuanDo(human, camp, cnt, skip)
  68. local flag = RoleSystemLogic.isOpen(human,RoleSystemDefine.ROLE_SYS_ID_402)
  69. if flag ~= true then
  70. return Broadcast.sendErr(human, Lang.XIANZHI_OPEN_NEED_LV)
  71. end
  72. cnt = 1
  73. if cnt < 1 then return end
  74. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  75. if not xianzhiConfig then return end
  76. local getID = nil
  77. local getCnt = nil
  78. -- 判断消耗
  79. local needItemID = ItemDefine.ITEM_XIANZHI_BAOZHU_ID
  80. local needItemCnt = cnt
  81. local nowItemCnt = BagLogic.getItemCnt(human, needItemID)
  82. if nowItemCnt < needItemCnt then
  83. return Broadcast.sendErr(human, Util.format(Lang.XIANZHI_NO_ITEM,ItemDefine.getValue(needItemID,"name")))
  84. end
  85. getID,getCnt = zhaohuanHero(human,camp, cnt)
  86. if getID == nil or getCnt == nil then
  87. return
  88. end
  89. human.db.drawCard.skip = skip or 0
  90. -- 扣消耗
  91. BagLogic.delItem(human, needItemID, needItemCnt, "xianzhi_zhaohuan")
  92. -- 增加物品
  93. local msgRet = Msg.gc.GC_XIANZHI_ZHAOHUAN_DO
  94. msgRet.camp = camp
  95. msgRet.list[0] = #getID
  96. BagLogic.cleanMomentItemList()
  97. for i = 1, #getID do
  98. local heroID = getID[i]
  99. local heroConfig = HeroExcel.hero[heroID]
  100. local isNew = nil
  101. if heroConfig then
  102. isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  103. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE7, heroConfig.seerLv, heroID)
  104. end
  105. BagLogic.updateMomentItem(2, getID[i], getCnt[i])
  106. -- BagLogic.addItem(human, getID[i], getCnt[i], "xianzhi_zhaohuan")
  107. HeroGrid.makeHeroNice(msgRet.list[i], getID[i], getCnt[i], isNew)
  108. end
  109. -- 额外增加的物品 30珠子 1转轴
  110. local exItemCnt1 = cnt * 100
  111. BagLogic.updateMomentItem(2, ItemDefine.ITEM_XIANZHI_ZHUFU_ID, exItemCnt1)
  112. BagLogic.addMomentItemList(human, "xianzhi_zhaohuan")
  113. msgRet.list[0] = msgRet.list[0] + 1
  114. HeroGrid.makeHeroNice(msgRet.list[msgRet.list[0]], ItemDefine.ITEM_XIANZHI_ZHUFU_ID, exItemCnt1)
  115. Msg.send(msgRet, human.fd)
  116. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_14,cnt)
  117. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE2, cnt)
  118. YunYingLogic.onCallBack(human, "onTMDrawCard", cnt)
  119. end
  120. -- 置换查询
  121. function zhihuanQuery(human, heroID, heroIndex)
  122. local flag = RoleSystemLogic.isOpen(human,RoleSystemDefine.ROLE_SYS_ID_402)
  123. if flag ~= true then
  124. return Broadcast.sendErr(human, Lang.XIANZHI_OPEN_NEED_LV)
  125. end
  126. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  127. if not heroGrid then return end
  128. -- 判断是否被锁
  129. if heroGrid.isLock then
  130. return
  131. end
  132. -- 阵营,星级判断
  133. local heroConfig = HeroExcel.hero[heroGrid.id]
  134. local camp = heroConfig.camp
  135. local star = heroConfig.star
  136. if heroConfig.grade ~= 4 or star ~= 5 then return end
  137. if camp == 4 or camp == 5 then
  138. return
  139. end
  140. local needItemCnt = 100
  141. -- 判断消耗
  142. local needItemID = ItemDefine.ITEM_XIANZHI_ZHUFU_ID
  143. local nowItemCnt = BagLogic.getItemCnt(human, needItemID)
  144. if nowItemCnt < needItemCnt then
  145. return Broadcast.sendErr(human, Util.format(Lang.XIANZHI_NO_ITEM,ItemDefine.getValue(needItemID,"name")))
  146. end
  147. -- 扣消耗
  148. BagLogic.delItem(human, needItemID, needItemCnt, "xianzhi_zhihuan")
  149. -- 生成新ID
  150. local nextHero = zhihuanHero(star, camp)
  151. -- 新ID不等于旧ID
  152. human.tempZhihuanID = nextHero
  153. human.tempZhihuanHeroID = heroID
  154. human.tempZhihuanHeroIndex = heroIndex
  155. -- 通知客户端
  156. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_QUERY
  157. msgRet.heroID = heroID
  158. msgRet.heroIndex = heroIndex
  159. msgRet.skip = human.db.drawCard.skip or 0
  160. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple, nextHero)
  161. HeroGrid.makeHeroStatic(msgRet.heroStatic,nextHero)
  162. Msg.send(msgRet, human.fd)
  163. end
  164. function zhihuanDo(human, heroID, heroIndex)
  165. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  166. if not heroGrid then return end
  167. -- 判断是否被锁
  168. if heroGrid.isLock then
  169. return
  170. end
  171. if human.tempZhihuanHeroID ~= heroID then return end
  172. if human.tempZhihuanHeroIndex ~= heroIndex then return end
  173. local tempGrid = heroGrid
  174. tempGrid.id = human.tempZhihuanID
  175. -- 先删
  176. HeroLogic.delHeroByIndex(human, heroIndex, "xianzhi_zhihuan")
  177. human.tempZhihuanID = nil
  178. human.tempZhihuanHeroID = nil
  179. human.tempZhihuanHeroIndex = nil
  180. -- 改db
  181. local newIndex = HeroLogic.addHeroByGrid(human, tempGrid, "xianzhi_zhihuan")
  182. -- 通知客户端
  183. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_DO
  184. HeroGrid.makeHeroSimple(msgRet.heroSimple, tempGrid, newIndex, human)
  185. Msg.send(msgRet, human.fd)
  186. end
  187. --------------------------功能函数---------------------------------
  188. function zhaohuanHero(human,camp, cnt)
  189. local xianzhiConfig = Util.copyTable(XianzhiExcel.xianzhi[camp])
  190. if not xianzhiConfig then return end
  191. local totalWeight = 0
  192. local totalWeight1 = 0
  193. for i = 1, #xianzhiConfig.zhaohuan do
  194. totalWeight = totalWeight + xianzhiConfig.zhaohuan[i][3]
  195. end
  196. for i = 1, #xianzhiConfig.zhaohuan1 do
  197. totalWeight1 = totalWeight1 + xianzhiConfig.zhaohuan1[i][3]
  198. end
  199. cnt = cnt * 5
  200. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_4)
  201. if cjPrivilege then
  202. local randNum = math.random(1,100)
  203. if randNum == 1 then
  204. cnt = cnt + 1
  205. end
  206. end
  207. local getID = {}
  208. local getCnt = {}
  209. for i = 1, cnt do
  210. if camp == 4 or camp == 5 then
  211. camp = math.random(4,5)
  212. end
  213. local tWeight = totalWeight
  214. local zhaohuan = xianzhiConfig.zhaohuan
  215. if i == 5 then
  216. zhaohuan = xianzhiConfig.zhaohuan1
  217. tWeight = totalWeight1
  218. end
  219. local randNum = math.random(1, tWeight)
  220. for j = 1, #zhaohuan do
  221. local tempConfig = zhaohuan[j]
  222. local tempWeight = tempConfig[3]
  223. if randNum <= tempWeight then --抽中
  224. if j == #zhaohuan or j == #zhaohuan - 1 then --抽中五星英雄
  225. local allWeight = 0
  226. for k,v in ipairs(tempConfig[1]) do
  227. allWeight = allWeight + v[2]
  228. end
  229. local nowNum = math.random(1, allWeight)
  230. for k, v in ipairs(tempConfig[1]) do
  231. local nowWeight = v[2]
  232. if nowNum <= nowWeight then
  233. local rate = v[1]
  234. local chipId = {}
  235. local index = 1
  236. for heroID,heroConfig in pairs(HeroExcel.hero) do
  237. if heroConfig.camp == camp and heroConfig.seerLv == rate then
  238. chipId[index] = heroID
  239. index = index + 1
  240. end
  241. end
  242. local randomNum = 0
  243. if index == 1 then
  244. return
  245. else
  246. randomNum = math.random(1,index -1)
  247. end
  248. getID[i] = chipId[randomNum]
  249. local minCnt = tempConfig[2][1]
  250. local maxCnt = tempConfig[2][2]
  251. getCnt[i] = math.random(minCnt,maxCnt)
  252. break
  253. end
  254. nowNum = nowNum - nowWeight
  255. end
  256. break
  257. else -- 抽到其他物品
  258. local allWeight = 0
  259. for k, v in ipairs(tempConfig[1]) do
  260. allWeight = allWeight + v[2]
  261. end
  262. local nowNum = math.random(1, allWeight)
  263. for k, v in ipairs(tempConfig[1]) do
  264. local nowWeight = v[2]
  265. if nowNum <= nowWeight then
  266. getID[i] = v[1]
  267. local minCnt = tempConfig[2][1]
  268. local maxCnt = tempConfig[2][2]
  269. getCnt[i] = math.random(minCnt,maxCnt)
  270. break
  271. end
  272. nowNum = nowNum - nowWeight
  273. end
  274. break
  275. end
  276. end
  277. randNum = randNum - tempWeight
  278. end
  279. end
  280. return getID, getCnt
  281. end
  282. function zhihuanHero(star, camp)
  283. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  284. if not xianzhiConfig then return end
  285. local nextHero = nil
  286. local preStarConfig = xianzhiConfig.preStarFive
  287. if not preStarConfig then return end
  288. local totalWeight = 0
  289. for k, v in ipairs(preStarConfig) do
  290. totalWeight = totalWeight + v[2]
  291. end
  292. local randNum = math.random(1, totalWeight)
  293. for k, v in ipairs(preStarConfig) do
  294. tempWeight = v[2]
  295. if randNum <= tempWeight then
  296. local rate = v[1]
  297. local chipId = { }
  298. local index = 0
  299. for heroID, heroConfig in pairs(HeroExcel.hero) do
  300. if heroConfig.camp == camp and heroConfig.zhihuanLv == rate then
  301. index = index + 1
  302. chipId[index] = heroID
  303. end
  304. end
  305. local randomNum = math.random(1, index)
  306. nextHero = chipId[randomNum]
  307. break
  308. end
  309. randNum = randNum - tempWeight
  310. end
  311. return nextHero
  312. end
  313. function preview(human, camp, star)
  314. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_PREVIEW
  315. if star < 5 then return end
  316. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  317. if not xianzhiConfig then return end
  318. local nextHero = nil
  319. local len = 0
  320. for k, v in ipairs (xianzhiConfig.preStarFive) do
  321. if len >= 50 then
  322. break
  323. end
  324. local rate = v[1]
  325. for heroID,heroConfig in pairs(HeroExcel.hero) do
  326. if heroConfig.camp == camp and heroConfig.zhihuanLv == rate then
  327. len = len + 1
  328. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple[len], heroID)
  329. end
  330. end
  331. end
  332. msgRet.heroSimple[0] = len
  333. Msg.send(msgRet, human.fd)
  334. end