XianzhiLogic.lua 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454
  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. local xianzhiOutPutId = 126
  25. local function makeShopElem(human,config)
  26. end
  27. function detail(human, camp)
  28. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  29. if not xianzhiConfig then return end
  30. local msgRet = Msg.gc.GC_XIANZHI_DETAIL
  31. local cnt = 0
  32. local bf = false
  33. local itemCnt = 0
  34. for heroID,heroConfig in pairs(HeroExcel.hero) do
  35. bf = false
  36. itemCnt = heroConfig.star == 5 and 50 or 30
  37. if camp == 4 then
  38. if (heroConfig.camp == 4 or heroConfig.camp == 5) and heroConfig.seerLv ~= 0 then
  39. bf = true
  40. end
  41. else
  42. if heroConfig.camp == camp and heroConfig.seerLv ~= 0 then
  43. bf = true
  44. end
  45. end
  46. if bf then
  47. cnt = cnt + 1
  48. Grid.makeItem(msgRet.item[cnt], heroID, itemCnt)
  49. end
  50. end
  51. for j = 1, #xianzhiConfig.zhaohuan do
  52. local tempConfig = xianzhiConfig.zhaohuan[j]
  53. if cnt > 50 then
  54. break
  55. end
  56. if j == #xianzhiConfig.zhaohuan or j == #xianzhiConfig.zhaohuan - 1 then
  57. else
  58. for k, v in ipairs(tempConfig[1]) do
  59. cnt = cnt + 1
  60. local minCnt = tempConfig[2][1]
  61. local maxCnt = tempConfig[2][2]
  62. Grid.makeItem(msgRet.item[cnt], v[1], minCnt)
  63. end
  64. end
  65. end
  66. msgRet.item[0] = cnt
  67. Msg.send(msgRet, human.fd)
  68. end
  69. -- 召唤
  70. function zhaohuanDo(human, camp, cnt, skip)
  71. local flag = RoleSystemLogic.isOpen(human,RoleSystemDefine.ROLE_SYS_ID_402)
  72. if flag ~= true then
  73. return Broadcast.sendErr(human, Lang.XIANZHI_OPEN_NEED_LV)
  74. end
  75. cnt = 1
  76. if cnt < 1 then return end
  77. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  78. if not xianzhiConfig then return end
  79. local getID = nil
  80. local getCnt = nil
  81. -- 判断消耗
  82. local needItemID = ItemDefine.ITEM_XIANZHI_BAOZHU_ID
  83. local needItemCnt = cnt
  84. local nowItemCnt = BagLogic.getItemCnt(human, needItemID)
  85. if nowItemCnt < needItemCnt then
  86. return Broadcast.sendErr(human, Util.format(Lang.XIANZHI_NO_ITEM,ItemDefine.getValue(needItemID,"name")))
  87. end
  88. getID,getCnt = zhaohuanHero(human,camp, cnt)
  89. if getID == nil or getCnt == nil then
  90. return
  91. end
  92. human.db.drawCard.skip = skip or 0
  93. -- 扣消耗
  94. BagLogic.delItem(human, needItemID, needItemCnt, "xianzhi_zhaohuan")
  95. -- 增加物品
  96. local msgRet = Msg.gc.GC_XIANZHI_ZHAOHUAN_DO
  97. msgRet.camp = camp
  98. msgRet.list[0] = #getID
  99. BagLogic.cleanMomentItemList()
  100. for i = 1, #getID do
  101. local heroID = getID[i]
  102. local heroConfig = HeroExcel.hero[heroID]
  103. local isNew = nil
  104. if heroConfig then
  105. isNew = not HeroBook.isGet(human, heroConfig.id, heroConfig.star)
  106. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE7, heroConfig.seerLv, heroID)
  107. end
  108. BagLogic.updateMomentItem(2, getID[i], getCnt[i])
  109. -- BagLogic.addItem(human, getID[i], getCnt[i], "xianzhi_zhaohuan")
  110. HeroGrid.makeHeroNice(msgRet.list[i], getID[i], getCnt[i], isNew)
  111. end
  112. BagLogic.updateMomentItem(2, xianzhiOutPutId, 1) --每次召唤获得精华1个
  113. -- 额外增加的物品 30珠子 1转轴
  114. local exItemCnt1 = cnt * 100
  115. BagLogic.updateMomentItem(2, ItemDefine.ITEM_XIANZHI_ZHUFU_ID, exItemCnt1)
  116. BagLogic.addMomentItemList(human, "xianzhi_zhaohuan")
  117. msgRet.list[0] = msgRet.list[0] + 1
  118. HeroGrid.makeHeroNice(msgRet.list[msgRet.list[0]], ItemDefine.ITEM_XIANZHI_ZHUFU_ID, exItemCnt1)
  119. Msg.send(msgRet, human.fd)
  120. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_14,cnt)
  121. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE2, cnt)
  122. YunYingLogic.onCallBack(human, "onTMDrawCard", cnt)
  123. end
  124. -- 置换查询
  125. function zhihuanQuery(human, heroID, heroIndex)
  126. local flag = RoleSystemLogic.isOpen(human,RoleSystemDefine.ROLE_SYS_ID_402)
  127. if flag ~= true then
  128. return Broadcast.sendErr(human, Lang.XIANZHI_OPEN_NEED_LV)
  129. end
  130. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  131. if not heroGrid then return end
  132. -- 判断是否被锁
  133. if heroGrid.isLock then
  134. return
  135. end
  136. -- 阵营,星级判断
  137. local heroConfig = HeroExcel.hero[heroGrid.id]
  138. local camp = heroConfig.camp
  139. local star = heroConfig.star
  140. if heroConfig.grade ~= 4 or star ~= 5 then return end
  141. if camp == 4 or camp == 5 then
  142. return
  143. end
  144. local needItemCnt = 100
  145. -- 判断消耗
  146. local needItemID = ItemDefine.ITEM_XIANZHI_ZHUFU_ID
  147. local nowItemCnt = BagLogic.getItemCnt(human, needItemID)
  148. if nowItemCnt < needItemCnt then
  149. return Broadcast.sendErr(human, Util.format(Lang.XIANZHI_NO_ITEM,ItemDefine.getValue(needItemID,"name")))
  150. end
  151. -- 扣消耗
  152. BagLogic.delItem(human, needItemID, needItemCnt, "xianzhi_zhihuan")
  153. -- 生成新ID
  154. local nextHero = zhihuanHero(star, camp,heroGrid.id)
  155. if not nextHero then
  156. -- 没有置换目标
  157. return
  158. end
  159. -- 新ID不等于旧ID
  160. human.tempZhihuanID = nextHero
  161. human.tempZhihuanHeroID = heroID
  162. human.tempZhihuanHeroIndex = heroIndex
  163. -- 通知客户端
  164. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_QUERY
  165. msgRet.heroID = heroID
  166. msgRet.heroIndex = heroIndex
  167. msgRet.skip = human.db.drawCard.skip or 0
  168. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple, nextHero)
  169. HeroGrid.makeHeroStatic(msgRet.heroStatic,nextHero)
  170. Msg.send(msgRet, human.fd)
  171. end
  172. function zhihuanDo(human, heroID, heroIndex)
  173. local heroGrid = HeroLogic.getHeroGrid(human, heroID, heroIndex)
  174. if not heroGrid then return end
  175. -- 判断是否被锁
  176. if heroGrid.isLock then
  177. return
  178. end
  179. if human.tempZhihuanHeroID ~= heroID then return end
  180. if human.tempZhihuanHeroIndex ~= heroIndex then return end
  181. local tempGrid = heroGrid
  182. tempGrid.id = human.tempZhihuanID
  183. -- 先删
  184. HeroLogic.delHeroByIndex(human, heroIndex, "xianzhi_zhihuan")
  185. human.tempZhihuanID = nil
  186. human.tempZhihuanHeroID = nil
  187. human.tempZhihuanHeroIndex = nil
  188. -- 改db
  189. local newIndex = HeroLogic.addHeroByGrid(human, tempGrid, "xianzhi_zhihuan")
  190. -- 通知客户端
  191. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_DO
  192. HeroGrid.makeHeroSimple(msgRet.heroSimple, tempGrid, newIndex, human)
  193. Msg.send(msgRet, human.fd)
  194. end
  195. --------------------------功能函数---------------------------------
  196. function zhaohuanHero(human,camp, cnt)
  197. local xianzhiConfig = Util.copyTable(XianzhiExcel.xianzhi[camp])
  198. if not xianzhiConfig then return end
  199. local totalWeight = 0
  200. local totalWeight1 = 0
  201. for i = 1, #xianzhiConfig.zhaohuan do
  202. totalWeight = totalWeight + xianzhiConfig.zhaohuan[i][3]
  203. end
  204. for i = 1, #xianzhiConfig.zhaohuan1 do
  205. totalWeight1 = totalWeight1 + xianzhiConfig.zhaohuan1[i][3]
  206. end
  207. cnt = cnt * 5
  208. local cjPrivilege = ChengjiuLogic.checkPrivilege(human,ChengjiuDefine.PRIVILEGE_TYPE_4)
  209. if cjPrivilege then
  210. local randNum = math.random(1,100)
  211. if randNum == 1 then
  212. cnt = cnt + 1
  213. end
  214. end
  215. local getID = {}
  216. local getCnt = {}
  217. for i = 1, cnt do
  218. if camp == 4 or camp == 5 then
  219. camp = math.random(4,5)
  220. end
  221. local tWeight = totalWeight
  222. local zhaohuan = xianzhiConfig.zhaohuan
  223. if i == 5 then
  224. zhaohuan = xianzhiConfig.zhaohuan1
  225. tWeight = totalWeight1
  226. end
  227. local randNum = math.random(1, tWeight)
  228. for j = 1, #zhaohuan do
  229. local tempConfig = zhaohuan[j]
  230. local tempWeight = tempConfig[3]
  231. if randNum <= tempWeight then --抽中
  232. if j == #zhaohuan or j == #zhaohuan - 1 then --抽中五星英雄
  233. local allWeight = 0
  234. for k,v in ipairs(tempConfig[1]) do
  235. allWeight = allWeight + v[2]
  236. end
  237. local nowNum = math.random(1, allWeight)
  238. for k, v in ipairs(tempConfig[1]) do
  239. local nowWeight = v[2]
  240. if nowNum <= nowWeight then
  241. local rate = v[1]
  242. local chipId = {}
  243. local index = 1
  244. for heroID,heroConfig in pairs(HeroExcel.hero) do
  245. if heroConfig.camp == camp and heroConfig.seerLv == rate then
  246. chipId[index] = heroID
  247. index = index + 1
  248. end
  249. end
  250. local randomNum = 0
  251. if index == 1 then
  252. return
  253. else
  254. randomNum = math.random(1,index -1)
  255. end
  256. getID[i] = chipId[randomNum]
  257. local minCnt = tempConfig[2][1]
  258. local maxCnt = tempConfig[2][2]
  259. getCnt[i] = math.random(minCnt,maxCnt)
  260. break
  261. end
  262. nowNum = nowNum - nowWeight
  263. end
  264. break
  265. else -- 抽到其他物品
  266. local allWeight = 0
  267. for k, v in ipairs(tempConfig[1]) do
  268. allWeight = allWeight + v[2]
  269. end
  270. local nowNum = math.random(1, allWeight)
  271. for k, v in ipairs(tempConfig[1]) do
  272. local nowWeight = v[2]
  273. if nowNum <= nowWeight then
  274. getID[i] = v[1]
  275. local minCnt = tempConfig[2][1]
  276. local maxCnt = tempConfig[2][2]
  277. getCnt[i] = math.random(minCnt,maxCnt)
  278. break
  279. end
  280. nowNum = nowNum - nowWeight
  281. end
  282. break
  283. end
  284. end
  285. randNum = randNum - tempWeight
  286. end
  287. end
  288. return getID, getCnt
  289. end
  290. function zhihuanHero(star, camp,heroId)
  291. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  292. if not xianzhiConfig then return end
  293. local nextHero = nil
  294. local preStarConfig = xianzhiConfig.preStarFive
  295. if not preStarConfig then return end
  296. local totalWeight = 0
  297. for k, v in ipairs(preStarConfig) do
  298. totalWeight = totalWeight + v[2]
  299. end
  300. local randNum = math.random(1, totalWeight)
  301. for k, v in ipairs(preStarConfig) do
  302. tempWeight = v[2]
  303. if randNum <= tempWeight then
  304. local rate = v[1]
  305. local chipId = { }
  306. local index = 0
  307. for heroID, heroConfig in pairs(HeroExcel.hero) do
  308. if heroID ~= heroId and heroConfig.camp == camp and heroConfig.zhihuanLv == rate then
  309. index = index + 1
  310. chipId[index] = heroID
  311. end
  312. end
  313. if index == 0 then
  314. return
  315. end
  316. local randomNum = math.random(1, index)
  317. nextHero = chipId[randomNum]
  318. break
  319. end
  320. randNum = randNum - tempWeight
  321. end
  322. return nextHero
  323. end
  324. function preview(human, camp, star)
  325. local msgRet = Msg.gc.GC_XIANZHI_ZHIHUAN_PREVIEW
  326. if star < 5 then return end
  327. local xianzhiConfig = XianzhiExcel.xianzhi[camp]
  328. if not xianzhiConfig then return end
  329. local nextHero = nil
  330. local len = 0
  331. for k, v in ipairs (xianzhiConfig.preStarFive) do
  332. if len >= 50 then
  333. break
  334. end
  335. local rate = v[1]
  336. for heroID,heroConfig in pairs(HeroExcel.hero) do
  337. if heroConfig.camp == camp and heroConfig.zhihuanLv == rate then
  338. len = len + 1
  339. HeroGrid.makeHeroSimpleByID(msgRet.heroSimple[len], heroID)
  340. end
  341. end
  342. end
  343. msgRet.heroSimple[0] = len
  344. Msg.send(msgRet, human.fd)
  345. end
  346. function shopQuery(human)
  347. local xianzhiShopCfg = XianzhiExcel.xianzhiShop
  348. local msgRet = Msg.gc.GC_XIANZHI_SHOP_QUERY
  349. --配置错误需要通知策划 或者分段传输
  350. local maxLength = 50
  351. if maxLength < #xianzhiShopCfg then
  352. Broadcast.sendErr(human, Lang.SKIN_CONF_ERR)
  353. return
  354. end
  355. msgRet.currency[0] = 1
  356. local totalCoin = BagLogic.getItemCnt(human,xianzhiOutPutId)
  357. Grid.makeItem(msgRet.currency[1],xianzhiOutPutId,totalCoin)
  358. local length = 0
  359. for id,cfg in pairs(xianzhiShopCfg) do
  360. length = length + 1
  361. --local goods = {}
  362. msgRet.production[length].id = id
  363. msgRet.production[length].price = cfg.price
  364. msgRet.production[length].goods[0] = 1
  365. Grid.makeItem(msgRet.production[length].goods[1],cfg.goods[1],cfg.goods[2])
  366. end
  367. msgRet.production[0] = length
  368. Msg.send(msgRet, human.fd)
  369. end
  370. function shopBuy(human,id,count)
  371. -- 判断道具是否足够
  372. local goodsCfg = XianzhiExcel.xianzhiShop[id]
  373. --
  374. if not goodsCfg then
  375. return Broadcast.sendErr(human, Util.format(Lang.XIANZHI_GOODS_NOT_FOUND,id))
  376. end
  377. local cnt = BagLogic.getItemCnt(human,xianzhiOutPutId)
  378. local needCnt = goodsCfg.price * count
  379. if cnt < needCnt then
  380. return Broadcast.sendErr(human, Util.format(Lang.XIANZHI_NO_ITEM,ItemDefine.getValue(xianzhiOutPutId,"name")))
  381. end
  382. -- 先扣款 再发道具
  383. BagLogic.delItem(human,xianzhiOutPutId,needCnt,"xianzhi_buy")
  384. BagLogic.addItemList(human,{{goodsCfg.goods[1],goodsCfg.goods[2] * count}},"xianzhi_buy")
  385. -- 同步客户端最新先知精华数量
  386. local msgRet = Msg.gc.GC_XIANZHI_SHOP_BUY
  387. msgRet.xianzhiCoin = BagLogic.getItemCnt(human,xianzhiOutPutId)
  388. Msg.send(msgRet, human.fd)
  389. end