ServerCommerceActRank.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616
  1. --------------------------------
  2. -- 文件名 : WeekendLoopActRank.lua
  3. -- 文件说明 : 周末冲刺-排行榜
  4. -- 创建时间 : 2024/12/09
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Msg = require("core.Msg")
  8. local Util = require("common.Util")
  9. local Lang = require("common.Lang")
  10. local CommonDB = require("common.CommonDB")
  11. local Broadcast = require("broadcast.Broadcast")
  12. local CommonDefine = require("common.CommonDefine")
  13. local Timer = require("core.Timer")
  14. local Config = require("Config")
  15. local Grid = require("bag.Grid")
  16. local ObjHuman = require("core.ObjHuman")
  17. local MailExcel = require("excel.mail")
  18. local MailManager = require("mail.MailManager")
  19. local RoleDBLogic = require("role.RoleDBLogic")
  20. local ServerCommerceMiddle = require("serverCommerce.ServerCommerceMiddle")
  21. local ServerCommerceDefine = require("serverCommerce.ServerCommerceActDefine")
  22. local ServerCommerceRankConf = require("excel.ServerCommerce").CommerceRank
  23. local ServerCommerceManager = require("serverCommerce.ServerCommerceManager")
  24. -- 缓存的排行榜数据
  25. local COMMERCE_RANK_CACHE = {}
  26. -- 缓存的ServerKey
  27. local COMMERCE_RANK_SERVER_KEY = nil
  28. -- 缓存的服务器排名
  29. local COMMERCE_RANK_SERVER_RANK = nil
  30. -- 待发送全服奖励的玩家
  31. local COMMRCE_RANK_SERVERMAIL_HUMAN = nil
  32. ----------------------------------------- 内部处理开始 -------------------------------------
  33. function CommercerActRank_QueryRankInfo(nRankType, nRankSubType)
  34. ServerCommerceMiddle.CommerveMiddle_QueryRankInfo(nRankType, nRankSubType)
  35. print("[CommercerActRank_QueryRankInfo] 向中心服请求排行榜 nRankType = "..nRankType.." nRankSubType = "..nRankSubType)
  36. CommercerActRank_CreateTime(ServerCommerceDefine.COMMERCEACT_RANKUPDATE, nRankType, nRankSubType)
  37. end
  38. -- 检查是否存在对应缓存
  39. local function CommercerActRank_CheckCache(nRankType, nRankSubType, nServerKey)
  40. if not COMMERCE_RANK_CACHE then
  41. return false
  42. end
  43. if not COMMERCE_RANK_CACHE[nRankType] or not COMMERCE_RANK_CACHE[nRankType][nRankSubType]
  44. or not COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey] then
  45. return false
  46. end
  47. return true
  48. end
  49. -- 获取上榜的最小条件
  50. local function CommercerActRank_GetInRankMinValue(nRankSubType, nRank)
  51. for nID, v in ipairs(ServerCommerceRankConf) do
  52. if v.nRankType == nRankSubType then
  53. if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
  54. return v.nPoint
  55. end
  56. end
  57. end
  58. return 0
  59. end
  60. -- 创建缓存
  61. local function CommercerActRank_CreateCache(nRankType, nRankSubType, nServerKey)
  62. if not COMMERCE_RANK_CACHE then
  63. COMMERCE_RANK_CACHE = {}
  64. end
  65. if not COMMERCE_RANK_CACHE[nRankType] then
  66. COMMERCE_RANK_CACHE[nRankType] = {}
  67. end
  68. if not COMMERCE_RANK_CACHE[nRankType][nRankSubType] then
  69. COMMERCE_RANK_CACHE[nRankType][nRankSubType] = {}
  70. end
  71. if not COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey] then
  72. COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey] = {}
  73. end
  74. end
  75. -- 获取缓存的排行榜数据
  76. local function CommercerActRank_GetCacheRankData(nRankType, nRankSubType, nServerKey)
  77. return COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey]
  78. end
  79. local function CommercerActRank_GetCacheRankDataByRank(nRankType, nRankSubType, nServerKey, nRank)
  80. return COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey][nRank]
  81. end
  82. -- 清空对应的排行榜
  83. local function CommercerActRank_ClearCache(nRankType, nRankSubType, nServerKey)
  84. COMMERCE_RANK_CACHE[nRankType][nRankSubType][nServerKey] = {}
  85. end
  86. -- 插入排行榜数据
  87. local function CommercerActRank_InsertRank(nRankType, nRankSubType, nServerKey, nRank, tRankInfo)
  88. local tCacheRankData = CommercerActRank_GetCacheRankData(nRankType, nRankSubType, nServerKey)
  89. tCacheRankData[nRank] = tRankInfo
  90. end
  91. local function CommercerActRank_GetRankInfoByUuid(nRankType, nRankSubType, uuid)
  92. local tCacheRankData = CommercerActRank_GetCacheRankData(nRankType, nRankSubType, COMMERCE_RANK_SERVER_KEY)
  93. if not tCacheRankData then
  94. return nil, nil
  95. end
  96. -- table.print_lua_table(tCacheRankData)
  97. local nGetRank, tGetRankInfo = nil, nil
  98. for nRank, v in pairs(tCacheRankData) do
  99. if "table" == type(v) then
  100. print("[CommercerActRank_GetRankInfoByUuid] v.uuid = "..v.uuid.." uuid = "..uuid)
  101. if v.uuid == uuid then
  102. print("[CommercerActRank_GetRankInfoByUuid] 相等的")
  103. end
  104. end
  105. if "table" == type(v) and v.uuid == uuid then
  106. nGetRank = nRank
  107. tGetRankInfo = v
  108. break
  109. end
  110. end
  111. return nGetRank, tGetRankInfo
  112. end
  113. -- 包装自己名次数据
  114. local function CommercerActRank_WrapOwnerData(nRankType, nRankSubType, net, uuid)
  115. local nRank, tRankInfo = CommercerActRank_GetRankInfoByUuid(nRankType, nRankSubType, uuid)
  116. net.rank = nRank or -1
  117. net.rankValue = tRankInfo and tRankInfo.nValue or 0
  118. local len = 0
  119. local nNeedPoint = 0
  120. if nRank and tRankInfo then
  121. for _, v in ipairs(ServerCommerceRankConf) do
  122. if v.nRankType == nRankSubType then
  123. if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
  124. for index, itemInfo in ipairs(v.Prize) do
  125. len = len + 1
  126. Grid.makeItem(net.items[index], itemInfo[1], itemInfo[2])
  127. nNeedPoint = v.nPoint
  128. end
  129. break
  130. end
  131. end
  132. end
  133. else
  134. local nMinRank, tMinPrize = 0, nil
  135. for _, v in ipairs(ServerCommerceRankConf) do
  136. if v.nRankType == nRankSubType then
  137. if v.nOrder[1] > nMinRank then
  138. nMinRank = v.nOrder[1]
  139. tMinPrize = v.Prize
  140. nNeedPoint = v.nPoint
  141. end
  142. end
  143. end
  144. if nil ~= tMinPrize then
  145. for index, itemInfo in ipairs(tMinPrize) do
  146. len = len + 1
  147. Grid.makeItem(net.items[index], itemInfo[1], itemInfo[2])
  148. end
  149. end
  150. end
  151. net.rankNeedValue = nNeedPoint
  152. net.servername = Config.NEW_SVR_INDEX.."区"
  153. net.items[0] = len
  154. end
  155. -- 包装档位名次数据
  156. local function CommercerActRank_WrapRankList(nRankType, nRankSubType, net, nRank)
  157. local tRankData = CommercerActRank_GetCacheRankDataByRank(nRankType, nRankSubType, COMMERCE_RANK_SERVER_KEY, nRank)
  158. net.rank = nRank
  159. net.rankNeedValue = CommercerActRank_GetInRankMinValue(nRankSubType, nRank)
  160. if tRankData and tRankData ~= -1 then
  161. net.uid = tRankData.uuid
  162. net.name = tRankData.name
  163. net.head = tRankData.head
  164. net.rankValue = tRankData.nValue
  165. net.headFrame = tRankData.headFrame
  166. net.servername = tRankData.servername
  167. else
  168. net.uid = "-1"
  169. net.name = ""
  170. net.head = -1
  171. net.rankValue = 0
  172. net.headFrame = -1
  173. net.servername = ""
  174. end
  175. local len, nNeedPoint = 0, 0
  176. for _, v in ipairs(ServerCommerceRankConf) do
  177. if v.nRankType == nRankSubType then
  178. if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
  179. nNeedPoint = v.nPoint
  180. for index, itemInfo in ipairs(v.Prize) do
  181. len = len + 1
  182. Grid.makeItem(net.items[index], itemInfo[1], itemInfo[2])
  183. end
  184. break
  185. end
  186. end
  187. end
  188. --Grid.makeItem(net.pointItem, ServerCommerceDefine.COMERCEACT_POINT_GOODSID, nNeedPoint)
  189. net.items[0] = len
  190. end
  191. ----------------------------------------- 外部调用 -------------------------------------
  192. function CommercerActRank_ResetData(human)
  193. if not human then
  194. return
  195. end
  196. --CommercerActRank_ResetCharge(human)
  197. end
  198. -- 活动结束
  199. function CommercerActRank_End()
  200. end
  201. function ClearCache()
  202. COMMERCE_RANK_CACHE = {}
  203. COMMERCE_RANK_SERVER_KEY = nil
  204. COMMERCE_RANK_SERVER_RANK = nil
  205. COMMRCE_RANK_SERVERMAIL_HUMAN = nil
  206. end
  207. -- 玩家点数改变
  208. function CommercerActRank_HumanPointChange(human, nNowPoint)
  209. ServerCommerceMiddle.CommerveMiddle_HumanPointChange(human, nNowPoint)
  210. end
  211. -- 服务器总点数改变
  212. function onAllPointChange()
  213. local nNowPoint = CommonDB.GetCommerceActInfo_Point()
  214. ServerCommerceMiddle.CommerveMiddle_ServerPointChange(nNowPoint)
  215. end
  216. -- 定时请求数据
  217. function CommercerActRank_CreateTime(nTime, nRankType, nRankSubType)
  218. local nNowTime = os.time()
  219. local nOpenTime, nEndTime = ServerCommerceManager.CommerceAct_GetOpenAndEndTime()
  220. if nEndTime == 0 or nEndTime < nNowTime then
  221. print("[CommercerActRank_CreateTime] 当前活动时间不满足条件 nEndTime = "..nEndTime.." nNowTime = "..nNowTime)
  222. return
  223. end
  224. Timer.addLater(nTime, CommercerActRank_QueryRankInfo, nRankType, nRankSubType)
  225. print("[CommercerActRank_CreateTime] 重新创建定时器成功")
  226. end
  227. -- 起服活动开启 请求排行榜数据
  228. function CommercerActRank_InitServerQueryRank()
  229. CommercerActRank_QueryRankInfo(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE,
  230. CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER)
  231. -- 延迟20秒请求 个人排行榜
  232. Timer.addLater(20, CommercerActRank_QueryRankInfo,
  233. CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_HUMAN)
  234. end
  235. -- 获取到排行榜数据
  236. function CommercerActRank_GetRankInfo(tGetData)
  237. local nRankType = tGetData.nRankType
  238. local nRankSubType = tGetData.nRankSubType
  239. local nServerKey = tGetData.nServerKey
  240. local nBegin = tGetData.nBegin
  241. local nEnd = tGetData.nEnd
  242. local tRankData = tGetData.tRankData
  243. print("[CommercerActRank_GetRankInfo] nRankType = "..nRankType.." nRankSubType = "..nRankSubType.." nServerKey = "..nServerKey
  244. .." nBegin = "..nBegin.." nEnd = "..nEnd)
  245. CommercerActRank_CreateCache(nRankType, nRankSubType, nServerKey)
  246. if COMMERCE_RANK_SERVER_KEY == nil then
  247. print("[CommercerActRank_GetRankInfo] 设置 nServerKey = "..nServerKey)
  248. COMMERCE_RANK_SERVER_KEY = nServerKey
  249. else
  250. if COMMERCE_RANK_SERVER_KEY ~= nServerKey then
  251. print("[CommercerActRank_GetRankInfo] 一个战区的 nServerKey 为什么会改变")
  252. COMMERCE_RANK_SERVER_KEY = nServerKey
  253. end
  254. end
  255. if nBegin == 1 then
  256. CommercerActRank_ClearCache(nRankType, nRankSubType, nServerKey)
  257. end
  258. local nAllLen = tRankData[0]
  259. if 0 < nAllLen then
  260. print("[CommercerActRank_GetRankInfo] 获取到排行榜数据,进行插入")
  261. for i = 1, nAllLen, 1 do
  262. CommercerActRank_InsertRank(nRankType, nRankSubType, nServerKey, tRankData[i].nRank, tRankData[i].tRankData)
  263. end
  264. end
  265. end
  266. -- 获取到排名信息
  267. function CommercerActRank_GetServerRank(tData)
  268. COMMERCE_RANK_SERVER_RANK = tData.nRank
  269. if tData.nOperate == ServerCommerceDefine.COMMERCEACT_SENDSERVERMAIL then
  270. CommercerActRank_SendServerRankPrize(tData)
  271. else
  272. CommercerActRank_SendServerMail2Human()
  273. end
  274. end
  275. -- 发送服务器排行榜奖励
  276. function CommercerActRank_SendServerRankPrize(tData)
  277. local nRank = tData.nRank
  278. local nNowServerPoint = CommonDB.GetCommerceActInfo_Point()
  279. local nMinPoint = nil
  280. local tPrize = nil
  281. for _, v in ipairs(ServerCommerceRankConf) do
  282. if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER then
  283. if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
  284. tPrize = v.Prize
  285. end
  286. if not nMinPoint then
  287. nMinPoint = v.nPoint
  288. else
  289. nMinPoint = math.min(nMinPoint, v.nPoint)
  290. end
  291. end
  292. end
  293. -- 写一次日志
  294. local szLogText = "[CommercerActRank_SendServerRankPrize] 发送服务器奖励 nRank = "..nRank.." 寻宝"..Config.NEW_SVR_INDEX.."区"
  295. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  296. if not tPrize then
  297. szLogText = szLogText .. "获取不到对应奖励"
  298. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  299. return
  300. end
  301. local nSendMail = ServerCommerceManager.CommerveManager_GetCommDBSendMail()
  302. if 1 == nSendMail then
  303. szLogText = szLogText .. "当前设置过全服奖励邮件了"
  304. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  305. return
  306. end
  307. -- 设置当前发送邮件奖励
  308. ServerCommerceManager.CommerveManager_SetCommDBSendMail(1)
  309. if nNowServerPoint < nMinPoint then
  310. szLogText = szLogText .. "当前服务器总积分小于最小排行奖励积分直接返回 nMinPoint = "..nMinPoint.." nNowServerPoint = "..nNowServerPoint
  311. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  312. else
  313. -- 遍历在线玩家
  314. local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_SERVERMAILID]
  315. local title = mailConfig.title
  316. local senderName = mailConfig.senderName
  317. local content = mailConfig.content
  318. for uuid, human in pairs(ObjHuman.onlineUuid) do
  319. local nNowHumanPoint = ServerCommerceManager.CommerceAct_GetHumanPoint(human)
  320. if nNowHumanPoint >= 1 then
  321. MailManager.add(MailManager.SYSTEM, uuid,
  322. title, Util.format(content, nRank), tPrize, senderName)
  323. -- 设置该玩家已经发送邮件
  324. ServerCommerceManager.CommerveManager_SetHumanSendServerMail(human, true)
  325. -- 记录信息
  326. ServerCommerceManager.CommerveManager_WriteLog(szLogText.."当前玩家发送战区排名奖励完成", human)
  327. end
  328. end
  329. -- 告诉中心服全服邮件在线的处理完成
  330. ServerCommerceMiddle.CommerceMiddle_TellServerMailOk()
  331. ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendServerRankPrize] 全服在线玩家邮件处理完成 向中心服发送处理个人排行榜奖励")
  332. end
  333. print("[CommercerActRank_SendServerRankPrize] 全服在线玩家邮件处理完成")
  334. end
  335. -- 发送玩家邮件奖励
  336. function CommercerActRank_SendHumanRankPrize(tData)
  337. local nRank, uuid = tData.nRank, tData.uuid
  338. local tPrize = nil
  339. for _, v in ipairs(ServerCommerceRankConf) do
  340. if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_HUMAN then
  341. if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
  342. tPrize = v.Prize
  343. break
  344. end
  345. end
  346. end
  347. local szLogText = "[CommercerActRank_SendHumanRankPrize] 发送个人奖励 nRank = "..nRank
  348. if not tPrize then
  349. szLogText = szLogText .. "获取不到对应奖励"
  350. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  351. return
  352. end
  353. local human = ObjHuman.onlineUuid[uuid]
  354. local bNowSave = false
  355. if not human then
  356. human = {}
  357. human.db = RoleDBLogic.getDb(uuid)
  358. bNowSave = true
  359. end
  360. if not human then
  361. szLogText = szLogText.." 获取不到玩家DB数据信息 uuid = "..uuid
  362. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  363. return
  364. end
  365. -- table.print_lua_table(human.db.ServerCommerce)
  366. print("[CommercerActRank_SendHumanRankPrize] 下发玩家奖励 name = "..human.db.name)
  367. local bSendMail = ServerCommerceManager.CommerveManager_GetHumanSendPlayerMail(human)
  368. if true == bSendMail then
  369. szLogText = szLogText .. "已经发送了邮件为什么又一次走到这里 name = "..human.db.name
  370. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  371. print(szLogText)
  372. return
  373. end
  374. -- 设置发送了邮件奖励
  375. ServerCommerceManager.CommerveManager_SetHumanSendPlayerMail(human, true)
  376. -- 发奖励
  377. local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_HUMANMAILID]
  378. local title = mailConfig.title
  379. local senderName = mailConfig.senderName
  380. local content = mailConfig.content
  381. MailManager.add(MailManager.SYSTEM, uuid,
  382. title, Util.format(content, nRank), tPrize, senderName)
  383. -- 写日志
  384. szLogText = szLogText.."发送奖励成功"
  385. ServerCommerceManager.CommerveManager_WriteLog(szLogText, human)
  386. print("[CommercerActRank_SendHumanRankPrize] 发送玩家奖励结束 name = "..human.db.name.." nRank = "..nRank)
  387. if true == bNowSave then
  388. print("[CommercerActRank_SendHumanRankPrize] 发送玩家奖励结束, 玩家不在线进行存库 name = "..human.db.name.." nRank = "..nRank)
  389. RoleDBLogic.saveRole(human.db)
  390. end
  391. end
  392. -- 玩家登录发送玩家邮件奖励(全服邮件奖励)
  393. function CommercerActRank_SendServerMailHumanLogin(human)
  394. if not COMMRCE_RANK_SERVERMAIL_HUMAN then
  395. COMMRCE_RANK_SERVERMAIL_HUMAN = {}
  396. end
  397. table.insert(COMMRCE_RANK_SERVERMAIL_HUMAN, human.db._id)
  398. -- 不存在请求一次排名
  399. if not COMMERCE_RANK_SERVER_RANK then
  400. print("[CommercerActRank_SendServerMailHumanLogin] 不存在排名直接请求")
  401. ServerCommerceMiddle.CommerceMiddle_QueryServerRank(ServerCommerceDefine.COMMERCEACT_GETSERVERRANK)
  402. else
  403. CommercerActRank_SendServerMail2Human()
  404. end
  405. end
  406. -- 发送活动结束后登录的的玩家(全服邮件奖励)
  407. function CommercerActRank_SendServerMail2Human()
  408. if not COMMRCE_RANK_SERVERMAIL_HUMAN or not COMMERCE_RANK_SERVER_RANK then
  409. print("[CommercerActRank_SendServerMail2Human] 不存在对应的数据")
  410. return
  411. end
  412. if COMMERCE_RANK_SERVER_RANK >= CommonDefine.COMMONRANK_SAVE_DB_LEN + 1 then
  413. ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendServerMail2Human] 获取到的名称不正确 "..COMMERCE_RANK_SERVER_RANK.." 寻宝"..Config.NEW_SVR_INDEX.."区")
  414. return
  415. end
  416. local nNowServerPoint = CommonDB.GetCommerceActInfo_Point()
  417. local tPrize = nil
  418. local nMinPoint = nil
  419. for _, v in ipairs(ServerCommerceRankConf) do
  420. if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER then
  421. if v.nOrder[1] <= COMMERCE_RANK_SERVER_RANK and v.nOrder[2] >= COMMERCE_RANK_SERVER_RANK then
  422. tPrize = v.Prize
  423. end
  424. if not nMinPoint then
  425. nMinPoint = v.nPoint
  426. else
  427. nMinPoint = math.min(nMinPoint, v.nPoint)
  428. end
  429. end
  430. end
  431. if not tPrize then
  432. return
  433. end
  434. if nNowServerPoint < nMinPoint then
  435. print("[CommercerActRank_SendServerMail2Human] 积分不满足直接返回 nMinPoint = "..nMinPoint.." nNowServerPoint = "..nNowServerPoint)
  436. return
  437. end
  438. local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_SERVERMAILID]
  439. local title = mailConfig.title
  440. local senderName = mailConfig.senderName
  441. local content = mailConfig.content
  442. for _, uuid in ipairs(COMMRCE_RANK_SERVERMAIL_HUMAN) do
  443. -- 设置该玩家已经发送邮件
  444. local human = ObjHuman.onlineUuid[uuid]
  445. if not human then
  446. human = RoleDBLogic.getDb(uuid)
  447. end
  448. if human then
  449. MailManager.add(MailManager.SYSTEM, uuid,
  450. title, Util.format(content, COMMERCE_RANK_SERVER_RANK), tPrize, senderName)
  451. -- 记录信息
  452. ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendServerMail2Human] 玩家登录发送全服奖励邮件完成", human)
  453. end
  454. end
  455. COMMRCE_RANK_SERVERMAIL_HUMAN = nil
  456. end
  457. -- 玩家登录活动结束发送个人排行榜邮件
  458. function CommercerActRank_SendHumanMailHumanLogin(human)
  459. local tPrize, nRank = nil, 0
  460. for _, v in ipairs(ServerCommerceRankConf) do
  461. if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_HUMAN then
  462. if v.nOrder[1] >= nRank then
  463. tPrize = v.Prize
  464. nRank = v.nOrder[1]
  465. end
  466. end
  467. end
  468. local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_HUMANMAILID]
  469. local title = mailConfig.title
  470. local senderName = mailConfig.senderName
  471. local content = mailConfig.content
  472. local newcontent = string.gsub(content, "{1}", "21+")
  473. MailManager.add(MailManager.SYSTEM, human.db._id,
  474. title, newcontent, tPrize, senderName)
  475. -- 写日志
  476. ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendHumanMailHumanLogin] 玩家登录发送邮件完成", human)
  477. end
  478. function CommercerActRank_GetRankServerKey(nServerKey)
  479. COMMERCE_RANK_SERVER_KEY = nServerKey
  480. print("[CommercerActRank_GetRankServerKey] 当前服务器收到战区Key nServerID = "..Config.SVR_INDEX.." nServerKey = "..COMMERCE_RANK_SERVER_KEY)
  481. end
  482. ----------------------------------------- 客户端请求 -------------------------------------
  483. -- 客户端请求
  484. function CommercerActRank_Query(human, nRankSubType)
  485. local msgRet = Msg.gc.GC_SERVEERCOMMERCE_ACT_RANK_QUERY
  486. local maxSendRank = CommonDefine.COMMONRANK_SENDPRIZE_LEN
  487. if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
  488. maxSendRank = ServerCommerceDefine.COMMERCEACT_SERVER_RANKLEN
  489. end
  490. local uuid = human.db._id
  491. if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
  492. uuid = tostring(Config.NEW_SVR_INDEX)
  493. end
  494. -- print("[CommercerActRank_Query] uuid = "..uuid)
  495. if false == CommercerActRank_CheckCache(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, COMMERCE_RANK_SERVER_KEY) then
  496. CommercerActRank_CreateCache(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, COMMERCE_RANK_SERVER_KEY)
  497. end
  498. CommercerActRank_WrapOwnerData(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, msgRet.ownerData, uuid)
  499. if 0 == msgRet.ownerData.rankValue then
  500. if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
  501. msgRet.ownerData.rankValue = CommonDB.GetCommerceActInfo_Point()
  502. else
  503. msgRet.ownerData.rankValue = ServerCommerceManager.CommerceAct_GetHumanPoint(human)
  504. end
  505. end
  506. print("[CommercerActRank_Query] 玩家的rank = "..msgRet.ownerData.rank)
  507. for rank = 1, maxSendRank do
  508. CommercerActRank_WrapRankList(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, msgRet.list[rank], rank)
  509. print("[CommercerActRank_Query] 遍历的rank = "..rank.." 下发的 "..msgRet.list[rank].rank)
  510. end
  511. msgRet.list[0] = maxSendRank
  512. Msg.send(msgRet, human.fd)
  513. end