jjcNewLadderLogic.lua 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405
  1. --------------------------------
  2. -- 文件名 : jjcNewLadderLogic.lua
  3. -- 文件说明 : 天梯赛-管理器
  4. -- 创建时间 : 2025/05/07
  5. -- 创建人 : FC
  6. --------------------------------
  7. local Util = require("common.Util")
  8. local Lang = require("common.Lang")
  9. local CommonDB = require("common.CommonDB")
  10. local JjcExcel = require("excel.jjc")
  11. local MonsterExcel = require("excel.monster")
  12. local MailExcel = require("excel.mail")
  13. local Msg = require("core.Msg")
  14. local ObjHuman = require("core.ObjHuman")
  15. local RoleDBLogic = require("role.RoleDBLogic")
  16. local Config = require("Config")
  17. local ItemDefine = require("bag.ItemDefine")
  18. local Grid = require("bag.Grid")
  19. local CombatVideo = require("combat.CombatVideo")
  20. local RoleLogic = require("role.RoleLogic")
  21. local JjcNewLadderDefine = require("jjcnewladder.jjcNewLadderDefine")
  22. local JjcNewLadderMiddle = require("jjcnewladder.jjcNewLadderMiddle")
  23. local JjcNewLadderDB = require("jjcnewladder.jjcNewLadderDB")
  24. local BagLogic = require("bag.BagLogic")
  25. local MiddleCommonLogic = require("middle.MiddleCommonLogic")
  26. local CombatDefine = require("combat.CombatDefine")
  27. local Broadcast = require("broadcast.Broadcast")
  28. local CombatLogic = require("combat.CombatLogic")
  29. local WarReportLogic = require("warReport.WarReportLogic")
  30. local MailManager = require("mail.MailManager")
  31. local Timer = require("core.Timer")
  32. local JjcActLogic = require("jjc.JjcActLogic")
  33. -- 请求加入天梯赛的玩家
  34. local tQueryJoinPlayer = {}
  35. -- 请求天梯赛前三排名的数据的玩家
  36. local tQueryLast3Rank = {}
  37. local bQueryLast = false
  38. -- 上一轮天梯赛前三的排名玩家
  39. local tLast3RankPlayerInfo = nil
  40. -- 排行榜数据
  41. local tCacheRankInfo = {
  42. -- nNextUpdateTime -- 更新时间
  43. -- tRankList = {}
  44. }
  45. local bQueryRank = nil
  46. -- 缓存请求排行榜的玩家
  47. local tCacheQueryRankPlaeyer = {}
  48. ------------------------------------- 内部判断 ----------------------------------------------------
  49. -- 判断是否开启
  50. local function JjcNewLadderLogic_CheckIsOpen()
  51. local nNowTime = os.time()
  52. local nEndTime = CommonDB.GetJjcLadderEndTime()
  53. print("[JjcNewLadderLogic_CheckIsOpen] nNowTime = "..nNowTime.." nEndTime = "..nEndTime)
  54. if 0 >= nEndTime then
  55. local tDate = os.date("*t",nNowTime)
  56. if tDate.wday >= JjcNewLadderDefine.JJC_NEWLADDER_OPENDAY and JjcNewLadderDefine.JJC_NEWLADDER_OPENDAY <= tDate.wday then
  57. if JjcNewLadderDefine.JJC_NEWLADDER_OPENDAY == tDate.wday then
  58. if tDate.hour >= JjcNewLadderDefine.JJC_NEWLADDER_ENDTIME then
  59. return false
  60. end
  61. end
  62. return true
  63. end
  64. return false
  65. else
  66. return nNowTime > nEndTime
  67. end
  68. end
  69. -- 获取剩余时间
  70. local function JjcNewLadder_GetLeftTime()
  71. local nNowTime = os.time()
  72. local nEndTime = CommonDB.GetJjcLadderEndTime()
  73. if not nEndTime or nEndTime < nNowTime then
  74. return 0
  75. end
  76. return nEndTime - nNowTime
  77. end
  78. -- 初始化玩家DB
  79. local function JjcNewLadderLogic_CreatDB(human)
  80. human.db.JjcNewLadder =
  81. {
  82. nRefresh = os.time(), -- 免费刷新时间
  83. nFreeNum = 5, -- 免费挑战次数
  84. nPayNum = 0, -- 购买挑战次数
  85. bJoin = false,
  86. nRank = -1,
  87. nPoint = 0, -- 积分
  88. tEnemy = nil, -- 对战敌方数据
  89. recordList = nil, -- 对战记录
  90. tWorship = nil, -- 点赞记录
  91. nLastEndTime = CommonDB.GetJjcLadderEndTime(), -- 上一次活动结束时间
  92. }
  93. end
  94. -- 获取玩家上一次活动结束时间
  95. local function JjcNewLadder_GetHumanLastEndTime(human)
  96. return human.db.JjcNewLadder.nLastEndTime
  97. end
  98. -- 设置玩家上一次活动结束时间
  99. local function JjcNewLadder_SetHumanLastEndTime(human, nValue)
  100. human.db.JjcNewLadder.nLastEndTime = nValue
  101. end
  102. -- 获取玩家是否参加了天梯赛
  103. local function JjcNewLadder_GetHumanJoin(human)
  104. return human.db.JjcNewLadder.bJoin
  105. end
  106. -- 设置玩家是否参加了天梯赛
  107. local function JjcNewLadder_SetHumanJoin(human, nValue)
  108. human.db.JjcNewLadder.bJoin = nValue
  109. end
  110. -- 获取玩家敌方数据
  111. local function JjcNewLadder_GetHumanEnemy(human)
  112. return human.db.JjcNewLadder.tEnemy
  113. end
  114. -- 设置玩家敌方数据
  115. local function JjcNewLadder_SetHumanEnemy(human, tEnemy)
  116. human.db.JjcNewLadder.tEnemy = tEnemy
  117. end
  118. -- 获取玩家排名数据
  119. local function JjcNewLadder_GetHumanRank(human)
  120. return human.db.JjcNewLadder.nRank
  121. end
  122. -- 设置玩家排名数据
  123. local function JjcNewLadder_SetHumanRank(human, nValue)
  124. human.db.JjcNewLadder.nRank = nValue
  125. end
  126. -- 获取玩家积分数据
  127. local function JjcNewLadder_GetHumanPoint(human)
  128. return human.db.JjcNewLadder.nPoint
  129. end
  130. -- 设置玩家积分数据
  131. local function JjcNewLadder_SetHumanPoint(human, nValue)
  132. human.db.JjcNewLadder.nPoint = nValue
  133. end
  134. -- 获取玩家免费刷新时间
  135. local function JjcNewLadder_GetHumanRefreshTime(human)
  136. return human.db.JjcNewLadder.nRefresh
  137. end
  138. -- 设置玩家免费刷新时间
  139. local function JjcNewLadder_SetHumanRefreshTime(human, nValue)
  140. human.db.JjcNewLadder.nRefresh = nValue
  141. end
  142. -- 获取玩家免费挑战次数
  143. local function JjcNewLadder_GetHumanFreeNum(human)
  144. return human.db.JjcNewLadder.nFreeNum
  145. end
  146. -- 设置玩家免费挑战次数
  147. local function JjcNewLadder_SetHumanFreeNum(human, nValue)
  148. human.db.JjcNewLadder.nFreeNum = human.db.JjcNewLadder.nFreeNum + nValue
  149. end
  150. -- 获取玩家付费挑战次数
  151. local function JjcNewLadder_GetHumanPayNum(human)
  152. return human.db.JjcNewLadder.nPayNum
  153. end
  154. -- 设置玩家付费挑战次数
  155. local function JjcNewLadder_SetHumanPayNumNum(human, nValue)
  156. human.db.JjcNewLadder.nPayNum = human.db.JjcNewLadder.nPayNum + nValue
  157. end
  158. -- 获取玩家所有挑战次数
  159. local function JjcNewLadder_GetAllFightNum(human)
  160. return JjcNewLadder_GetHumanFreeNum(human) + JjcNewLadder_GetHumanPayNum(human)
  161. end
  162. -- 获取对战记录
  163. local function JjcNewLadder_GetRecordList(human)
  164. return human.db.JjcNewLadder.recordList
  165. end
  166. -- 设置对战记录
  167. local function JjcNewLadder_SetRecordList(human, videoUuid)
  168. if not human.db.JjcNewLadder.recordList then
  169. human.db.JjcNewLadder.recordList = {}
  170. end
  171. table.insert(human.db.JjcNewLadder.recordList, {videoUuid = videoUuid, time = os.time()})
  172. end
  173. -- 尝试删除对接记录的视频UID
  174. local function JjcNewLadder_TryDelRecordList(human)
  175. local tRecordList = JjcNewLadder_GetRecordList(human)
  176. if nil == tRecordList then
  177. return
  178. end
  179. local nLen = #tRecordList
  180. if JjcNewLadderDefine.JJC_NEWLADDER_SAVE_RECORDLIST_LEN >= nLen then
  181. return
  182. end
  183. local nDelLen = nLen - JjcNewLadderDefine.JJC_NEWLADDER_SAVE_RECORDLIST_LEN
  184. for i = nDelLen, 1, -1 do
  185. table.remove(tRecordList, i)
  186. end
  187. end
  188. -- 获取是否加入天梯赛
  189. local function JjcNewLadderLogic_GetJoin(human)
  190. return human.db.JjcNewLadder.bJoin
  191. end
  192. -- 设置是否加入天梯赛
  193. local function JjcNewLadderLogic_SetJoin(human, nValue)
  194. human.db.JjcNewLadder.bJoin = nValue
  195. end
  196. -- 获取是否点赞
  197. local function JjcNewLadderLogic_GetWorShip(human, uuid)
  198. if not human.db.JjcNewLadder.tWorship or not human.db.JjcNewLadder.tWorship[uuid] then
  199. return JjcNewLadderDefine.JJC_NEWLADDER_NOWORSHIP
  200. end
  201. return human.db.JjcNewLadder.tWorship[uuid]
  202. end
  203. -- 设置是否点赞
  204. local function JjcNewLadderLogic_SetWorShip(human, uuid, nValue)
  205. if not human.db.JjcNewLadder.tWorship then
  206. human.db.JjcNewLadder.tWorship = {}
  207. end
  208. human.db.JjcNewLadder.tWorship[uuid] = nValue
  209. end
  210. -- 获取对应uuid的一些数据
  211. local function JjcNewLadderLogic_GetInfoByUUID(human, uuid, nType)
  212. local tPlayInfo = nil
  213. if nType == JjcNewLadderDefine.JJC_NEWLADDER_QUERYUID_ENEMY_TYPE then
  214. local tEnemy = JjcNewLadder_GetHumanEnemy(human)
  215. if not tEnemy or nil == _G.next(tEnemy) then
  216. return tPlayInfo
  217. end
  218. for _, v in pairs(tEnemy) do
  219. if v.uuid == uuid then
  220. tPlayInfo = v
  221. return tPlayInfo
  222. end
  223. end
  224. else
  225. for i = 1, JjcNewLadderDefine.JJC_NEWLADDER_RANK_SEND_LEN, 1 do
  226. local tRankData = tCacheRankInfo.tRankList[i]
  227. if not tRankData then
  228. return tPlayInfo
  229. end
  230. if tRankData.uuid == uuid then
  231. tPlayInfo = tRankData
  232. return tPlayInfo
  233. end
  234. end
  235. end
  236. return tPlayInfo
  237. end
  238. -- 请求加入天梯赛
  239. local function JjcNewLadderLogic_JoinLadder(human)
  240. JjcNewLadderMiddle.JjcNewLadderMiddle_JoinLadder(human)
  241. end
  242. -- 进行匹配对手
  243. local function JjcNewLadderLogic_MatchRival(uuid)
  244. return JjcNewLadderDB.JjcNewLadderDB_MatchRival(uuid)
  245. end
  246. -- 获取对应uid的DB数据
  247. local function JjcNewLadderLogic_GetDataByuid(uuid)
  248. return JjcNewLadderDB.JjcNewLadderDB_GetDBDataByuid(uuid)
  249. end
  250. -- 组装下发的主界面数据
  251. local function JjcNewLadder_GetInterfaceInfo(human)
  252. local tMsgData = Msg.gc.GC_JJC_NEW_LADDER_QUERY
  253. tMsgData.ownRank = JjcNewLadder_GetHumanRank(human)
  254. tMsgData.ownJifen = JjcNewLadder_GetHumanPoint(human)
  255. tMsgData.atkZDL = human.db.zhandouli
  256. tMsgData.leftSec = JjcNewLadder_GetLeftTime()
  257. tMsgData.challengeCnt = JjcNewLadder_GetAllFightNum(human)
  258. tMsgData.isQuick = 0
  259. Grid.makeItem(tMsgData.challengeCostItem,ItemDefine.ITEM_JJC_TICKET_ID, JjcNewLadderDefine.JJC_NEWLADDER_COST_ITEM_NUM)
  260. -- 红点
  261. tMsgData.dotList[0] = 3
  262. tMsgData.dotList[1] = tMsgData.challengeCnt > 0 and 1 or 0
  263. tMsgData.dotList[2] = 0
  264. tMsgData.dotList[3] = 0
  265. -- 敌人
  266. local tEnemy = JjcNewLadder_GetHumanEnemy(human)
  267. if not tEnemy then
  268. tMsgData.tEnemy[0] = 0
  269. else
  270. tMsgData.tEnemy[0] = 5
  271. local nIndex = 0
  272. for _, v in pairs(tEnemy) do
  273. nIndex = nIndex + 1
  274. local tData = tMsgData.tEnemy[nIndex]
  275. tData.head = v.head
  276. tData.headFrame = v.headFrame
  277. tData.nPower = v.zhandouli
  278. tData.name = v.name
  279. tData.nPoint = v.point
  280. end
  281. end
  282. return tMsgData
  283. end
  284. -- 发送对手数据
  285. local function JjcNewLadder_SendEnemy(human)
  286. local tMsgData = Msg.gc.GC_JJC_NEW_LADDER_TARGET_FIND
  287. tMsgData.leftFreeCnt = JjcNewLadder_GetHumanFreeNum(human)
  288. local tEnemy = JjcNewLadder_GetHumanEnemy(human)
  289. if not tEnemy then
  290. tMsgData.tEnemy[0] = 0
  291. else
  292. tMsgData.tEnemy[0] = 5
  293. local nIndex = 0
  294. for _, v in pairs(tEnemy) do
  295. nIndex = nIndex + 1
  296. local tData = tMsgData.tEnemy[nIndex]
  297. tData.head = v.head
  298. tData.headFrame = v.headFrame
  299. tData.nPower = v.zhandouli
  300. tData.name = v.name
  301. tData.nPoint = v.point
  302. end
  303. end
  304. Msg.send(tMsgData, human.fd)
  305. end
  306. -- 发送上一轮前3名数据
  307. local function JjcNewLadder_SendLast3Rank(human)
  308. local tMsgData = Msg.gc.GC_JJC_NEW_LADDER_QUERY_LAST_RANK
  309. tMsgData.tList[0] = 0
  310. if tLast3RankPlayerInfo then
  311. local nIndex = 0
  312. for _, v in pairs(tLast3RankPlayerInfo) do
  313. nIndex = nIndex + 1
  314. local tData = tMsgData.tList[nIndex]
  315. tData.head = v.head
  316. tData.headFrame = v.headFrame
  317. tData.name = v.name
  318. tData.szServerName = v.szServerName
  319. tData.uuid = v.uuid
  320. tData.worshipCnt = v.worshipCnt
  321. tData.worshipState = JjcNewLadderLogic_GetWorShip(human, v.uuid)
  322. end
  323. end
  324. Msg.send(tMsgData, human.fd)
  325. end
  326. -- 发送排行榜数据
  327. local function JjcNewLadder_SendRankInfo(human)
  328. local tMsgData = Msg.gc.GC_JJC_NEW_LADDER_RANK_QUERY
  329. tMsgData.ownRank.nRank = JjcNewLadder_GetHumanRank(human)
  330. tMsgData.ownRank.head = human.db.head
  331. tMsgData.ownRank.headFrame = human.db.headFrame
  332. tMsgData.ownRank.nPower = human.db.zhandouli
  333. tMsgData.ownRank.name = human.db.name
  334. tMsgData.ownRank.szServerName = "寻宝"..Config.NEW_SVR_INDEX.."区"
  335. tMsgData.ownRank.uuid = human.db.uuid
  336. tMsgData.topList[0] = JjcNewLadderDefine.JJC_NEWLADDER_RANK_SEND_LEN
  337. for i = 1, JjcNewLadderDefine.JJC_NEWLADDER_RANK_SEND_LEN, 1 do
  338. local tRankData = tCacheRankInfo.tRankList[i]
  339. if tRankData then
  340. local tData = tMsgData.topList[i]
  341. tData.nRank = i
  342. tData.head = tRankData.head
  343. tData.headFrame = tRankData.headFrame or -1
  344. tData.nPower = tRankData.zhandouli
  345. tData.name = tRankData.name
  346. tData.uuid = tRankData.uuid
  347. tData.szServerName = tRankData.szServerName
  348. else
  349. print("[JjcNewLadder_SendRankInfo] 不存在对应排名对应的排行榜数据 i = "..i)
  350. return
  351. end
  352. end
  353. Msg.send(tMsgData, human.fd)
  354. end
  355. -- 保存对战录像和数据
  356. local function JjcNewLadder_SaveRecord(human, combatInfo)
  357. -- 添加录像
  358. local combatVideo = CombatVideo.createCombatVideo(CombatVideo.VIDEOTYPE_JJCLODDER, combatInfo, human.db._id)
  359. local videoUuid = combatVideo._id
  360. JjcNewLadder_SetRecordList(human, videoUuid)
  361. end
  362. -- 发送战败邮件(真人)
  363. local function JjcNewLadder_SendFailMail(uuidDes, nServerID, SrcServerName, SrcName, nNewRank)
  364. JjcNewLadderMiddle.JjcNewLadderMiddle_SendFailMail(uuidDes, nServerID, SrcServerName, SrcName, nNewRank)
  365. end
  366. -- 获取当前玩家对战列表缓存的uuid
  367. local function JjcNewLaader_GetAllEnemyUID(human)
  368. local tEnemy = JjcNewLadder_GetHumanEnemy(human)
  369. if not tEnemy then
  370. return nil
  371. end
  372. local tEnemyUid = {}
  373. for _, v in pairs(tEnemy) do
  374. table.insert(tEnemyUid, v.uuid)
  375. end
  376. return tEnemyUid
  377. end
  378. ---------------------------------- 内部调用 ----------------------------------------------
  379. -- 请求加入天梯赛(数据服)
  380. function JjcNewLadderLogic_JoinHuman(tData)
  381. local bRet = JjcNewLadderDB.JjcNewLadderDB_AddHuman(tData)
  382. if false == bRet then
  383. print("[JjcNewLadderLogic_JoinHuman] 加入DB数据失败")
  384. return
  385. end
  386. local nNowRank = JjcNewLadderDB.JjcNewLadderDB_GetRankByuid(tData.uuid)
  387. if not nNowRank then
  388. print("[JjcNewLadderLogic_JoinHuman] 加入DB后还是不存在对应的排名值 uuid = "..tData.uuid)
  389. return
  390. end
  391. local tRival = JjcNewLadderLogic_MatchRival(tData.uuid)
  392. if nil == tRival then
  393. print("[JjcNewLadderLogic_JoinHuman] 获取匹配对手的uid失败")
  394. return
  395. end
  396. local tRivalData = {}
  397. for nRank, v in pairs(tRival) do
  398. local tJjcData = JjcNewLadderDB.JjcNewLadderDB_GetDBDataByRank(nRank)
  399. if nil == tJjcData then
  400. print("[JjcNewLadderLogic_JoinHuman] 获取不到对应的DB数据 nRank = "..nRank)
  401. return
  402. end
  403. local tSendData = {
  404. name = tJjcData.name,
  405. head = tJjcData.head,
  406. headFrame = tJjcData.headFrame,
  407. uuid = tJjcData.uuid,
  408. nIsHuman = tJjcData.nIsHuman,
  409. nRank = nRank,
  410. zhandouli = tJjcData.zhandouli,
  411. point = tJjcData.point,
  412. nServerID = tJjcData.nServerID or Config.SVR_INDEX,
  413. monsterOutID = tJjcData.monsterOutID or 0
  414. }
  415. table.insert(tRivalData, tSendData)
  416. end
  417. if tData.nSrcServerID == Config.SVR_INDEX then
  418. else
  419. JjcNewLadderMiddle.JjcNewLadderMiddle_JoinLadder_D2C(tData.uuid, tData.nSrcServerID, nNowRank, tRivalData)
  420. end
  421. end
  422. -- 加入天梯赛回包(普通服)
  423. function JjcNewLadderLogic_JoinHumanOk(tData)
  424. local uuid, nRank, nPoint, tEnemy = tData.uuid, tData.nRank, tData.nPoint, tData.tEnemy
  425. local human = ObjHuman.onlineUuid[uuid]
  426. if not human then
  427. human = {}
  428. human.db = RoleDBLogic.getDb(uuid)
  429. human.db.JjcNewLadder.bJoin = true
  430. human.db.JjcNewLadder.nRank = nRank
  431. human.db.JjcNewLadder.tEnemy = tEnemy
  432. human.dn.JjcNewLadder.nPoint = nPoint
  433. RoleDBLogic.saveRole(human.db)
  434. else
  435. human.db.JjcNewLadder.bJoin = true
  436. human.db.JjcNewLadder.nRank = nRank
  437. human.db.JjcNewLadder.tEnemy = tEnemy
  438. human.dn.JjcNewLadder.nPoint = nPoint
  439. local tMsgData = JjcNewLadder_GetInterfaceInfo(human)
  440. Msg.send(tMsgData, human.fd)
  441. end
  442. end
  443. -- 数据服收到刷新对战列表
  444. function JjcNewLadderLogic_RefeshEnemy(tData)
  445. local tRival = JjcNewLadderLogic_MatchRival(tData.uuid)
  446. if nil == tRival then
  447. print("[JjcNewLadderLogic_JoinHuman] 获取匹配对手的uid失败")
  448. return
  449. end
  450. local tRivalData = {}
  451. for nRank, v in pairs(tRival) do
  452. local tJjcData = JjcNewLadderDB.JjcNewLadderDB_GetDBDataByRank(nRank)
  453. if nil == tJjcData then
  454. print("[JjcNewLadderLogic_JoinHuman] 获取不到对应的DB数据 nRank = "..nRank)
  455. return
  456. end
  457. local tSendData = {
  458. name = tJjcData.name,
  459. head = tJjcData.head,
  460. headFrame = tJjcData.headFrame,
  461. uuid = tJjcData.uuid,
  462. nIsHuman = tJjcData.nIsHuman,
  463. nRank = nRank,
  464. zhandouli = tJjcData.zhandouli,
  465. point = tJjcData.point,
  466. nServerID = tJjcData.nServerID or Config.SVR_INDEX,
  467. monsterOutID = tJjcData.monsterOutID or 0,
  468. lv = tJjcData.lv or 0,
  469. identity = tJjcData.identity or 0,
  470. }
  471. table.insert(tRivalData, tSendData)
  472. end
  473. if tData.nSrcServerID == Config.SVR_INDEX then
  474. else
  475. JjcNewLadderMiddle.JjcNewLadderMiddle_RefreshEnemy_D2C(tData.uuid, tData.nSrcServerID, tRivalData)
  476. end
  477. end
  478. -- 刷新对战列表回包(普通服)
  479. function JjcNewLadderLogic_RefeshEnemyOK(tData)
  480. local uuid, tEnemy = tData.uuid, tData.tEnemy
  481. local human = ObjHuman.onlineUuid[uuid]
  482. if not human then
  483. human = {}
  484. human.db = RoleDBLogic.getDb(uuid)
  485. human.db.JjcNewLadder.tEnemy = tEnemy
  486. RoleDBLogic.saveRole(human.db)
  487. else
  488. JjcNewLadder_SetHumanEnemy(human, tEnemy)
  489. JjcNewLadder_SendEnemy(human)
  490. end
  491. end
  492. -- 请求上一轮前3玩家信息(回包)
  493. function JjcNewLadderLogic_GetLast3RankOK(tData)
  494. tLast3RankPlayerInfo = tData
  495. for uuid, _ in pairs(tQueryLast3Rank) do
  496. local human = ObjHuman.onlineUuid[uuid]
  497. if human then
  498. JjcNewLadder_SendLast3Rank(human)
  499. end
  500. end
  501. tQueryLast3Rank = {}
  502. bQueryLast = false
  503. end
  504. -- 进行点赞(中心->数据(被点赞玩家所在服))
  505. function JjcNewLadderLogic_AddWorShip(tData)
  506. local uuidDes = tData.uuidDes
  507. local human = ObjHuman.onlineUuid[uuidDes]
  508. local bSave = false
  509. if not human then
  510. human = {}
  511. human.db = RoleDBLogic.getDb(uuidDes)
  512. bSave = true
  513. end
  514. if not human.db.jjcBeWorship then
  515. human.db.jjcBeWorship = 0
  516. end
  517. human.db.jjcBeWorship = human.db.jjcBeWorship + 1
  518. if true == bSave then
  519. RoleDBLogic.saveRole(human.db)
  520. end
  521. JjcNewLadderMiddle.JjcNewLadderMiddle_AddWorShip_D2C(tData, human.db.jjcBeWorship)
  522. end
  523. -- 点赞成功
  524. function JjcNewLadderLogic_AddWorShipOK(tData)
  525. if not tLast3RankPlayerInfo then
  526. print("[JjcNewLadderLogic_AddWorShipOK] 为什么点赞完不存在数据了")
  527. return
  528. end
  529. local uuidDes, nNowWorShip = tData.uuidDes, tData.nNowWorShip
  530. for _, v in pairs(tLast3RankPlayerInfo) do
  531. if v.uuid == uuidDes then
  532. v.worshipCnt = nNowWorShip
  533. break
  534. end
  535. end
  536. local human = ObjHuman.onlineUuid[tData.uuidSrc]
  537. local bSave = false
  538. if not human then
  539. human = {}
  540. human.db = RoleDBLogic.getDb(uuidDes)
  541. bSave = true
  542. end
  543. -- 设置已点赞
  544. JjcNewLadderLogic_SetWorShip(human, uuidDes, JjcNewLadderDefine.JJC_NEWLADDER_WORSHIP)
  545. if true == bSave then
  546. RoleDBLogic.saveRole(human.db)
  547. end
  548. if false == bSave then
  549. local tMsgData = Msg.gc.GC_JJC_NEW_LADDER_CHAMPION_WORSHIP
  550. tMsgData.worshipCnt = nNowWorShip
  551. tMsgData.dot = 0
  552. Msg.send(tMsgData, human.fd)
  553. end
  554. end
  555. -- 更新缓存的点赞数据
  556. function JjcNewLadderLogic_UpdateWorShip(tData)
  557. if not tLast3RankPlayerInfo then
  558. print("[JjcNewLadderLogic_UpdateWorShip] 更新缓存的点赞数据 为什么不存在数据了")
  559. return
  560. end
  561. for _, v in pairs(tLast3RankPlayerInfo) do
  562. if v.uuid == tData.uuidDes then
  563. v.worshipCnt = tData.nNowWorShip
  564. break
  565. end
  566. end
  567. end
  568. -- 请求天梯赛排行榜数据(中心->战区数据服)
  569. function JjcNewLadderLogic_GetRankInfo(tData)
  570. local tSendRankData = {}
  571. local nFirst = 1
  572. for i = 1, JjcNewLadderDefine.JJC_NEWLADDER_RANK_SEND_LEN, 1 do
  573. local tRank = JjcNewLadderDB.JjcNewLadderDB_GetDBDataByRank(i)
  574. table.insert(tSendRankData, {tRankData = tRank, nRank = i})
  575. local nLen = #tSendRankData
  576. if JjcNewLadderDefine.JJC_NEWLADDER_RANK_ONE_SEND_LEN <= nLen then
  577. local nFinish = i == JjcNewLadderDefine.JJC_NEWLADDER_RANK_SEND_LEN and 1 or 0
  578. JjcNewLadderMiddle.JjcNewLadderMiddle_QueryRankInfo_D2C(tSendRankData, nFinish, tData.nSrcServerID, nFirst)
  579. nFirst = 0
  580. end
  581. end
  582. end
  583. -- 获取到天梯赛排行榜数据(中心->普通)
  584. function JjcNewLadderLogic_GetRankInfoOK(tData)
  585. local nFirst, nIsEnd = tData.nFirst, tData.nIsEnd
  586. local tRankInfo = tData.tRankInfo
  587. if nFirst then
  588. tCacheRankInfo = {
  589. nNextUpdateTime = os.time() + JjcNewLadderDefine.JJC_NEWLADDER_RANK_NEXT_UPDATE_TIME + math.random(1, 30),
  590. tRankList = {}
  591. }
  592. end
  593. for _, v in ipairs(tRankInfo) do
  594. local nRank = v.nRank
  595. local tRankData = v.tRankData
  596. tCacheRankInfo.tRankList[nRank] = tRankData
  597. end
  598. if nIsEnd == 1 then
  599. for uuid, v in pairs(tCacheQueryRankPlaeyer) do
  600. local human = ObjHuman.onlineUuid[uuid]
  601. if human then
  602. JjcNewLadder_SendRankInfo(human)
  603. end
  604. end
  605. -- 清空缓存请求排行榜的玩家
  606. tCacheQueryRankPlaeyer = {}
  607. bQueryRank = nil
  608. end
  609. end
  610. -- 查询是否能够战斗(中心->战区数据服)
  611. function JjcNewLadderLogic_CheckCanFight(tData)
  612. local uuid, uuidDes = tData.uuid, tData.uuidDes
  613. local nCanFight = JjcNewLadderDefine.JJC_NEWLADDER_NO_CAN_FIGHT
  614. -- 检查挑战者
  615. local tRankData = JjcNewLadderDB.JjcNewLadderDB_GetDBDataByuid(uuid)
  616. if not tRankData then
  617. JjcNewLadderMiddle.JjcNewLadderMiddle_ReplyCheckFight(tData, nCanFight)
  618. return
  619. end
  620. if tRankData.nInFight == JjcNewLadderDefine.JJC_NEWLADDER_IN_FIGHT then
  621. -- 还在持续时间内不能战斗
  622. if tRankData.nLastFightTime + JjcNewLadderDefine.JJC_NEWLADDER_FIGHT_DURATION > os.time() then
  623. JjcNewLadderMiddle.JjcNewLadderMiddle_ReplyCheckFight(tData, nCanFight)
  624. return
  625. end
  626. end
  627. -- 检查被挑战者
  628. local tRankEnemyData = JjcNewLadderDB.JjcNewLadderDB_GetDBDataByuid(uuidDes)
  629. if not tRankEnemyData then
  630. JjcNewLadderMiddle.JjcNewLadderMiddle_ReplyCheckFight(tData, nCanFight)
  631. return
  632. end
  633. if tRankEnemyData.nInFight == JjcNewLadderDefine.JJC_NEWLADDER_IN_FIGHT then
  634. -- 还在持续时间内不能战斗
  635. if tRankEnemyData.nLastFightTime + JjcNewLadderDefine.JJC_NEWLADDER_FIGHT_DURATION > os.time() then
  636. JjcNewLadderMiddle.JjcNewLadderMiddle_ReplyCheckFight(tData, nCanFight)
  637. return
  638. end
  639. end
  640. -- 可以战斗
  641. tRankData.nInFight = JjcNewLadderDefine.JJC_NEWLADDER_IN_FIGHT
  642. tRankData.nLastFightTime = os.time()
  643. tRankEnemyData.nInFight = JjcNewLadderDefine.JJC_NEWLADDER_IN_FIGHT
  644. tRankEnemyData.nLastFightTime = os.time()
  645. nCanFight = JjcNewLadderDefine.JJC_NEWLADDER_CAN_FIGHT
  646. JjcNewLadderMiddle.JjcNewLadderMiddle_ReplyCheckFight(tData, nCanFight)
  647. end
  648. -- 查询是否能够战斗(中心->普通)
  649. function JjcNewLadderLogic_CheckCanFightOK(tData)
  650. local uuid, uuidDes, nIsFight = tData.uuid, tData.uuidDes, tData.nIsFight
  651. local human = ObjHuman.onlineUuid[uuid]
  652. -- 已经不在线了,直接返回
  653. if not human then
  654. return
  655. end
  656. if JjcNewLadderDefine.JJC_NEWLADDER_NO_CAN_FIGHT == nIsFight then
  657. return Broadcast.sendErr(human, Lang.JJCNEWLADDERNOFIGHT)
  658. else
  659. -- 开始正在的战斗流程
  660. JjcLadderLogic_TrueFight(human, uuidDes)
  661. end
  662. end
  663. -- 战斗结束(中心->战区数据服)
  664. function JjcNewLadderLogic_FightEnd(tData)
  665. local uuid, uuidDes, nResult = tData.uuid, tData.uuidDes, tData.nResult
  666. local tEnemyInfo = JjcNewLadderDB.JjcNewLadderDB_GetDBDataByuid(uuidDes)
  667. if not tEnemyInfo then
  668. print("[JjcNewLadderLogic_FightEnd] 不存在对战人物的DB数据 uuidDes = "..uuidDes.." nResult = "..nResult)
  669. return
  670. end
  671. local tPlayerInfo = JjcNewLadderDB.JjcNewLadderDB_GetDBDataByuid(uuid)
  672. if not tPlayerInfo then
  673. print("[JjcNewLadderLogic_FightEnd] 不存在玩家的DB数据 uuidDes = "..uuid.." nResult = "..nResult)
  674. return
  675. end
  676. -- 增加积分(会重新排序)
  677. JjcNewLadderDB.JjcNewLadderDB_AddPoint(uuid, 1)
  678. local nNewPlayerRank = JjcNewLadderDB.JjcNewLadderDB_GetRankByuid(uuid)
  679. local nNewEnemyRank = JjcNewLadderDB.JjcNewLadderDB_GetRankByuid(uuidDes)
  680. if nResult == CombatDefine.RESULT_WIN then
  681. -- 真人要发邮件
  682. if tEnemyInfo.nIsHuman == 1 then
  683. JjcNewLadder_SendFailMail(uuidDes, tEnemyInfo.nServerID, tPlayerInfo.szServerName, tPlayerInfo.name, nNewEnemyRank)
  684. end
  685. end
  686. -- 操作对战列表
  687. local tOldEnemyData, tChoseRank = {}, {}
  688. -- 防止选到已对战的角色
  689. tChoseRank[nNewEnemyRank] = 1
  690. for _, uuidEnemy in ipairs(tData.tEnemyUid) do
  691. if uuidEnemy ~= uuidDes then
  692. local tRankData = JjcNewLadderDB.JjcNewLadderDB_GetRankByuid(uuidEnemy)
  693. if tRankData then
  694. local nRank = JjcNewLadderDB_GetRankByuid(uuidEnemy)
  695. table.insert(tOldEnemyData, {uuid = uuidEnemy, nRank = nRank, nPoint = v.point})
  696. tChoseRank[nRank] = 1
  697. end
  698. end
  699. end
  700. local nNewOneRank = JjcNewLadderDB.JjcNewLadderDB_FindOneEnemy(uuid, tChoseRank)
  701. if -1 >= nNewOneRank then
  702. nNewOneRank = nNewEnemyRank
  703. end
  704. -- 组装新的对战人物数据
  705. local tJjcData = JjcNewLadderDB.JjcNewLadderDB_GetDBDataByRank(nNewOneRank)
  706. local tSendData = {
  707. name = tJjcData.name,
  708. head = tJjcData.head,
  709. headFrame = tJjcData.headFrame,
  710. uuid = tJjcData.uuid,
  711. nIsHuman = tJjcData.nIsHuman,
  712. nRank = nNewOneRank,
  713. zhandouli = tJjcData.zhandouli,
  714. point = tJjcData.point,
  715. nServerID = tJjcData.nServerID or Config.SVR_INDEX,
  716. monsterOutID = tJjcData.monsterOutID or 0
  717. }
  718. JjcNewLadderMiddle.JjcNewLadderMiddle_ReplyFightD2C(uuid, uuidDes, tData.nSrcServerID, nNewPlayerRank, tPlayerInfo.point, tOldEnemyData, tSendData)
  719. end
  720. -- 战斗结束(中心 -> 普通)
  721. function JjcNewLadderLogic_FightEndOK(tData)
  722. local uuid, nNewRank, nNewPoint = tData.uuid, tData.nNewRank, tData.nNewPoint
  723. local uuidDes, tNewOneEnemy, tOldEnemyData = tData.uuidDes, tData.tNewOneEnemy, tData.tOldEnemyData
  724. local human = ObjHuman.onlineUuid[uuid]
  725. local bSave = false
  726. if not human then
  727. human = {}
  728. human.db = RoleDBLogic.getDb(uuid)
  729. bSave = true
  730. end
  731. JjcNewLadder_SetHumanRank(human, nNewRank)
  732. JjcNewLadder_SetHumanPoint(human, nNewPoint)
  733. -- 更新对战列表数据
  734. local tEnemy = JjcNewLadder_GetHumanEnemy(human)
  735. local nIndex = nil
  736. for i, v in ipairs(tEnemy) do
  737. if v.uuid == uuidDes then
  738. nIndex = i
  739. else
  740. for _, tUpdateData in ipairs(tOldEnemyData) do
  741. if tUpdateData.uuid == v.uuid then
  742. v.point = tUpdateData.nPoint
  743. v.nRank = tUpdateData.nRank
  744. end
  745. end
  746. end
  747. end
  748. if nIndex then
  749. tEnemy[nIndex] = tNewOneEnemy
  750. else
  751. print("[JjcNewLadderLogic_FightEndOK] 居然找不到对应对战角色数据记录的下标")
  752. end
  753. if true == bSave then
  754. RoleDBLogic.saveRole(human.db)
  755. else
  756. JjcNewLadderLogic_Query(human)
  757. end
  758. end
  759. -- 发送战败邮件
  760. function JjcNewLadderLogic_SendFailMailOK(tData)
  761. local uuid, szServerName, szName, nNewRank = tData.uuidDes, tData.szServerName, tData.szName, tData.nNewRank
  762. local human = ObjHuman.onlineUuid[uuid]
  763. local bSave = false
  764. if not human then
  765. human = {}
  766. human.db = RoleDBLogic.getDb(uuid)
  767. bSave = true
  768. end
  769. local mailConfig = MailExcel.mail[JjcNewLadderDefine.JJC_NEWLADDER_FAIL_MAIL_ID]
  770. local title = mailConfig.title
  771. local senderName = mailConfig.senderName
  772. local content = Util.format(mailConfig.content, szServerName, szName, nNewRank)
  773. MailManager.add(MailManager.SYSTEM, human.db._id, title, content, nil, senderName)
  774. end
  775. -- 发送排名奖励(中心->普通)
  776. function JjcNewLadderLogic_SendPrizeMail(tData)
  777. local tConfig = JjcExcel.skyladderRank
  778. local uuid, nRank = tData.uuid, tData.nRank
  779. local tPrize = nil
  780. for _, v in ipairs(tConfig) do
  781. if v.nMinRank <= nRank and v.nMaxRank >= nRank then
  782. tPrize = v.tPrize
  783. break
  784. end
  785. end
  786. -- 发送奖励
  787. if tPrize then
  788. local mailConfig = MailExcel.mail[JjcNewLadderDefine.JJC_NEWLADDER_RANKPRIZE_MAIL_ID]
  789. local title = mailConfig.title
  790. local senderName = mailConfig.senderName
  791. local content = mailConfig.content
  792. MailManager.add(MailManager.SYSTEM, uuid,
  793. title, Util.format(content, nRank), tPrize, senderName)
  794. end
  795. end
  796. ---------------------------------- 客户端请求 ----------------------------------------------
  797. -- 请求天梯赛信息
  798. function JjcNewLadderLogic_Query(human)
  799. if not human.db.JjcNewLadder then
  800. JjcNewLadderLogic_CreatDB(human)
  801. end
  802. if false == JjcNewLadderLogic_GetJoin() then
  803. local uuid = human.db._id
  804. if not tQueryJoinPlayer[uuid] then
  805. tQueryJoinPlayer[uuid] = os.time()
  806. JjcNewLadderLogic_JoinLadder()
  807. else
  808. if tQueryJoinPlayer[uuid] + JjcNewLadderDefine.JJC_NEWLADDER_JOINTIME <= os.time() then
  809. tQueryJoinPlayer[uuid] = os.time()
  810. JjcNewLadderLogic_JoinLadder()
  811. else
  812. return
  813. end
  814. end
  815. else
  816. local tMsgData = JjcNewLadder_GetInterfaceInfo(human)
  817. Msg.send(tMsgData, human.fd)
  818. end
  819. end
  820. -- 天梯赛对战记录查询
  821. function JjcNewLadderLogic_RecordQuery(human)
  822. JjcNewLadder_TryDelRecordList(human)
  823. local tRecordList = JjcNewLadder_GetRecordList(human)
  824. local tMsgData = Msg.gc.GC_JJC_NEW_LADDER_RECORD_QUERY
  825. tMsgData.leftFreeCnt = JjcNewLadder_GetHumanFreeNum(human)
  826. tMsgData.recordList[0] = 0
  827. if tRecordList then
  828. for i, v in ipairs(tRecordList) do
  829. local videoUuid = v.videoUuid
  830. local combatVideo = CombatVideo.getCombatVideo(videoUuid)
  831. if combatVideo then
  832. tMsgData.recordList[0] = tMsgData.recordList[0] + 1
  833. local net = tMsgData.recordList[tMsgData.recordList[0]]
  834. local combatInfo = combatVideo.combatInfo
  835. local parms = combatInfo.endParam and Util.split(combatInfo.endParam, "|")
  836. net.time = combatInfo.time
  837. net.identity = combatVideo._id
  838. if combatInfo.attacker.uuid == human.db._id then
  839. RoleLogic.makeRoleBase(combatInfo.defender, net.roleBase)
  840. net.result = combatInfo.isWin and JJC_RESULT_ATK_WIN or JJC_RESULT_ATK_FAIL
  841. net.jifenChange = tonumber(parms and parms[3]) or 0
  842. else
  843. RoleLogic.makeRoleBase(combatInfo.attacker, net.roleBase)
  844. net.result = (not combatInfo.isWin) and JJC_RESULT_DEF_WIN or JJC_RESULT_DEF_FAIL
  845. net.jifenChange = tonumber(parms and parms[4]) or 0
  846. end
  847. end
  848. end
  849. end
  850. Msg.send(tMsgData, human.fd)
  851. end
  852. -- 天梯赛对手查询
  853. function JjcNewLadderLogic_TargetFind(human)
  854. JjcNewLadderMiddle.JjcNewLadderMiddle_RefreshEnemy(human)
  855. end
  856. -- 膜拜
  857. function JjcNewLadderLogic_Worship(human, uuid)
  858. if not tLast3RankPlayerInfo then
  859. print("[JjcNewLadderLogic_Worship] 不存在上一轮数据排名前3的数据")
  860. return
  861. end
  862. local nState = JjcNewLadderLogic_GetWorShip(human, uuid)
  863. if nState == JjcNewLadderDefine.JJC_NEWLADDER_WORSHIP then
  864. return
  865. end
  866. local nServerID
  867. for _, v in pairs(tLast3RankPlayerInfo) do
  868. if v.uuid == uuid then
  869. nServerID = v.nServerID
  870. break
  871. end
  872. end
  873. if not nServerID then
  874. print("[JjcNewLadderLogic_Worship] 获取对应uuid对应的服务器ID失败 name = "..human.db.name.." uuid = "..uuid)
  875. return
  876. end
  877. JjcNewLadderMiddle.JjcNewLadderMiddle_SendWorShip(human.db._id, uuid, nServerID)
  878. -- 点赞奖励
  879. local tItem = {}
  880. table.insert(tItem, {JjcNewLadderDefine.JJC_NEWLADDER_WORSHIP_GOODID, JjcNewLadderDefine.JJC_NEWLADDER_WORSHIP_GOODNUM})
  881. BagLogic.addItemList(human, tItem, "jjc_ladder")
  882. -- JjcNewLadderLogic_SetWorShip(human, uuid, JjcNewLadderDefine.JJC_NEWLADDER_WORSHIP)
  883. end
  884. -- 排行榜查询
  885. function JjcNewLadderLogic_RankQuery(human)
  886. if not tCacheRankInfo or not tCacheRankInfo.tRankList then
  887. local uuid = human.db._id
  888. if tCacheQueryRankPlaeyer[uuid] then
  889. return
  890. else
  891. tCacheQueryRankPlaeyer[uuid] = 1
  892. if not bQueryRank then
  893. bQueryRank = true
  894. JjcNewLadderMiddle.JjcNewLadderMiddle_QueryRankInfo()
  895. end
  896. return
  897. end
  898. else
  899. JjcNewLadder_SendRankInfo(human)
  900. -- 时间过期了,再次请求排行榜数据
  901. local nNextUpdateTime = tCacheRankInfo.nNextUpdateTime
  902. if nNextUpdateTime <= os.time() then
  903. JjcNewLadderMiddle.JjcNewLadderMiddle_QueryRankInfo()
  904. end
  905. end
  906. end
  907. -- 请求一键挑战 -- 直接获取奖励
  908. function JjcNewLadderLogic_OneClickChange(human)
  909. local tConfig = JjcExcel.skyladderFightPrize
  910. local nFreeNum = JjcNewLadder_GetHumanFreeNum(human)
  911. if 0 >= nFreeNum then
  912. return
  913. end
  914. local tItem = {}
  915. for _, v in ipairs(tConfig[1].tPrize) do
  916. local nGoodNum = v[2] * nFreeNum
  917. local nGoodID = v[1]
  918. table.insert(tItem, {nGoodID, nGoodNum})
  919. end
  920. if nil ~= _G.next(tItem) then
  921. BagLogic.addItemList(human, tItem, "jjc_ladder")
  922. JjcNewLadder_SetHumanFreeNum(human, -nFreeNum)
  923. JjcNewLadderLogic_Query(human)
  924. end
  925. end
  926. -- 请求天梯赛上一轮排名前三
  927. function JjcNewLadderLogic_LastRankQuery(human)
  928. if not tLast3RankPlayerInfo then
  929. local uuid = human.db._id
  930. if tQueryLast3Rank[uuid] then
  931. return
  932. end
  933. tQueryLast3Rank[uuid] = 1
  934. if bQueryLast == false then
  935. JjcNewLadderMiddle.JjcNewLadderMiddle_QueryLastRank()
  936. bQueryLast = true
  937. end
  938. else
  939. JjcNewLadder_SendLast3Rank(human)
  940. end
  941. end
  942. -- 请求排行榜奖励信息
  943. function JjcNewLadderLogic_RankPrizeQuery(human)
  944. local tMsgData = Msg.gc.GC_JJC_NEW_LADDER_QUERY_RANKPRIZE
  945. tMsgData.nOwnRank = JjcNewLadder_GetHumanRank(human)
  946. tMsgData.tOwnPrize[0] = 0
  947. tMsgData.tRankPrize[0] = 0
  948. for _, v in ipairs(JjcExcel.skyladderRank) do
  949. tMsgData.tRankPrize[0] = tMsgData.tRankPrize[0] + 1
  950. local tData = tMsgData.tRankPrize[tMsgData.tRankPrize[0]]
  951. tData.nMinRank = v.nMinRank
  952. tData.nMaxRank = v.nMaxRank
  953. tData.tList = #v.tPrize
  954. for nIndex, tItem in ipairs(v.tPrize) do
  955. local nGoodsID = tItem[1]
  956. local nGoodNum = tItem[2]
  957. Grid.makeItem(tData.tList[nIndex], nGoodsID, nGoodNum)
  958. end
  959. -- 个人排行榜奖励
  960. if tData.nMinRank <= tMsgData.nOwnRank and tData.nMaxRank >= tMsgData.nOwnRank then
  961. tMsgData.tOwnPrize[0] = #v.tPrize
  962. for nIndex, tItem in ipairs(v.tPrize) do
  963. local nGoodsID = tItem[1]
  964. local nGoodNum = tItem[2]
  965. Grid.makeItem(tMsgData.tOwnPrize[nIndex], nGoodsID, nGoodNum)
  966. end
  967. end
  968. end
  969. Msg.send(tMsgData, human.fd)
  970. end
  971. -- 请求人物所有信息
  972. function JjcNewLadderLogic_QueryAllInfo(human, uuid, nType)
  973. local tPlayInfo = JjcNewLadderLogic_GetInfoByUUID(human, uuid, nType)
  974. if nil == tPlayInfo then
  975. print("[JjcNewLadderLogic_QueryAllInfo] 获取所有数据失败 name = "..human.db.name)
  976. return
  977. end
  978. -- 假人不用请求了, 直接组装
  979. if 0 == tPlayInfo.nIsHuman then
  980. local msgRet = Msg.gc.GC_CHAT_PLAYER_INFO
  981. -- 参考 makePlayInfoByOther
  982. RoleLogic.makeOtherPlayInfo(msgRet, tPlayInfo)
  983. msgRet.vipLv = 0
  984. msgRet.isFriend = 0
  985. msgRet.unionName = ""
  986. msgRet.svrName = tPlayInfo.ServerName
  987. Msg.send(msgRet, human.fd)
  988. else
  989. local tQueryMsg =
  990. {
  991. uuid = uuid,
  992. nServerIndex = tPlayInfo.nServerID
  993. }
  994. MiddleCommonLogic.MiddleCommonLogic_GetChatPlayInfo_LW(human, tQueryMsg)
  995. end
  996. end
  997. ---------------------------------- 战斗相关 ----------------------------------------------
  998. -- 检测能否战斗
  999. function CheckCanFight(human, uuidEnemy)
  1000. JjcNewLadderMiddle.JjcNewLadderMiddle_CheckCanFightBegin(human, uuidEnemy)
  1001. end
  1002. function JjcLadderLogic_TrueFight(human, uuidDes)
  1003. local tPlayInfo = JjcNewLadderLogic_GetInfoByUUID(human, uuidDes, JjcNewLadderDefine.JJC_NEWLADDER_QUERYUID_ENEMY_TYPE)
  1004. if not tPlayInfo then
  1005. print("[JjcLadderLogic_TrueFight] 不存在对应的敌方数据, 上一步是如何通过的")
  1006. return
  1007. end
  1008. -- 扣门票
  1009. BagLogic.delItem(human, ItemDefine.ITEM_JJC_TICKET_ID, 3, "jjc_fight")
  1010. local nFreeNum = JjcNewLadder_GetHumanFreeNum(human)
  1011. if nFreeNum > 0 then
  1012. JjcNewLadder_SetHumanFreeNum(human, -1)
  1013. else
  1014. local nPayNum = JjcNewLadder_GetHumanPayNum(human)
  1015. if nPayNum > 0 then
  1016. JjcNewLadder_SetHumanPayNumNum(human, -1)
  1017. end
  1018. end
  1019. if 0 == tPlayInfo.nIsHuman then
  1020. local args = {
  1021. [1] = uuidDes
  1022. }
  1023. CombatLogic.combatBegin(human, nil, args, CombatDefine.COMBAT_TYPE29, uuidDes)
  1024. print("[JjcLadderLogic_TrueFight] 对战的角色是人机进行对战")
  1025. else
  1026. local tData =
  1027. {
  1028. combatType = CombatDefine.COMBAT_TYPE29,
  1029. nServerIndex = tPlayInfo.nServerID,
  1030. param = uuidDes.."|"..human.db._id
  1031. }
  1032. MiddleCommonLogic.MiddleCommonLogic_CombatBegin_LW(human, tData)
  1033. print("[JjcLadderLogic_TrueFight] 与真人开始对战 nServerID = "..tPlayInfo.nServerID)
  1034. end
  1035. end
  1036. -- 调用开始战斗
  1037. function fight(human, args, combatType)
  1038. if CombatDefine.COMBAT_TYPE29 ~= combatType then
  1039. return
  1040. end
  1041. -- 对战角色的UID
  1042. local uuidEnemy = args[1]
  1043. local tPlayInfo = JjcNewLadderLogic_GetInfoByUUID(human, uuidEnemy, JjcNewLadderDefine.JJC_NEWLADDER_QUERYUID_ENEMY_TYPE)
  1044. if not tPlayInfo then
  1045. print("[JjcNewLadderLogic_fight] 不存在对应的敌方数据")
  1046. return
  1047. end
  1048. -- 检测挑战次数
  1049. local nFreeNum = JjcNewLadder_GetHumanFreeNum(human)
  1050. if nFreeNum <= 0 then
  1051. local nPayNum = JjcNewLadder_GetHumanPayNum(human)
  1052. if nPayNum <= 0 then
  1053. print("[JjcNewLadderLogic_fight] 可用的挑战次数不足")
  1054. return
  1055. end
  1056. end
  1057. -- 去中心服查询是否能够战斗
  1058. CheckCanFight(human, uuidEnemy)
  1059. end
  1060. -- 获取人物对战列表
  1061. function getCombatObjList(human, side, args)
  1062. if side ~= CombatDefine.ATTACK_SIDE then return end
  1063. return CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE1)
  1064. end
  1065. -- 获取机器人对应战斗ID
  1066. function getCombatMonsterOutID(human, side, args)
  1067. if side ~= CombatDefine.DEFEND_SIDE then
  1068. return
  1069. end
  1070. local uuid = args[1]
  1071. local tPlayInfo = JjcNewLadderLogic_GetInfoByUUID(human, uuid, JjcNewLadderDefine.JJC_NEWLADDER_QUERYUID_ENEMY_TYPE)
  1072. if not tPlayInfo then
  1073. return
  1074. end
  1075. if not tPlayInfo.monsterOutID then
  1076. return
  1077. end
  1078. return tPlayInfo.monsterOutID, tPlayInfo.zhandouli
  1079. end
  1080. -- 挑战结束
  1081. function onFightEnd(human, result, combatType, defUuid, combatInfo)
  1082. local tPrize = result == CombatDefine.RESULT_WIN and JjcExcel.skyladderFightPrize[1] or JjcExcel.skyladderFightPrize[2]
  1083. -- 存对战录像
  1084. JjcNewLadder_SaveRecord(human, combatInfo)
  1085. -- 添加战报
  1086. local nMyRank = JjcNewLadder_GetHumanRank(human)
  1087. local tPlayInfo = JjcNewLadderLogic_GetInfoByUUID(human, defUuid, JjcNewLadderDefine.JJC_NEWLADDER_QUERYUID_ENEMY_TYPE)
  1088. if tPlayInfo then
  1089. WarReportLogic.add(WarReportLogic.WAR_REPORT_3, combatInfo, nMyRank, tPlayInfo.nRank)
  1090. else
  1091. print("[JjcNewLadderLogic_onFightEnd] 不存在对战人物的缓存信息")
  1092. end
  1093. -- 获取对战列表的UID,需要刷新
  1094. local tEnemyUuid = JjcNewLaader_GetAllEnemyUID(human)
  1095. -- 通知中心服对战结果
  1096. JjcNewLadderMiddle.JjcNewLadderMiddle_FightEndO2C(human.db._id, defUuid, result, tEnemyUuid)
  1097. -- 给物品
  1098. BagLogic.addItemList(human, tPrize.tPrize, "jjc_fight")
  1099. end
  1100. ---------------------------------- 刷新相关 ----------------------------------------------
  1101. function JjcLadderLogic_LaterOperate()
  1102. -- 清除数据
  1103. JjcNewLadderDB.JjcNewLadderDB_OnHourOpen()
  1104. for _, human in pairs(ObjHuman.onlineUuid) do
  1105. JjcNewLadderLogic_CreatDB(human)
  1106. end
  1107. end
  1108. -- 定时处理
  1109. function onHour(nHour)
  1110. if JjcNewLadderDefine.JJC_NEWLADDER_OPENTIME ~= nHour or JjcNewLadderDefine.JJC_NEWLADDER_ENDTIME ~= nHour then
  1111. return
  1112. end
  1113. print("[JjcLadderLogic_onHour] 当前对应的时间为 nHour = "..nHour)
  1114. local nNowTime = os.time()
  1115. local tDate = os.date("*t",nNowTime)
  1116. if JjcNewLadderDefine.JJC_NEWLADDER_OPENDAY == tDate.wday and JjcNewLadderDefine.JJC_NEWLADDER_OPENTIME == nHour then
  1117. local nNextTime = nNowTime + 3 * 86400
  1118. local tEndDate = os.date("*t",nNextTime)
  1119. tEndDate.hour = 23
  1120. tEndDate.min = 0
  1121. tEndDate.sec = 0
  1122. local nEndTime = os.time(tEndDate)
  1123. CommonDB.SetJjcLadderEndTime(nEndTime)
  1124. Timer.addLater(JjcNewLadderDefine.JJC_NEWLADDER_OPEN_LATER_TIME, JjcLadderLogic_LaterOperate)
  1125. elseif JjcNewLadderDefine.JJC_NEWLADDER_ENDDAY == tDate.wday and JjcNewLadderDefine.JJC_NEWLADDER_ENDTIME == nHour then
  1126. JjcNewLadderDB.JjcNewLadderDB_SendRankMail()
  1127. else
  1128. return
  1129. end
  1130. end
  1131. -- 玩家登录处理
  1132. function onLogin(human)
  1133. if false == JjcNewLadderLogic_CheckIsOpen() then
  1134. return
  1135. end
  1136. if not human.db.JjcNewLadder then
  1137. JjcNewLadderLogic_CreatDB(human)
  1138. else
  1139. local nLastEndTime = JjcNewLadder_GetHumanLastEndTime(human)
  1140. local nNowEndTime = CommonDB.GetJjcLadderEndTime()
  1141. if nNowEndTime > nLastEndTime then
  1142. JjcNewLadderLogic_CreatDB(human)
  1143. else
  1144. local nRefreshTime = JjcNewLadder_GetHumanRefreshTime(human)
  1145. local nNowTime = os.time()
  1146. if false == Util.isSameDayByTimes(nRefreshTime, nNowTime) then
  1147. JjcNewLadder_SetHumanRefreshTime(human, nNowTime)
  1148. JjcNewLadder_SetHumanFreeNum(human, JjcNewLadderDefine.JJC_NEWLADDER_JJC_DAY_FREE_NUM)
  1149. end
  1150. end
  1151. end
  1152. end
  1153. -- 获取活动状态
  1154. function getActState()
  1155. local bRet = JjcNewLadderLogic_CheckIsOpen()
  1156. if false == bRet then
  1157. return JjcActLogic.STATE_NOOPEN, 0
  1158. end
  1159. return JjcActLogic.STATE_START, JjcNewLadder_GetLeftTime()
  1160. end
  1161. function isActRed(human)
  1162. if human.db.lv < 50 then
  1163. return false
  1164. end
  1165. if false == JjcNewLadderLogic_CheckIsOpen() then
  1166. return false
  1167. end
  1168. if not human.db.JjcNewLadder then
  1169. JjcNewLadderLogic_CreatDB(human)
  1170. end
  1171. local nFreeNum = JjcNewLadder_GetHumanFreeNum(human)
  1172. if nFreeNum > 0 then
  1173. return true
  1174. end
  1175. local nPayNum = JjcNewLadder_GetHumanPayNum(human)
  1176. if nPayNum > 0 then
  1177. return true
  1178. end
  1179. return false
  1180. end
  1181. function Init()
  1182. print("[JjcNewLadderLogic_Init] 起服操作开始")
  1183. -- if true == JjcNewLadderLogic_CheckIsOpen() then
  1184. local nEndTime = CommonDB.GetJjcLadderEndTime()
  1185. if 0 >= nEndTime then
  1186. local nNowTime = os.time()
  1187. local tDate = os.date("*t",nNowTime)
  1188. tDate.wday = JjcNewLadderDefine.JJC_NEWLADDER_ENDDAY
  1189. tDate.hour = 23
  1190. tDate.min = 0
  1191. tDate.sec = 0
  1192. nEndTime = os.time(tDate)
  1193. CommonDB.SetJjcLadderEndTime(nEndTime)
  1194. print("[JjcNewLadderLogic_Init] 设置了结束时间 nEndTime = "..nEndTime)
  1195. end
  1196. JjcNewLadderDB.JjcNewLadderDB_initAfterStart()
  1197. -- else
  1198. -- print("[JjcNewLadderLogic_Init] 当前不在时间内直接返回 ")
  1199. -- end
  1200. end