XianzhiLogic.lua 15 KB

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