XianzhiLogic.lua 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  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,heroGrid.id)
  151. if not nextHero then
  152. -- 没有置换目标
  153. return
  154. end
  155. -- 新ID不等于旧ID
  156. human.tempZhihuanID = nextHero
  157. human.tempZhihuanHeroID = heroID
  158. human.tempZhihuanHeroIndex = heroIndex
  159. -- 通知客户端
  160. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_QUERY
  161. msgRet.heroID = heroID
  162. msgRet.heroIndex = heroIndex
  163. msgRet.skip = human.db.drawCard.skip or 0
  164. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple, nextHero)
  165. HeroGrid.makeHeroStatic(msgRet.heroStatic,nextHero)
  166. Msg.send(msgRet, human.fd)
  167. end
  168. function zhihuanDo(human, heroID, heroIndex)
  169. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  170. if not heroGrid then return end
  171. -- 判断是否被锁
  172. if heroGrid.isLock then
  173. return
  174. end
  175. if human.tempZhihuanHeroID ~= heroID then return end
  176. if human.tempZhihuanHeroIndex ~= heroIndex then return end
  177. local tempGrid = heroGrid
  178. tempGrid.id = human.tempZhihuanID
  179. -- 先删
  180. HeroLogic.delHeroByIndex(human, heroIndex, "xianzhi_zhihuan")
  181. human.tempZhihuanID = nil
  182. human.tempZhihuanHeroID = nil
  183. human.tempZhihuanHeroIndex = nil
  184. -- 改db
  185. local newIndex = HeroLogic.addHeroByGrid(human, tempGrid, "xianzhi_zhihuan")
  186. -- 通知客户端
  187. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_DO
  188. HeroGrid.makeHeroSimple(msgRet.heroSimple, tempGrid, newIndex, human)
  189. Msg.send(msgRet, human.fd)
  190. end
  191. --------------------------功能函数---------------------------------
  192. function zhaohuanHero(human,camp, cnt)
  193. local xianzhiConfig = Util.copyTable(XianzhiExcel.xianzhi[camp])
  194. if not xianzhiConfig then return end
  195. local totalWeight = 0
  196. local totalWeight1 = 0
  197. for i = 1, #xianzhiConfig.zhaohuan do
  198. totalWeight = totalWeight + xianzhiConfig.zhaohuan[i][3]
  199. end
  200. for i = 1, #xianzhiConfig.zhaohuan1 do
  201. totalWeight1 = totalWeight1 + xianzhiConfig.zhaohuan1[i][3]
  202. end
  203. cnt = cnt * 5
  204. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_4)
  205. if cjPrivilege then
  206. local randNum = math.random(1,100)
  207. if randNum == 1 then
  208. cnt = cnt + 1
  209. end
  210. end
  211. local getID = {}
  212. local getCnt = {}
  213. for i = 1, cnt do
  214. if camp == 4 or camp == 5 then
  215. camp = math.random(4,5)
  216. end
  217. local tWeight = totalWeight
  218. local zhaohuan = xianzhiConfig.zhaohuan
  219. if i == 5 then
  220. zhaohuan = xianzhiConfig.zhaohuan1
  221. tWeight = totalWeight1
  222. end
  223. local randNum = math.random(1, tWeight)
  224. for j = 1, #zhaohuan do
  225. local tempConfig = zhaohuan[j]
  226. local tempWeight = tempConfig[3]
  227. if randNum <= tempWeight then --抽中
  228. if j == #zhaohuan or j == #zhaohuan - 1 then --抽中五星英雄
  229. local allWeight = 0
  230. for k,v in ipairs(tempConfig[1]) do
  231. allWeight = allWeight + v[2]
  232. end
  233. local nowNum = math.random(1, allWeight)
  234. for k, v in ipairs(tempConfig[1]) do
  235. local nowWeight = v[2]
  236. if nowNum <= nowWeight then
  237. local rate = v[1]
  238. local chipId = {}
  239. local index = 1
  240. for heroID,heroConfig in pairs(HeroExcel.hero) do
  241. if heroConfig.camp == camp and heroConfig.seerLv == rate then
  242. chipId[index] = heroID
  243. index = index + 1
  244. end
  245. end
  246. local randomNum = 0
  247. if index == 1 then
  248. return
  249. else
  250. randomNum = math.random(1,index -1)
  251. end
  252. getID[i] = chipId[randomNum]
  253. local minCnt = tempConfig[2][1]
  254. local maxCnt = tempConfig[2][2]
  255. getCnt[i] = math.random(minCnt,maxCnt)
  256. break
  257. end
  258. nowNum = nowNum - nowWeight
  259. end
  260. break
  261. else -- 抽到其他物品
  262. local allWeight = 0
  263. for k, v in ipairs(tempConfig[1]) do
  264. allWeight = allWeight + v[2]
  265. end
  266. local nowNum = math.random(1, allWeight)
  267. for k, v in ipairs(tempConfig[1]) do
  268. local nowWeight = v[2]
  269. if nowNum <= nowWeight then
  270. getID[i] = v[1]
  271. local minCnt = tempConfig[2][1]
  272. local maxCnt = tempConfig[2][2]
  273. getCnt[i] = math.random(minCnt,maxCnt)
  274. break
  275. end
  276. nowNum = nowNum - nowWeight
  277. end
  278. break
  279. end
  280. end
  281. randNum = randNum - tempWeight
  282. end
  283. end
  284. return getID, getCnt
  285. end
  286. function zhihuanHero(star, camp,heroId)
  287. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  288. if not xianzhiConfig then return end
  289. local nextHero = nil
  290. local preStarConfig = xianzhiConfig.preStarFive
  291. if not preStarConfig then return end
  292. local totalWeight = 0
  293. for k, v in ipairs(preStarConfig) do
  294. totalWeight = totalWeight + v[2]
  295. end
  296. local randNum = math.random(1, totalWeight)
  297. for k, v in ipairs(preStarConfig) do
  298. tempWeight = v[2]
  299. if randNum <= tempWeight then
  300. local rate = v[1]
  301. local chipId = { }
  302. local index = 0
  303. for heroID, heroConfig in pairs(HeroExcel.hero) do
  304. if heroID ~= heroId and heroConfig.camp == camp and heroConfig.zhihuanLv == rate then
  305. index = index + 1
  306. chipId[index] = heroID
  307. end
  308. end
  309. if index == 0 then
  310. return
  311. end
  312. local randomNum = math.random(1, index)
  313. nextHero = chipId[randomNum]
  314. break
  315. end
  316. randNum = randNum - tempWeight
  317. end
  318. return nextHero
  319. end
  320. function preview(human, camp, star)
  321. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_PREVIEW
  322. if star < 5 then return end
  323. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  324. if not xianzhiConfig then return end
  325. local nextHero = nil
  326. local len = 0
  327. for k, v in ipairs (xianzhiConfig.preStarFive) do
  328. if len >= 50 then
  329. break
  330. end
  331. local rate = v[1]
  332. for heroID,heroConfig in pairs(HeroExcel.hero) do
  333. if heroConfig.camp == camp and heroConfig.zhihuanLv == rate then
  334. len = len + 1
  335. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple[len], heroID)
  336. end
  337. end
  338. end
  339. msgRet.heroSimple[0] = len
  340. Msg.send(msgRet, human.fd)
  341. end