JjcLadderLogic.lua 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351
  1. -----------------------------------------------------------------
  2. -- 天梯争霸
  3. -- 提示说明在notice配置79
  4. -- 活动开始前x秒,本服发送单人竞技场前100名数据到跨服
  5. -- 人物db
  6. -- db.jjcLadder.useCnt 已使用体力
  7. -- db.jjcLadder.buyCnt 已购买体力
  8. -- db.jjcLadder.mobais 已膜拜列表 [rank]=是否膜拜
  9. -- db.jjcLadder.beMobaiCnt 历史被膜拜次数
  10. -- common db
  11. -- db.state 当前阶段
  12. -- db.endTime 阶段结束时间戳
  13. -- db.uuid2sign [本服]报名列表 [uuid] = time
  14. -- db.sendDataList [本服]同步列表
  15. -- db.lastTopList [跨服]上一届前三 可膜拜对象 [rank] = rolebase
  16. -- db.rank2uuid [跨服]本次排名 [rank] = uuid
  17. -- db.uuid2rank [跨服]本次排名 [uuid] = rank
  18. -- db.logReds [跨服]日志红点 [uuid] = 是否有新记录
  19. -- db.uuid2logs [跨服]日志记录 [uuid] = {[index]=videoUuid}
  20. -- 活动配置jjcLadder.xlsx
  21. -- 活动时间周六0点-周日23点
  22. -- 活动开始前60秒(周五23点55分-周六0点)为准备阶段,本服同步jjc活动前100名的角色信息到跨服作为活动参赛者
  23. -----------------------------------------------------------------
  24. local Config = require("Config")
  25. local JjcLadderExcel = require("excel.jjcLadder")
  26. local JjcLadderDefine = JjcLadderExcel.define[1]
  27. local MailExcel = require("excel.mail")
  28. local Util = require("common.Util")
  29. local Lang = require("common.Lang")
  30. local CommonDB = require("common.CommonDB")
  31. local Msg = require("core.Msg")
  32. local Timer = require("core.Timer")
  33. local InnerMsg = require("core.InnerMsg")
  34. local ObjHuman = require("core.ObjHuman")
  35. local Broadcast = require("broadcast.Broadcast")
  36. local Grid = require("bag.Grid")
  37. local BagLogic = require("bag.BagLogic")
  38. local CombatLogic = require("combat.CombatLogic")
  39. local CombatDefine = require("combat.CombatDefine")
  40. local CombatPosLogic = require("combat.CombatPosLogic")
  41. local MiddleConnect = require("middle.MiddleConnect")
  42. local MiddleManager = require("middle.MiddleManager")
  43. local MailManager = require("mail.MailManager")
  44. local MailDefine = require("mail.MailIdDefine")
  45. local JjcDB = require("jjc.JjcDB")
  46. local JjcActLogic = require("jjc.JjcActLogic")
  47. local JjcLadderMiddle = require("jjcLadder.JjcLadderMiddle")
  48. local RoleDBLogic = require("role.RoleDBLogic")
  49. local RoleDefine = require("role.RoleDefine")
  50. local RoleLogic = require("role.RoleLogic")
  51. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  52. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  53. local UnionDBLogic = require("union.UnionDBLogic")
  54. local LiLianLogic = require("dailyTask.LiLianLogic")
  55. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  56. local WarReportLogic = require("warReport.WarReportLogic")
  57. local MonsterOutExcel = require("excel.monster").monsterOut
  58. local MonsterExcel = require("excel.monster").monster
  59. local HeroGrid = require("hero.HeroGrid")
  60. local HeroExcel = require("excel.hero")
  61. local ItemDefine = require("bag.ItemDefine")
  62. local RoleSystemExcel = require("excel.roleSystem")
  63. local RoleHeadLogic = require("role.RoleHeadLogic")
  64. STATE_ACT_NO_OPEN = 0 -- 未开放 可能没开跨服
  65. STATE_ACT_START = 1 -- 活动进行中
  66. STATE_ACT_READY = 2 -- 活动准备中-活动未开始
  67. STATE_ACT_SENDDATA = 3 -- 活动准备中-数据同步
  68. READY_TIME = 60 -- 准备阶段时间 秒
  69. REFRESH_TIME = 5 -- 刷新间隔 秒
  70. SENDDATA_PLAYER_CNT = 100 -- 每个服同步x人
  71. SENDDATA_PER_TIME = 10 -- 每次同步x个玩家数据
  72. MOBAI_PLAYER_CNT = 3 -- 可膜拜人数
  73. JJCLADDER_MOBAICNT = JJCLADDER_MOBAICNT or 0 -- 可膜拜人数
  74. UUID_2_COMBATINFO = UUID_2_COMBATINFO or {}
  75. local TEMP_REWARD_LIST = {{}}
  76. -- 获得活动最新状态 state, startTime, endTime
  77. local function getNewState()
  78. local nowTime = os.time()
  79. local weekStartTime = Util.getWeekStartTime(nowTime)
  80. local scf = JjcLadderDefine.startTime
  81. local startTime = weekStartTime + (scf.week - 1) * 86400 + scf.hour * 3600 + scf.min * 60
  82. local ecf = JjcLadderDefine.endTime
  83. local endTime = weekStartTime + (ecf.week - 1) * 86400 + ecf.hour * 3600 + ecf.min * 60
  84. if startTime <= nowTime and nowTime < endTime then
  85. return STATE_ACT_START, endTime
  86. end
  87. if nowTime < startTime then
  88. if startTime - nowTime <= READY_TIME then
  89. return STATE_ACT_SENDDATA, startTime
  90. else
  91. return STATE_ACT_READY, startTime - READY_TIME
  92. end
  93. end
  94. return STATE_ACT_READY, startTime + 7 * 86400 - READY_TIME
  95. end
  96. function getActTime()
  97. local weekStartTime = Util.getWeekStartTime(os.time())
  98. local scf = JjcLadderDefine.startTime
  99. local startTime = weekStartTime + (scf.week - 1) * 86400 + scf.hour * 3600 + scf.min * 60
  100. local ecf = JjcLadderDefine.endTime
  101. local endTime = weekStartTime + (ecf.week - 1) * 86400 + ecf.hour * 3600 + ecf.min * 60
  102. return startTime, endTime
  103. end
  104. -- 获取活动当前状态(显示用)
  105. function getState()
  106. if not _G.is_middle and not MiddleConnect.IS_MIDDLE_CONNECT then
  107. return STATE_ACT_NO_OPEN, 0
  108. end
  109. local commonDB = getCommonDB()
  110. if not commonDB.state then
  111. onTimer()
  112. commonDB = getCommonDB()
  113. end
  114. if commonDB.state == STATE_ACT_START then
  115. return STATE_ACT_START, commonDB.endTime - os.time()
  116. end
  117. if commonDB.state == STATE_ACT_READY then
  118. return STATE_ACT_READY, commonDB.endTime + READY_TIME - os.time()
  119. end
  120. return STATE_ACT_READY, commonDB.endTime - os.time()
  121. end
  122. -- 是否开放
  123. function isOpen(human)
  124. local state = getState()
  125. if state == STATE_ACT_NO_OPEN then -- 跨服未启动
  126. Broadcast.sendErr(human, Lang.MIDDLE_SVR_ERR_CONNECT)
  127. return
  128. end
  129. -- 判断开放等级
  130. local config = RoleSystemExcel.roleSystem[RoleSystemDefine.ROLE_SYS_ID_1401]
  131. local openDay = CommonDB.getServerOpenDay()
  132. if config and openDay and config.openSvrDay <= openDay then
  133. else
  134. return
  135. end
  136. -- if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1401, true) then
  137. -- print(" reutrn 111 ", state)
  138. -- return
  139. -- end
  140. return state
  141. end
  142. -- 检查是否有 配开启 天梯
  143. function isSysOpen()
  144. local config = RoleSystemExcel.roleSystem[RoleSystemDefine.ROLE_SYS_ID_1401]
  145. local openDay = CommonDB.getServerOpenDay()
  146. if config and openDay and config.openSvrDay < openDay then
  147. return true
  148. end
  149. return false
  150. end
  151. -- 红点
  152. function isDot(human)
  153. -- 可膜拜
  154. for rank = 1, JJCLADDER_MOBAICNT do
  155. if not isMobai(human, rank) then
  156. return true
  157. end
  158. end
  159. -- 有挑战次数
  160. local state = getState()
  161. if state == STATE_ACT_START then
  162. if getLeftCnt(human) > 0 and isSignAct(human.db._id) then
  163. return true
  164. end
  165. end
  166. end
  167. -- 随机奖励
  168. function randomReward(confs)
  169. local weightSum = 0
  170. for _, conf in pairs(confs) do
  171. weightSum = weightSum + conf.weight
  172. end
  173. if weightSum < 0 then
  174. return
  175. end
  176. local r = math.random(1, weightSum)
  177. local tconf = nil
  178. for _, conf in pairs(confs) do
  179. if r <= conf.weight then
  180. tconf = conf
  181. break
  182. end
  183. r = r - conf.weight
  184. end
  185. if not tconf then return end
  186. local itemCnt = math.random(tconf.itemCnt1, tconf.itemCnt2)
  187. return tconf.itemID, itemCnt
  188. end
  189. -- 根据名次获取排名奖励
  190. function getRewardByRank(rank)
  191. for _, conf in ipairs(JjcLadderExcel.reward) do
  192. if conf.rankMin > rank then
  193. break
  194. end
  195. if rank <= conf.rankMax then
  196. return conf
  197. end
  198. end
  199. end
  200. -- 获取玩家公会旗帜
  201. function getUnionName(unionUuid)
  202. if unionUuid and unionUuid ~= "" then
  203. local union = UnionDBLogic.getUnion(unionUuid)
  204. if union then
  205. return union.name
  206. end
  207. end
  208. return ""
  209. end
  210. -- 创建人物信息
  211. local function createHumanData(uuid)
  212. local fakeHuman = CombatLogic.createCombatFakeHuman(uuid)
  213. if not fakeHuman then return end
  214. -- 空了就取征战队伍
  215. local combatHero = CombatPosLogic.getCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE16 ) -- CombatDefine.COMBAT_TYPE16
  216. if CombatLogic.isCombatHeroEmpty(combatHero) then
  217. CombatPosLogic.copyCombatHeros(fakeHuman, CombatDefine.COMBAT_TYPE1, CombatDefine.COMBAT_TYPE16)
  218. RoleDBLogic.saveRoleSset(fakeHuman.db)
  219. end
  220. local objList, helpList, rolebase, formation, jiban, elfList = CombatLogic.getHumanObjList(fakeHuman, CombatDefine.COMBAT_TYPE16) --COMBAT_TYPE16
  221. if not objList then return end
  222. rolebase.svrName = Config.SVR_NAME
  223. rolebase.svrIndex = Config.SVR_INDEX
  224. rolebase.beMobaiCnt = getBeMobaiCnt(fakeHuman) -- 历史被点赞数
  225. rolebase.unionName = getUnionName(rolebase.unionUuid)
  226. local playerData = {}
  227. playerData._id = uuid
  228. playerData.rolebase = rolebase
  229. playerData.objList = objList
  230. playerData.helpList = helpList
  231. playerData.elfList = elfList
  232. playerData.formation = formation
  233. playerData.jiban = jiban
  234. return playerData
  235. end
  236. -- 创建NPC信息
  237. local function createNPCData(jjcData)
  238. local objList, helpList, rolebase, formation, jiban = CombatLogic.getMonsterObjList(jjcData.monsterOutID)
  239. if not objList then return end
  240. rolebase.name = jjcData.name
  241. rolebase.lv = jjcData.lv
  242. rolebase.head = jjcData.head
  243. rolebase.headFrame = RoleDefine.DEFAULT_HEAD_FRAME
  244. rolebase.zhandouli = jjcData.zhandouli
  245. rolebase.uuid = jjcData._id
  246. rolebase.svrName = Config.SVR_NAME
  247. rolebase.svrIndex = Config.SVR_INDEX
  248. rolebase.beMobaiCnt = nil -- 历史被点赞数
  249. rolebase.unionName = ""
  250. local _, mcf = CombatLogic.getMonsterIDByOutID(jjcData.monsterOutID)
  251. rolebase.body = mcf and mcf.body or 0
  252. local playerData = {}
  253. playerData._id = jjcData._id
  254. playerData.rolebase = rolebase
  255. playerData.objList = objList
  256. playerData.helpList = helpList
  257. playerData.formation = formation
  258. playerData.jiban = jiban
  259. return playerData
  260. end
  261. -- 根据竞技场数据创建传送到跨服的玩家数据
  262. function createPlayerData(jjcData)
  263. if jjcData.monsterOutID then
  264. return createNPCData(jjcData)
  265. else
  266. return createHumanData(jjcData._id)
  267. end
  268. end
  269. ----------------------------------------------- db --------------------------------------------------
  270. -- 每日刷新
  271. function updateDaily(human)
  272. if not human.db.jjcLadder then
  273. return
  274. end
  275. human.db.jjcLadder.useCnt = nil
  276. human.db.jjcLadder.buyCnt = nil
  277. human.db.jjcLadder.mobais = nil
  278. end
  279. -- 阵容/基础信息变化
  280. function onUpdatePos(human)
  281. if not isSignAct(human.db._id) then
  282. return
  283. end
  284. local playerData = createHumanData(human.db._id)
  285. if not playerData then return end
  286. sendLWPlayerData(playerData)
  287. end
  288. -- 英雄变化
  289. function onUpdateHeroZDL(human, index)
  290. if not isSignAct(human.db._id) then
  291. return
  292. end
  293. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE16) --CombatDefine.COMBAT_TYPE16
  294. if not combatHero then return end
  295. local isFind = nil
  296. for _, heroIndex in pairs(combatHero) do
  297. if heroIndex == index then
  298. isFind = true
  299. break
  300. end
  301. end
  302. if not isFind then return end
  303. local playerData = createHumanData(human.db._id)
  304. if not playerData then return end
  305. sendLWPlayerData(playerData)
  306. end
  307. -- 已使用体力
  308. function getUseCnt(human)
  309. if not human.db.jjcLadder then
  310. return 0
  311. end
  312. return human.db.jjcLadder.useCnt or 0
  313. end
  314. --
  315. function addUseCnt(human, value)
  316. if not human.db.jjcLadder then
  317. human.db.jjcLadder = {}
  318. end
  319. local oldValue = human.db.jjcLadder.useCnt or 0
  320. human.db.jjcLadder.useCnt = oldValue + (value or 1)
  321. end
  322. -- 已购买体力次数
  323. function getBuyCnt(human)
  324. if not human.db.jjcLadder then
  325. return 0
  326. end
  327. return human.db.jjcLadder.buyCnt or 0
  328. end
  329. --
  330. function addBuyCnt(human, value)
  331. if not human.db.jjcLadder then
  332. human.db.jjcLadder = {}
  333. end
  334. local oldValue = human.db.jjcLadder.buyCnt or 0
  335. human.db.jjcLadder.buyCnt = oldValue + (value or 1)
  336. end
  337. -- 剩余可挑战次数
  338. function getLeftCnt(human)
  339. local maxCnt = JjcLadderDefine.initCnt + getBuyCnt(human)
  340. local useCnt = getUseCnt(human)
  341. return math.max(maxCnt - useCnt, 0)
  342. end
  343. -- 剩余购买次数
  344. function getLeftBuyCnt(human)
  345. local maxCnt = #JjcLadderDefine.buyCosts
  346. local buyCnt = getBuyCnt(human)
  347. return math.max(maxCnt - buyCnt, 0)
  348. end
  349. -- 购买体力价格
  350. function getBuyPrice(human)
  351. local buyCnt = getBuyCnt(human)
  352. local price = JjcLadderDefine.buyCosts[buyCnt + 1]
  353. if not price then
  354. price = JjcLadderDefine.buyCosts[#JjcLadderDefine.buyCosts]
  355. end
  356. return price
  357. end
  358. -- 是否已膜拜
  359. function isMobai(human, rank)
  360. if not human.db.jjcLadder then
  361. return
  362. end
  363. local mobais = human.db.jjcLadder.mobais
  364. if not mobais then return end
  365. return Util.getBit(mobais, rank) > 0
  366. end
  367. -- 设置膜拜
  368. function setMobai(human, rank)
  369. if not human.db.jjcLadder then
  370. human.db.jjcLadder = {}
  371. end
  372. local mobais = human.db.jjcLadder.mobais or 0
  373. human.db.jjcLadder.mobais = Util.setBit(mobais, rank)
  374. end
  375. -- 是否存在可膜拜
  376. function isMobaiRed(human, mobaiCnt)
  377. for i = 1, mobaiCnt do
  378. if not isMobai(human, i) then
  379. return true
  380. end
  381. end
  382. end
  383. -- 刷新剩余时间
  384. function getRefreshLeftTime(human)
  385. if not human.jjcLadderRefreshTime then
  386. return 0
  387. end
  388. local time = os.time() - human.jjcLadderRefreshTime
  389. return math.max(0, REFRESH_TIME - time)
  390. end
  391. -- 历史被膜拜次数
  392. function getBeMobaiCnt(human)
  393. if not human.db.jjcLadder then
  394. return 0
  395. end
  396. return human.db.jjcLadder.beMobaiCnt or 0
  397. end
  398. function setBeMobaiCnt(human, cnt)
  399. if not human.db.jjcLadder then
  400. human.db.jjcLadder = {}
  401. end
  402. human.db.jjcLadder.beMobaiCnt = cnt
  403. end
  404. function saveCommonDB(data)
  405. data = data or {}
  406. CommonDB.updateValue(CommonDB.KEY_JJC_LADDER, data)
  407. end
  408. local TEMP_COMMONDB = {}
  409. function getCommonDB()
  410. return CommonDB.getValueByKey(CommonDB.KEY_JJC_LADDER) or TEMP_COMMONDB
  411. end
  412. -- 是否有参赛资格
  413. function isSignAct(uuid)
  414. local commonDB = getCommonDB()
  415. if commonDB.uuid2sign and commonDB.uuid2sign[uuid] then
  416. return true
  417. end
  418. end
  419. ------------------------------------------------ msg --------------------------------------------------
  420. -- 查询主界面
  421. function query(human)
  422. if not isOpen(human) then
  423. return
  424. end
  425. local msgInner = InnerMsg.lw.LW_JJC_LADDER_QUERY
  426. msgInner.uuid = human.db._id
  427. InnerMsg.sendMsg(0, msgInner)
  428. end
  429. -- 真打 参数 targetRank|targetUuid
  430. function fight(human, args, combatType)
  431. local cacheCombatInfo = UUID_2_COMBATINFO[human.db._id]
  432. if cacheCombatInfo and cacheCombatInfo.time == os.time() then
  433. return -- 防止连按的情况
  434. end
  435. local state = isOpen(human)
  436. if not state then return end
  437. if state ~= STATE_ACT_START then
  438. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  439. end
  440. if not isSignAct(human.db._id) then
  441. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_JOIN)
  442. end
  443. if getLeftCnt(human) < 1 then
  444. if getLeftBuyCnt(human) > 0 then
  445. if not buyCnt(human) then
  446. return
  447. end
  448. else
  449. return Broadcast.sendErr(human, Lang.JJC_LADDER_FIGHT_ERR_CNT)
  450. end
  451. end
  452. local targetRank = tonumber(args[1])
  453. local targetUuid = args[2]
  454. if not targetRank or not targetUuid then
  455. return
  456. end
  457. if targetUuid == human.db._id then
  458. return -- 不能挑战自己哦
  459. end
  460. local msgInner = InnerMsg.lw.LW_JJC_LADDER_COMBAT_ASK
  461. msgInner.uuid = human.db._id
  462. msgInner.targetUuid = targetUuid
  463. msgInner.targetRank = targetRank
  464. InnerMsg.sendMsg(0, msgInner)
  465. --print("fight", targetUuid, targetRank)
  466. end
  467. -- 战斗结束回调
  468. function onFightEnd(human, result, combatType, cbParam, combatInfo, param, isSaodang)
  469. print(" onFightEnd onFightEnd onFightEnd onFightEnd")
  470. --print("fight end", result, combatInfo, result)
  471. if not cbParam or not cbParam.uuid then
  472. return
  473. end
  474. if not param or not param.uuid then
  475. print(" not param ")
  476. end
  477. UUID_2_COMBATINFO[cbParam.uuid] = combatInfo
  478. local rolebase = cbParam.playerData.rolebase
  479. combatInfo.attacker.name = combatInfo.attacker.name
  480. combatInfo.defender.name = rolebase.name
  481. if combatInfo.isWin and cbParam.rank > cbParam.targetRank then
  482. combatInfo.endParam = cbParam.targetRank .. "|" .. cbParam.rank .. "|" .. cbParam.rank .. "|" .. cbParam.targetRank
  483. else
  484. combatInfo.endParam = cbParam.rank .. "|" .. cbParam.targetRank .. "|" .. cbParam.rank .. "|" .. cbParam.targetRank
  485. end
  486. local msgRet = Msg.gc.GC_JJC_LADDER_AFTER_FIGHT
  487. local len = 0
  488. if getLeftCnt(human) > 0 then
  489. -- 扣次数 给奖励
  490. addUseCnt(human)
  491. local config = combatInfo.isWin and JjcLadderExcel.winReward or JjcLadderExcel.failReward
  492. local itemID, itemCnt = randomReward(config)
  493. if itemID then
  494. BagLogic.addItem(human, itemID, itemCnt, "jjc_ladder")
  495. combatInfo.rewardItem = {}
  496. combatInfo.rewardItem[1] = {itemID, itemCnt}
  497. len = len + 1
  498. Grid.makeItem(msgRet.items[len], itemID, itemCnt)
  499. end
  500. end
  501. local state = getState()
  502. local newRank, newTargetRank = cbParam.rank , cbParam.targetRank
  503. if state == STATE_ACT_START then
  504. if combatInfo.isWin and (cbParam.rank > cbParam.targetRank) then
  505. newRank, newTargetRank = cbParam.targetRank, cbParam.rank
  506. end
  507. else
  508. combatInfo.isActEnd = true
  509. end
  510. msgRet.result = result
  511. msgRet.rank = cbParam.rank
  512. msgRet.newRank = newRank
  513. msgRet.targetRank = cbParam.targetRank
  514. msgRet.targetNewRank = newTargetRank
  515. RoleLogic.makeRoleBase(combatInfo.attacker, msgRet.atkRole)
  516. RoleLogic.makeRoleBase(combatInfo.defender, msgRet.defRole)
  517. msgRet.items[0] = len
  518. Msg.send(msgRet, human.fd)
  519. local msgInner = InnerMsg.lw.LW_JJC_LADDER_COMBAT_RESULT
  520. msgInner.uuid = cbParam.uuid
  521. msgInner.rank = cbParam.rank
  522. msgInner.targetUuid = cbParam.targetUuid
  523. msgInner.targetRank = cbParam.targetRank
  524. msgInner.combatInfo = combatInfo
  525. InnerMsg.sendMsg(0, msgInner)
  526. if result == CombatDefine.RESULT_WIN then
  527. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID4,1)
  528. end
  529. -- 战报
  530. WarReportLogic.add(WarReportLogic.WAR_REPORT_3, combatInfo, cbParam.rank, cbParam.targetRank)
  531. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  532. end
  533. -- 一键挑战
  534. function combatOneKey(human)
  535. local state = isOpen(human)
  536. if not state then return end
  537. if state ~= STATE_ACT_START then
  538. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  539. end
  540. ObjHuman.updateDaily(human)
  541. if getLeftCnt(human) < 1 then
  542. if getLeftBuyCnt(human) > 0 then
  543. if not buyCnt(human) then
  544. return
  545. end
  546. else
  547. return Broadcast.sendErr(human, Lang.JJC_LADDER_FIGHT_ERR_CNT)
  548. end
  549. end
  550. if not isSignAct(human.db._id) then
  551. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_JOIN)
  552. end
  553. -- 扣次数 给奖励 名次不变
  554. addUseCnt(human)
  555. local itemID, itemCnt = randomReward(JjcLadderExcel.winReward)
  556. if itemID then
  557. BagLogic.addItem(human, itemID, itemCnt, "jjc_ladder")
  558. TEMP_REWARD_LIST[1][1] = itemID
  559. TEMP_REWARD_LIST[1][2] = itemCnt
  560. BagLogic.sendItemGetList(human, TEMP_REWARD_LIST)
  561. end
  562. sendBuyCnt(human)
  563. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  564. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID4,1)
  565. end
  566. -- 购买挑战次数
  567. function buyCnt(human)
  568. local state = isOpen(human)
  569. if not state then return end
  570. if state ~= STATE_ACT_START then
  571. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  572. end
  573. ObjHuman.updateDaily(human)
  574. if getLeftBuyCnt(human) < 1 then
  575. return Broadcast.sendErr(human, Lang.JJC_LADDER_BUY_ERR_CNT)
  576. end
  577. local needPrice = getBuyPrice(human)
  578. if not ObjHuman.checkRMB(human, needPrice) then
  579. return Broadcast.sendErr(human, Lang.COMMON_NO_ZUANSHI)
  580. end
  581. if not isSignAct(human.db._id) then
  582. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_JOIN)
  583. end
  584. print(" decZuanshi ", -needPrice)
  585. -- 扣钻石,给次数
  586. ObjHuman.decZuanshi(human, -needPrice, "jjc_ladder")
  587. addBuyCnt(human)
  588. sendBuyCnt(human)
  589. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  590. return true
  591. end
  592. function sendBuyCnt(human)
  593. local msgRet = Msg.gc.GC_JJC_LADDER_BUYCNT
  594. msgRet.leftCnt = getLeftCnt(human)
  595. msgRet.leftBuyCnt = getLeftBuyCnt(human)
  596. msgRet.buyCost = getBuyPrice(human)
  597. Msg.send(msgRet, human.fd)
  598. end
  599. -- 刷新挑战对象
  600. function refresh(human)
  601. local state = isOpen(human)
  602. if not state then return end
  603. if state ~= STATE_ACT_START then
  604. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  605. end
  606. if not isSignAct(human.db._id) then
  607. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_JOIN)
  608. end
  609. -- 判断刷新间隔
  610. local leftTime = getRefreshLeftTime(human)
  611. if leftTime > 0 then
  612. return Broadcast.sendErr(human, Util.format(Lang.JJC_LADDER_REFRESH_TOO_QUICK, leftTime))
  613. end
  614. human.jjcLadderRefreshTime = os.time()
  615. query(human)
  616. end
  617. -- 查询膜拜列表
  618. function mobaiQuery(human)
  619. if not isOpen(human) then
  620. return
  621. end
  622. local msgInner = InnerMsg.lw.LW_JJC_LADDER_MOBAI_QUERY
  623. msgInner.uuid = human.db._id
  624. InnerMsg.sendMsg(0, msgInner)
  625. end
  626. -- 膜拜
  627. function mobai(human, rank, isOk)
  628. if not isOpen(human) then
  629. return
  630. end
  631. if rank < 1 or rank > MOBAI_PLAYER_CNT then
  632. return
  633. end
  634. if isMobai(human, rank) then
  635. return Broadcast.sendErr(human, Lang.JJC_LADDER_MOBAI_ERR_HAD)
  636. end
  637. if isOk then
  638. setMobai(human, rank)
  639. for _, item in ipairs(JjcLadderDefine.mobaiItems) do
  640. local itemID = item[1]
  641. local itemCnt = item[2]
  642. BagLogic.addItem(human, itemID, itemCnt, "jjc_ladder_mobai")
  643. end
  644. local itemID = JjcLadderDefine.mobaiItems[1][1]
  645. local itemCnt = JjcLadderDefine.mobaiItems[1][2]
  646. Broadcast.sendErr(human, Util.format(Lang.JJC_LADDER_MOBAI_SUCCEED, ItemDefine.getValue(itemID, "name"), itemCnt) )
  647. else
  648. local msgInner = InnerMsg.lw.LW_JJC_LADDER_MOBAI
  649. msgInner.uuid = human.db._id
  650. msgInner.rank = rank
  651. InnerMsg.sendMsg(0, msgInner)
  652. end
  653. end
  654. -- 查看当前排行/上一期排行榜
  655. function boardQuery(human)
  656. local state = isOpen(human)
  657. if not state then return end
  658. local msgInner = InnerMsg.lw.LW_JJC_LADDER_BOARD
  659. msgInner.uuid = human.db._id
  660. InnerMsg.sendMsg(0, msgInner)
  661. end
  662. -- 排名奖励
  663. function queryReward(human, rank)
  664. local state = isOpen(human)
  665. if not state then return end
  666. if rank then
  667. local msgRet = Msg.gc.GC_JJC_LADDER_REWARD_QUERY
  668. msgRet.list[0] = #JjcLadderExcel.reward
  669. for i = 1, msgRet.list[0] do
  670. local net = msgRet.list[i]
  671. local conf = JjcLadderExcel.reward[i]
  672. net.rankMin = conf.rankMin
  673. net.rankMax = conf.rankMax
  674. net.items[0] = #conf.reward
  675. for j = 1, net.items[0] do
  676. local itemID = conf.reward[j][1]
  677. local itemCnt = conf.reward[j][2]
  678. Grid.makeItem(net.items[j], itemID, itemCnt)
  679. end
  680. end
  681. local myConf = getRewardByRank(rank)
  682. msgRet.rank = nil
  683. msgRet.myRank = rank
  684. msgRet.myReward[0] = myConf and #myConf.reward or 0
  685. for i = 1, msgRet.myReward[0] do
  686. local itemID = myConf.reward[i][1]
  687. local itemCnt = myConf.reward[i][2]
  688. Grid.makeItem(msgRet.myReward[i], itemID, itemCnt)
  689. end
  690. --Msg.trace(msgRet)
  691. Msg.send(msgRet, human.fd)
  692. else
  693. local msgInner = InnerMsg.lw.LW_JJC_LADDER_RANK
  694. msgInner.uuid = human.db._id
  695. InnerMsg.sendMsg(0, msgInner)
  696. end
  697. end
  698. -- 日志查看
  699. function logQuery(human)
  700. print(" logQuery !!!!!! " )
  701. local state = isOpen(human)
  702. if not state then return end
  703. if state ~= STATE_ACT_START then
  704. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  705. end
  706. local msgInner = InnerMsg.lw.LW_JJC_LADDER_LOG
  707. msgInner.uuid = human.db._id
  708. InnerMsg.sendMsg(0, msgInner)
  709. end
  710. -- 查看录像
  711. function repeatVideo(human, videoUuid)
  712. local state = isOpen(human)
  713. if not state then return end
  714. if state ~= STATE_ACT_START then
  715. return Broadcast.sendErr(human, Lang.JJC_LADDER_ERR_TIME)
  716. end
  717. local msgInner = InnerMsg.lw.LW_JJC_LADDER_REPEAT_VIDEO
  718. msgInner.uuid = human.db._id
  719. msgInner.videoUuid = videoUuid
  720. InnerMsg.sendMsg(0, msgInner)
  721. end
  722. -------------------------------------- middle -------------------------------------------
  723. local function cmpRank(a, b)
  724. return a.roleBase.rank < b.roleBase.rank
  725. end
  726. -- 封装 英雄
  727. local function fontHeroList(net,data)
  728. local len = 0
  729. local monsterOutID = data.monsterOutID
  730. if monsterOutID then
  731. for k,v in ipairs(MonsterOutExcel[monsterOutID].member) do
  732. if v[1] > 0 then
  733. len = len + 1
  734. HeroGrid.makeHeroSimpleByMonsterID(net[len],v[1],{lv = v[2]})
  735. end
  736. end
  737. else
  738. for i = 1,CombatDefine.COMBAT_HERO_CNT do
  739. local obj = data.objList[i]
  740. if obj then
  741. len = len + 1
  742. if HeroExcel.hero[obj.id] then
  743. HeroGrid.makeHeroSimpleByID(net[len],obj.id, obj.bagIndex,{lv = obj.lv,star = obj.star})
  744. else
  745. HeroGrid.makeHeroSimpleByMonsterID(net[len],obj.id,{lv = obj.lv,star = obj.star})
  746. end
  747. end
  748. end
  749. end
  750. net[0] = len
  751. end
  752. -- 返回主界面信息
  753. function WL_JJC_LADDER_QUERY(uuid, targetList, mobaiCnt, logRed, myRank)
  754. local human = ObjHuman.onlineUuid[uuid]
  755. if not human then return end
  756. ObjHuman.updateDaily(human)
  757. local state, leftTime = getState()
  758. local msgRet = Msg.gc.GC_JJC_LADDER_QUERY
  759. local dataNet = msgRet.data
  760. dataNet.state = state
  761. print(" state getState() dataNet.state ", state , dataNet.state)
  762. dataNet.leftTime = leftTime
  763. dataNet.mobaiRed = isMobaiRed(human, mobaiCnt) and 1 or 0
  764. dataNet.logRed = logRed
  765. local startTime,endTime = getActTime()
  766. local cleanTime = Util.getDayStartTime(endTime + 60 * 60 * 24)
  767. if state == STATE_ACT_START then
  768. dataNet.list[0] = #targetList
  769. if dataNet.list[0] > 1 then
  770. table.sort(targetList, cmpRank)
  771. end
  772. for i = 1, dataNet.list[0] do
  773. local rankNet = dataNet.list[i]
  774. local rankData = targetList[i].roleBase
  775. rankNet.rank = rankData.rank
  776. rankNet.uuid = rankData.uuid
  777. rankNet.name = rankData.name
  778. rankNet.svrName = rankData.svrName
  779. rankNet.body = rankData.body or 0
  780. rankNet.head = rankData.head
  781. rankNet.headFrame = rankData.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  782. rankNet.zhandouli = rankData.zhandouli
  783. rankNet.unionName = rankData.unionName
  784. rankNet.svrIndex = rankData.svrIndex or 0
  785. fontHeroList(rankNet.heroList, targetList[i])
  786. end
  787. else
  788. dataNet.list[0] = 0
  789. if (state == STATE_ACT_READY and os.time() >= startTime and os.time() < cleanTime) then
  790. dataNet.state = 3
  791. if #targetList > 0 then
  792. dataNet.list[0] = #targetList
  793. if dataNet.list[0] > 1 then
  794. table.sort(targetList, cmpRank)
  795. end
  796. for i = 1, dataNet.list[0] do
  797. local rankNet = dataNet.list[i]
  798. local rankData = targetList[i].roleBase
  799. rankNet.rank = rankData.rank
  800. rankNet.uuid = rankData.uuid
  801. rankNet.name = rankData.name
  802. rankNet.svrName = rankData.svrName
  803. rankNet.body = rankData.body or 0
  804. rankNet.head = rankData.head
  805. rankNet.headFrame = rankData.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  806. rankNet.zhandouli = rankData.zhandouli
  807. rankNet.unionName = rankData.unionName
  808. rankNet.svrIndex = rankData.svrIndex or 0
  809. fontHeroList(rankNet.heroList, targetList[i])
  810. end
  811. end
  812. end
  813. end
  814. dataNet.myRank = myRank
  815. dataNet.leftCnt = getLeftCnt(human)
  816. dataNet.leftBuyCnt = getLeftBuyCnt(human)
  817. dataNet.buyCost = getBuyPrice(human)
  818. --Msg.trace(msgRet)
  819. Msg.send(msgRet, human.fd)
  820. human.jjcLadderTargetList = targetList
  821. JJCLADDER_MOBAICNT = mobaiCnt
  822. end
  823. -- 行为检测
  824. function WL_JJC_LADDER_RANK(uuid, rank)
  825. local human = ObjHuman.onlineUuid[uuid]
  826. if not human then return end
  827. queryReward(human, rank)
  828. end
  829. -- 膜拜查询
  830. function WL_JJC_LADDER_MOBAI_QUERY(uuid, list)
  831. local human = ObjHuman.onlineUuid[uuid]
  832. if not human then return end
  833. local msgRet = Msg.gc.GC_JJC_LADDER_MOBAI_QUERY
  834. msgRet.list[0] = list and #list or 0
  835. for i = 1, msgRet.list[0] do
  836. local net = msgRet.list[i]
  837. local rankData = list[i]
  838. net.rank = i
  839. net.uuid = rankData.uuid
  840. net.name = rankData.name
  841. net.svrName = rankData.svrName
  842. net.head = rankData.head
  843. net.headFrame = rankData.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  844. net.body = rankData.body or 0
  845. net.cnt = rankData.beMobaiCnt or 0
  846. net.isMobai = isMobai(human, i) and 1 or 0
  847. net.svrIndex = rankData.svrIndex or 0
  848. end
  849. --Msg.trace(msgRet)
  850. Msg.send(msgRet, human.fd)
  851. end
  852. -- 膜拜点赞
  853. function WL_JJC_LADDER_MOBAI(uuid, rank)
  854. local human = ObjHuman.onlineUuid[uuid]
  855. if not human then return end
  856. mobai(human, rank, true)
  857. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  858. end
  859. -- 封装排行榜结构体
  860. local function fontBoardNet(net, data, db)
  861. if data.rank and data.uuid then
  862. net.rank = data.rank
  863. net.uuid = data.uuid
  864. net.head = data.head
  865. net.headFrame = data.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  866. net.name = data.name
  867. net.svrName = data.svrName
  868. net.unionName = data.unionName or ""
  869. net.zhandouli = data.zhandouli
  870. else
  871. local union = UnionDBLogic.getUnion(db.unionUuid)
  872. net.rank = 0
  873. net.uuid = db._id
  874. net.head = db.head
  875. net.headFrame = db.headFrame or RoleDefine.DEFAULT_HEAD_FRAME
  876. net.name = db.name
  877. net.svrName = Config.SVR_NAME
  878. net.unionName = union and union.name or ""
  879. net.zhandouli = db.zhandouli
  880. end
  881. end
  882. -- 排行榜查询
  883. function WL_JJC_LADDER_BOARD(uuid, list, myData)
  884. local human = ObjHuman.onlineUuid[uuid]
  885. if not human then return end
  886. local msgRet = Msg.gc.GC_JJC_LADDER_BOARD
  887. msgRet.list[0] = list and #list or 0
  888. for i = 1, msgRet.list[0] do
  889. local rankData = list[i]
  890. RoleLogic.makeRoleBase(rankData, msgRet.list[i].rolebase)
  891. msgRet.list[i].rolebase.serverName = rankData.serverName and rankData.serverName or msgRet.list[i].rolebase.serverName -- and msgRet.list[i].rolebase.svrName or rankData.serverName
  892. msgRet.list[i].unionName = rankData.unionName or ""
  893. end
  894. if myData.uuid then
  895. RoleLogic.makeRoleBase(myData, msgRet.myData.rolebase)
  896. msgRet.myData.unionName = myData.unionName or ""
  897. else
  898. RoleLogic.makeRoleBase(human.db, msgRet.myData.rolebase)
  899. msgRet.myData.unionName = getUnionName(human.db.unionUuid)
  900. end
  901. msgRet.myRank = myData.rank or 0
  902. --Msg.trace(msgRet)
  903. Msg.send(msgRet, human.fd)
  904. end
  905. -- 战斗请求返回
  906. function WL_JJC_LADDER_COMBAT_ASK(uuid, rank, targetUuid, targetRank, playerData)
  907. local human = ObjHuman.onlineUuid[uuid]
  908. if not human then return end
  909. -- 开打
  910. local cbParam = {}
  911. cbParam.uuid = uuid
  912. cbParam.rank = rank
  913. cbParam.targetUuid = targetUuid
  914. cbParam.targetRank = targetRank
  915. cbParam.playerData = playerData
  916. local param = {}
  917. param.defender = playerData.objList
  918. param.defHelp = playerData.helpList
  919. param.defRBase = playerData.rolebase
  920. param.defFormation = playerData.formation
  921. param.defJiban = playerData.jiban
  922. print(" WL_JJC_LADDER_COMBAT_ASK !!!!!! ", cbParam.uuid)
  923. CombatLogic.combatBegin(human, 1001, param, CombatDefine.COMBAT_TYPE15, cbParam)
  924. end
  925. -- 战斗结果播放
  926. function WL_JJC_LADDER_COMBAT_RESULT(uuid, rank, targetUuid, targetRank)
  927. local human = ObjHuman.onlineUuid[uuid]
  928. if not human then return end
  929. local cacheCombatInfo = UUID_2_COMBATINFO[uuid]
  930. UUID_2_COMBATINFO[uuid] = nil
  931. if cacheCombatInfo then
  932. -- CombatLogic.addCombatCache(human.db._id, cacheCombatInfo, nil, true)
  933. -- CombatLogic.sendCombatData(human, cacheCombatInfo)
  934. end
  935. end
  936. function fontJJCLog(net, log)
  937. net.time = log.time
  938. RoleLogic.makeRoleBase(log.attacker, net.attacker )
  939. RoleLogic.makeRoleBase(log.defender, net.defender)
  940. net.isWin = log.isWin and 1 or 0
  941. net.videoUuid = log.videoUuid or ""
  942. net.atkRank = log.atkRank
  943. net.defRank = log.defRank
  944. net.atkSvr = log.attacker.serverName
  945. net.defSvr = log.defender.serverName
  946. end
  947. -- 战斗日志
  948. function WL_JJC_LADDER_LOG(uuid, logs, godLogs)
  949. local human = ObjHuman.onlineUuid[uuid]
  950. if not human then return end
  951. local msgRet = Msg.gc.GC_JJC_LADDER_LOG
  952. msgRet.list[0] = logs and #logs or 0
  953. for i = 1, msgRet.list[0] do
  954. local net = msgRet.list[i]
  955. fontJJCLog(net, logs[i])
  956. end
  957. msgRet.godList[0] = godLogs and #godLogs or 0
  958. msgRet.godList[0] = msgRet.godList[0] < 10 and msgRet.godList[0] or 10
  959. for i = 1, msgRet.godList[0] do
  960. local net = msgRet.godList[i]
  961. fontJJCLog(net, godLogs[i])
  962. end
  963. -- Msg.trace(msgRet)
  964. Msg.send(msgRet, human.fd)
  965. end
  966. -- 战斗回放
  967. function WL_JJC_LADDER_REPEAT_VIDEO(uuid, combatInfo)
  968. local human = ObjHuman.onlineUuid[uuid]
  969. if not human then return end
  970. if not next(combatInfo) then
  971. Broadcast.sendErr(human, Lang.COMBAT_ERR_NOT_VIDEO)
  972. else
  973. CombatLogic.repeatCombat(human, combatInfo)
  974. end
  975. end
  976. -- 比赛结果 发奖励
  977. local FieldJjcFinal = {lv = 1}
  978. function WL_JJC_LADDER_FINAL_RESULT(list)
  979. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_JJC_LADDER]
  980. local title = mailConfig.title
  981. local senderName = mailConfig.senderName
  982. local needLv = 0 -- RoleSystemLogic.getOpenLv(RoleSystemDefine.ROLE_SYS_ID_10012)
  983. for _, conf in ipairs(JjcLadderExcel.reward) do
  984. for rank = conf.rankMin, conf.rankMax do
  985. local uuid = list[rank]
  986. local db = uuid and RoleDBLogic.getDb(uuid, FieldJjcFinal)
  987. if db and (db.lv >= needLv) then
  988. -- 发邮件
  989. local content = Util.format(mailConfig.content, rank)
  990. MailManager.add(MailManager.SYSTEM, uuid, title, content, conf.reward, senderName)
  991. -- 回调
  992. LiLianLogic.onCallbackByUuid(uuid,LiLianLogic.LILIAN_OUTID3,1,rank,nil,true)
  993. end
  994. end
  995. end
  996. end
  997. --
  998. function WL_JJC_LADDER_MOBAI_CNT(mobaiCnt)
  999. JJCLADDER_MOBAICNT = mobaiCnt
  1000. --print("JJCLADDER_MOBAICNT",JJCLADDER_MOBAICNT)
  1001. end
  1002. -- 点赞数同步
  1003. local FieldJjcBemobai = {jjcLadder = 1}
  1004. function WL_JJC_LADDER_BEMOBAICNT(uuid, beMobaiCnt)
  1005. local db = RoleDBLogic.getDb(uuid, FieldJjcBemobai)
  1006. if db then
  1007. db.jjcLadder = db.jjcLadder or {}
  1008. db.jjcLadder.beMobaiCnt = beMobaiCnt
  1009. RoleDBLogic.saveRoleSset(db)
  1010. end
  1011. end
  1012. -- 刷新红点
  1013. function updateReds()
  1014. for _, human in pairs(ObjHuman.onlineUuid) do
  1015. if human.fd then
  1016. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1401)
  1017. end
  1018. end
  1019. end
  1020. local function getChengHaoIDByRank(rank)
  1021. if rank > 3 then
  1022. return 0
  1023. end
  1024. local config = JjcLadderExcel.godWarBoard[rank]
  1025. if config then
  1026. local chenghao = config.reward[#config.reward]
  1027. return chenghao
  1028. end
  1029. return 0
  1030. end
  1031. function WL_JJC_LADDER_CHENGHAO_DEL(msg)
  1032. for uuid, db in pairs(msg.list) do
  1033. if db.svrIndex == Config.SVR_INDEX then
  1034. local chenghao = getChengHaoIDByRank(db.rank)
  1035. if chenghao and chenghao > 0 then
  1036. RoleHeadLogic.unActive(uuid, RoleHeadLogic.HEAD_TYPE_4, chenghao)
  1037. end
  1038. end
  1039. end
  1040. end
  1041. ------------------------------------- 活动状态变化 ------------------------------------------
  1042. -- 活动开始
  1043. function onActStart()
  1044. if _G.is_middle then
  1045. return JjcLadderMiddle.onActStart()
  1046. end
  1047. Timer.addLater(1, updateReds)
  1048. end
  1049. -- 活动结束
  1050. function onActEnd()
  1051. if _G.is_middle then
  1052. return JjcLadderMiddle.onActEnd()
  1053. end
  1054. local commonDB = getCommonDB()
  1055. commonDB.uuid2sign = nil
  1056. commonDB.sendDataList = nil
  1057. saveCommonDB(commonDB)
  1058. Timer.addLater(1, updateReds)
  1059. end
  1060. -- 活动准备开始
  1061. function onActReady()
  1062. if _G.is_middle then
  1063. return JjcLadderMiddle.onActReady()
  1064. end
  1065. print(" onActReady !!! go ")
  1066. local openDay = CommonDB.getServerOpenDay()
  1067. if not openDay then
  1068. return
  1069. end
  1070. if openDay < 3 then
  1071. return
  1072. end
  1073. local commonDB = getCommonDB()
  1074. commonDB.sendDataList = {}
  1075. commonDB.uuid2sign = {}
  1076. for i = SENDDATA_PLAYER_CNT, 1, -1 do
  1077. local jjcData = JjcDB.RANK_2_JJCDATA[i]
  1078. if jjcData then
  1079. local listLen = #commonDB.sendDataList
  1080. commonDB.sendDataList[listLen + 1] = jjcData
  1081. end
  1082. end
  1083. saveCommonDB(commonDB)
  1084. end
  1085. -- l->w
  1086. function sendLWPlayerData(playerData)
  1087. local msgInner = InnerMsg.lw.LW_JJC_LADDER_SENDDATA
  1088. msgInner.player = playerData
  1089. InnerMsg.sendMsg(0, msgInner)
  1090. end
  1091. -- 同步玩家数据到跨服 l->w
  1092. function sendData2Middle()
  1093. local commonDB = getCommonDB()
  1094. if not commonDB.sendDataList then
  1095. return
  1096. end
  1097. local nowTime = os.time()
  1098. for i = 1, SENDDATA_PER_TIME do
  1099. local listLen = #commonDB.sendDataList
  1100. local jjcData = commonDB.sendDataList[listLen]
  1101. if not jjcData then break end
  1102. commonDB.sendDataList[listLen] = nil
  1103. local playerData = createPlayerData(jjcData)
  1104. if playerData then
  1105. sendLWPlayerData(playerData)
  1106. commonDB.uuid2sign[playerData._id] = nowTime
  1107. end
  1108. end
  1109. -- 全部发完,清空
  1110. if #commonDB.sendDataList < 1 then
  1111. commonDB.sendDataList = nil
  1112. end
  1113. saveCommonDB(commonDB)
  1114. end
  1115. function getCleanUpTime()
  1116. local _,endTime = getActTime()
  1117. return Util.getDayStartTime(endTime + 60 * 60 * 24)
  1118. end
  1119. -- 定时器
  1120. TEMP_TIMER_STAMPTIME = TEMP_TIMER_STAMPTIME or nil
  1121. function onTimer()
  1122. if not TEMP_TIMER_STAMPTIME then
  1123. _, TEMP_TIMER_STAMPTIME = getNewState()
  1124. end
  1125. local nowTime = os.time()
  1126. local commonDB = getCommonDB()
  1127. if (not commonDB.endTime) or
  1128. (commonDB.endTime <= nowTime) or
  1129. (commonDB.endTime ~= TEMP_TIMER_STAMPTIME) then
  1130. local oldState = commonDB.state
  1131. local state, endTime = getNewState()
  1132. print(" onTimer ", state, endTime)
  1133. commonDB.state = state
  1134. commonDB.endTime = endTime
  1135. TEMP_TIMER_STAMPTIME = endTime
  1136. saveCommonDB(commonDB)
  1137. --print("jjcLadder state",state,oldState,endTime)
  1138. if state == STATE_ACT_START then
  1139. onActStart()
  1140. elseif state == STATE_ACT_READY then
  1141. onActEnd()
  1142. elseif state == STATE_ACT_SENDDATA then
  1143. onActReady()
  1144. end
  1145. end
  1146. if _G.is_middle then
  1147. -- 跨服
  1148. if not commonDB.cleanTime then
  1149. commonDB.cleanTime = getCleanUpTime()
  1150. saveCommonDB(commonDB)
  1151. end
  1152. -- print(" endTime, cleanTime ",nowTime , commonDB.cleanTime- nowTime, nowTime > commonDB.cleanTime , Util.getWeekDay(commonDB.endTime), Util.getWeekDay(cleanTime) ,os.time(), os.time() >= commonDB.endTime )
  1153. if nowTime > commonDB.cleanTime then
  1154. print(" read clean up")
  1155. JjcLadderMiddle.resetDbActEnd()
  1156. end
  1157. else
  1158. -- 本服
  1159. sendData2Middle()
  1160. end
  1161. end
  1162. -- 返回活动列表的状态
  1163. function getActState()
  1164. if not MiddleConnect.IS_MIDDLE_CONNECT then
  1165. return JjcActLogic.STATE_NOOPEN, 0
  1166. end
  1167. local state, leftTime = getState()
  1168. if state == STATE_ACT_START then
  1169. -- 如果是 是当天开服 则没有走 0点逻辑 没有对手 没有天梯比赛
  1170. local openDay = CommonDB.getServerOpenDay()
  1171. if not openDay then
  1172. return JjcActLogic.STATE_NOOPEN, 0
  1173. end
  1174. if openDay and openDay <= 4 then
  1175. return JjcActLogic.STATE_NOOPEN, 0
  1176. end
  1177. return JjcActLogic.STATE_START, leftTime
  1178. end
  1179. return JjcActLogic.STATE_READY, leftTime
  1180. end
  1181. -- 描述
  1182. function getActDesc(desc)
  1183. if not MiddleConnect.IS_MIDDLE_CONNECT then
  1184. return Lang.MIDDLE_SVR_ERR_CONNECT
  1185. end
  1186. return desc
  1187. end