ServerCommerceActRank.lua 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611
  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. local szLogText = "[CommercerActRank_SendServerRankPrize] 发送服务器奖励 nRank = "..nRank
  294. if not tPrize then
  295. szLogText = szLogText .. "获取不到对应奖励"
  296. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  297. return
  298. end
  299. local nSendMail = ServerCommerceManager.CommerveManager_GetCommDBSendMail()
  300. if true == nSendMail then
  301. return
  302. end
  303. -- 设置当前发送邮件奖励
  304. ServerCommerceManager.CommerveManager_SetCommDBSendMail(1)
  305. if nNowServerPoint < nMinPoint then
  306. szLogText = szLogText .. "当前服务器总积分小于最小排行奖励积分直接返回 nMinPoint = "..nMinPoint.." nNowServerPoint = "..nNowServerPoint
  307. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  308. else
  309. -- 遍历在线玩家
  310. local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_SERVERMAILID]
  311. local title = mailConfig.title
  312. local senderName = mailConfig.senderName
  313. local content = mailConfig.content
  314. for uuid, human in pairs(ObjHuman.onlineUuid) do
  315. local nNowHumanPoint = ServerCommerceManager.CommerceAct_GetHumanPoint(human)
  316. if nNowHumanPoint >= 1 then
  317. MailManager.add(MailManager.SYSTEM, uuid,
  318. title, Util.format(content, nRank), tPrize, senderName)
  319. -- 设置该玩家已经发送邮件
  320. ServerCommerceManager.CommerveManager_SetHumanSendServerMail(human, true)
  321. -- 记录信息
  322. ServerCommerceManager.CommerveManager_WriteLog(szLogText, human)
  323. end
  324. end
  325. -- 告诉中心服全服邮件在线的处理完成
  326. ServerCommerceMiddle.CommerceMiddle_TellServerMailOk()
  327. ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendServerRankPrize] 全服在线玩家邮件处理完成 向中心服发送处理个人排行榜奖励")
  328. end
  329. print("[CommercerActRank_SendServerRankPrize] 全服在线玩家邮件处理完成")
  330. end
  331. -- 发送玩家邮件奖励
  332. function CommercerActRank_SendHumanRankPrize(tData)
  333. local nRank, uuid = tData.nRank, tData.uuid
  334. local tPrize = nil
  335. for _, v in ipairs(ServerCommerceRankConf) do
  336. if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_HUMAN then
  337. if v.nOrder[1] <= nRank and v.nOrder[2] >= nRank then
  338. tPrize = v.Prize
  339. break
  340. end
  341. end
  342. end
  343. local szLogText = "[CommercerActRank_SendHumanRankPrize] 发送个人奖励 nRank = "..nRank
  344. if not tPrize then
  345. szLogText = szLogText .. "获取不到对应奖励"
  346. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  347. return
  348. end
  349. local human = ObjHuman.onlineUuid[uuid]
  350. local bNowSave = false
  351. if not human then
  352. human = {}
  353. human.db = RoleDBLogic.getDb(uuid)
  354. bNowSave = true
  355. end
  356. if not human then
  357. szLogText = szLogText.." 获取不到玩家DB数据信息 uuid = "..uuid
  358. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  359. return
  360. end
  361. table.print_lua_table(human.db.ServerCommerce)
  362. print("[CommercerActRank_SendHumanRankPrize] 下发玩家奖励 name = "..human.db.name)
  363. local bSendMail = ServerCommerceManager.CommerveManager_GetHumanSendPlayerMail(human)
  364. if true == bSendMail then
  365. szLogText = szLogText .. "已经发送了邮件为什么又一次走到这里 name = "..human.db.name
  366. ServerCommerceManager.CommerveManager_WriteLog(szLogText)
  367. print(szLogText)
  368. return
  369. end
  370. -- 设置发送了邮件奖励
  371. ServerCommerceManager.CommerveManager_SetHumanSendPlayerMail(human, true)
  372. -- 发奖励
  373. local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_HUMANMAILID]
  374. local title = mailConfig.title
  375. local senderName = mailConfig.senderName
  376. local content = mailConfig.content
  377. MailManager.add(MailManager.SYSTEM, uuid,
  378. title, Util.format(content, nRank), tPrize, senderName)
  379. -- 写日志
  380. szLogText = szLogText.."发送奖励成功"
  381. ServerCommerceManager.CommerveManager_WriteLog(szLogText, human)
  382. print("[CommercerActRank_SendHumanRankPrize] 发送玩家奖励结束 name = "..human.db.name.." nRank = "..nRank)
  383. if true == bNowSave then
  384. print("[CommercerActRank_SendHumanRankPrize] 发送玩家奖励结束, 玩家不在线进行存库 name = "..human.db.name.." nRank = "..nRank)
  385. RoleDBLogic.saveRole(human.db)
  386. end
  387. end
  388. -- 玩家登录发送玩家邮件奖励(全服邮件奖励)
  389. function CommercerActRank_SendServerMailHumanLogin(human)
  390. if not COMMRCE_RANK_SERVERMAIL_HUMAN then
  391. COMMRCE_RANK_SERVERMAIL_HUMAN = {}
  392. end
  393. table.insert(COMMRCE_RANK_SERVERMAIL_HUMAN, human.db._id)
  394. -- 不存在请求一次排名
  395. if not COMMERCE_RANK_SERVER_RANK then
  396. print("[CommercerActRank_SendServerMailHumanLogin] 不存在排名直接请求")
  397. ServerCommerceMiddle.CommerceMiddle_QueryServerRank(ServerCommerceDefine.COMMERCEACT_GETSERVERRANK)
  398. else
  399. CommercerActRank_SendServerMail2Human()
  400. end
  401. end
  402. -- 发送活动结束后登录的的玩家(全服邮件奖励)
  403. function CommercerActRank_SendServerMail2Human()
  404. if not COMMRCE_RANK_SERVERMAIL_HUMAN or not COMMERCE_RANK_SERVER_RANK then
  405. print("[CommercerActRank_SendServerMail2Human] 不存在对应的数据")
  406. return
  407. end
  408. local nNowServerPoint = CommonDB.GetCommerceActInfo_Point()
  409. local tPrize = nil
  410. local nMinPoint = nil
  411. for _, v in ipairs(ServerCommerceRankConf) do
  412. if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER then
  413. if v.nOrder[1] <= COMMERCE_RANK_SERVER_RANK and v.nOrder[2] >= COMMERCE_RANK_SERVER_RANK then
  414. tPrize = v.Prize
  415. end
  416. if not nMinPoint then
  417. nMinPoint = v.nPoint
  418. else
  419. nMinPoint = math.min(nMinPoint, v.nPoint)
  420. end
  421. end
  422. end
  423. if not tPrize then
  424. return
  425. end
  426. if nNowServerPoint < nMinPoint then
  427. print("[CommercerActRank_SendServerMail2Human] 积分不满足直接返回 nMinPoint = "..nMinPoint.." nNowServerPoint = "..nNowServerPoint)
  428. return
  429. end
  430. local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_SERVERMAILID]
  431. local title = mailConfig.title
  432. local senderName = mailConfig.senderName
  433. local content = mailConfig.content
  434. for _, uuid in ipairs(COMMRCE_RANK_SERVERMAIL_HUMAN) do
  435. -- 设置该玩家已经发送邮件
  436. local human = ObjHuman.onlineUuid[uuid]
  437. if not human then
  438. human = RoleDBLogic.getDb(uuid)
  439. end
  440. if human then
  441. MailManager.add(MailManager.SYSTEM, uuid,
  442. title, Util.format(content, COMMERCE_RANK_SERVER_RANK), tPrize, senderName)
  443. -- 记录信息
  444. ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendServerMail2Human] 玩家登录发送全服奖励邮件完成", human)
  445. end
  446. end
  447. COMMRCE_RANK_SERVERMAIL_HUMAN = nil
  448. end
  449. -- 玩家登录活动结束发送个人排行榜邮件
  450. function CommercerActRank_SendHumanMailHumanLogin(human)
  451. local tPrize, nRank = nil, 0
  452. for _, v in ipairs(ServerCommerceRankConf) do
  453. if v.nRankType == CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_HUMAN then
  454. if v.nOrder[1] >= nRank then
  455. tPrize = v.Prize
  456. nRank = v.nOrder[1]
  457. end
  458. end
  459. end
  460. --print("[CommercerActRank_SendHumanMailHumanLogin] nRank = "..nRank)
  461. --table.print_lua_table(tPrize)
  462. local mailConfig = MailExcel.mail[ServerCommerceDefine.COMMERCEACT_HUMANMAILID]
  463. local title = mailConfig.title
  464. local senderName = mailConfig.senderName
  465. local content = mailConfig.content
  466. local newcontent = string.gsub(content, "{1}", "21+")
  467. --print("[CommercerActRank_SendHumanMailHumanLogin] 新的文本 "..newcontent)
  468. MailManager.add(MailManager.SYSTEM, human.db._id,
  469. title, newcontent, tPrize, senderName)
  470. -- 写日志
  471. ServerCommerceManager.CommerveManager_WriteLog("[CommercerActRank_SendHumanMailHumanLogin] 玩家登录发送邮件完成", human)
  472. end
  473. function CommercerActRank_GetRankServerKey(nServerKey)
  474. COMMERCE_RANK_SERVER_KEY = nServerKey
  475. print("[CommercerActRank_GetRankServerKey] 当前服务器收到战区Key nServerID = "..Config.SVR_INDEX.." nServerKey = "..COMMERCE_RANK_SERVER_KEY)
  476. end
  477. ----------------------------------------- 客户端请求 -------------------------------------
  478. -- 客户端请求
  479. function CommercerActRank_Query(human, nRankSubType)
  480. local msgRet = Msg.gc.GC_SERVEERCOMMERCE_ACT_RANK_QUERY
  481. local maxSendRank = CommonDefine.COMMONRANK_SENDPRIZE_LEN
  482. if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
  483. maxSendRank = ServerCommerceDefine.COMMERCEACT_SERVER_RANKLEN
  484. end
  485. local uuid = human.db._id
  486. if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
  487. uuid = tostring(Config.NEW_SVR_INDEX)
  488. end
  489. -- print("[CommercerActRank_Query] uuid = "..uuid)
  490. if false == CommercerActRank_CheckCache(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, COMMERCE_RANK_SERVER_KEY) then
  491. CommercerActRank_CreateCache(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, COMMERCE_RANK_SERVER_KEY)
  492. end
  493. CommercerActRank_WrapOwnerData(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, msgRet.ownerData, uuid)
  494. if 0 == msgRet.ownerData.rankValue then
  495. if CommonDefine.COMMONRANK_SUB_TYPE_SERVERCOMMERCE_SERVER == nRankSubType then
  496. msgRet.ownerData.rankValue = CommonDB.GetCommerceActInfo_Point()
  497. else
  498. msgRet.ownerData.rankValue = ServerCommerceManager.CommerceAct_GetHumanPoint(human)
  499. end
  500. end
  501. print("[CommercerActRank_Query] 玩家的rank = "..msgRet.ownerData.rank)
  502. for rank = 1, maxSendRank do
  503. CommercerActRank_WrapRankList(CommonDefine.COMMONRANK_TYPE_SERVERCOMMERCE, nRankSubType, msgRet.list[rank], rank)
  504. print("[CommercerActRank_Query] 遍历的rank = "..rank.." 下发的 "..msgRet.list[rank].rank)
  505. end
  506. msgRet.list[0] = maxSendRank
  507. Msg.send(msgRet, human.fd)
  508. end