XianzhiLogic.lua 14 KB

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