ZhuanpanLogic.lua 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679
  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. local ClutterDataLogic = require("clutter.ClutterDataLogic")
  22. local ClutterDataDefine = require("clutter.ClutterDataDefine")
  23. local ZhuanpanGift = require("zhuanpan.ZhuanpanGift")
  24. local Log = require("common.Log")
  25. local DB = require("common.DB")
  26. local LuaMongo = _G.lua_mongo
  27. local MailManager = require("mail.MailManager")
  28. -- 允许的渠道
  29. local ALLOW_CHANNELS = {
  30. [11] = true,
  31. [17] = true, -- 美团2楼
  32. }
  33. DEFAULT_ZHUANPAN_TYPE_NORMAL = 1 -- 基础转盘
  34. DEFAULT_ZHUANPAN_TYPE_GAOJI = 2 -- 高级转盘
  35. DEFAULT_BUY_ZHUANPAN_CNT = 50 -- 购买许愿珠所需钻石
  36. DEFAULT_FREE_REFRESH_TIME = 10800 -- 免费刷新的时间
  37. ZHUAN_PAN_ITEM_KIND_CNT = 8 -- 转盘种类数量
  38. DEFAULT_MAX_LUCK = 1000
  39. REWARD_RECORD = { index={}, order={} }
  40. REWARD_RECORD_CNT = 15
  41. function getLuckConfig(mainType)
  42. local config = nil
  43. if mainType == DEFAULT_ZHUANPAN_TYPE_NORMAL then
  44. config = ZhuanpanExcel.luck1
  45. elseif mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  46. config = ZhuanpanExcel.luck2
  47. end
  48. return config
  49. end
  50. function red(human, type)
  51. if not human.db.zhuanpan then return end
  52. local zhuanpan = human.db.zhuanpan[type]
  53. local config = getLuckConfig(type)
  54. if zhuanpan then
  55. local luck = zhuanpan.luck or 0
  56. local luckStatus = zhuanpan.luckStatus
  57. for k, v in pairs(config) do
  58. if luck >= k then
  59. if luckStatus[k] == 1 then
  60. return true
  61. end
  62. end
  63. end
  64. end
  65. if zhuanpan.free == 1 then
  66. return true
  67. end
  68. end
  69. -- 转盘查询
  70. function query(human, mainType)
  71. local zhuanpanConfig = ZhuanpanExcel[mainType]
  72. if not zhuanpanConfig then return end
  73. -- 高级转盘判断等级
  74. local roleConfig = nil
  75. local flag, roleConfig = RoleSystemLogic.isOpen(human,RoleSystemDefine.ROLE_SYS_ID_501)
  76. if mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  77. if flag ~= true then
  78. return Broadcast.sendErr(human, Lang.ZHUANPAN_GAIJI_NEED_LV)
  79. end
  80. end
  81. local oldCnt = getCntByType(human, mainType)
  82. local oldLuck
  83. local tOldStatus = nil
  84. if human.db.zhuanpan and human.db.zhuanpan[mainType] then
  85. oldLuck = human.db.zhuanpan[mainType].luck
  86. if human.db.zhuanpan[mainType].luckStatus then
  87. tOldStatus = Util.copyTable(human.db.zhuanpan[mainType].luckStatus)
  88. end
  89. end
  90. -- 更新
  91. update(human, mainType)
  92. -- 初始化
  93. initDB(human, mainType, oldCnt,oldLuck, tOldStatus)
  94. local zuanpan = human.db.zhuanpan[mainType]
  95. local config = ZhuanpanExcel.define[mainType]
  96. local msgRet = Msg.gc.GC_ZHUANPAN_QUERY
  97. msgRet.type = mainType
  98. msgRet.isFirst = zuanpan.free == 1 and 1 or 0
  99. local now = os.time()
  100. local ts1 = now - zuanpan.ts1
  101. msgRet.refreshTime = 24 * 60 * 60 - ts1
  102. msgRet.freeRefreshTime = DEFAULT_FREE_REFRESH_TIME - (now - zuanpan.ts2)
  103. if msgRet.freeRefreshTime < 0 then
  104. msgRet.freeRefreshTime = 0
  105. end
  106. Grid.makeItem(msgRet.itemID, config.useItemID , 1)
  107. msgRet.itemCnt[0] = 2
  108. msgRet.itemCnt[1] = config.useItemCnt1
  109. msgRet.itemCnt[2] = config.useItemCnt2
  110. msgRet.drawCnt = config.drawCnt2
  111. Grid.makeItem(msgRet.zuanshiNeed, config.refreshCost[1][1], config.refreshCost[1][2])
  112. msgRet.needLv = config and config.lv or 0
  113. if mainType == DEFAULT_ZHUANPAN_TYPE_NORMAL then
  114. msgRet.needLv = ZhuanpanExcel.define[DEFAULT_ZHUANPAN_TYPE_GAOJI].lv
  115. elseif mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  116. msgRet.needLv = ZhuanpanExcel.define[DEFAULT_ZHUANPAN_TYPE_NORMAL].lv
  117. end
  118. msgRet.needVipLv = VipLogic.getPowerNeedLv(VipLogic.VIP_POWER15)
  119. for i = 1, ZHUAN_PAN_ITEM_KIND_CNT do
  120. local data = zuanpan[i]
  121. local dataID = data.id
  122. local tempConfig = zhuanpanConfig[dataID]
  123. Grid.makeItem(msgRet.list[i].item, data.itemID, data.itemCnt)
  124. msgRet.list[i].id = dataID
  125. msgRet.list[i].chance = tempConfig.chance
  126. msgRet.list[i].maxCnt = tempConfig.getCnt
  127. msgRet.list[i].getCnt = 0
  128. if data.getCnt then
  129. msgRet.list[i].getCnt = data.getCnt
  130. end
  131. end
  132. local luckConfig = getLuckConfig(mainType)
  133. msgRet.luck = zuanpan.luck or 0
  134. local len = 0
  135. for k, v in pairs(luckConfig) do
  136. len = len + 1
  137. local net = msgRet.luckList[len]
  138. net.id = k
  139. net.status = zuanpan.luckStatus[k] or 0
  140. Grid.makeItem(net.item, v.reward[1] , v.reward[2])
  141. end
  142. msgRet.luckList[0] = len
  143. len = 0
  144. if REWARD_RECORD[mainType] then
  145. for k, v in ipairs(REWARD_RECORD[mainType]) do
  146. len = len + 1
  147. local net = msgRet.record[len]
  148. net.id = k
  149. net.tips = v.tips
  150. net.timer = v.timer
  151. net.order = v.order
  152. end
  153. end
  154. msgRet.record[0] = len
  155. msgRet.list[0] = ZHUAN_PAN_ITEM_KIND_CNT
  156. len = 0
  157. local totalWeight = 0
  158. local chanceList = {}
  159. for k, v in pairs(zhuanpanConfig) do
  160. totalWeight = totalWeight + v.chance
  161. chanceList[k] = chanceList[k] or {}
  162. local rewardWeight = 0
  163. for a, b in ipairs(v.rewardID) do
  164. rewardWeight = rewardWeight + b[3]
  165. end
  166. chanceList[k].totalWeight = rewardWeight
  167. end
  168. -- 大全重占比
  169. local temp = {}
  170. for k, v in pairs(zhuanpanConfig) do
  171. local chance = chanceList[k]
  172. local scale = v.chance / totalWeight
  173. for a, b in ipairs(v.rewardID) do
  174. local itemID = b[1]
  175. if not temp[itemID] then
  176. local weight = b[3] / chance.totalWeight
  177. len = len + 1
  178. local net = msgRet.chanceList[len]
  179. local itemConfig = ItemDefine.getConfig(itemID)
  180. if not itemConfig then
  181. print(itemID)
  182. end
  183. net.tips = itemConfig and itemConfig.name or ""
  184. net.chance = weight * scale * 100
  185. temp[itemID] = 1
  186. end
  187. end
  188. end
  189. msgRet.chanceList[0] = len
  190. local red1 = red(human, DEFAULT_ZHUANPAN_TYPE_NORMAL)
  191. msgRet.red1 = red1 == true and 1 or 0
  192. local red2 = red(human, DEFAULT_ZHUANPAN_TYPE_GAOJI)
  193. msgRet.red2 = red2 == true and 1 or 0
  194. Msg.send(msgRet, human.fd)
  195. end
  196. function refresh(human, mainType, needTime, bRefreshLuck)
  197. if not ZhuanpanExcel[mainType] then
  198. return
  199. end
  200. local oldCnt = getCntByType(human, mainType)
  201. local oldLuck
  202. local tOldStatus = nil
  203. if human.db.zhuanpan and human.db.zhuanpan[mainType] then
  204. oldLuck = human.db.zhuanpan[mainType].luck
  205. if human.db.zhuanpan[mainType].luckStatus and not bRefreshLuck then
  206. tOldStatus = Util.copyTable(human.db.zhuanpan[mainType].luckStatus)
  207. end
  208. end
  209. -- 更新
  210. update(human, mainType)
  211. -- 初始化
  212. initDB(human, mainType, oldCnt,oldLuck,tOldStatus)
  213. -- 判断是否免费
  214. if needTime then
  215. local config = ZhuanpanExcel.define[mainType]
  216. local needCost = 0
  217. local now = os.time()
  218. local ts2 = now - human.db.zhuanpan[mainType].ts2
  219. local leftTime = DEFAULT_FREE_REFRESH_TIME - ts2
  220. if leftTime > 0 then
  221. needCost = config.refreshCost[1][2]
  222. end
  223. -- 判断消耗
  224. local cnt = BagLogic.getItemCnt(human, config.refreshCost[1][1])
  225. if cnt < needCost then
  226. return
  227. end
  228. -- 扣消耗
  229. if needCost > 0 then
  230. BagLogic.delItem(human, config.refreshCost[1][1], needCost, "zhuanpan_refresh")
  231. end
  232. -- 改db
  233. local dayStartTime = Util.getDayStartTime(now)
  234. human.db.zhuanpan[mainType].ts2 = now
  235. human.db.zhuanpan[mainType].ts1 = dayStartTime
  236. end
  237. addRandomReward(human, mainType)
  238. -- 通知客户端
  239. if needTime then
  240. query(human, mainType)
  241. end
  242. end
  243. -- 刷新数据
  244. function updateDaily(human)
  245. refresh(human, DEFAULT_ZHUANPAN_TYPE_NORMAL)
  246. refresh(human, DEFAULT_ZHUANPAN_TYPE_GAOJI)
  247. human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].free = 1
  248. human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].freeCnt = 0
  249. ZhuanpanGift.updateDaily(human)
  250. end
  251. -- 抽奖
  252. function getReward(human, mainType, cnt)
  253. local config = ZhuanpanExcel.define[mainType]
  254. if not ZhuanpanExcel[mainType] then
  255. return
  256. end
  257. local needItemID = config.useItemID
  258. local needItemCnt = nil
  259. if cnt == 1 then
  260. needItemCnt = config.useItemCnt1
  261. elseif cnt == config.drawCnt2 then
  262. needItemCnt = config.useItemCnt2
  263. -- 多次抽奖需要达到指定vip等级
  264. --[[local needVipLv = VipLogic.getPowerNeedLv(VipLogic.VIP_POWER15)
  265. if VipLogic.getVipLv(human) < needVipLv then
  266. return Broadcast.sendErr(human, Util.format(Lang.ROLE_VIP_ERROR2, needVipLv))
  267. end]]
  268. end
  269. if needItemCnt == nil then
  270. return
  271. end
  272. local oldCnt = getCntByType(human, mainType)
  273. local oldLuck
  274. local tOldStatus = nil
  275. if human.db.zhuanpan and human.db.zhuanpan[mainType] then
  276. oldLuck = human.db.zhuanpan[mainType].luck
  277. if human.db.zhuanpan[mainType].luckStatus then
  278. tOldStatus = Util.copyTable(human.db.zhuanpan[mainType].luckStatus)
  279. end
  280. end
  281. -- 更新
  282. update(human, mainType)
  283. -- 初始化
  284. initDB(human, mainType, oldCnt,oldLuck, tOldStatus)
  285. local zhuanpan = human.db.zhuanpan[mainType]
  286. if not BagLogic.checkItemCnt(human, needItemID, needItemCnt) then
  287. return
  288. end
  289. -- 每日可抽取次数检测
  290. -- local dayTimes = ClutterDataLogic.GetZhuanPanTimes(human)
  291. -- if dayTimes < cnt then
  292. -- return Broadcast.sendErr(human, Lang.JINBI_EXCHANGE_ERR_CNT)
  293. -- end
  294. -- --更新每次抽取次数
  295. -- dayTimes = dayTimes - cnt
  296. -- 改为只更新次数
  297. ClutterDataLogic.UpdateZhuanPanTimes(human, cnt)
  298. -- 扣消耗
  299. BagLogic.delItem(human, needItemID, needItemCnt, "zhuanpan_get")
  300. local msgRet = Msg.gc.GC_ZHUANPAN_GET_REWARD
  301. msgRet.type = mainType
  302. msgRet.list[0] = cnt
  303. local len = 0
  304. for i = 1, cnt do
  305. local result = getLuckDrawSingle(human, mainType)
  306. if result == nil then
  307. assert(nil)
  308. end
  309. -- 改db
  310. local data = zhuanpan[result]
  311. local zhuanpanConfig = ZhuanpanExcel[mainType]
  312. local tempConfig = zhuanpanConfig[data.id]
  313. local nowGetCnt = data.getCnt or 0
  314. local maxGetCnt = tempConfig.getCnt
  315. if maxGetCnt ~= 0 then
  316. data.getCnt = nowGetCnt + 1
  317. end
  318. -- 加道具
  319. local itemID = data.itemID
  320. local itemCnt = data.itemCnt
  321. BagLogic.addItem(human, itemID, itemCnt, "zhuanpan_get")
  322. local itemConfig = ItemExcel[itemID]
  323. local heroConfig = HeroExcel[itemID]
  324. -- 存在部分 英雄配表里面的id 和装备配表重合了
  325. if itemConfig and itemConfig.subType == ItemDefine.ITEM_SUBTYPE_SUIPIAN and heroConfig and heroConfig.star == 5 then
  326. if mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  327. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE11, tempConfig.grade, itemID)
  328. else
  329. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE10, tempConfig.grade, itemID)
  330. end
  331. end
  332. if tempConfig.getCnt > 0 then
  333. if not REWARD_RECORD[mainType] then
  334. REWARD_RECORD[mainType] = {}
  335. end
  336. local record = REWARD_RECORD[mainType]
  337. local index = REWARD_RECORD.index[mainType] or 1
  338. local order = REWARD_RECORD.order[mainType] or 1
  339. record[index] = record[index] or {}
  340. record[index].tips = Util.format(Lang.ZHUANPAN_RECORD_TWO, human.db.name, ItemDefine.getValue(itemID,"name"), itemCnt)
  341. record[index].timer = os.time()
  342. record[index].order = order
  343. index = index + 1
  344. if index > REWARD_RECORD_CNT then
  345. index = 1
  346. end
  347. REWARD_RECORD.order[mainType] = order + 1
  348. REWARD_RECORD.index[mainType] = index
  349. end
  350. msgRet.list[i] = data.id
  351. len = len + 1
  352. if not ItemDefine.isEquip(itemID) then
  353. Grid.makeItem(msgRet.item[len], itemID, itemCnt)
  354. else
  355. EquipLogic.makeEquipItemOne(human, msgRet.item[len])
  356. end
  357. end
  358. msgRet.item[0] = len
  359. -- 增加积分
  360. local itemID = ItemDefine.ITEM_LUCK_ID
  361. local itemCnt = cnt * 10
  362. BagLogic.addItem(human, itemID, itemCnt, "zhuanpan_back")
  363. msgRet.luckItem[0] = 1
  364. Grid.makeItem(msgRet.luckItem[1], itemID, itemCnt)
  365. zhuanpan.cnt = zhuanpan.cnt or 0
  366. zhuanpan.cnt = zhuanpan.cnt + cnt
  367. zhuanpan.luck = zhuanpan.luck or 0
  368. zhuanpan.luck = zhuanpan.luck + cnt * 10
  369. zhuanpan.luckStatus = zhuanpan.luckStatus or {}
  370. local luckConfig = getLuckConfig(mainType)
  371. -- 集火幸运值 奖励
  372. local luckStatus = zhuanpan.luckStatus
  373. for k, v in pairs(luckConfig) do
  374. if zhuanpan.luck >= k then
  375. if luckStatus[k] == nil then
  376. luckStatus[k] = 1
  377. end
  378. end
  379. end
  380. Msg.send(msgRet, human.fd)
  381. query(human, mainType)
  382. YunYingLogic.onCallBack(human, "onFindStar", cnt)
  383. TriggerLogic.PublishEvent(TriggerDefine.EVENT_TYPE_FINDSTAR, human.db._id, cnt)
  384. --周任务,寻星
  385. WeekTaskLogic.recordWeekTaskFinishCnt(human, WeekTaskLogic.WEEK_TASK_ID_1, cnt)
  386. end
  387. -- 购买许愿珠
  388. function buyCnt(human, mainType, cnt)
  389. if cnt < 1 then return end
  390. if mainType ~= DEFAULT_ZHUANPAN_TYPE_NORMAL then
  391. return
  392. end
  393. local needZuanshi = 50 * cnt
  394. -- 判断消耗
  395. if not ObjHuman.checkRMB(human, needZuanshi) then
  396. return
  397. end
  398. -- 扣消耗
  399. ObjHuman.decZuanshi(human, -needZuanshi, "zhuanpan_buy_cnt", ItemDefine.ITEM_BASE_QIYUANZHU_ID, cnt)
  400. -- 增加物品
  401. BagLogic.addItem(human, ItemDefine.ITEM_BASE_QIYUANZHU_ID, cnt, "zhuanpan_buy_cnt")
  402. -- 通知客户端
  403. local msgRet = Msg.gc.GC_BUY_ZHUANPAN_CNT
  404. Msg.send(msgRet, human.fd)
  405. end
  406. ------------------------------功能函数--------------------------------------
  407. function addRandomReward(human, mainType)
  408. local zhuanpanConfig = ZhuanpanExcel[mainType]
  409. if not zhuanpanConfig then return end
  410. local nowLv = human.db.lv
  411. local itemID = nil
  412. local itemCnt = nil
  413. local cntIndex = 0
  414. for i = 1, #zhuanpanConfig do
  415. local tempConfig = zhuanpanConfig[i]
  416. if not tempConfig then return end
  417. if mainType == DEFAULT_ZHUANPAN_TYPE_NORMAL then
  418. if nowLv >= tempConfig.minLv and nowLv <= tempConfig.maxLv then
  419. itemID, itemCnt = getRandomItem(human, tempConfig)
  420. if itemID and itemCnt then
  421. cntIndex = cntIndex + 1
  422. human.db.zhuanpan[mainType][cntIndex] = {}
  423. human.db.zhuanpan[mainType][cntIndex].id = i
  424. human.db.zhuanpan[mainType][cntIndex].itemID = itemID
  425. human.db.zhuanpan[mainType][cntIndex].itemCnt = itemCnt
  426. end
  427. end
  428. elseif mainType == DEFAULT_ZHUANPAN_TYPE_GAOJI then
  429. itemID, itemCnt = getRandomItem(human, tempConfig)
  430. if itemID and itemCnt then
  431. cntIndex = cntIndex + 1
  432. human.db.zhuanpan[mainType][cntIndex] = {}
  433. human.db.zhuanpan[mainType][cntIndex].id = i
  434. human.db.zhuanpan[mainType][cntIndex].itemID = itemID
  435. human.db.zhuanpan[mainType][cntIndex].itemCnt = itemCnt
  436. end
  437. end
  438. end
  439. end
  440. function getLuckDrawSingle(human, mainType)
  441. local zhuanpanConfig = ZhuanpanExcel[mainType]
  442. if not zhuanpanConfig then return end
  443. local totalWeight = 0
  444. local recordData = nil
  445. for i = 1, ZHUAN_PAN_ITEM_KIND_CNT do
  446. local data = human.db.zhuanpan[mainType][i]
  447. local drawID = data.id
  448. local tempConfig = zhuanpanConfig[drawID]
  449. local nowGetCnt = data.getCnt or 0
  450. local maxGetCnt = tempConfig.getCnt
  451. if maxGetCnt == 0 or maxGetCnt > nowGetCnt then
  452. totalWeight = totalWeight + tempConfig.chance
  453. end
  454. end
  455. local randNum = math.random(1,totalWeight)
  456. for i = 1, ZHUAN_PAN_ITEM_KIND_CNT do
  457. local data = human.db.zhuanpan[mainType][i]
  458. local drawID = data.id
  459. local tempConfig = zhuanpanConfig[drawID]
  460. local nowGetCnt = data.getCnt or 0
  461. local maxGetCnt = tempConfig.getCnt
  462. if maxGetCnt == 0 or maxGetCnt > nowGetCnt then
  463. local tempWeight = tempConfig.chance
  464. if randNum <= tempWeight then
  465. return i
  466. end
  467. randNum = randNum - tempWeight
  468. end
  469. end
  470. end
  471. function initDB(human, mainType, cnt, oldluck, tOldStatus)
  472. if human.db.zhuanpan ~= nil and
  473. human.db.zhuanpan[mainType] ~= nil then
  474. return
  475. end
  476. local now = os.time()
  477. human.db.zhuanpan = human.db.zhuanpan or {}
  478. human.db.zhuanpan[mainType] = {}
  479. local dayStartTime = Util.getDayStartTime(now)
  480. human.db.zhuanpan[mainType].ts1 = dayStartTime
  481. human.db.zhuanpan[mainType].ts2 = now - DEFAULT_FREE_REFRESH_TIME
  482. human.db.zhuanpan[mainType].cnt = cnt
  483. human.db.zhuanpan[mainType].luck = oldluck
  484. human.db.zhuanpan[mainType].free = 1
  485. if tOldStatus then
  486. human.db.zhuanpan[mainType].luckStatus = tOldStatus
  487. else
  488. human.db.zhuanpan[mainType].luckStatus = {}
  489. end
  490. addRandomReward(human, mainType)
  491. end
  492. function update(human, mainType)
  493. if human.db.zhuanpan == nil or human.db.zhuanpan[mainType] == nil then
  494. return
  495. end
  496. if human.db.zhuanpan[mainType].ts1 then
  497. -- 防止前端 在结束倒计时结束 发送查询 , 这边还没有结束 返回一样的数据
  498. local now = os.time() + 1
  499. local ts1 = now - human.db.zhuanpan[mainType].ts1
  500. local leftTime = 24 * 60 * 60 - ts1
  501. if leftTime <= 0 then
  502. human.db.zhuanpan[mainType] = nil
  503. end
  504. end
  505. end
  506. function getRandomItem(human, tempConfig)
  507. local totalWeight = 0
  508. for k, v in ipairs(tempConfig.rewardID) do
  509. totalWeight = totalWeight + v[3]
  510. end
  511. local random = math.random(1, totalWeight)
  512. for k, v in ipairs(tempConfig.rewardID) do
  513. local weight = v[3]
  514. local itemID = v[1]
  515. local itemCnt = v[2]
  516. if random <= weight then
  517. return itemID, itemCnt
  518. end
  519. random = random - weight
  520. end
  521. end
  522. function zhuanpanByGm(human,mainType,val)
  523. if not mainType and not val then
  524. return
  525. end
  526. if mainType == 0 or mainType > 2 or val < 5 then
  527. return
  528. end
  529. if human.db.zhuanpan[mainType] then
  530. local now = os.time()
  531. human.db.zhuanpan[mainType].ts1 = now - 24 * 60 * 60 + val
  532. end
  533. end
  534. function getCntByType(human, mainType)
  535. local num = 0
  536. if human.db.zhuanpan and human.db.zhuanpan[mainType] then
  537. human.db.zhuanpan[mainType].cnt = human.db.zhuanpan[mainType].cnt or 0
  538. num = human.db.zhuanpan[mainType].cnt
  539. end
  540. return num
  541. end
  542. function getLuck(human, msg)
  543. local mainType = msg.type
  544. local config = getLuckConfig(mainType)
  545. if not config then
  546. return
  547. end
  548. local zhuanpan = human.db.zhuanpan[mainType]
  549. if zhuanpan == nil then
  550. return
  551. end
  552. if zhuanpan.luck <= 0 then
  553. return
  554. end
  555. local luckStatus = zhuanpan.luckStatus
  556. if luckStatus == nil then
  557. luckStatus = {}
  558. zhuanpan.luckStatus = luckStatus
  559. end
  560. -- 收集所有可领取的奖励(status == 1)
  561. local itemList = {}
  562. local itemListLen = 0
  563. -- 遍历所有配置的奖励,找到可领取的(status == 1)
  564. for k, v in pairs(config) do
  565. if luckStatus[k] == 1 then
  566. -- 标记为已领取
  567. luckStatus[k] = 2
  568. -- 添加奖励到背包
  569. BagLogic.addItem(human, v.reward[1], v.reward[2], "zhuanpan_back")
  570. -- 收集到奖励列表
  571. itemListLen = itemListLen + 1
  572. itemList[itemListLen] = {v.reward[1], v.reward[2]}
  573. end
  574. end
  575. -- 如果没有可领取的奖励,直接返回
  576. if itemListLen == 0 then
  577. return
  578. end
  579. -- 循环处理幸运值扣除和重新激活奖励(可能领取多轮)
  580. while true do
  581. -- 计算是否需要重新扣除幸运值 重新激活奖励
  582. local luck = zhuanpan.luck
  583. local calc = true
  584. for k, v in pairs(config) do
  585. if luckStatus[k] == nil or luckStatus[k] ~= 2 then
  586. calc = false
  587. end
  588. end
  589. -- 如果所有奖励都已领取,扣除幸运值并重新激活
  590. if calc == true then
  591. zhuanpan.luckStatus = {}
  592. luck = luck - DEFAULT_MAX_LUCK
  593. luck = luck < 0 and 0 or luck
  594. zhuanpan.luck = luck
  595. -- 重新激活幸运值奖励
  596. luckStatus = zhuanpan.luckStatus
  597. for k, v in pairs(config) do
  598. if zhuanpan.luck >= k then
  599. if luckStatus[k] == nil then
  600. luckStatus[k] = 1
  601. end
  602. end
  603. end
  604. -- 如果重新激活后还有可领取的奖励,继续循环领取
  605. local hasMore = false
  606. for k, v in pairs(config) do
  607. if luckStatus[k] == 1 then
  608. hasMore = true
  609. -- 领取这个奖励
  610. luckStatus[k] = 2
  611. BagLogic.addItem(human, v.reward[1], v.reward[2], "zhuanpan_back")
  612. itemListLen = itemListLen + 1
  613. itemList[itemListLen] = {v.reward[1], v.reward[2]}
  614. end
  615. end
  616. -- 如果没有更多可领取的奖励,退出循环
  617. if not hasMore then
  618. break
  619. end
  620. else
  621. -- 不是所有奖励都已领取,退出循环
  622. break
  623. end
  624. end
  625. -- 发送所有奖励列表
  626. if itemListLen > 0 then
  627. BagLogic.sendItemGetList(human, itemList, "zhuanpan_back")
  628. end
  629. query(human, msg.type)
  630. end
  631. function isDot(human)
  632. local red1 = red(human, DEFAULT_ZHUANPAN_TYPE_NORMAL)
  633. if red1 then return true end
  634. --local red2 = red(human, DEFAULT_ZHUANPAN_TYPE_GAOJI)
  635. --if red2 then return true end
  636. return false
  637. end
  638. function getFree(human)
  639. local oldLuck
  640. local tOldStatus = nil
  641. if human.db.zhuanpan and human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL] then
  642. oldLuck = human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].luck
  643. if human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].luckStatus then
  644. tOldStatus = Util.copyTable(human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].luckStatus)
  645. end
  646. end
  647. initDB(human,DEFAULT_ZHUANPAN_TYPE_NORMAL,nil, oldLuck,tOldStatus)
  648. if human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].free ~= 1 then
  649. return
  650. end
  651. human.db.zhuanpan[DEFAULT_ZHUANPAN_TYPE_NORMAL].free = 0
  652. local zhuanpanConfig = ZhuanpanExcel.define[DEFAULT_ZHUANPAN_TYPE_NORMAL]
  653. local len = #zhuanpanConfig.freeCnt
  654. local totalWeight = 0
  655. for i = 1,len do
  656. totalWeight = totalWeight + zhuanpanConfig.freeCnt[i][2]
  657. end
  658. local itemCnt = nil
  659. local randomWeight = math.random(1,totalWeight)
  660. for i = 1,len do
  661. if randomWeight < zhuanpanConfig.freeCnt[i][2] then
  662. itemCnt = zhuanpanConfig.freeCnt[i][1]
  663. break
  664. else
  665. randomWeight = randomWeight - zhuanpanConfig.freeCnt[i][2]
  666. end
  667. end
  668. if itemCnt then
  669. local item = {}
  670. item[1] = {zhuanpanConfig.useItemID,itemCnt}
  671. item[2] = zhuanpanConfig.freeitem[1]
  672. BagLogic.addItemList(human, item, "zhuanpan_get")
  673. else
  674. assert()
  675. end
  676. end
  677. -- 检查账号下是否有任何角色已领取每日固定奖励(账号级别判断)
  678. local function checkAccountDailyFixedReward(account)
  679. if not account then
  680. return false
  681. end
  682. local QueryByAccount = {account = account}
  683. local fields = {zhuanpan = 1}
  684. LuaMongo.find(DB.db_char, QueryByAccount, fields)
  685. while true do
  686. local data = {}
  687. if not LuaMongo.next(data) then
  688. break
  689. end
  690. if data.zhuanpan and data.zhuanpan.dailyFixedReward then
  691. local getTime = data.zhuanpan.dailyFixedReward.getTime
  692. if getTime and Util.isSameDay(getTime) then
  693. return true -- 账号下已有角色今日领取过
  694. end
  695. end
  696. end
  697. return false -- 账号下没有角色今日领取过
  698. end
  699. -- 获取账号下最早创建的角色注册日期(账号级别判断)
  700. local function getAccountEarliestCreateTime(account)
  701. if not account then
  702. return nil
  703. end
  704. local QueryByAccount = {account = account}
  705. local fields = {createTime = 1}
  706. LuaMongo.find(DB.db_char, QueryByAccount, fields)
  707. local earliestTime = nil
  708. while true do
  709. local data = {}
  710. if not LuaMongo.next(data) then
  711. break
  712. end
  713. if data.createTime then
  714. if not earliestTime or data.createTime < earliestTime then
  715. earliestTime = data.createTime
  716. end
  717. end
  718. end
  719. return earliestTime
  720. end
  721. -- 检查渠道17是否已超过注册后15天(基于当前角色注册时间)
  722. local function isChannel18Over15Days(human)
  723. if not human or not human.db or not human.db.createTime then
  724. return false
  725. end
  726. local createTime = human.db.createTime
  727. local registerDayStart = Util.getDayStartTime(createTime)
  728. local now = os.time()
  729. local todayDayStart = Util.getDayStartTime(now)
  730. -- 计算从注册日期到今天已经过了多少天(注册日期是第1天)
  731. local daysSinceRegister = math.floor((todayDayStart - registerDayStart) / 86400) + 1
  732. -- 如果超过15天,则不能领取
  733. return daysSinceRegister > 7
  734. end
  735. -- 检查账号下是否有任何角色已领取一次性奖励(账号级别判断)
  736. local function checkAccountOnceReward(account)
  737. if not account then
  738. return false
  739. end
  740. local QueryByAccount = {account = account}
  741. local fields = {zhuanpan = 1}
  742. LuaMongo.find(DB.db_char, QueryByAccount, fields)
  743. while true do
  744. local data = {}
  745. if not LuaMongo.next(data) then
  746. break
  747. end
  748. if data.zhuanpan and data.zhuanpan.onceReward then
  749. local getTime = data.zhuanpan.onceReward.getTime
  750. if getTime then
  751. return true -- 账号下已有角色领取过
  752. end
  753. end
  754. end
  755. return false -- 账号下没有角色领取过
  756. end
  757. -- 检查账号下是否有任何角色已领取订阅奖励(账号级别判断)
  758. local function checkAccountSubscribeReward(account)
  759. if not account then
  760. return false
  761. end
  762. local QueryByAccount = {account = account}
  763. local fields = {zhuanpan = 1}
  764. LuaMongo.find(DB.db_char, QueryByAccount, fields)
  765. while true do
  766. local data = {}
  767. if not LuaMongo.next(data) then
  768. break
  769. end
  770. if data.zhuanpan and data.zhuanpan.subscribeReward then
  771. local getTime = data.zhuanpan.subscribeReward.getTime
  772. if getTime then
  773. return true -- 账号下已有角色领取过
  774. end
  775. end
  776. end
  777. return false -- 账号下没有角色领取过
  778. end
  779. -- 从newUniqueTag解析渠道ID (格式: "channelID|serverTag|account")
  780. local function getChannelIdFromNewUniqueTag(newUniqueTag)
  781. if not newUniqueTag then
  782. return nil
  783. end
  784. local parts = {}
  785. for part in string.gmatch(newUniqueTag, "([^|]+)") do
  786. table.insert(parts, part)
  787. end
  788. if #parts >= 1 then
  789. return tonumber(parts[1])
  790. end
  791. return nil
  792. end
  793. -- 获取每日固定奖励配置(根据渠道ID)
  794. local function getDailyFixedRewardConfig(channelId)
  795. if channelId == 17 then
  796. -- 渠道17(美图2楼):[[101,20000],[111,5000]]
  797. return {
  798. {101, 20000},
  799. {111, 5000}
  800. }
  801. else
  802. -- 渠道11(默认):[[102, 50]]
  803. return {
  804. {102, 50}
  805. }
  806. end
  807. end
  808. -- 每日固定奖励查询
  809. function dailyFixedRewardQuery(human)
  810. local msgRet = Msg.gc.GC_ZHUANPAN_DAILY_FIXED_QUERY
  811. if not msgRet then
  812. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] 错误: msgRet为nil")
  813. return
  814. end
  815. -- 每日更新检查
  816. ObjHuman.updateDaily(human)
  817. local account = human.db.account
  818. local isReceived = false
  819. -- 先读取当日是否已领取(必须在 or {} 初始化之前读,否则可能被空表覆盖导致刚写入的 getTime 丢失)
  820. local getTime = nil
  821. if human.db.zhuanpan and human.db.zhuanpan.dailyFixedReward then
  822. getTime = human.db.zhuanpan.dailyFixedReward.getTime
  823. end
  824. if getTime and Util.isSameDay(getTime) then
  825. isReceived = true
  826. else
  827. isReceived = checkAccountDailyFixedReward(account)
  828. end
  829. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] getTime=" .. tostring(getTime) .. ", isReceived=" .. tostring(isReceived) .. ", account=" .. tostring(account))
  830. -- 初始化数据库(放在读取 getTime 之后,避免覆盖已有 dailyFixedReward 导致 isReceived 错误)
  831. human.db.zhuanpan = human.db.zhuanpan or {}
  832. human.db.zhuanpan.dailyFixedReward = human.db.zhuanpan.dailyFixedReward or {}
  833. -- 渠道17(美团2楼)需要满足:
  834. -- 1) 当日从2楼登录(mtFrom2floor == 1,且 mtFrom2floorDay 是今天)
  835. -- 2) 订阅奖励已领取且在7日有效期内
  836. local newUniqueTag = human.db.newUniqueTag or human.newUniqueTag
  837. local channelId = getChannelIdFromNewUniqueTag(newUniqueTag)
  838. if channelId == 17 then
  839. -- 2楼登录状态(mtFrom2floor 可能为字符串;Util.isSameDay 同天返回 now 时间戳,否则 nil,转为布尔)
  840. local from2floorOk = false
  841. if tonumber(human.db.mtFrom2floor) == 1 and human.db.mtFrom2floorDay then
  842. from2floorOk = (Util.isSameDay(human.db.mtFrom2floorDay) and true or false)
  843. end
  844. -- 订阅相关状态(mtSubscribe 可能为字符串 "1",用 tonumber 统一判断)
  845. local isSubscribed = (tonumber(human.db.mtSubscribe) == 1)
  846. local zhuanpan = human.db.zhuanpan
  847. local hasSubscribeReward = zhuanpan and zhuanpan.subscribeReward and zhuanpan.subscribeReward.getTime
  848. local inValidPeriod = hasSubscribeReward and isSubscribeRewardInValidPeriod(human)
  849. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] channelId=17 from2floorOk=" .. tostring(from2floorOk) .. ", mtFrom2floor=" .. tostring(human.db.mtFrom2floor) .. ", mtFrom2floorDay=" .. tostring(human.db.mtFrom2floorDay) .. ", isSubscribed=" .. tostring(isSubscribed) .. ", hasSubscribeReward=" .. tostring(hasSubscribeReward) .. ", inValidPeriod=" .. tostring(inValidPeriod))
  850. if not isSubscribed then
  851. -- 未订阅:不可领取
  852. msgRet.status = 3 -- 未激活(未订阅)
  853. elseif isReceived then
  854. -- 当日已领取:固定为 2,不因 mtFrom2floor 被置 0 而变成 0
  855. msgRet.status = 2 -- 已领取(今日已领取)
  856. elseif not from2floorOk then
  857. -- 当天未从2楼进入:不可领取
  858. msgRet.status = 0
  859. else
  860. if not hasSubscribeReward or not inValidPeriod then
  861. -- 已订阅,但订阅奖励尚未领取,或已超过7日有效期
  862. msgRet.status = 3 -- 未激活(订阅奖励未领或15天已满)
  863. else
  864. msgRet.status = 1 -- 可领取(已激活且在7日内,且今日未领)
  865. end
  866. end
  867. else
  868. -- 其他渠道保持原有逻辑
  869. if isReceived then
  870. msgRet.status = 2 -- 已领取(账号级别)
  871. else
  872. msgRet.status = 1 -- 可领取
  873. end
  874. end
  875. -- 根据渠道ID设置奖励物品
  876. local newUniqueTag = human.db.newUniqueTag or human.newUniqueTag
  877. local channelId = getChannelIdFromNewUniqueTag(newUniqueTag)
  878. local rewardConfig = getDailyFixedRewardConfig(channelId or 11) -- 默认渠道11
  879. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] 查询奖励信息: rewardConfig",rewardConfig)
  880. -- 循环处理所有奖励物品
  881. for i = 1, #rewardConfig do
  882. Grid.makeItem(msgRet.reward[i], rewardConfig[i][1], rewardConfig[i][2])
  883. end
  884. msgRet.reward[0] = #rewardConfig -- 设置数组长度
  885. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] channelId=" .. tostring(channelId) .. ", status=" .. tostring(msgRet.status))
  886. if human.fd then
  887. Msg.send(msgRet, human.fd)
  888. else
  889. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardQuery] 错误: human.fd为nil,无法发送协议")
  890. end
  891. end
  892. -- 每日固定奖励领取
  893. function dailyFixedRewardGet(human, channelId)
  894. if not ALLOW_CHANNELS[channelId] then
  895. Log.write(
  896. Log.LOGID_DEBUG,
  897. "[dailyFixedRewardGet] 渠道不匹配: channelId=" .. (channelId or "nil") .. ", 允许=11,16,18"
  898. )
  899. return Broadcast.sendErr(human, "渠道不匹配")
  900. end
  901. -- 每日更新检查
  902. ObjHuman.updateDaily(human)
  903. -- 初始化数据库
  904. human.db.zhuanpan = human.db.zhuanpan or {}
  905. human.db.zhuanpan.dailyFixedReward = human.db.zhuanpan.dailyFixedReward or {}
  906. -- 账号级别判断:先检查当前角色的内存数据,再检查数据库
  907. local account = human.db.account
  908. local isReceived = false
  909. -- 先检查当前角色的内存数据
  910. local getTime = human.db.zhuanpan.dailyFixedReward.getTime
  911. if getTime and Util.isSameDay(getTime) then
  912. isReceived = true
  913. else
  914. -- 再检查账号下其他角色(数据库)
  915. isReceived = checkAccountDailyFixedReward(account)
  916. end
  917. if isReceived then
  918. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 账号今日已领取: account="..(account or "nil"))
  919. return Broadcast.sendErr(human, "今日已领取")
  920. end
  921. -- 渠道17(美团2楼)额外条件:
  922. -- 1) 当日从2楼登录(mtFrom2floor == 1 且 mtFrom2floorDay 为今天)
  923. -- 2) 订阅奖励已领取且在7日有效期内
  924. if channelId == 17 then
  925. -- 2楼登录状态(mtFrom2floor 可能为字符串,Util.isSameDay 同天返回时间戳,转为布尔)
  926. local from2floorOk = false
  927. if tonumber(human.db.mtFrom2floor) == 1 and human.db.mtFrom2floorDay then
  928. from2floorOk = (Util.isSameDay(human.db.mtFrom2floorDay) and true or false)
  929. end
  930. if not from2floorOk then
  931. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 渠道17当日未从2楼进入,无法领取: account="..(account or "nil"))
  932. return Broadcast.sendErr(human, "条件不足,无法领取")
  933. end
  934. -- 订阅有效期检查(mtSubscribe 可能为字符串 "1")
  935. if tonumber(human.db.mtSubscribe) ~= 1 or not isSubscribeRewardInValidPeriod(human) then
  936. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 渠道17订阅未激活或已过期,无法领取: account="..(account or "nil"))
  937. return Broadcast.sendErr(human, "订阅未激活或已过期")
  938. end
  939. end
  940. BagLogic.cleanMomentItemList()
  941. -- 根据渠道ID发放不同的奖励(循环处理所有奖励)
  942. local rewardConfig = getDailyFixedRewardConfig(channelId)
  943. for i = 1, #rewardConfig do
  944. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, rewardConfig[i][1], rewardConfig[i][2])
  945. end
  946. -- 复用已有的日志类型,避免未定义的logType导致断言
  947. local success, err = pcall(function()
  948. BagLogic.addMomentItemList(human, "zhuanpan_once_reward")
  949. end)
  950. if not success then
  951. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 错误: 添加到背包失败: "..(err or "unknown"))
  952. return Broadcast.sendErr(human, "发放奖励失败")
  953. end
  954. -- 记录领取时间
  955. local nowTime = os.time()
  956. human.db.zhuanpan.dailyFixedReward.getTime = nowTime
  957. -- 渠道17:领取成功后,消耗当天的2楼登录资格,防止同日重复触发
  958. if channelId == 17 then
  959. human.db.mtFrom2floor = 0
  960. end
  961. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 领取成功 account=" .. tostring(human.db.account) .. " channelId=" .. tostring(channelId) .. " getTime=" .. tostring(nowTime) .. " mtFrom2floor=" .. tostring(human.db.mtFrom2floor))
  962. -- 领取成功后下发查询协议
  963. local querySuccess, queryErr = pcall(function()
  964. dailyFixedRewardQuery(human)
  965. end)
  966. if not querySuccess then
  967. Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 错误: 发送查询协议失败: "..(queryErr or "unknown"))
  968. -- 即使查询协议发送失败,奖励已经发放,所以不返回错误
  969. end
  970. -- Log.write(Log.LOGID_DEBUG, "[dailyFixedRewardGet] 领取完成")
  971. end
  972. -- 抖音渠道一次性奖励查询
  973. function onceRewardQuery(human)
  974. local msgRet = Msg.gc.GC_ZHUANPAN_ONCE_REWARD_QUERY
  975. if not msgRet then
  976. Log.write(Log.LOGID_DEBUG, "[onceRewardQuery] 错误: msgRet为nil")
  977. return
  978. end
  979. -- 初始化数据库
  980. human.db.zhuanpan = human.db.zhuanpan or {}
  981. human.db.zhuanpan.onceReward = human.db.zhuanpan.onceReward or {}
  982. -- 账号级别判断:先检查当前角色的内存数据,再检查数据库
  983. local account = human.db.account
  984. local isReceived = false
  985. -- 先检查当前角色的内存数据
  986. local getTime = human.db.zhuanpan.onceReward.getTime
  987. if getTime then
  988. isReceived = true
  989. else
  990. -- 再检查账号下其他角色(数据库)
  991. isReceived = checkAccountOnceReward(account)
  992. end
  993. if isReceived then
  994. msgRet.status = 2 -- 已领取(账号级别)
  995. else
  996. msgRet.status = 1 -- 可领取
  997. end
  998. -- 设置奖励物品列表:[[102,500],[118,10],[111,100000]]
  999. local success, err = pcall(function()
  1000. Grid.makeItem(msgRet.reward[1], 102, 500)
  1001. Grid.makeItem(msgRet.reward[2], 118, 10)
  1002. Grid.makeItem(msgRet.reward[3], 111, 100000)
  1003. msgRet.reward[0] = 3 -- 设置数组长度
  1004. end)
  1005. if not success then
  1006. Log.write(Log.LOGID_DEBUG, "[onceRewardQuery] 错误: 设置奖励物品失败: "..tostring(err))
  1007. return
  1008. end
  1009. if human.fd then
  1010. Msg.send(msgRet, human.fd)
  1011. end
  1012. end
  1013. -- 抖音渠道一次性奖励领取
  1014. function onceRewardGet(human, channelId)
  1015. if not ALLOW_CHANNELS[channelId] then
  1016. Log.write(
  1017. Log.LOGID_DEBUG,
  1018. "[onceRewardGet] 渠道不匹配: channelId=" .. (channelId or "nil") .. ", 允许=11,12"
  1019. )
  1020. return Broadcast.sendErr(human, "渠道不匹配")
  1021. end
  1022. -- 初始化数据库
  1023. human.db.zhuanpan = human.db.zhuanpan or {}
  1024. human.db.zhuanpan.onceReward = human.db.zhuanpan.onceReward or {}
  1025. -- 账号级别判断:先检查当前角色的内存数据,再检查数据库
  1026. local account = human.db.account
  1027. local isReceived = false
  1028. -- 先检查当前角色的内存数据
  1029. local getTime = human.db.zhuanpan.onceReward.getTime
  1030. if getTime then
  1031. isReceived = true
  1032. else
  1033. -- 再检查账号下其他角色(数据库)
  1034. isReceived = checkAccountOnceReward(account)
  1035. end
  1036. if isReceived then
  1037. Log.write(Log.LOGID_DEBUG, "[onceRewardGet] 账号已领取过,无法重复领取: account="..(account or "nil"))
  1038. return Broadcast.sendErr(human, "已领取过,无法重复领取")
  1039. end
  1040. BagLogic.cleanMomentItemList()
  1041. -- 发放奖励:[[102,500],[118,10],[111,100000]]
  1042. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, 102, 500)
  1043. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, 118, 10)
  1044. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, 111, 100000)
  1045. local success, err = pcall(function()
  1046. BagLogic.addMomentItemList(human, "zhuanpan_once_reward")
  1047. end)
  1048. if not success then
  1049. Log.write(Log.LOGID_DEBUG, "[onceRewardGet] 错误: 添加到背包失败: "..(err or "unknown"))
  1050. return Broadcast.sendErr(human, "发放奖励失败")
  1051. end
  1052. -- 记录领取时间(永久记录)
  1053. human.db.zhuanpan.onceReward.getTime = os.time()
  1054. local querySuccess, queryErr = pcall(function()
  1055. onceRewardQuery(human)
  1056. end)
  1057. if not querySuccess then
  1058. Log.write(Log.LOGID_DEBUG, "[onceRewardGet] 错误: 发送查询协议失败: "..(queryErr or "unknown"))
  1059. -- 即使查询协议发送失败,奖励已经发放,所以不返回错误
  1060. end
  1061. end
  1062. -- 检查当前角色订阅奖励是否在7日有效期内(从订阅奖励领取时间起算)
  1063. function isSubscribeRewardInValidPeriod(human)
  1064. if not human or not human.db then
  1065. return false
  1066. end
  1067. local zhuanpan = human.db.zhuanpan
  1068. if not zhuanpan or not zhuanpan.subscribeReward or not zhuanpan.subscribeReward.getTime then
  1069. return false
  1070. end
  1071. local activateTime = zhuanpan.subscribeReward.getTime
  1072. local activateDayStart = Util.getDayStartTime(activateTime)
  1073. local nowTs = os.time()
  1074. local todayDayStart = Util.getDayStartTime(nowTs)
  1075. -- 激活日为第1天,7日内有效
  1076. local daysSinceActivate = math.floor((todayDayStart - activateDayStart) / 86400) + 1
  1077. return daysSinceActivate <= 7
  1078. end
  1079. -- 检查美团2楼玩家每日固定奖励领取情况(晚上11点调用)
  1080. function checkMtFrom2floorDailyReward()
  1081. if _G.is_middle == true then
  1082. return
  1083. end
  1084. local QueryMtFrom2floor = {mtFrom2floor = 1}
  1085. local fields = {_id = 1, zhuanpan = 1, createTime = 1, mtSubscribe = 1, account = 1}
  1086. LuaMongo.find(DB.db_char, QueryMtFrom2floor, fields)
  1087. local now = os.time()
  1088. local todayDayStart = Util.getDayStartTime(now)
  1089. local dailyMailSentCount = 0
  1090. local subscribeMailSentCount = 0
  1091. while true do
  1092. local data = {}
  1093. if not LuaMongo.next(data) then
  1094. break
  1095. end
  1096. -- 检查是否在订阅有效期内(如果从未激活订阅奖励,视为未激活,不发每日固定奖励)
  1097. if data.mtSubscribe ~= 1 then
  1098. goto continue
  1099. end
  1100. local inValidPeriod = false
  1101. if data.zhuanpan and data.zhuanpan.subscribeReward and data.zhuanpan.subscribeReward.getTime then
  1102. local activateTime = data.zhuanpan.subscribeReward.getTime
  1103. local activateDayStart = Util.getDayStartTime(activateTime)
  1104. local daysSinceActivate = math.floor((todayDayStart - activateDayStart) / 86400) + 1
  1105. inValidPeriod = (daysSinceActivate <= 7)
  1106. end
  1107. -- 订阅奖励未激活或已过期,则不发每日固定奖励
  1108. if not inValidPeriod then
  1109. goto continue
  1110. end
  1111. -- 检查今天是否已领取每日固定奖励
  1112. local hasReceivedToday = false
  1113. if data.zhuanpan and data.zhuanpan.dailyFixedReward then
  1114. local getTime = data.zhuanpan.dailyFixedReward.getTime
  1115. if getTime and Util.isSameDay(getTime) then
  1116. hasReceivedToday = true
  1117. end
  1118. end
  1119. -- 如果今天没领取,发送邮件,并将 mtFrom2floor 置为0,防止当天再次通过登录触发
  1120. if not hasReceivedToday then
  1121. local title = "每日固定奖励提醒"
  1122. local content = "您今日尚未领取每日固定奖励,请及时领取!"
  1123. local rewardItems = {{101, 20000}, {111, 5000}} -- 渠道17的奖励
  1124. local success, err = pcall(function()
  1125. MailManager.add(MailManager.SYSTEM, data._id, title, content, rewardItems)
  1126. -- 更新数据库:标记今日已通过邮件发放,并清除当天的2楼标记
  1127. local updateFields = {
  1128. ["zhuanpan.dailyFixedReward.getTime"] = now,
  1129. ["mtFrom2floor"] = 0,
  1130. }
  1131. LuaMongo.update(DB.db_char, {_id = data._id}, updateFields, false, false)
  1132. end)
  1133. if success then
  1134. dailyMailSentCount = dailyMailSentCount + 1
  1135. Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 发送每日固定奖励邮件并更新状态成功: uuid="..data._id)
  1136. else
  1137. Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 发送每日固定奖励邮件或更新状态失败: uuid="..data._id..", err="..tostring(err))
  1138. end
  1139. end
  1140. -- 检查订阅奖励:如果已订阅(mtSubscribe == 1)且未领取,发送邮件
  1141. if data.mtSubscribe == 1 then
  1142. -- 检查账号下是否已领取订阅奖励
  1143. local hasReceivedSubscribe = checkAccountSubscribeReward(data.account)
  1144. if not hasReceivedSubscribe then
  1145. local title = "订阅奖励提醒"
  1146. local content = "您已订阅但尚未领取订阅奖励,请及时领取!"
  1147. local rewardItems = {{101, 50000}, {112, 100}} -- 订阅奖励
  1148. local success, err = pcall(function()
  1149. MailManager.add(MailManager.SYSTEM, data._id, title, content, rewardItems)
  1150. end)
  1151. if success then
  1152. subscribeMailSentCount = subscribeMailSentCount + 1
  1153. Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 发送订阅奖励邮件成功: uuid="..data._id)
  1154. else
  1155. Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 发送订阅奖励邮件失败: uuid="..data._id..", err="..tostring(err))
  1156. end
  1157. end
  1158. end
  1159. ::continue::
  1160. end
  1161. Log.write(Log.LOGID_DEBUG, "[checkMtFrom2floorDailyReward] 检查完成,每日固定奖励邮件数量: "..dailyMailSentCount..", 订阅奖励邮件数量: "..subscribeMailSentCount)
  1162. end
  1163. -- 美团订阅奖励查询(同时接收并存储订阅状态)
  1164. function subscribeRewardQuery(human, msg)
  1165. local msgRet = Msg.gc.GC_ZHUANPAN_SUBSCRIBE_REWARD_QUERY
  1166. if not msgRet then
  1167. Log.write(Log.LOGID_DEBUG, "[subscribeRewardQuery] 错误: msgRet为nil")
  1168. return
  1169. end
  1170. -- 如果前端上传了订阅状态,则进行存储
  1171. if msg and msg.mtSubscribe ~= nil then
  1172. local val = tonumber(msg.mtSubscribe) or 0
  1173. -- 只从 0 -> 1,避免重复覆盖或回退
  1174. if val == 1 and human.db then
  1175. human.db.mtSubscribe = human.db.mtSubscribe or 0
  1176. if human.db.mtSubscribe ~= 1 then
  1177. human.db.mtSubscribe = 1
  1178. Log.write(Log.LOGID_DEBUG, "[subscribeRewardQuery] 更新订阅状态为1, account="..tostring(human.db.account))
  1179. end
  1180. end
  1181. end
  1182. -- 初始化数据库
  1183. human.db.zhuanpan = human.db.zhuanpan or {}
  1184. human.db.zhuanpan.subscribeReward = human.db.zhuanpan.subscribeReward or {}
  1185. -- 检查是否订阅(mtSubscribe == 1)
  1186. local isSubscribed = (human.db.mtSubscribe == 1)
  1187. -- 账号级别判断:先检查当前角色的内存数据,再检查数据库
  1188. local account = human.db.account
  1189. local isReceived = false
  1190. if isSubscribed then
  1191. -- 先检查当前角色的内存数据
  1192. local getTime = human.db.zhuanpan.subscribeReward.getTime
  1193. if getTime then
  1194. isReceived = true
  1195. else
  1196. -- 再检查账号下其他角色(数据库)
  1197. isReceived = checkAccountSubscribeReward(account)
  1198. end
  1199. end
  1200. if not isSubscribed then
  1201. msgRet.status = 0 -- 不可领取(未订阅)
  1202. elseif isReceived then
  1203. msgRet.status = 2 -- 已领取
  1204. else
  1205. msgRet.status = 1 -- 可领取
  1206. end
  1207. -- 设置奖励物品列表:[[101,50000],[112,100]]
  1208. local success, err = pcall(function()
  1209. Grid.makeItem(msgRet.reward[1], 101, 50000)
  1210. Grid.makeItem(msgRet.reward[2], 112, 100)
  1211. msgRet.reward[0] = 2 -- 设置数组长度
  1212. end)
  1213. if not success then
  1214. Log.write(Log.LOGID_DEBUG, "[subscribeRewardQuery] 错误: 设置奖励物品失败: "..tostring(err))
  1215. return
  1216. end
  1217. if human.fd then
  1218. Msg.send(msgRet, human.fd)
  1219. end
  1220. end
  1221. -- 美团订阅奖励领取
  1222. function subscribeRewardGet(human, channelId)
  1223. -- 检查渠道,只有渠道ID=17(美团2楼)才能领取
  1224. if not channelId or channelId ~= 17 then
  1225. Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 渠道不匹配: channelId="..(channelId or "nil")..", 需要=18")
  1226. return Broadcast.sendErr(human, "渠道不匹配")
  1227. end
  1228. -- 检查是否订阅(mtSubscribe == 1)
  1229. if human.db.mtSubscribe ~= 1 then
  1230. Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 未订阅: mtSubscribe="..(human.db.mtSubscribe or "nil"))
  1231. return Broadcast.sendErr(human, "未订阅,无法领取")
  1232. end
  1233. -- 初始化数据库
  1234. human.db.zhuanpan = human.db.zhuanpan or {}
  1235. human.db.zhuanpan.subscribeReward = human.db.zhuanpan.subscribeReward or {}
  1236. -- 账号级别判断:先检查当前角色的内存数据,再检查数据库
  1237. local account = human.db.account
  1238. local isReceived = false
  1239. -- 先检查当前角色的内存数据
  1240. local getTime = human.db.zhuanpan.subscribeReward.getTime
  1241. if getTime then
  1242. isReceived = true
  1243. else
  1244. -- 再检查账号下其他角色(数据库)
  1245. isReceived = checkAccountSubscribeReward(account)
  1246. end
  1247. if isReceived then
  1248. Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 账号已领取过,无法重复领取: account="..(account or "nil"))
  1249. return Broadcast.sendErr(human, "已领取过,无法重复领取")
  1250. end
  1251. BagLogic.cleanMomentItemList()
  1252. -- 发放奖励:[[101,50000],[112,100]]
  1253. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, 101, 50000)
  1254. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, 112, 100)
  1255. -- 使用已存在的日志类型,避免日志定义缺失导致的断言
  1256. local success, err = pcall(function()
  1257. BagLogic.addMomentItemList(human, "zhuanpan_once_reward")
  1258. end)
  1259. if not success then
  1260. Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 错误: 添加到背包失败: "..(err or "unknown"))
  1261. return Broadcast.sendErr(human, "发放奖励失败")
  1262. end
  1263. -- 记录领取时间(永久记录)
  1264. human.db.zhuanpan.subscribeReward.getTime = os.time()
  1265. local querySuccess, queryErr = pcall(function()
  1266. subscribeRewardQuery(human)
  1267. end)
  1268. if not querySuccess then
  1269. Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 错误: 发送订阅奖励查询协议失败: "..(queryErr or "unknown"))
  1270. -- 即使查询协议发送失败,奖励已经发放,所以不返回错误
  1271. end
  1272. -- 领取订阅奖励后,同时下发每日固定奖励查询协议
  1273. local dailyQuerySuccess, dailyQueryErr = pcall(function()
  1274. dailyFixedRewardQuery(human)
  1275. end)
  1276. if not dailyQuerySuccess then
  1277. Log.write(Log.LOGID_DEBUG, "[subscribeRewardGet] 错误: 发送每日固定奖励查询协议失败: "..(dailyQueryErr or "unknown"))
  1278. -- 即使查询协议发送失败,奖励已经发放,所以不返回错误
  1279. end
  1280. end
  1281. -----------------------淘宝小程序桌面活动-----------------------
  1282. -- 奖励配置(占位,按需修改)
  1283. local TB_ENTER_REWARD = {{112, 100}} -- 桌面进入奖励(每日1次)
  1284. local TB_SECOND_FLOOR_REWARD = {{127, 10}} -- 二楼进入奖励(每日1次)
  1285. local TB_DESKTOP_REWARD = {{118, 5}} -- 添加桌面奖励(仅1次)
  1286. -- 渠道校验:仅 hanman.pf == "tbminiapp" 的玩家可参与
  1287. local function isTbMiniApp(human)
  1288. return human.pf_info and human.pf_info.pf == "tbminiapp"
  1289. end
  1290. -- 淘宝小程序桌面活动查询
  1291. -- status: 1=桌面进入 2=二楼进入
  1292. function tbminiappQuery(human, status)
  1293. local msgRet = Msg.gc.GC_ZHUANPAN_TB_QUERY
  1294. if not msgRet then
  1295. Log.write(Log.LOGID_DEBUG, "[tbminiappQuery] 错误: msgRet为nil")
  1296. return
  1297. end
  1298. if not isTbMiniApp(human) then
  1299. return Broadcast.sendErr(human, "渠道不匹配")
  1300. end
  1301. ObjHuman.updateDaily(human)
  1302. human.db.zhuanpan = human.db.zhuanpan or {}
  1303. human.db.zhuanpan.tbminiapp = human.db.zhuanpan.tbminiapp or {}
  1304. local tb = human.db.zhuanpan.tbminiapp
  1305. -- 是否已添加桌面
  1306. msgRet.isDesktopAdded = tb.desktopAdded and 1 or 0
  1307. -- 是否已领取添加桌面奖励(一次性)
  1308. msgRet.isDesktopRewardReceived = (tb.desktopReward and tb.desktopReward.getTime) and 1 or 0
  1309. -- 是否已领取桌面进入奖励(每日1次)
  1310. local enterTime = tb.enterReward and tb.enterReward.getTime
  1311. msgRet.isEnterRewardReceived = (enterTime and Util.isSameDay(enterTime)) and 1 or 0
  1312. -- 是否已领取二楼进入奖励(每日1次)
  1313. local floorTime = tb.floorReward and tb.floorReward.getTime
  1314. msgRet.isFloorRewardReceived = (floorTime and Util.isSameDay(floorTime)) and 1 or 0
  1315. Log.write(Log.LOGID_DEBUG, "[tbminiappQuery] status=" .. tostring(status)
  1316. .. " isDesktopAdded=" .. tostring(msgRet.isDesktopAdded)
  1317. .. " isDesktopRewardReceived=" .. tostring(msgRet.isDesktopRewardReceived)
  1318. .. " isEnterRewardReceived=" .. tostring(msgRet.isEnterRewardReceived)
  1319. .. " isFloorRewardReceived=" .. tostring(msgRet.isFloorRewardReceived)
  1320. .. " account=" .. tostring(human.db.account))
  1321. if human.fd then
  1322. Msg.send(msgRet, human.fd)
  1323. else
  1324. Log.write(Log.LOGID_DEBUG, "[tbminiappQuery] 错误: human.fd为nil,无法发送协议")
  1325. end
  1326. end
  1327. -- 淘宝小程序添加桌面上报:记录添加状态
  1328. function tbminiappAddDesktop(human)
  1329. if not isTbMiniApp(human) then
  1330. return Broadcast.sendErr(human, "渠道不匹配")
  1331. end
  1332. human.db.zhuanpan = human.db.zhuanpan or {}
  1333. human.db.zhuanpan.tbminiapp = human.db.zhuanpan.tbminiapp or {}
  1334. human.db.zhuanpan.tbminiapp.desktopAdded = true
  1335. Log.write(Log.LOGID_DEBUG, "[tbminiappAddDesktop] 添加桌面成功 account=" .. tostring(human.db.account))
  1336. local querySuccess, queryErr = pcall(function()
  1337. tbminiappQuery(human, 0)
  1338. end)
  1339. if not querySuccess then
  1340. Log.write(Log.LOGID_DEBUG, "[tbminiappAddDesktop] 错误: 发送查询协议失败: "..(queryErr or "unknown"))
  1341. end
  1342. end
  1343. -- 淘宝小程序活动奖励领取
  1344. -- status: 1=桌面进入奖励(每日1次)2=二楼进入奖励(每日1次)3=添加桌面奖励(仅1次)
  1345. function tbminiappRewardGet(human, status)
  1346. if not isTbMiniApp(human) then
  1347. return Broadcast.sendErr(human, "渠道不匹配")
  1348. end
  1349. ObjHuman.updateDaily(human)
  1350. human.db.zhuanpan = human.db.zhuanpan or {}
  1351. human.db.zhuanpan.tbminiapp = human.db.zhuanpan.tbminiapp or {}
  1352. local tb = human.db.zhuanpan.tbminiapp
  1353. local rewardConfig = nil
  1354. if status == 1 then
  1355. -- 桌面进入奖励(每日1次)
  1356. local enterTime = tb.enterReward and tb.enterReward.getTime
  1357. if enterTime and Util.isSameDay(enterTime) then
  1358. Log.write(Log.LOGID_DEBUG, "[tbminiappRewardGet] 今日已领取桌面进入奖励 account=" .. tostring(human.db.account))
  1359. return Broadcast.sendErr(human, "今日已领取桌面进入奖励")
  1360. end
  1361. rewardConfig = TB_ENTER_REWARD
  1362. elseif status == 2 then
  1363. -- 二楼进入奖励(每日1次)
  1364. local floorTime = tb.floorReward and tb.floorReward.getTime
  1365. if floorTime and Util.isSameDay(floorTime) then
  1366. Log.write(Log.LOGID_DEBUG, "[tbminiappRewardGet] 今日已领取二楼进入奖励 account=" .. tostring(human.db.account))
  1367. return Broadcast.sendErr(human, "今日已领取二楼进入奖励")
  1368. end
  1369. rewardConfig = TB_SECOND_FLOOR_REWARD
  1370. elseif status == 3 then
  1371. -- 添加桌面奖励(仅1次)
  1372. if not tb.desktopAdded then
  1373. Log.write(Log.LOGID_DEBUG, "[tbminiappRewardGet] 尚未添加桌面 account=" .. tostring(human.db.account))
  1374. return Broadcast.sendErr(human, "尚未添加桌面")
  1375. end
  1376. if tb.desktopReward and tb.desktopReward.getTime then
  1377. Log.write(Log.LOGID_DEBUG, "[tbminiappRewardGet] 添加桌面奖励已领取 account=" .. tostring(human.db.account))
  1378. return Broadcast.sendErr(human, "添加桌面奖励已领取")
  1379. end
  1380. rewardConfig = TB_DESKTOP_REWARD
  1381. else
  1382. return Broadcast.sendErr(human, "无效的status参数")
  1383. end
  1384. -- 发放奖励
  1385. BagLogic.cleanMomentItemList()
  1386. for _, v in ipairs(rewardConfig) do
  1387. BagLogic.updateMomentItem(BagLogic.ADDITEM_TYPE_1, v[1], v[2])
  1388. end
  1389. local success, err = pcall(function()
  1390. BagLogic.addMomentItemList(human, "zhuanpan_once_reward")
  1391. end)
  1392. if not success then
  1393. Log.write(Log.LOGID_DEBUG, "[tbminiappRewardGet] 错误: 添加到背包失败: "..(err or "unknown"))
  1394. return Broadcast.sendErr(human, "发放奖励失败")
  1395. end
  1396. -- 记录领取时间
  1397. local nowTime = os.time()
  1398. if status == 1 then
  1399. tb.enterReward = tb.enterReward or {}
  1400. tb.enterReward.getTime = nowTime
  1401. elseif status == 2 then
  1402. tb.floorReward = tb.floorReward or {}
  1403. tb.floorReward.getTime = nowTime
  1404. elseif status == 3 then
  1405. tb.desktopReward = tb.desktopReward or {}
  1406. tb.desktopReward.getTime = nowTime
  1407. end
  1408. Log.write(Log.LOGID_DEBUG, "[tbminiappRewardGet] 领取成功 status=" .. tostring(status) .. " account=" .. tostring(human.db.account))
  1409. -- 下发查询协议
  1410. local querySuccess, queryErr = pcall(function()
  1411. tbminiappQuery(human, 0)
  1412. end)
  1413. if not querySuccess then
  1414. Log.write(Log.LOGID_DEBUG, "[tbminiappRewardGet] 错误: 发送查询协议失败: "..(queryErr or "unknown"))
  1415. end
  1416. end