ZhuanpanLogic.lua 21 KB

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