XianzhiLogic.lua 17 KB

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