ZhuanpanLogic.lua 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. local Lang = require("common.Lang")
  2. local Msg = require("core.Msg")
  3. local ObjHuman = require("core.ObjHuman")
  4. local ZhuanpanExcel = require("excel.zhuanpan")
  5. local ItemDefine = require("bag.ItemDefine")
  6. local BagLogic = require("bag.BagLogic")
  7. local Grid = require("bag.Grid")
  8. local Broadcast = require("broadcast.Broadcast")
  9. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  10. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  11. local ItemExcel = require("excel.item").item
  12. local Util = require("common.Util")
  13. local HeroExcel = require("excel.hero").hero
  14. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  15. local VipLogic = require("vip.VipLogic")
  16. local EquipLogic = require("equip.EquipLogic")
  17. local YunYingLogic = require("yunying.YunYingLogic")
  18. DEFAULT_ZHUANPAN_TYPE_NORMAL = 1 -- 基础转盘
  19. DEFAULT_ZHUANPAN_TYPE_GAOJI = 2 -- 高级转盘
  20. DEFAULT_BUY_ZHUANPAN_CNT = 50 -- 购买许愿珠所需钻石
  21. DEFAULT_FREE_REFRESH_TIME = 10800 -- 免费刷新的时间
  22. ZHUAN_PAN_ITEM_KIND_CNT = 8 -- 转盘种类数量
  23. DEFAULT_MAX_LUCK = 1000
  24. REWARD_RECORD = { index={}, order={} }
  25. REWARD_RECORD_CNT = 15
  26. function getLuckConfig(mainType)
  27. local config = nil
  28. if mainType == DEFAULT_ZHUANPAN_TYPE_NORMAL then
  29. config = ZhuanpanExcel.luck1
  30. elseif mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  31. config = ZhuanpanExcel.luck2
  32. end
  33. return config
  34. end
  35. function red(human, type)
  36. if not human.db.zhuanpan then return end
  37. local zhuanpan = human.db.zhuanpan[type]
  38. local config = getLuckConfig(type)
  39. if zhuanpan then
  40. local luck = zhuanpan.luck or 0
  41. local luckStatus = zhuanpan.luckStatus
  42. for k, v in pairs(config) do
  43. if luck >= k then
  44. if luckStatus[k] == 1 then
  45. return true
  46. end
  47. end
  48. end
  49. end
  50. if zhuanpan.free == 1 then
  51. return true
  52. end
  53. end
  54. -- 转盘查询
  55. function query(human, mainType)
  56. local zhuanpanConfig = ZhuanpanExcel[mainType]
  57. if not zhuanpanConfig then return end
  58. -- 高级转盘判断等级
  59. local roleConfig = nil
  60. local flag, roleConfig = RoleSystemLogic.isOpen(human,RoleSystemDefine.ROLE_SYS_ID_501)
  61. if mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  62. if flag ~= true then
  63. return Broadcast.sendErr(human, Lang.ZHUANPAN_GAIJI_NEED_LV)
  64. end
  65. end
  66. local oldCnt = getCntByType(human, mainType)
  67. local oldLuck
  68. if human.db.zhuanpan and human.db.zhuanpan[mainType] then
  69. oldLuck = human.db.zhuanpan[mainType].luck
  70. end
  71. -- 更新
  72. update(human, mainType)
  73. -- 初始化
  74. initDB(human, mainType, oldCnt,oldLuck)
  75. local zuanpan = human.db.zhuanpan[mainType]
  76. local config = ZhuanpanExcel.define[mainType]
  77. local msgRet = Msg.gc.GC_ZHUANPAN_QUERY
  78. msgRet.type = mainType
  79. msgRet.isFirst = zuanpan.free == 1 and 1 or 0
  80. local now = os.time()
  81. local ts1 = now - zuanpan.ts1
  82. msgRet.refreshTime = 24 * 60 * 60 - ts1
  83. msgRet.freeRefreshTime = DEFAULT_FREE_REFRESH_TIME - (now - zuanpan.ts2)
  84. if msgRet.freeRefreshTime < 0 then
  85. msgRet.freeRefreshTime = 0
  86. end
  87. Grid.makeItem(msgRet.itemID, config.useItemID , 1)
  88. msgRet.itemCnt[0] = 2
  89. msgRet.itemCnt[1] = config.useItemCnt1
  90. msgRet.itemCnt[2] = config.useItemCnt2
  91. msgRet.drawCnt = config.drawCnt2
  92. Grid.makeItem(msgRet.zuanshiNeed, config.refreshCost[1][1], config.refreshCost[1][2])
  93. msgRet.needLv = config and config.lv or 0
  94. if mainType == DEFAULT_ZHUANPAN_TYPE_NORMAL then
  95. msgRet.needLv = ZhuanpanExcel.define[DEFAULT_ZHUANPAN_TYPE_GAOJI].lv
  96. elseif mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  97. msgRet.needLv = ZhuanpanExcel.define[DEFAULT_ZHUANPAN_TYPE_NORMAL].lv
  98. end
  99. msgRet.needVipLv = VipLogic.getPowerNeedLv(VipLogic.VIP_POWER15)
  100. for i = 1, ZHUAN_PAN_ITEM_KIND_CNT do
  101. local data = zuanpan[i]
  102. local dataID = data.id
  103. local tempConfig = zhuanpanConfig[dataID]
  104. Grid.makeItem(msgRet.list[i].item, data.itemID, data.itemCnt)
  105. msgRet.list[i].id = dataID
  106. msgRet.list[i].chance = tempConfig.chance
  107. msgRet.list[i].maxCnt = tempConfig.getCnt
  108. msgRet.list[i].getCnt = 0
  109. if data.getCnt then
  110. msgRet.list[i].getCnt = data.getCnt
  111. end
  112. end
  113. local luckConfig = getLuckConfig(mainType)
  114. msgRet.luck = zuanpan.luck or 0
  115. local len = 0
  116. for k, v in pairs(luckConfig) do
  117. len = len + 1
  118. local net = msgRet.luckList[len]
  119. net.id = k
  120. net.status = zuanpan.luckStatus[k] or 0
  121. Grid.makeItem(net.item, v.reward[1] , v.reward[2])
  122. end
  123. msgRet.luckList[0] = len
  124. len = 0
  125. if REWARD_RECORD[mainType] then
  126. for k, v in ipairs(REWARD_RECORD[mainType]) do
  127. len = len + 1
  128. local net = msgRet.record[len]
  129. net.id = k
  130. net.tips = v.tips
  131. net.timer = v.timer
  132. net.order = v.order
  133. end
  134. end
  135. msgRet.record[0] = len
  136. msgRet.list[0] = ZHUAN_PAN_ITEM_KIND_CNT
  137. len = 0
  138. local totalWeight = 0
  139. local chanceList = {}
  140. for k, v in pairs(zhuanpanConfig) do
  141. totalWeight = totalWeight + v.chance
  142. chanceList[k] = chanceList[k] or {}
  143. local rewardWeight = 0
  144. for a, b in ipairs(v.rewardID) do
  145. rewardWeight = rewardWeight + b[3]
  146. end
  147. chanceList[k].totalWeight = rewardWeight
  148. end
  149. -- 大全重占比
  150. local temp = {}
  151. for k, v in pairs(zhuanpanConfig) do
  152. local chance = chanceList[k]
  153. local scale = v.chance / totalWeight
  154. for a, b in ipairs(v.rewardID) do
  155. local itemID = b[1]
  156. if not temp[itemID] then
  157. local weight = b[3] / chance.totalWeight
  158. len = len + 1
  159. local net = msgRet.chanceList[len]
  160. local itemConfig = ItemDefine.getConfig(itemID)
  161. if not itemConfig then
  162. print(itemID)
  163. end
  164. net.tips = itemConfig and itemConfig.name or ""
  165. net.chance = weight * scale * 100
  166. temp[itemID] = 1
  167. end
  168. end
  169. end
  170. msgRet.chanceList[0] = len
  171. local red1 = red(human, DEFAULT_ZHUANPAN_TYPE_NORMAL)
  172. msgRet.red1 = red1 == true and 1 or 0
  173. local red2 = red(human, DEFAULT_ZHUANPAN_TYPE_GAOJI)
  174. msgRet.red2 = red2 == true and 1 or 0
  175. Msg.send(msgRet, human.fd)
  176. end
  177. function refresh(human, mainType, needTime)
  178. if not ZhuanpanExcel[mainType] then
  179. return
  180. end
  181. local oldCnt = getCntByType(human, mainType)
  182. local oldLuck
  183. if human.db.zhuanpan and human.db.zhuanpan[mainType] then
  184. oldLuck = human.db.zhuanpan[mainType].luck
  185. end
  186. -- 更新
  187. update(human, mainType)
  188. -- 初始化
  189. initDB(human, mainType, oldCnt,oldLuck)
  190. -- 判断是否免费
  191. if needTime then
  192. local config = ZhuanpanExcel.define[mainType]
  193. local needCost = 0
  194. local now = os.time()
  195. local ts2 = now - human.db.zhuanpan[mainType].ts2
  196. local leftTime = DEFAULT_FREE_REFRESH_TIME - ts2
  197. if leftTime > 0 then
  198. needCost = config.refreshCost[1][2]
  199. end
  200. -- 判断消耗
  201. local cnt = BagLogic.getItemCnt(human, config.refreshCost[1][1])
  202. if cnt < needCost then
  203. return
  204. end
  205. -- 扣消耗
  206. if needCost > 0 then
  207. BagLogic.delItem(human, config.refreshCost[1][1], needCost, "zhuanpan_refresh")
  208. end
  209. -- 改db
  210. local dayStartTime = Util.getDayStartTime(now)
  211. human.db.zhuanpan[mainType].ts2 = now
  212. human.db.zhuanpan[mainType].ts1 = dayStartTime
  213. end
  214. addRandomReward(human, mainType)
  215. -- 通知客户端
  216. if needTime then
  217. query(human, mainType)
  218. end
  219. end
  220. -- 刷新数据
  221. function updateDaily(human)
  222. refresh(human, DEFAULT_ZHUANPAN_TYPE_NORMAL)
  223. refresh(human, DEFAULT_ZHUANPAN_TYPE_GAOJI)
  224. human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].free = 1
  225. human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].freeCnt = 0
  226. end
  227. -- 抽奖
  228. function getReward(human, mainType, cnt)
  229. local config = ZhuanpanExcel.define[mainType]
  230. if not ZhuanpanExcel[mainType] then
  231. return
  232. end
  233. local needItemID = config.useItemID
  234. local needItemCnt = nil
  235. if cnt == 1 then
  236. needItemCnt = config.useItemCnt1
  237. elseif cnt == config.drawCnt2 then
  238. needItemCnt = config.useItemCnt2
  239. -- 多次抽奖需要达到指定vip等级
  240. --[[local needVipLv = VipLogic.getPowerNeedLv(VipLogic.VIP_POWER15)
  241. if VipLogic.getVipLv(human) < needVipLv then
  242. return Broadcast.sendErr(human, Util.format(Lang.ROLE_VIP_ERROR2, needVipLv))
  243. end]]
  244. end
  245. if needItemCnt == nil then
  246. return
  247. end
  248. local oldCnt = getCntByType(human, mainType)
  249. local oldLuck
  250. if human.db.zhuanpan and human.db.zhuanpan[mainType] then
  251. oldLuck = human.db.zhuanpan[mainType].luck
  252. end
  253. -- 更新
  254. update(human, mainType)
  255. -- 初始化
  256. initDB(human, mainType, oldCnt,oldLuck)
  257. local zhuanpan = human.db.zhuanpan[mainType]
  258. if not BagLogic.checkItemCnt(human, needItemID, needItemCnt) then
  259. return
  260. end
  261. -- 扣消耗
  262. BagLogic.delItem(human, needItemID, needItemCnt, "zhuanpan_get")
  263. local msgRet = Msg.gc.GC_ZHUANPAN_GET_REWARD
  264. msgRet.type = mainType
  265. msgRet.list[0] = cnt
  266. local len = 0
  267. for i = 1, cnt do
  268. local result = getLuckDrawSingle(human, mainType)
  269. if result == nil then
  270. assert(nil)
  271. end
  272. -- 改db
  273. local data = zhuanpan[result]
  274. local zhuanpanConfig = ZhuanpanExcel[mainType]
  275. local tempConfig = zhuanpanConfig[data.id]
  276. local nowGetCnt = data.getCnt or 0
  277. local maxGetCnt = tempConfig.getCnt
  278. if maxGetCnt ~= 0 then
  279. data.getCnt = nowGetCnt + 1
  280. end
  281. -- 加道具
  282. local itemID = data.itemID
  283. local itemCnt = data.itemCnt
  284. BagLogic.addItem(human, itemID, itemCnt, "zhuanpan_get")
  285. local itemConfig = ItemExcel[itemID]
  286. local heroConfig = HeroExcel[itemID]
  287. -- 存在部分 英雄配表里面的id 和装备配表重合了
  288. if itemConfig and itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN and heroConfig and heroConfig.star == 5 then
  289. if mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  290. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE11, tempConfig.grade, itemID)
  291. else
  292. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE10, tempConfig.grade, itemID)
  293. end
  294. end
  295. if tempConfig.getCnt > 0 then
  296. if not REWARD_RECORD[mainType] then
  297. REWARD_RECORD[mainType] = {}
  298. end
  299. local record = REWARD_RECORD[mainType]
  300. local index = REWARD_RECORD.index[mainType] or 1
  301. local order = REWARD_RECORD.order[mainType] or 1
  302. record[index] = record[index] or {}
  303. record[index].tips = Util.format(Lang.ZHUANPAN_RECORD_TWO, human.db.name, ItemDefine.getValue(itemID,"name"), itemCnt)
  304. record[index].timer = os.time()
  305. record[index].order = order
  306. index = index + 1
  307. if index > REWARD_RECORD_CNT then
  308. index = 1
  309. end
  310. REWARD_RECORD.order[mainType] = order + 1
  311. REWARD_RECORD.index[mainType] = index
  312. end
  313. msgRet.list[i] = data.id
  314. len = len + 1
  315. if not ItemDefine.isEquip(itemID) then
  316. Grid.makeItem(msgRet.item[len], itemID, itemCnt)
  317. else
  318. EquipLogic.makeEquipItemOne(human, msgRet.item[len])
  319. end
  320. end
  321. msgRet.item[0] = len
  322. -- 增加积分
  323. local itemID = ItemDefine.ITEM_LUCK_ID
  324. local itemCnt = cnt * 10
  325. BagLogic.addItem(human, itemID, itemCnt, "zhuanpan_back")
  326. msgRet.luckItem[0] = 1
  327. Grid.makeItem(msgRet.luckItem[1], itemID, itemCnt)
  328. zhuanpan.cnt = zhuanpan.cnt or 0
  329. zhuanpan.cnt = zhuanpan.cnt + cnt
  330. zhuanpan.luck = zhuanpan.luck or 0
  331. zhuanpan.luck = zhuanpan.luck + cnt * 10
  332. zhuanpan.luckStatus = zhuanpan.luckStatus or {}
  333. local luckConfig = getLuckConfig(mainType)
  334. -- 集火幸运值 奖励
  335. local luckStatus = zhuanpan.luckStatus
  336. for k, v in pairs(luckConfig) do
  337. if zhuanpan.luck >= k then
  338. if luckStatus[k] == nil then
  339. luckStatus[k] = 1
  340. end
  341. end
  342. end
  343. Msg.send(msgRet, human.fd)
  344. query(human, mainType)
  345. YunYingLogic.onCallBack(human, "onFindStar", cnt)
  346. end
  347. -- 购买许愿珠
  348. function buyCnt(human, mainType, cnt)
  349. if cnt < 1 then return end
  350. if mainType ~= DEFAULT_ZHUANPAN_TYPE_NORMAL then
  351. return
  352. end
  353. local needZuanshi = 50 * cnt
  354. -- 判断消耗
  355. if not ObjHuman.checkRMB(human, needZuanshi) then
  356. return
  357. end
  358. -- 扣消耗
  359. ObjHuman.decZuanshi(human, -needZuanshi, "zhuanpan_buy_cnt", ItemDefine.ITEM_BASE_QIYUANZHU_ID, cnt)
  360. -- 增加物品
  361. BagLogic.addItem(human, ItemDefine.ITEM_BASE_QIYUANZHU_ID, cnt, "zhuanpan_buy_cnt")
  362. -- 通知客户端
  363. local msgRet = Msg.gc.GC_BUY_ZHUANPAN_CNT
  364. Msg.send(msgRet, human.fd)
  365. end
  366. ------------------------------功能函数--------------------------------------
  367. function addRandomReward(human, mainType)
  368. local zhuanpanConfig = ZhuanpanExcel[mainType]
  369. if not zhuanpanConfig then return end
  370. local nowLv = human.db.lv
  371. local itemID = nil
  372. local itemCnt = nil
  373. local cntIndex = 0
  374. for i = 1, #zhuanpanConfig do
  375. local tempConfig = zhuanpanConfig[i]
  376. if not tempConfig then return end
  377. if mainType == DEFAULT_ZHUANPAN_TYPE_NORMAL then
  378. if nowLv >= tempConfig.minLv and nowLv <= tempConfig.maxLv then
  379. itemID, itemCnt = getRandomItem(human, tempConfig)
  380. if itemID and itemCnt then
  381. cntIndex = cntIndex + 1
  382. human.db.zhuanpan[mainType][cntIndex] = {}
  383. human.db.zhuanpan[mainType][cntIndex].id = i
  384. human.db.zhuanpan[mainType][cntIndex].itemID = itemID
  385. human.db.zhuanpan[mainType][cntIndex].itemCnt = itemCnt
  386. end
  387. end
  388. elseif mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  389. itemID, itemCnt = getRandomItem(human, tempConfig)
  390. if itemID and itemCnt then
  391. cntIndex = cntIndex + 1
  392. human.db.zhuanpan[mainType][cntIndex] = {}
  393. human.db.zhuanpan[mainType][cntIndex].id = i
  394. human.db.zhuanpan[mainType][cntIndex].itemID = itemID
  395. human.db.zhuanpan[mainType][cntIndex].itemCnt = itemCnt
  396. end
  397. end
  398. end
  399. end
  400. function getLuckDrawSingle(human, mainType)
  401. local zhuanpanConfig = ZhuanpanExcel[mainType]
  402. if not zhuanpanConfig then return end
  403. local totalWeight = 0
  404. local recordData = nil
  405. for i = 1, ZHUAN_PAN_ITEM_KIND_CNT do
  406. local data = human.db.zhuanpan[mainType][i]
  407. local drawID = data.id
  408. local tempConfig = zhuanpanConfig[drawID]
  409. local nowGetCnt = data.getCnt or 0
  410. local maxGetCnt = tempConfig.getCnt
  411. if maxGetCnt == 0 or maxGetCnt > nowGetCnt then
  412. totalWeight = totalWeight + tempConfig.chance
  413. end
  414. end
  415. local randNum = math.random(1,totalWeight)
  416. for i = 1, ZHUAN_PAN_ITEM_KIND_CNT do
  417. local data = human.db.zhuanpan[mainType][i]
  418. local drawID = data.id
  419. local tempConfig = zhuanpanConfig[drawID]
  420. local nowGetCnt = data.getCnt or 0
  421. local maxGetCnt = tempConfig.getCnt
  422. if maxGetCnt == 0 or maxGetCnt > nowGetCnt then
  423. local tempWeight = tempConfig.chance
  424. if randNum <= tempWeight then
  425. return i
  426. end
  427. randNum = randNum - tempWeight
  428. end
  429. end
  430. end
  431. function initDB(human, mainType, cnt,oldluck)
  432. if human.db.zhuanpan ~= nil and
  433. human.db.zhuanpan[mainType] ~= nil then
  434. return
  435. end
  436. local now = os.time()
  437. human.db.zhuanpan = human.db.zhuanpan or {}
  438. human.db.zhuanpan[mainType] = {}
  439. local dayStartTime = Util.getDayStartTime(now)
  440. human.db.zhuanpan[mainType].ts1 = dayStartTime
  441. human.db.zhuanpan[mainType].ts2 = now - DEFAULT_FREE_REFRESH_TIME
  442. human.db.zhuanpan[mainType].cnt = cnt
  443. human.db.zhuanpan[mainType].luck = oldluck
  444. human.db.zhuanpan[mainType].free = 1
  445. human.db.zhuanpan[mainType].luckStatus = {}
  446. addRandomReward(human, mainType)
  447. end
  448. function update(human, mainType)
  449. if human.db.zhuanpan == nil or human.db.zhuanpan[mainType] == nil then
  450. return
  451. end
  452. if human.db.zhuanpan[mainType].ts1 then
  453. -- 防止前端 在结束倒计时结束 发送查询 , 这边还没有结束 返回一样的数据
  454. local now = os.time() + 1
  455. local ts1 = now - human.db.zhuanpan[mainType].ts1
  456. local leftTime = 24 * 60 * 60 - ts1
  457. if leftTime <= 0 then
  458. human.db.zhuanpan[mainType] = nil
  459. end
  460. end
  461. end
  462. function getRandomItem(human, tempConfig)
  463. local totalWeight = 0
  464. for k, v in ipairs(tempConfig.rewardID) do
  465. totalWeight = totalWeight + v[3]
  466. end
  467. local random = math.random(1, totalWeight)
  468. for k, v in ipairs(tempConfig.rewardID) do
  469. local weight = v[3]
  470. local itemID = v[1]
  471. local itemCnt = v[2]
  472. if random <= weight then
  473. return itemID, itemCnt
  474. end
  475. random = random - weight
  476. end
  477. end
  478. function zhuanpanByGm(human,mainType,val)
  479. if not mainType and not val then
  480. return
  481. end
  482. if mainType == 0 or mainType > 2 or val < 5 then
  483. return
  484. end
  485. if human.db.zhuanpan[mainType] then
  486. local now = os.time()
  487. human.db.zhuanpan[mainType].ts1 = now - 24 * 60 * 60 + val
  488. end
  489. end
  490. function getCntByType(human, mainType)
  491. local num = 0
  492. if human.db.zhuanpan and human.db.zhuanpan[mainType] then
  493. human.db.zhuanpan[mainType].cnt = human.db.zhuanpan[mainType].cnt or 0
  494. num = human.db.zhuanpan[mainType].cnt
  495. end
  496. return num
  497. end
  498. function getLuck(human, msg)
  499. local mainType = msg.type
  500. local config = getLuckConfig(mainType)
  501. if not config then
  502. return
  503. end
  504. local zhuanpan = human.db.zhuanpan[mainType]
  505. if zhuanpan == nil then
  506. return
  507. end
  508. if zhuanpan.luck <= 0 then
  509. return
  510. end
  511. local luckStatus = zhuanpan.luckStatus
  512. if luckStatus == nil or luckStatus[msg.id] ~= 1 then
  513. return
  514. end
  515. luckStatus[msg.id] = 2
  516. BagLogic.addItem(human, config[msg.id].reward[1], config[msg.id].reward[2], "zhuanpan_back")
  517. local itemList = {[1] = {config[msg.id].reward[1],config[msg.id].reward[2]}}
  518. BagLogic.sendItemGetList(human,itemList, "zhuanpan_back")
  519. --计算是否需要重新扣除幸运值 重新激活奖励
  520. local luck = zhuanpan.luck
  521. local calc = true
  522. for k, v in pairs(config) do
  523. if luckStatus[k] == nil or luckStatus[k] ~= 2 then
  524. calc = false
  525. end
  526. end
  527. if calc == true then
  528. zhuanpan.luckStatus = {}
  529. luck = luck - DEFAULT_MAX_LUCK
  530. luck = luck < 0 and 0 or luck
  531. zhuanpan.luck = luck
  532. -- 集火幸运值 奖励
  533. local luckStatus = zhuanpan.luckStatus
  534. for k, v in pairs(config) do
  535. if zhuanpan.luck >= k then
  536. if luckStatus[k] == nil then
  537. luckStatus[k] = 1
  538. end
  539. end
  540. end
  541. end
  542. query(human, msg.type)
  543. end
  544. function isDot(human)
  545. local red1 = red(human, DEFAULT_ZHUANPAN_TYPE_NORMAL)
  546. if red1 then return true end
  547. --local red2 = red(human, DEFAULT_ZHUANPAN_TYPE_GAOJI)
  548. --if red2 then return true end
  549. return false
  550. end
  551. function getFree(human)
  552. local oldLuck
  553. if human.db.zhuanpan and human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL] then
  554. oldLuck = human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].luck
  555. end
  556. initDB(human,DEFAULT_ZHUANPAN_TYPE_NORMAL,nil,oldLuck)
  557. if human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].free ~= 1 then
  558. return
  559. end
  560. human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].free = 0
  561. local zhuanpanConfig = ZhuanpanExcel.define[DEFAULT_ZHUANPAN_TYPE_NORMAL]
  562. local len = #zhuanpanConfig.freeCnt
  563. local totalWeight = 0
  564. for i = 1,len do
  565. totalWeight = totalWeight + zhuanpanConfig.freeCnt[i][2]
  566. end
  567. local itemCnt = nil
  568. local randomWeight = math.random(1,totalWeight)
  569. for i = 1,len do
  570. if randomWeight < zhuanpanConfig.freeCnt[i][2] then
  571. itemCnt = zhuanpanConfig.freeCnt[i][1]
  572. break
  573. else
  574. randomWeight = randomWeight - zhuanpanConfig.freeCnt[i][2]
  575. end
  576. end
  577. if itemCnt then
  578. local item = {}
  579. item[1] = {zhuanpanConfig.useItemID,itemCnt}
  580. item[2] = zhuanpanConfig.freeitem[1]
  581. BagLogic.addItemList(human, item, "zhuanpan_get")
  582. else
  583. assert()
  584. end
  585. end