XianzhiLogic.lua 14 KB

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