ServerCommerceActPeakBettle.lua 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719
  1. --------------------------------
  2. -- 文件名 : ServerCommerceActPeakBettle.lua
  3. -- 文件说明 : 巅峰战场
  4. -- 创建时间 : 2025/11/13
  5. -- 创建人 : WWF
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local Lang = require("common.Lang")
  9. local Msg = require("core.Msg")
  10. local ObjHuman = require("core.ObjHuman")
  11. local Broadcast = require("broadcast.Broadcast")
  12. local BagLogic = require("bag.BagLogic")
  13. local Grid = require("bag.Grid")
  14. local ItemDefine = require("bag.ItemDefine")
  15. local CombatLogic = require("combat.CombatLogic")
  16. local CombatDefine = require("combat.CombatDefine")
  17. local CombatPosLogic = require("combat.CombatPosLogic")
  18. local RoleLogic = require("role.RoleLogic")
  19. local RoleDBLogic = require("role.RoleDBLogic")
  20. local MailManager = require("mail.MailManager")
  21. local MailExcel = require("excel.mail")
  22. local ServerCommerceManager = require("serverCommerce.ServerCommerceManager")
  23. local ServerCommerceActDefine = require("serverCommerce.ServerCommerceActDefine")
  24. -- Excel配置表
  25. local PeakBattlefieldRewardExcel = require("excel.peakbattlefieldReward")
  26. -- 巅峰战场常量定义
  27. local INIT_RANK = 999
  28. local MATCH_RANK_MIN_OFFSET = 50 -- 向下偏移
  29. local MATCH_RANK_MAX_OFFSET = 10 -- 向上偏移
  30. local MATCH_RANK_MIN = 1 -- 最小排名
  31. local MATCH_RANK_MAX = 999 -- 最大排名
  32. local OPPONENT_LIST_SIZE = 5
  33. local DAILY_FREE_CHALLENGE_CNT = 5
  34. local CHALLENGE_COST_ITEM_ID = 115
  35. local CHALLENGE_COST_ITEM_CNT = 3
  36. local REWARD_ID_WIN = 1001 -- 战胜奖励
  37. local REWARD_ID_LOSE = 1002 -- 战败奖励
  38. local INIT_HERO_CNT_PER_CAMP = 5
  39. local MAIL_ID_DEFEAT = 1 -- 战败通知邮件ID
  40. local MAIL_ID_RANK_REWARD = 0 -- 排名奖励邮件ID
  41. -- 战斗类型
  42. local COMBAT_TYPE_PEAK_BATTLEFIELD = CombatDefine.COMBAT_TYPE35 or 35
  43. -- 数据库相关
  44. local LuaMongo = _G.lua_mongo
  45. local DB = require("common.DB")
  46. -- 排名映射:uuid -> rank
  47. local UUID_2_RANK = {}
  48. -- 排名数据:rank -> data
  49. local RANK_2_DATA = {}
  50. -- 查询条件
  51. local QueryByUuid = {_id = nil}
  52. ----------------------------------------- 内部处理开始 -------------------------------------
  53. -- 获取玩家排名
  54. local function getRank(uuid)
  55. local rank = UUID_2_RANK[uuid]
  56. return rank or 0
  57. end
  58. -- 获取玩家数据
  59. local function getData(uuid)
  60. local rank = UUID_2_RANK[uuid]
  61. if not rank then return end
  62. return RANK_2_DATA[rank]
  63. end
  64. -- 获取对手列表
  65. local function getOpponentList(uuid)
  66. local data = getData(uuid)
  67. if not data then return {} end
  68. return data.opponentList or {}
  69. end
  70. -- 获取已解锁英雄列表
  71. local function getUnlockedHeroes(uuid)
  72. local data = getData(uuid)
  73. if not data then return {} end
  74. return data.unlockedHeroes or {}
  75. end
  76. -- 获取每日免费挑战次数
  77. local function getFreeChallengeCnt(uuid)
  78. local data = getData(uuid)
  79. if not data then return DAILY_FREE_CHALLENGE_CNT end
  80. -- 检查是否需要重置(跨天)
  81. local lastResetTime = data.lastResetTime or 0
  82. if not Util.isSameDay(lastResetTime, os.time()) then
  83. return DAILY_FREE_CHALLENGE_CNT
  84. end
  85. return data.freeChallengeCnt or DAILY_FREE_CHALLENGE_CNT
  86. end
  87. -- 消耗免费挑战次数
  88. local function consumeFreeChallenge(uuid)
  89. local data = getData(uuid)
  90. if not data then return false end
  91. local lastResetTime = data.lastResetTime or 0
  92. local freeCnt = getFreeChallengeCnt(uuid)
  93. if freeCnt <= 0 then
  94. return false
  95. end
  96. -- 跨天重置
  97. if not Util.isSameDay(lastResetTime, os.time()) then
  98. data.freeChallengeCnt = DAILY_FREE_CHALLENGE_CNT
  99. data.lastResetTime = os.time()
  100. end
  101. data.freeChallengeCnt = (data.freeChallengeCnt or DAILY_FREE_CHALLENGE_CNT) - 1
  102. updateData(data)
  103. return true
  104. end
  105. -- 排名比较函数(排名越小越靠前)
  106. local function rankCmp(a, b)
  107. if a.rank ~= b.rank then
  108. return a.rank < b.rank
  109. end
  110. return (a.time or 0) < (b.time or 0)
  111. end
  112. -- 排序排名
  113. local function sortRank()
  114. if #RANK_2_DATA > 1 then
  115. table.sort(RANK_2_DATA, rankCmp)
  116. end
  117. for rank = 1, #RANK_2_DATA do
  118. local uuid = RANK_2_DATA[rank]._id
  119. UUID_2_RANK[uuid] = rank
  120. RANK_2_DATA[rank].rank = rank
  121. end
  122. end
  123. -- 添加玩家
  124. local function addPlayer(human)
  125. local rank = UUID_2_RANK[human.db._id]
  126. if rank then return end
  127. local data = {}
  128. data._id = human.db._id
  129. data.rank = INIT_RANK
  130. data.opponentList = {}
  131. data.unlockedHeroes = {}
  132. data.freeChallengeCnt = DAILY_FREE_CHALLENGE_CNT
  133. data.lastResetTime = os.time()
  134. data.time = os.time()
  135. data.name = human.db.name or ""
  136. data.lv = human.db.lv or 1
  137. data.head = human.db.head or 0
  138. data.zhandouli = human.db.zhandouli or 0
  139. LuaMongo.insert(DB.db_peak_battlefield, data)
  140. RANK_2_DATA[#RANK_2_DATA + 1] = data
  141. sortRank()
  142. end
  143. -- 交换排名(挑战胜利时)
  144. local function swapRank(atkUuid, defUuid)
  145. local atkRank = UUID_2_RANK[atkUuid]
  146. local defRank = UUID_2_RANK[defUuid]
  147. if not atkRank or not defRank then return end
  148. local atkData = RANK_2_DATA[atkRank]
  149. local defData = RANK_2_DATA[defRank]
  150. if not atkData or not defData then return end
  151. -- 交换排名
  152. local tempRank = atkData.rank
  153. atkData.rank = defData.rank
  154. defData.rank = tempRank
  155. atkData.time = os.time()
  156. defData.time = os.time()
  157. -- 清空对手列表(需要重新匹配)
  158. atkData.opponentList = {}
  159. defData.opponentList = {}
  160. updateData(atkData)
  161. updateData(defData)
  162. sortRank()
  163. end
  164. -- 设置对手列表
  165. local function setOpponentList(uuid, opponentList)
  166. local data = getData(uuid)
  167. if not data then return end
  168. data.opponentList = opponentList or {}
  169. updateData(data)
  170. end
  171. -- 更新已解锁英雄
  172. local function updateUnlockedHeroes(uuid, heroList)
  173. local data = getData(uuid)
  174. if not data then return end
  175. data.unlockedHeroes = heroList or {}
  176. updateData(data)
  177. end
  178. -- 更新数据库
  179. local function updateData(data)
  180. QueryByUuid._id = data._id
  181. LuaMongo.update(DB.db_peak_battlefield, QueryByUuid, data)
  182. end
  183. -- 获取排名范围内的玩家(用于匹配)
  184. local function getPlayersInRankRange(minRank, maxRank, excludeUuid)
  185. local result = {}
  186. excludeUuid = excludeUuid or ""
  187. for rank = 1, #RANK_2_DATA do
  188. local data = RANK_2_DATA[rank]
  189. if data.rank >= minRank and data.rank <= maxRank and data._id ~= excludeUuid then
  190. result[#result + 1] = data
  191. end
  192. end
  193. return result
  194. end
  195. -- 获取活动剩余时间(秒)
  196. local function getActivityLeftTime()
  197. local nStartTime, nEndTime = ServerCommerceManager.CommerceAct_GetOpenAndEndTime()
  198. if not nEndTime or nEndTime == 0 then
  199. return 0
  200. end
  201. local now = os.time()
  202. local leftTime = math.max(nEndTime - now, 0)
  203. return leftTime
  204. end
  205. -- 生成对手列表
  206. local function generateOpponents(uuid, rank)
  207. if rank <= 0 then
  208. rank = INIT_RANK
  209. end
  210. local minRank = math.max(rank - MATCH_RANK_MIN_OFFSET, MATCH_RANK_MIN)
  211. local maxRank = math.min(rank + MATCH_RANK_MAX_OFFSET, MATCH_RANK_MAX)
  212. local candidates = getPlayersInRankRange(minRank, maxRank, uuid)
  213. -- 随机选择5个对手
  214. local opponentList = {}
  215. local selected = {}
  216. local needCnt = OPPONENT_LIST_SIZE
  217. if #candidates > 0 then
  218. for i = 1, math.min(needCnt, #candidates) do
  219. local idx = math.random(1, #candidates)
  220. while selected[idx] do
  221. idx = math.random(1, #candidates)
  222. end
  223. selected[idx] = true
  224. opponentList[#opponentList + 1] = {
  225. uuid = candidates[idx]._id,
  226. rank = candidates[idx].rank
  227. }
  228. end
  229. end
  230. return opponentList
  231. end
  232. -- 检查并解锁英雄(使用系统英雄表,按阵营解锁)
  233. local function checkAndUnlockHeroes(human, rank)
  234. local HeroExcel = require("excel.hero").hero
  235. local currentUnlocked = getUnlockedHeroes(human.db._id)
  236. local newUnlocked = {}
  237. -- 根据排名解锁英雄:初始排名时解锁每个阵营的初始英雄
  238. if rank <= INIT_RANK then
  239. -- 使用 CombatDefine 中的阵营定义
  240. local camps = {
  241. CombatDefine.CAMP_TYPE1, -- 恶魔(人族)
  242. CombatDefine.CAMP_TYPE2, -- 圣堂(妖族)
  243. CombatDefine.CAMP_TYPE3 -- 不死(兽族)
  244. }
  245. for _, camp in ipairs(camps) do
  246. -- 从HeroExcel中获取该阵营的所有英雄
  247. local campHeroes = {}
  248. for heroId, heroConfig in pairs(HeroExcel) do
  249. if heroConfig.camp == camp then
  250. campHeroes[#campHeroes + 1] = heroId
  251. end
  252. end
  253. -- 随机选择初始数量的英雄
  254. if #campHeroes > 0 then
  255. local count = INIT_HERO_CNT_PER_CAMP
  256. local maxSelect = math.min(count, #campHeroes)
  257. for i = 1, maxSelect do
  258. local idx = math.random(1, #campHeroes)
  259. local heroId = campHeroes[idx]
  260. -- 检查是否已解锁
  261. local found = false
  262. for k = 1, #currentUnlocked do
  263. if currentUnlocked[k] == heroId then
  264. found = true
  265. break
  266. end
  267. end
  268. if not found then
  269. newUnlocked[#newUnlocked + 1] = heroId
  270. currentUnlocked[#currentUnlocked + 1] = heroId
  271. end
  272. -- 移除已选择的英雄,避免重复
  273. table.remove(campHeroes, idx)
  274. if #campHeroes == 0 then break end
  275. end
  276. end
  277. end
  278. end
  279. if #newUnlocked > 0 then
  280. updateUnlockedHeroes(human.db._id, currentUnlocked)
  281. -- 发送提示
  282. Broadcast.sendErr(human, "解锁新英雄!")
  283. end
  284. end
  285. -- 发送战败邮件
  286. local function sendDefeatMail(defeatedUuid, attackerUuid, newRank)
  287. local attackerDb = RoleDBLogic.getDb(attackerUuid)
  288. if not attackerDb then return end
  289. -- 获取邮件配置
  290. local mailID = MAIL_ID_DEFEAT
  291. if not mailID or mailID == 0 then
  292. return
  293. end
  294. local mailConfig = MailExcel.mail[mailID]
  295. if not mailConfig then
  296. print("[sendDefeatMail] 邮件配置不存在,mailID=" .. (mailID or 0))
  297. return
  298. end
  299. -- 格式化邮件内容
  300. local content = Util.format(mailConfig.content or "", attackerDb.name or "", newRank)
  301. -- 发送邮件
  302. MailManager.add(MailManager.SYSTEM, defeatedUuid, mailConfig.title or "巅峰战区赛", content, nil, mailConfig.senderName or "系统")
  303. end
  304. ----------------------------------------- 外部调用 -------------------------------------
  305. -- 起服初始化
  306. function Init()
  307. -- 从数据库加载所有玩家数据
  308. local cursor = LuaMongo.find(DB.db_peak_battlefield, {})
  309. if cursor then
  310. RANK_2_DATA = {}
  311. UUID_2_RANK = {}
  312. local data = LuaMongo.next(cursor)
  313. while data do
  314. RANK_2_DATA[#RANK_2_DATA + 1] = data
  315. data = LuaMongo.next(cursor)
  316. end
  317. sortRank()
  318. print("[ServerCommerceActPeakBettle - Init] 巅峰战场数据加载完成")
  319. end
  320. return true
  321. end
  322. -- 活动结束
  323. function End()
  324. -- 活动结束后可以重置数据(如果需要)
  325. end
  326. -- 重置玩家数据
  327. function ResetData(human)
  328. if not human then
  329. return
  330. end
  331. end
  332. ----------------------------------------- 客户端请求 -------------------------------------
  333. -- 查询巅峰战场数据
  334. function CommerceActPeakBettle_Query(human)
  335. -- 确保玩家已加入
  336. if not getData(human.db._id) then
  337. addPlayer(human)
  338. end
  339. local data = getData(human.db._id)
  340. if not data then return end
  341. local rank = getRank(human.db._id)
  342. local freeCnt = getFreeChallengeCnt(human.db._id)
  343. local opponentList = getOpponentList(human.db._id)
  344. local unlockedHeroes = getUnlockedHeroes(human.db._id)
  345. -- 如果没有对手列表,生成对手
  346. if not opponentList or #opponentList == 0 then
  347. opponentList = generateOpponents(human.db._id, rank)
  348. setOpponentList(human.db._id, opponentList)
  349. end
  350. local msgRet = Msg.gc.GC_PEAK_BATTLEFIELD_QUERY
  351. msgRet.rank = rank
  352. msgRet.freeChallengeCnt = freeCnt
  353. -- 填充对手列表
  354. local len = 0
  355. for i = 1, #opponentList do
  356. if len >= OPPONENT_LIST_SIZE then break end
  357. local opponent = opponentList[i]
  358. local opponentData = getData(opponent.uuid)
  359. if opponentData then
  360. len = len + 1
  361. local net = msgRet.opponentList[len]
  362. net.uuid = opponent.uuid
  363. net.rank = opponent.rank or opponentData.rank
  364. -- 填充角色信息
  365. local db = RoleDBLogic.getDb(opponent.uuid)
  366. if db then
  367. RoleLogic.makeRoleBase(db, net.roleBase)
  368. else
  369. -- 如果是NPC或离线玩家,使用缓存数据
  370. net.roleBase.name = opponentData.name or ""
  371. net.roleBase.lv = opponentData.lv or 1
  372. net.roleBase.head = opponentData.head or 0
  373. net.roleBase.zhandouli = opponentData.zhandouli or 0
  374. end
  375. end
  376. end
  377. msgRet.opponentList[0] = len
  378. -- 填充已解锁英雄
  379. len = 0
  380. for i = 1, #unlockedHeroes do
  381. if len >= 50 then break end
  382. len = len + 1
  383. msgRet.unlockedHeroes[len] = unlockedHeroes[i]
  384. end
  385. msgRet.unlockedHeroes[0] = len
  386. -- 活动剩余时间
  387. msgRet.leftTime = getActivityLeftTime()
  388. Msg.send(msgRet, human.fd)
  389. end
  390. -- 刷新对手列表
  391. function CommerceActPeakBettle_Refresh(human)
  392. local rank = getRank(human.db._id)
  393. local opponentList = generateOpponents(human.db._id, rank)
  394. setOpponentList(human.db._id, opponentList)
  395. local msgRet = Msg.gc.GC_PEAK_BATTLEFIELD_REFRESH
  396. local len = 0
  397. for i = 1, #opponentList do
  398. if len >= OPPONENT_LIST_SIZE then break end
  399. local opponent = opponentList[i]
  400. local opponentData = getData(opponent.uuid)
  401. if opponentData then
  402. len = len + 1
  403. local net = msgRet.opponentList[len]
  404. net.uuid = opponent.uuid
  405. net.rank = opponent.rank or opponentData.rank
  406. local db = RoleDBLogic.getDb(opponent.uuid)
  407. if db then
  408. RoleLogic.makeRoleBase(db, net.roleBase)
  409. else
  410. net.roleBase.name = opponentData.name or ""
  411. net.roleBase.lv = opponentData.lv or 1
  412. net.roleBase.head = opponentData.head or 0
  413. net.roleBase.zhandouli = opponentData.zhandouli or 0
  414. end
  415. end
  416. end
  417. msgRet.opponentList[0] = len
  418. Msg.send(msgRet, human.fd)
  419. end
  420. -- 挑战对手
  421. function CommerceActPeakBettle_Challenge(human, opponentUuid)
  422. -- 检查对手是否在对手列表中
  423. local opponentList = getOpponentList(human.db._id)
  424. local found = false
  425. for i = 1, #opponentList do
  426. if opponentList[i].uuid == opponentUuid then
  427. found = true
  428. break
  429. end
  430. end
  431. if not found then
  432. return Broadcast.sendErr(human, "对手不在列表中")
  433. end
  434. -- 检查挑战次数
  435. local freeCnt = getFreeChallengeCnt(human.db._id)
  436. if freeCnt > 0 then
  437. -- 使用免费次数
  438. if not consumeFreeChallenge(human.db._id) then
  439. return Broadcast.sendErr(human, "免费挑战次数不足")
  440. end
  441. else
  442. -- 消耗道具
  443. if not BagLogic.checkItem(human, CHALLENGE_COST_ITEM_ID, CHALLENGE_COST_ITEM_CNT) then
  444. return Broadcast.sendErr(human, "挑战券不足")
  445. end
  446. BagLogic.delItem(human, CHALLENGE_COST_ITEM_ID, CHALLENGE_COST_ITEM_CNT, "peak_battlefield_challenge")
  447. end
  448. -- 启动战斗
  449. local cbParam = {
  450. opponentUuid = opponentUuid,
  451. combatType = COMBAT_TYPE_PEAK_BATTLEFIELD
  452. }
  453. CombatLogic.combatBegin(human, nil, {opponentUuid = opponentUuid}, COMBAT_TYPE_PEAK_BATTLEFIELD, cbParam, false)
  454. end
  455. -- 战斗结束回调
  456. function CommerceActPeakBettle_OnFightEnd(human, result, combatType, cbParam, combatInfo, param)
  457. if combatType ~= COMBAT_TYPE_PEAK_BATTLEFIELD then return end
  458. if not cbParam or not cbParam.opponentUuid then return end
  459. local opponentUuid = cbParam.opponentUuid
  460. local isWin = (result == CombatDefine.RESULT_WIN)
  461. local oldRank = getRank(human.db._id)
  462. local newRank = oldRank
  463. -- 胜利:交换排名
  464. if isWin then
  465. swapRank(human.db._id, opponentUuid)
  466. newRank = getRank(human.db._id)
  467. -- 刷新对手列表
  468. local rank = getRank(human.db._id)
  469. local opponentList = generateOpponents(human.db._id, rank)
  470. setOpponentList(human.db._id, opponentList)
  471. -- 检查英雄解锁
  472. checkAndUnlockHeroes(human, newRank)
  473. end
  474. -- 失败:发送邮件通知(给被挑战者)
  475. if not isWin then
  476. sendDefeatMail(opponentUuid, human.db._id, newRank)
  477. end
  478. -- 发放奖励(挑战奖励,rewardType=1)
  479. local rewardId = isWin and REWARD_ID_WIN or REWARD_ID_LOSE
  480. local rewardConfig = PeakBattlefieldRewardExcel.rankReward[rewardId]
  481. if rewardConfig and rewardConfig.rewardType == 1 and rewardConfig.reward then
  482. BagLogic.addItemList(human, rewardConfig.reward, "peak_battlefield_challenge")
  483. end
  484. -- 发送结果
  485. local msgRet = Msg.gc.GC_PEAK_BATTLEFIELD_CHALLENGE
  486. msgRet.result = isWin and 1 or 2
  487. msgRet.newRank = newRank
  488. -- 填充奖励
  489. msgRet.reward[0] = 0
  490. if rewardConfig and rewardConfig.rewardType == 1 and rewardConfig.reward then
  491. for i = 1, #rewardConfig.reward do
  492. local item = rewardConfig.reward[i]
  493. msgRet.reward[0] = msgRet.reward[0] + 1
  494. Grid.makeItem(msgRet.reward[msgRet.reward[0]], item[1], item[2])
  495. end
  496. end
  497. -- 胜利时发送新的对手列表
  498. if isWin then
  499. local opponentList = getOpponentList(human.db._id)
  500. local len = 0
  501. for i = 1, #opponentList do
  502. if len >= OPPONENT_LIST_SIZE then break end
  503. local opponent = opponentList[i]
  504. local opponentData = getData(opponent.uuid)
  505. if opponentData then
  506. len = len + 1
  507. local net = msgRet.opponentList[len]
  508. net.uuid = opponent.uuid
  509. net.rank = opponent.rank or opponentData.rank
  510. local db = RoleDBLogic.getDb(opponent.uuid)
  511. if db then
  512. RoleLogic.makeRoleBase(db, net.roleBase)
  513. else
  514. net.roleBase.name = opponentData.name or ""
  515. net.roleBase.lv = opponentData.lv or 1
  516. net.roleBase.head = opponentData.head or 0
  517. net.roleBase.zhandouli = opponentData.zhandouli or 0
  518. end
  519. end
  520. end
  521. msgRet.opponentList[0] = len
  522. else
  523. msgRet.opponentList[0] = 0
  524. end
  525. Msg.send(msgRet, human.fd)
  526. end
  527. -- 查询排名奖励
  528. function CommerceActPeakBettle_RankRewardQuery(human)
  529. local rank = getRank(human.db._id)
  530. local msgRet = Msg.gc.GC_PEAK_BATTLEFIELD_RANK_REWARD_QUERY
  531. msgRet.rank = rank
  532. -- 填充奖励列表(从Excel配置读取,只读取排名奖励 rewardType=2或3)
  533. local len = 0
  534. if PeakBattlefieldRewardExcel.rankReward then
  535. for rewardID, config in pairs(PeakBattlefieldRewardExcel.rankReward) do
  536. -- 只处理排名奖励(rewardType=2或3),排除挑战奖励(rewardType=1)
  537. if config.rewardType and (config.rewardType == 2 or config.rewardType == 3) then
  538. if config.rank and type(config.rank) == "table" and #config.rank >= 2 then
  539. local rankMin = config.rank[1]
  540. local rankMax = config.rank[2]
  541. if rank >= rankMin and rank <= rankMax then
  542. len = len + 1
  543. if len <= 20 then
  544. msgRet.rewardList[len] = rewardID
  545. end
  546. end
  547. end
  548. end
  549. end
  550. end
  551. msgRet.rewardList[0] = len
  552. Msg.send(msgRet, human.fd)
  553. end
  554. -- 活动结算(活动结束时发放排名奖励)
  555. function CommerceActPeakBettle_OnActivityEnd()
  556. -- 获取所有玩家数据
  557. if not RANK_2_DATA then return end
  558. -- 遍历所有排名,发放奖励
  559. for rank = 1, #RANK_2_DATA do
  560. local data = RANK_2_DATA[rank]
  561. if data and data._id then
  562. -- 根据排名查找对应的奖励配置(只处理排名奖励 rewardType=2或3)
  563. if PeakBattlefieldRewardExcel.rankReward then
  564. for rewardID, config in pairs(PeakBattlefieldRewardExcel.rankReward) do
  565. -- 只处理排名奖励,排除挑战奖励
  566. if config.rewardType and (config.rewardType == 2 or config.rewardType == 3) then
  567. if config.rank and type(config.rank) == "table" and #config.rank >= 2 then
  568. local rankMin = config.rank[1]
  569. local rankMax = config.rank[2]
  570. if rank >= rankMin and rank <= rankMax then
  571. -- 发放排名奖励(通过邮件)
  572. local mailID = MAIL_ID_RANK_REWARD
  573. if mailID and mailID > 0 then
  574. local mailConfig = MailExcel.mail[mailID]
  575. if mailConfig and config.reward then
  576. local content = Util.format(mailConfig.content or "", rank)
  577. MailManager.add(MailManager.SYSTEM, data._id, mailConfig.title or "巅峰战场排名奖励", content, config.reward, mailConfig.senderName or "系统")
  578. end
  579. end
  580. break -- 找到对应奖励后跳出
  581. end
  582. end
  583. end
  584. end
  585. end
  586. end
  587. end
  588. end
  589. -- 检查红点
  590. function isRed(human)
  591. -- 可以根据需要实现红点逻辑
  592. return false
  593. end
  594. ----------------------------------------- 战斗模块接口 -------------------------------------
  595. -- 供战斗模块使用的公共接口
  596. -- 获取玩家数据(供战斗模块使用)
  597. function GetData(uuid)
  598. return getData(uuid)
  599. end
  600. -- 检查对手是否存在(供战斗模块使用)
  601. function CheckOpponent(opponentUuid)
  602. local data = getData(opponentUuid)
  603. return data ~= nil
  604. end