ZhuanpanLogic.lua 19 KB

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