ZhuanpanLogic.lua 20 KB

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